Created
November 25, 2011 14:07
-
-
Save craigrodway/1393600 to your computer and use it in GitHub Desktop.
Revisions
-
Craig A Rodway created this gist
Nov 25, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ /** * In the <head> */ var jsq = (function(){ var q = []; // internal queue of functions that are added var fs = {}; // public exportable functions // Add a function to the queue fs.add = function(f){ q.push(f); }; // Run the queued functions fs.run = function(){ if (typeof(q) != "undefined") { for (var i=0, len=q.length; i<len; i++) { q[i](); } } }; return fs; })(); /** * In the middle of the page, anywhere: * * <script>jsq.add(function(){ * // Initialise some jQuery thing * $("div.example").doSomething(); * })</script> * * * At the foot of the page: * * <script src="js/jquery-1.7.1.min.js"></script> * <script type="text/javascript"> * $(document).ready(function(){ jsq.run(); }); * </script> * */