Like SystemiConnectFri 15 Oct 2021, 04:50
Auto Save MessagesLGforumFri 26 Feb 2021, 13:31
New tutorial questionTheCrowMon 15 Feb 2021, 08:12
Support iOS Emojis (and other platforms)LGforumSun 14 Feb 2021, 01:25
LGforum (2806)
fmAddon Vote_lcapfmAddon Voting_barfmAddon Vote_rcap 
Mr.Easybb (1587)
fmAddon Vote_lcapfmAddon Voting_barfmAddon Vote_rcap 
Bloodbath (745)
fmAddon Vote_lcapfmAddon Voting_barfmAddon Vote_rcap 
Rukiafan (533)
fmAddon Vote_lcapfmAddon Voting_barfmAddon Vote_rcap 
Dom (513)
fmAddon Vote_lcapfmAddon Voting_barfmAddon Vote_rcap 
puppycheese (446)
fmAddon Vote_lcapfmAddon Voting_barfmAddon Vote_rcap 
pedro (330)
fmAddon Vote_lcapfmAddon Voting_barfmAddon Vote_rcap 
Neymar (301)
fmAddon Vote_lcapfmAddon Voting_barfmAddon Vote_rcap 
Hitsu (281)
fmAddon Vote_lcapfmAddon Voting_barfmAddon Vote_rcap 
Flora (275)
fmAddon Vote_lcapfmAddon Voting_barfmAddon Vote_rcap 


fmAddon

HitsuHitsu
Status : Finished on working fmAPI.

Posts : 281
Join date : 2013-09-09
Age : 25
Location : Indonesia
Thu 30 Apr 2015, 10:45
Forumotion might have useful things for developers. They have jQuery already in install, special things such as [ic]my_setcookie[/ic], and the [ic]_userdata[/ic] object. Why wouldn't we add a few of little addons in FM, so we can customize it freely as we like? [ic]fmAddon[/ic] would do things for you. This code might check for post IDs, storing [ic]_userdata[/ic] object in [ic]localStorage[/ic], and a few more addons.

For v.0.1, I'll only added post IDs. Maybe tomorrow I'll update the code. I'll just build a wrapper function for this, tomorrow I'll update it with selectors and JOL (JavaScript Object Literal). Don't bother the [ic]imported[/ic] part, it's just for checking imported file so it would prevent double script in the directory.

Code:
var imported = [];
if(imported[0] != 'fmAddon' || imported.length === 0) {
 imported.push('fmAddon');
}

/* start script */

/* script coming soon */
Ange TuteurAnge Tuteur
Status : No status yet...

Posts : 109
Join date : 2014-02-18
Age : 28
Location : North America
Thu 30 Apr 2015, 22:50
Something like a library, right ? I remember Ea released one fairly recently which simplifies a number of things. It was posted here : http://forum.forumactif.com/t375697-librairie-javascript-forumactif ( it's in French )

You can usually do a check for the forum version by the content wrapper of the forum. ( except for modified templates )
Code:
[panda=js]if ($('.bodyline')[0]) console.log('phpbb2');
else if ($('.pun')[0]) console.log('punbb');
else if (document.getElementById('wrap')) console.log('phpbb3');
else if (document.getElementById('ipbwrapper')) console.log('invision');
else console.warn('cannot identify forum version');
HitsuHitsu
Status : Finished on working fmAPI.

Posts : 281
Join date : 2013-09-09
Age : 25
Location : Indonesia
Thu 30 Apr 2015, 23:30
Thanks, Ange! I'll update the code in a short time.
Yes, right, it's like a library. But it's not.
BloodbathBloodbath
Status : No status yet...

Posts : 745
Join date : 2013-05-31
Age : 28
Fri 01 May 2015, 00:03
I dislike the way that Ea person wrote the code (it looks just like a jQuery knockoff), but alas, as long as it works.

Your code, Hitsu, also has quite a few logic and compare errors, well, I call them errors, but they won't actually be thrown as errors but your script will not be working as you expect it to.

I too was planning on writing something like this, but it ended up being stuck at the drafting phase. You will need some more JS knowledge, that's your best bet for it. And don't learn just jQuery, that's bad.
avatarNewbie JS
Status : No status yet...

Posts : 30
Join date : 2015-01-23
Age : 35
Location : England
Sun 03 May 2015, 06:14
You might want to do like so

Code:
[panda=js]var imported = []; //set an empty array to the variable imported
if(!imported[0]) { //check the imported variable value, if true then do the action below
 var impo = ['value']; //we might want to retrieve new variable
 Array.prototype.push.apply(imported, impo); //pushes the impo variable into the imported variable
}else{ //check the imported variable value, this is the action when it returns false
 console.warn('..........'); //warn to console
}

As this code

Code:
[panda=js]var imported = [];
if(imported === null) {
 imported.push('fmAddon');
}else if (imported === 'fmAddon') {
  alert("fmAddon is already imported");
}

Might not work like you expected. Change the code into the example I provided below.

And for the post IDs it doesn't really work correctly. A simple example below might give you an ideas.

Code:
[panda=js]function foo() {
 var promptu = prompt('What day is it?');
 if(promptu > 0) {
  alert('You entered ' + promptu);
 }else if(promptu.toLowerCase() === 'not sure') {
  alert('You entered not sure');
 }else{
  alert('Enter something will you!');
 }
}

For the fix

Code:
[panda=js]if (document.getElementsByClassName('bodyline')[0]) console.log('phpbb2');
else if (document.getElementsByClassName('pun')[0]) console.log('punbb');
else if (document.getElementById('wrap')) console.log('phpbb3');
else if (document.getElementById('ipbwrapper')) console.log('invision');
else console.warn('cannot identify forum version');

And also you can do appending script to the head like this

Code:
[panda=js]function logScript(url) {
 var head = document.getElementsByTagName('head')[0];
 var script = document.createElement('script');
 script.type('text/javascript');
 script.src = url;
 head.appendChild(script);
}

You can also fire a callback to the script like

Code:
[panda=js]function logScript(url, callback) {
 var head = document.getElementsByTagName('head')[0];
 var script = document.createElement('script');
 script.type('text/javascript');
 script.onreadystatechange = callback;
 script.onload = callback;
 script.src = url;
 head.appendChild(script);
}

Or for less functioning

Code:
[panda=js]var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type('text/javascript');
script.src = url;
head.appendChild(script);

Wink
BloodbathBloodbath
Status : No status yet...

Posts : 745
Join date : 2013-05-31
Age : 28
Sun 03 May 2015, 12:21
I don't quite understand the usage of arrays anyhow.

If you want to use arrays, don't bother playing around with prototypes and calls, it's already an array and has all methods the prototype defines anyway.

Code:
var imported = [];
Array.prototype.push.apply(imported, ['value']);

Is exactly the same as:

Code:
var imported = [];
imported.push('value');

You were right that the script wouldn't work as he wanted it to.

This snippet here never executes the if condition and always goes to the else block:

Code:
var imported = [];
if(imported === null) {
  console.log("Hi.");
} else {
  console.log("Hello.");
}

First off, since you're using the [ic]===[/ic] operator, it requires both arguments to be of the same type, which they aren't because [ic]imported[/ic] is an array while [ic]null[/ic] is an object.

If we wanted to check the array, we could write any of the variants below:

Code:
var imported = [];
imported.length === 0; // true
!imported.length; // true
imported[0] == null; // true
imported[0] == undefined; // true
imported[0] === null; // FALSE, null is not strictly equal to undefined
imported[0] === undefined; // true

Now, since this code checks for a certain variable, the easiest way is to use a boolean.

Code:
var imported = false;
(function(){
  // run your module script here
  imported = true;
})();
if(!imported) {
  console.log("The module code did not load yet.");
} else {
  console.log("The module code already executed.");
}

Now, I don't want you to think that I am condescending to you, but this shows that you do need some more understanding of the language itself. I do highly recommend you read books on the matter -- I learned most of what I know from David Flanagan's "JavaScript: The Definitive Guide".

If you want to know more about JavaScript, I am always reading this section of AvacWeb, you can always ask about anything and I will do my best to answer.
LGforumLGforum
Status : Working to restore AWC!

Posts : 2806
Join date : 2011-10-05
Age : 30
Location : UK
Mon 04 May 2015, 21:07
When ya'll see the way I've written the new Avacweb JavaScript for the new theme. You'll see how it's truly done Razz
I might share generic snippets of it that can be applied elsewhere.
HitsuHitsu
Status : Finished on working fmAPI.

Posts : 281
Join date : 2013-09-09
Age : 25
Location : Indonesia
Thu 28 May 2015, 06:36
I've improved the script a bit and delete the main script until I can (finally) finish managing my school things and get back my laptop again.
Sponsored content