coolerator.vision 0.2.9 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
    
        data/.gitignore
    CHANGED
    
    
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.2. | 
| 1 | 
            +
            0.2.10
         | 
    
        data/coolerator.vision.gemspec
    CHANGED
    
    
| @@ -1,12 +1,4 @@ | |
| 1 1 | 
             
            (function($) {
         | 
| 2 | 
            -
              $(function() {
         | 
| 3 | 
            -
                $.each(__ready__, function(i, fn) {
         | 
| 4 | 
            -
                  fn();
         | 
| 5 | 
            -
                });
         | 
| 6 | 
            -
             | 
| 7 | 
            -
                __after__ && __after__();
         | 
| 8 | 
            -
              });
         | 
| 9 | 
            -
             | 
| 10 2 | 
             
              $.extend(Coolerator, {
         | 
| 11 3 | 
             
                Registrar : {
         | 
| 12 4 | 
             
                  subscriptions : {},
         | 
| @@ -45,7 +37,7 @@ | |
| 45 37 | 
             
                      }
         | 
| 46 38 | 
             
                    }
         | 
| 47 39 |  | 
| 48 | 
            -
                    function subscription( | 
| 40 | 
            +
                    function subscription() {
         | 
| 49 41 | 
             
                      var result = {
         | 
| 50 42 | 
             
                        on : function on(event_type, selector) {
         | 
| 51 43 | 
             
                          var selector = selector || 'body';
         | 
| @@ -53,11 +45,11 @@ | |
| 53 45 | 
             
                          function use(handler) {
         | 
| 54 46 | 
             
                            if($.isArray(selector)) {
         | 
| 55 47 | 
             
                              $.each(selector, function each_selector() {
         | 
| 56 | 
            -
                                 | 
| 48 | 
            +
                                register(event_type, { selector: this, handler: handler });
         | 
| 57 49 | 
             
                              });
         | 
| 58 50 | 
             
                            }
         | 
| 59 51 | 
             
                            else {
         | 
| 60 | 
            -
                               | 
| 52 | 
            +
                              register(event_type, { selector: selector, handler: handler });
         | 
| 61 53 | 
             
                            }
         | 
| 62 54 |  | 
| 63 55 | 
             
                            return this;
         | 
| @@ -72,7 +64,7 @@ | |
| 72 64 | 
             
                          function on(event_type, selector) {
         | 
| 73 65 | 
             
                            var selector = selector || 'body';
         | 
| 74 66 |  | 
| 75 | 
            -
                             | 
| 67 | 
            +
                            register(event_type, { selector: selector, handler: handler });
         | 
| 76 68 | 
             
                            return this;
         | 
| 77 69 | 
             
                          }
         | 
| 78 70 |  | 
| @@ -85,12 +77,28 @@ | |
| 85 77 | 
             
                      return result;
         | 
| 86 78 | 
             
                    }
         | 
| 87 79 |  | 
| 88 | 
            -
                     | 
| 89 | 
            -
                       | 
| 90 | 
            -
             | 
| 80 | 
            +
                    if($.isReady) {
         | 
| 81 | 
            +
                      fn.call(listener, subscription());
         | 
| 82 | 
            +
                    }
         | 
| 83 | 
            +
                    else {
         | 
| 84 | 
            +
                      __ready__.push(function() {
         | 
| 85 | 
            +
                        fn.call(listener, subscription());
         | 
| 86 | 
            +
                      });
         | 
| 87 | 
            +
                    }
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                    $(function() {
         | 
| 90 | 
            +
                      while(__ready__.length) {
         | 
| 91 | 
            +
                        var ready_fn = __ready__.shift();
         | 
| 92 | 
            +
                        ready_fn();
         | 
| 93 | 
            +
                      }
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                      if(__after__ && __after__()) {
         | 
| 96 | 
            +
                        delete __after__;
         | 
| 97 | 
            +
                      }
         | 
| 91 98 | 
             
                    });
         | 
| 92 99 | 
             
                  },
         | 
| 93 100 |  | 
| 101 | 
            +
                  // NOTE: *for now*, this will only fire after the *initial* ready.
         | 
| 94 102 | 
             
                  after_ready : function after_ready(fn) {
         | 
| 95 103 | 
             
                    __after__ = fn;
         | 
| 96 104 | 
             
                  }
         | 
| @@ -5,5 +5,46 @@ Screw.Unit(function(c) { with(c) { | |
| 5 5 | 
             
                it("is added to the Coolerator namespace", function() {
         | 
| 6 6 | 
             
                  expect(typeof Coolerator.Registrar).to(equal, 'object');
         | 
| 7 7 | 
             
                });
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                describe(".subscribe", function() {
         | 
| 10 | 
            +
                  context("pre-document 'ready'", function() {
         | 
| 11 | 
            +
                    before(function() {
         | 
| 12 | 
            +
                      $.isReady = false;
         | 
| 13 | 
            +
                      mock($.fn, 'ready', function(fn) {
         | 
| 14 | 
            +
                        $.readyList = $.readyList || [];
         | 
| 15 | 
            +
                        $.readyList.push(fn);
         | 
| 16 | 
            +
                      });
         | 
| 17 | 
            +
                    });
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    after(function() {
         | 
| 20 | 
            +
                      $.isReady   = true;
         | 
| 21 | 
            +
                      $.readyList = null;
         | 
| 22 | 
            +
                      $.fn.ready  = $.fn.ready.original_function;
         | 
| 23 | 
            +
                    });
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    it("adds an array of callbacks to jQuery's readyList", function() {
         | 
| 26 | 
            +
                      Coolerator.Registrar.subscribe(this, function() {});
         | 
| 27 | 
            +
                      Coolerator.Registrar.subscribe(this, function() {});
         | 
| 28 | 
            +
                      Coolerator.Registrar.subscribe(this, function() {});
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                      expect($.readyList).to(have_length, 3);
         | 
| 31 | 
            +
                    });
         | 
| 32 | 
            +
                  });
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  context("post-document 'ready", function() {
         | 
| 35 | 
            +
                    var called;
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                    before(function() {
         | 
| 38 | 
            +
                      called = false;
         | 
| 39 | 
            +
                    });
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                    it("fires the callback immediately", function() {
         | 
| 42 | 
            +
                      Coolerator.Registrar.subscribe(this, function() {
         | 
| 43 | 
            +
                        called = true;
         | 
| 44 | 
            +
                      });
         | 
| 45 | 
            +
                      expect(called).to(be_true);
         | 
| 46 | 
            +
                    });
         | 
| 47 | 
            +
                  });
         | 
| 48 | 
            +
                });
         | 
| 8 49 | 
             
              });
         | 
| 9 50 | 
             
            }});
         |