vendor: 7,257 bytes, lines 1-179
1/*! 2 * hoverIntent v1.9.0 // 2017.09.01 // jQuery v1.7.0+ 3 * http://briancherne.github.io/jquery-hoverIntent/ 4 * 5 * You may use hoverIntent under the terms of the MIT license. Basically that 6 * means you are free to use hoverIntent as long as this header is left intact. 7 * Copyright 2007-2017 Brian Cherne 8 */ 9 10/* hoverIntent is similar to jQuery's built-in "hover" method except that 11 * instead of firing the handlerIn function immediately, hoverIntent checks 12 * to see if the user's mouse has slowed down (beneath the sensitivity 13 * threshold) before firing the event. The handlerOut function is only 14 * called after a matching handlerIn. 15 * 16 * // basic usage ... just like .hover() 17 * .hoverIntent( handlerIn, handlerOut ) 18 * .hoverIntent( handlerInOut ) 19 * 20 * // basic usage ... with event delegation! 21 * .hoverIntent( handlerIn, handlerOut, selector ) 22 * .hoverIntent( handlerInOut, selector ) 23 * 24 * // using a basic configuration object 25 * .hoverIntent( config ) 26 * 27 * @param handlerIn function OR configuration object 28 * @param handlerOut function OR selector for delegation OR undefined 29 * @param selector selector OR undefined 30 * @author Brian Cherne <brian(at)cherne(dot)net> 31 */ 32 33; 34(function (factory) { 35 'use strict'; 36 if (typeof define === 'function' && define.amd) { 37 define(['jquery'], factory); 38 } else if (jQuery && !jQuery.fn.hoverIntent) { 39 factory(jQuery); 40 } 41})(function ($) { 42 'use strict'; 43 44 // default configuration values 45 var _cfg = { 46 interval: 100, 47 sensitivity: 6, 48 timeout: 0 49 }; 50 51 // counter used to generate an ID for each instance 52 var INSTANCE_COUNT = 0; 53 54 // current X and Y position of mouse, updated during mousemove tracking (shared across instances) 55 var cX, cY; 56 57 // saves the current pointer position coordinates based on the given mousemove event 58 var track = function (ev) { 59 cX = ev.pageX; 60 cY = ev.pageY; 61 }; 62 63 // compares current and previous mouse positions 64 var compare = function (ev, $el, s, cfg) { 65 // compare mouse positions to see if pointer has slowed enough to trigger `over` function 66 if (Math.sqrt((s.pX - cX) * (s.pX - cX) + (s.pY - cY) * (s.pY - cY)) < cfg.sensitivity) { 67 $el.off(s.event, track); 68 delete s.timeoutId; 69 // set hoverIntent state as active for this element (permits `out` handler to trigger) 70 s.isActive = true; 71 // overwrite old mouseenter event coordinates with most recent pointer position 72 ev.pageX = cX; 73 ev.pageY = cY; 74 // clear coordinate data from state object 75 delete s.pX; 76 delete s.pY; 77 return cfg.over.apply($el[0], [ev]); 78 } else { 79 // set previous coordinates for next comparison 80 s.pX = cX; 81 s.pY = cY; 82 // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs) 83 s.timeoutId = setTimeout(function () { 84 compare(ev, $el, s, cfg); 85 }, cfg.interval); 86 } 87 }; 88 89 // triggers given `out` function at configured `timeout` after a mouseleave and clears state 90 var delay = function (ev, $el, s, out) { 91 delete $el.data('hoverIntent')[s.id]; 92 return out.apply($el[0], [ev]); 93 }; 94 95 $.fn.hoverIntent = function (handlerIn, handlerOut, selector) { 96 // instance ID, used as a key to store and retrieve state information on an element 97 var instanceId = INSTANCE_COUNT++; 98 99 // extend the default configuration and parse parameters 100 var cfg = $.extend({}, _cfg); 101 if ($.isPlainObject(handlerIn)) { 102 cfg = $.extend(cfg, handlerIn); 103 if (!$.isFunction(cfg.out)) { 104 cfg.out = cfg.over; 105 } 106 } else if ($.isFunction(handlerOut)) { 107 cfg = $.extend(cfg, {over: handlerIn, out: handlerOut, selector: selector}); 108 } else { 109 cfg = $.extend(cfg, {over: handlerIn, out: handlerIn, selector: handlerOut}); 110 } 111 112 // A private function for handling mouse 'hovering' 113 var handleHover = function (e) { 114 // cloned event to pass to handlers (copy required for event object to be passed in IE) 115 var ev = $.extend({}, e); 116 117 // the current target of the mouse event, wrapped in a jQuery object 118 var $el = $(this); 119 120 // read hoverIntent data from element (or initialize if not present) 121 var hoverIntentData = $el.data('hoverIntent'); 122 if (!hoverIntentData) { 123 $el.data('hoverIntent', (hoverIntentData = {})); 124 } 125 126 // read per-instance state from element (or initialize if not present) 127 var state = hoverIntentData[instanceId]; 128 if (!state) { 129 hoverIntentData[instanceId] = state = {id: instanceId}; 130 } 131 132 // state properties: 133 // id = instance ID, used to clean up data 134 // timeoutId = timeout ID, reused for tracking mouse position and delaying "out" handler 135 // isActive = plugin state, true after `over` is called just until `out` is called 136 // pX, pY = previously-measured pointer coordinates, updated at each polling interval 137 // event = string representing the namespaced event used for mouse tracking 138 139 // clear any existing timeout 140 if (state.timeoutId) { 141 state.timeoutId = clearTimeout(state.timeoutId); 142 } 143 144 // namespaced event used to register and unregister mousemove tracking 145 var mousemove = state.event = 'mousemove.hoverIntent.hoverIntent' + instanceId; 146 147 // handle the event, based on its type 148 if (e.type === 'mouseenter') { 149 // do nothing if already active 150 if (state.isActive) { 151 return; 152 } 153 // set "previous" X and Y position based on initial entry point 154 state.pX = ev.pageX; 155 state.pY = ev.pageY; 156 // update "current" X and Y position based on mousemove 157 $el.off(mousemove, track).on(mousemove, track); 158 // start polling interval (self-calling timeout) to compare mouse coordinates over time 159 state.timeoutId = setTimeout(function () { 160 compare(ev, $el, state, cfg); 161 }, cfg.interval); 162 } else { // "mouseleave" 163 // do nothing if not already active 164 if (!state.isActive) { 165 return; 166 } 167 // unbind expensive mousemove event 168 $el.off(mousemove, track); 169 // if hoverIntent state is true, then call the mouseOut function after the specified delay 170 state.timeoutId = setTimeout(function () { 171 delay(ev, $el, state, cfg.out); 172 }, cfg.timeout); 173 } 174 }; 175 176 // listen for mouseenter and mouseleave 177 return this.on({'mouseenter.hoverIntent': handleHover, 'mouseleave.hoverIntent': handleHover}, cfg.selector); 178 }; 179});
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.