Lets apply the Best practices to the Image Gallery .
/*** index.html ***/
/*** showPic.js ***/
/** * Created by Administrator on 9/9/2015. */function addLoadEvent(func) { var oldonload = window.onload; if( typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } }}function prepareGallery() { if( !document.getElementsByTagName ) return false; if( !document.getElementById ) return false; if( !document.getElementById("imagegallery") ) return false; var gallery = document.getElementById("imagegallery"); var links = gallery.getElementsByTagName("a"); for(var i=0; i
/*** layout.css ***/
body{ font-family: "Helvetica", "Arial", serif; color: #333; background-color: #ccc; margin: 1em 10%;}h1{ color: #333; /*background-color: #777;*/}a{ color: #c60; background-color: transparent; font-weight: bold; text-decoration: none;}ul{ padding: 0;}li{ float: left; padding: 1em; list-style: none;}img { display: block; clear: both;}
I think there is a function you can use in the furture, thats the addLoadEvent() :
function addLoadEvent(func) { var oldonload = window.onload; if( typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } }}
This is a good plan for the future expansion.
This effectively creates a queue of functions to be executed when the page loads.
To add functions to this queue, I just need to write :
addLoadEvent( firstFunction );
addLoadEvent( secondFunction );