/*
 * ready
 * Watch for when an element becomes available in the DOM
 * @param {String} selector
 * @param {Function} fn
 */

(function(win){
    'use strict';

    var listeners = [], 
    doc = win.document, 
    MutationObserver = win.MutationObserver || win.WebKitMutationObserver,
    observer;

    function ready(selector, fn){
        // Store the selector and callback to be monitored
        listeners.push({
            selector: selector,
            fn: fn
        });
        if(!observer){
            // Watch for changes in the document
            observer = new MutationObserver(check);
            observer.observe(doc.documentElement, {
                childList: true,
                subtree: true
            });
        }
        // Check if the element is currently in the DOM
        check();
    }

    function check(){
        // Check the DOM for elements matching a stored selector
        for(var i = 0, len = listeners.length, listener, elements; i < len; i++){
            listener = listeners[i];
            // Query for elements matching the specified selector
            elements = doc.querySelectorAll(listener.selector);
            for(var j = 0, jLen = elements.length, element; j < jLen; j++){
                element = elements[j];
                // Make sure the callback isn't invoked with the 
                // same element more than once
                if(!element.ready){
                    element.ready = true;
                    // Invoke the callback with the element
                    listener.fn.call(element, element);
                }
            }
        }
    }

    // Expose `ready`
    win.ready = ready;
            
})(this);
@@ -597,16 +597,25 @@
 er(check
+Listeners
 );%0A     
@@ -820,16 +820,28 @@
   check(
+selector, fn
 );%0A    %7D
@@ -860,16 +860,25 @@
 on check
+Listeners
 ()%7B%0A    
@@ -997,18 +997,8 @@
 ener
-, elements
 ; i 
@@ -1051,24 +1051,122 @@
 i%5D;%0A        
+    check(listener.selector, listener.fn);%0A        %7D%0A    %7D%0A%0A    function check(selector, fn)%7B%0A    
     // Query
@@ -1211,35 +1211,35 @@
 elector%0A        
-   
+var
  elements = doc.
@@ -1259,57 +1259,27 @@
 All(
-listener.selector);%0A            for(var j
+selector), i
  = 0, 
-jL
+l
 en =
@@ -1308,29 +1308,38 @@
 ent;
- j %3C jL
+%0A        for(; i %3C l
 en; 
-j
+i
 ++)%7B%0A
-    
     
@@ -1369,16 +1369,12 @@
 nts%5B
-j
+i
 %5D;%0A
-    
     
@@ -1443,20 +1443,16 @@
         
-    
 // same 
@@ -1482,28 +1482,24 @@
             
-    
 if(!element.
@@ -1518,28 +1518,24 @@
             
-    
 element.read
@@ -1544,20 +1544,16 @@
 = true;%0A
-    
         
@@ -1620,21 +1620,8 @@
     
-    listener.
 fn.c
@@ -1647,26 +1647,8 @@
 t);%0A
-                %7D%0A
     

Remove unneccessary query checks