If you use the Scripty libraries, then you doubtless know this function:
function cleanLibs()
{
fwPage.scriptyLibs.sort();
// Get rid of duplicates and out of range values
var i = 0;
while(i < fwPage.scriptyLibs.length)
if(fwPage.scriptyLibs[i+1] && fwPage.scriptyLibs[i] == fwPage.scriptyLibs[i+1])
fwPage.scriptyLibs.splice(i+1, 1);
else if(fwPage.scriptyLibs[i] > gLibraries.length-1 || fwPage.scriptyLibs[i] < 0)
fwPage.scriptyLibs.splice(i, 1);
else
i++;
}
It’s meant to reduce the array of scriptyLibs to unique values. Except it doesn’t work at the 0 index for some reason (bonus points to anyone who can explain this to me, I can’t see it).
Here’s an implementation that works. Note that it needs another helper method to work around the problem that Freeway’s version of JavaScript does not include Array#indexOf, and adding on to the Array Prototype has explosive consequences for other code in the same document, as previously noted.
var include = function(arr, obj) {
for(var i = -1, j = arr.length; ++i < j;)
if(arr[i] === obj) return true;
return false;
};
/* Clean up the list of libraries by sorting them in their correct order (according to
scripty specs) and removing dupes */
function cleanLibs(){
var out = [];
for (var i=0; i < fwPage.scriptyLibs.length; i++) {
if( ! (include(out, fwPage.scriptyLibs[i])) &&
(fwPage.scriptyLibs[i] < gLibraries.length) &&
(fwPage.scriptyLibs[i] >= 0) ){
out.push(fwPage.scriptyLibs[i]);
}
};
fwPage.scriptyLibs = out.sort();
}
Hope this helps.
Walter
actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options