Skip to content

Instantly share code, notes, and snippets.

@craigrodway
Created November 25, 2011 14:07
Show Gist options
  • Select an option

  • Save craigrodway/1393600 to your computer and use it in GitHub Desktop.

Select an option

Save craigrodway/1393600 to your computer and use it in GitHub Desktop.

Revisions

  1. Craig A Rodway created this gist Nov 25, 2011.
    44 changes: 44 additions & 0 deletions jsq.js
    Original 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>
    *
    */