If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Function Library

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.

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.

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.

Easter computus

Code:

function easter(year) {
// function to calculate the date of Easter Sunday
// as given by the Gregorian calendar reform of 1582
// Note: this function returns a Date object
// with its time set to NOON local time
// function by Juuitchan
if (typeof(year)!='number') return false;
if (year%1!=0) return false;
if (year<1582) return false;
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
var moontable=new Array();
var wheel=seed; var finger=0; var p29=-1; var p28=-1;
for (finger=0; finger<19; finger++) {
moontable[finger]=wheel;
if (wheel==29) p29=finger; // gets special treatment
if (wheel==28) p28=finger; // might get special treatment
wheel-=11; if (wheel<0) wheel+=30; }
if (p29>=0 && p28>=0) moontable[p28]=27;
if (p29>=0) moontable[p29]=28;
var pfmoffset=moontable[gsnum];
// Paschal Full Moon is this many days past March 21
var work=new Date(year,3-1,21+pfmoffset,12,0,0);
// work is set to date of Paschal Full Moon
// (time is set to noon to avoid a problem
// with JS Date objects near midnight)
work.setDate(work.getDate()+(7-work.getDay()));
// this sets the date to the following Sunday
return work;
// More comments:
// Ash Wednesday = Easter Sunday - 46 days
// (Sundays are not counted in the 40 days of Lent)
// Palm Sunday = Easter Sunday - 7 days
// Good Friday = Easter Sunday - 2 days
// Pentecost = Easter Sunday + 49 days
}

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.