Similar to my Prototype Function Collection thread: Here are 2 prototype-functions I created.
This thread is the place to share your cross-browser and reusable functions. If your function is a prototype-function, post it in the above link instead. If you don't even know what a prototype-function is, chances are your function isn't one and it should be posted here.

In JavaScript, if you try to compare two Arrays it will always return false, even this simple comparison: ([3]==[3]). So to see if two arrays are actually identical you can use this function, I could have made it accept more than two arrays but thought it was nice and simple as it was. It can take multi-dimensional arrays.

note: In the case of multiple external JS files that all will need to append to the onload event and you don't want to define the addFunctionToOnload function twice, use this code in each JS extneral file to define the function:

It checks to see if it is already defined, then if it is undefined, then defines it. Then simply proceed in your JS file with the addFunctionToOnload defined as usual. Do make sure to put the defining code at the very top of your JS file so no futher code in it will require it's usage prior to it's defination.

12-08-2005, 12:40 PM

MstrBob

I don't normally revive threads like this, but this time I figured, why not? I've found myself using this a couple of times already - it's a function to get the contents of an XML element and convert it to text. Like innerHTML, only using the DOM and without the entities. Found myself needing this for AJAX type applications, when it's neccessary to send back the contents of an element (all of them) to the server without always knowing just what would be there.

It's been a while since I've done much Javascript (well, until lately at least) but it's been working out fine for me.

02-13-2006, 10:23 AM

Scriptage

Meh, spent some time on this so thought I'd share

Someone wanted to change the order of dynamically assigned event handlers and as seen as there is no guarantee of which fires first I set about writing a program that would handle it, however I got no response so I thought I'd see if anybody else has a use for it.

It's still a little off of a finished product but I can see it has its' uses. There is no support for arguments in the functions that are called as of yet and no support for capturing and bubbling but what the hell:

Check the bottom of the program for usage... I might add support for event capturing and bubbling if anybody is interested.

if(k == index){ // Check to see if we are at the index of the listener

isIndex = true; // Set the flag telling the loop that we have passed the index
finalArray[k] = func; // Add the function to the array at the index point
finalArray[k+1] = tempArray[k]; // Shift the next listener up

var ccpass=Math.floor(year/100)-15;
// Century changes since the calendar reform

var gsnum=year%19;
// Used in a table lookup

// Calculate the seed for the table
var seed=22; // it was initialized to this in 1582
seed+=(ccpass-Math.ceil(ccpass/4)); // Solar Equation
seed-=(8*Math.floor(ccpass/25)+Math.floor((ccpass%25)/3));
// the line above is the Lunar Equation
seed%=30; // seed is restricted to range 0-29

Ever want to add a StyleSheet to your document using the full CSS without having to use a load of addRules and insertRules?
Although this is non-standard it is a pretty niffy approach that I'm sure can be expanded upon.

The addNewStyleSheetByFullCSS function accepts one argument, the full CSS to be used within the styleSheet, and the new StyleSheet is appended to the DOM Tree automatically.