vendor: 5,763 bytes, lines 1-187
1/*! 2 * jQuery iframe click tracking plugin 3 * 4 * @author Vincent Paré 5 * @copyright © 2013-<%= grunt.template.today("yyyy") %> Vincent Paré 6 * @license http://opensource.org/licenses/Apache-2.0 7 * @version <%= pkg.version %> 8 */ 9(function($) { 10 // Tracking handler manager 11 $.fn.iframeTracker = function(handler) { 12 // Building handler object from handler function 13 if (typeof handler == "function") { 14 handler = { 15 blurCallback: handler 16 }; 17 } 18 19 var target = this.get(); 20 if (handler === null || handler === false) { 21 $.iframeTracker.untrack(target); 22 } else if (typeof handler == "object") { 23 $.iframeTracker.track(target, handler); 24 } else { 25 throw new Error("Wrong handler type (must be an object, or null|false to untrack)"); 26 } 27 return this; 28 }; 29 30 // Iframe tracker common object 31 $.iframeTracker = { 32 // State 33 focusRetriever: null, // Element used for restoring focus on window (element) 34 focusRetrieved: false, // Says if the focus was retrieved on the current page (bool) 35 handlersList: [], // Store a list of every trakers (created by calling $(selector).iframeTracker...) 36 isIE8AndOlder: false, // true for Internet Explorer 8 and older 37 38 // Init (called once on document ready) 39 init: function() { 40 // Determine browser version (IE8-) ($.browser.msie is deprecated since jQuery 1.9) 41 try { 42 if ($.browser.msie === true && $.browser.version < 9) { 43 this.isIE8AndOlder = true; 44 } 45 } catch (ex) { 46 try { 47 var matches = navigator.userAgent.match(/(msie) ([\w.]+)/i); 48 if (matches[2] < 9) { 49 this.isIE8AndOlder = true; 50 } 51 } catch (ex2) {} 52 } 53 54 // Listening window blur 55 $(window).focus(); 56 $(window).blur(function(e) { 57 $.iframeTracker.windowLoseFocus(e); 58 }); 59 60 // Focus retriever (get the focus back to the page, on mouse move) 61 $("body").append('<div style="position:fixed; top:0; left:0; overflow:hidden;"><input style="position:absolute; left:-300px;" type="text" value="" id="focus_retriever" readonly="true" /></div>'); 62 this.focusRetriever = $("#focus_retriever"); 63 this.focusRetrieved = false; 64 65 // Special processing to make it work with my old friend IE8 (and older) ;) 66 if (this.isIE8AndOlder) { 67 // Blur doesn't works correctly on IE8-, so we need to trigger it manually 68 this.focusRetriever.blur(function(e) { 69 e.stopPropagation(); 70 e.preventDefault(); 71 $.iframeTracker.windowLoseFocus(e); 72 }); 73 74 // Keep focus on window (fix bug IE8-, focusable elements) 75 $("body").click(function(e) { 76 $(window).focus(); 77 }); 78 $("form").click(function(e) { 79 e.stopPropagation(); 80 }); 81 82 // Same thing for "post-DOMready" created forms (issue #6) 83 try { 84 $("body").on("click", "form", function(e) { 85 e.stopPropagation(); 86 }); 87 } catch (ex) { 88 console.log("[iframeTracker] Please update jQuery to 1.7 or newer. (exception: " + ex.message + ")"); 89 } 90 } 91 }, 92 93 // Add tracker to target using handler (bind boundary listener + register handler) 94 // target: Array of target elements (native DOM elements) 95 // handler: User handler object 96 track: function(target, handler) { 97 // Adding target elements references into handler 98 handler.target = target; 99 100 // Storing the new handler into handler list 101 $.iframeTracker.handlersList.push(handler); 102 103 // Binding boundary listener 104 $(target) 105 .bind("mouseover", { handler: handler }, $.iframeTracker.mouseoverListener) 106 .bind("mouseout", { handler: handler }, $.iframeTracker.mouseoutListener); 107 }, 108 109 // Remove tracking on target elements 110 // target: Array of target elements (native DOM elements) 111 untrack: function(target) { 112 if (typeof Array.prototype.filter != "function") { 113 console.log("Your browser doesn't support Array filter, untrack disabled"); 114 return; 115 } 116 117 // Unbinding boundary listener 118 $(target).each(function(index) { 119 $(this) 120 .unbind("mouseover", $.iframeTracker.mouseoverListener) 121 .unbind("mouseout", $.iframeTracker.mouseoutListener); 122 }); 123 124 // Handler garbage collector 125 var nullFilter = function(value) { 126 return value === null ? false : true; 127 }; 128 for (var i in this.handlersList) { 129 // Prune target 130 for (var j in this.handlersList[i].target) { 131 if ($.inArray(this.handlersList[i].target[j], target) !== -1) { 132 this.handlersList[i].target[j] = null; 133 } 134 } 135 this.handlersList[i].target = this.handlersList[i].target.filter(nullFilter); 136 137 // Delete handler if unused 138 if (this.handlersList[i].target.length === 0) { 139 this.handlersList[i] = null; 140 } 141 } 142 this.handlersList = this.handlersList.filter(nullFilter); 143 }, 144 145 // Target mouseover event listener 146 mouseoverListener: function(e) { 147 e.data.handler.over = true; 148 $.iframeTracker.retrieveFocus(); 149 try { 150 e.data.handler.overCallback(this, e); 151 } catch (ex) {} 152 }, 153 154 // Target mouseout event listener 155 mouseoutListener: function(e) { 156 e.data.handler.over = false; 157 $.iframeTracker.retrieveFocus(); 158 try { 159 e.data.handler.outCallback(this, e); 160 } catch (ex) {} 161 }, 162 163 // Give back focus from an iframe to parent page 164 retrieveFocus: function() { 165 if (document.activeElement && document.activeElement.tagName === "IFRAME") { 166 $.iframeTracker.focusRetriever.focus(); 167 $.iframeTracker.focusRetrieved = true; 168 } 169 }, 170 171 // Calls blurCallback for every handler with over=true on window blur 172 windowLoseFocus: function(e) { 173 for (var i in this.handlersList) { 174 if (this.handlersList[i].over === true) { 175 try { 176 this.handlersList[i].blurCallback(e); 177 } catch (ex) {} 178 } 179 } 180 } 181 }; 182 183 // Init the iframeTracker on document ready 184 $(document).ready(function() { 185 $.iframeTracker.init(); 186 }); 187})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.