diff --git a/javascript/loader.js b/javascript/loader.js new file mode 100644 index 000000000..a89cb4312 --- /dev/null +++ b/javascript/loader.js @@ -0,0 +1,86 @@ +/* + * common/js/loader.js + * Common file, to be included before any of the other common/js scripts + */ + +/* + * Gracefully deal with a whole lot of modules wanting to set the onload() event handler + */ +if(typeof _LOADERS == 'undefined') _LOADERS = Array(); + +function callAllLoaders() { + var i, loaderFunc; + for(i=0;i<_LOADERS.length;i++) { + loaderFunc = _LOADERS[i]; + if(loaderFunc != callAllLoaders) loaderFunc(); + } +} + +function appendLoader(loaderFunc) { + if(window.onload && window.onload != callAllLoaders) + _LOADERS[_LOADERS.length] = window.onload; + + window.onload = callAllLoaders; + + _LOADERS[_LOADERS.length] = loaderFunc; +} + + +/* + * Call the given function on any element of the given tag and class + */ +function setUpHandlers(tagName,className, handlerFunction) { + var allElements = document.getElementsByTagName(tagName); + for(var i = 0;i