PageSourceSearch

https://www.opwglobal.com/assets/js/libs/jquery.hoverIntent.js

js opwglobal.com collected 2026-10-02 03:03:47 UTC 6,059 bytes, 137 lines download raw bytes

vendor: 6,059 bytes, lines 1-137
1/*!
2 * hoverIntent v1.8.1 // 2014.08.11 // jQuery v1.9.1+
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, 2014 Brian Cherne
8 */
9
10//  (function(factory) {
11//     'use strict';
12//     if (typeof define === 'function' && define.amd) {
13//         define(['jquery'], factory);
14//     } else if (jQuery && !jQuery.fn.hoverIntent) {
15//         factory(jQuery);
16//     }
17// })
18
19jq3(function($) {
20    'use strict';
21
22    // default configuration values
23    var _cfg = {
24        interval: 100,
25        sensitivity: 6,
26        timeout: 0
27    };
28
29    // counter used to generate an ID for each instance
30    var INSTANCE_COUNT = 0;
31
32    // current X and Y position of mouse, updated during mousemove tracking (shared across instances)
33    var cX, cY;
34
35    // saves the current pointer position coordinates based on the given mousemove event
36    var track = function(ev) {
37        cX = ev.pageX;
38        cY = ev.pageY;
39    };
40
41    // compares current and previous mouse positions
42    var compare = function(ev,$el,s,cfg) {
43        // compare mouse positions to see if pointer has slowed enough to trigger `over` function
44        if ( Math.sqrt( (s.pX-cX)*(s.pX-cX) + (s.pY-cY)*(s.pY-cY) ) < cfg.sensitivity ) {
45            $el.off(s.event,track);
46            delete s.timeoutId;
47            // set hoverIntent state as active for this element (permits `out` handler to trigger)
48            s.isActive = true;
49            // overwrite old mouseenter event coordinates with most recent pointer position
50            ev.pageX = cX; ev.pageY = cY;
51            // clear coordinate data from state object
52            delete s.pX; delete s.pY;
53            return cfg.over.apply($el[0],[ev]);
54        } else {
55            // set previous coordinates for next comparison
56            s.pX = cX; s.pY = cY;
57            // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
58            s.timeoutId = setTimeout( function(){compare(ev, $el, s, cfg);} , cfg.interval );
59        }
60    };
61
62    // triggers given `out` function at configured `timeout` after a mouseleave and clears state
63    var delay = function(ev,$el,s,out) {
64        delete $el.data('hoverIntent')[s.id];
65        return out.apply($el[0],[ev]);
66    };
67
68    $.fn.hoverIntent = function(handlerIn,handlerOut,selector) {
69        // instance ID, used as a key to store and retrieve state information on an element
70        var instanceId = INSTANCE_COUNT++;
71
72        // extend the default configuration and parse parameters
73        var cfg = $.extend({}, _cfg);
74        if ( $.isPlainObject(handlerIn) ) {
75            cfg = $.extend(cfg, handlerIn);
76            if ( !$.isFunction(cfg.out) ) {
77                cfg.out = cfg.over;
78            }
79        } else if ( $.isFunction(handlerOut) ) {
80            cfg = $.extend(cfg, { over: handlerIn, out: handlerOut, selector: selector } );
81        } else {
82            cfg = $.extend(cfg, { over: handlerIn, out: handlerIn, selector: handlerOut } );
83        }
84
85        // A private function for handling mouse 'hovering'
86        var handleHover = function(e) {
87            // cloned event to pass to handlers (copy required for event object to be passed in IE)
88            var ev = $.extend({},e);
89
90            // the current target of the mouse event, wrapped in a jQuery object
91            var $el = $(this);
92
93            // read hoverIntent data from element (or initialize if not present)
94            var hoverIntentData = $el.data('hoverIntent');
95            if (!hoverIntentData) { $el.data('hoverIntent', (hoverIntentData = {})); }
96
97            // read per-instance state from element (or initialize if not present)
98            var state = hoverIntentData[instanceId];
99            if (!state) { hoverIntentData[instanceId] = state = { id: instanceId }; }
100
101            // state properties:
102            // id = instance ID, used to clean up data
103            // timeoutId = timeout ID, reused for tracking mouse position and delaying "out" handler
104            // isActive = plugin state, true after `over` is called just until `out` is called
105            // pX, pY = previously-measured pointer coordinates, updated at each polling interval
106            // event = string representing the namespaced event used for mouse tracking
107
108            // clear any existing timeout
109            if (state.timeoutId) { state.timeoutId = clearTimeout(state.timeoutId); }
110
111            // namespaced event used to register and unregister mousemove tracking
112            var mousemove = state.event = 'mousemove.hoverIntent.hoverIntent'+instanceId;
113
114            // handle the event, based on its type
115            if (e.type === 'mouseenter') {
116                // do nothing if already active
117                if (state.isActive) { return; }
118                // set "previous" X and Y position based on initial entry point
119                state.pX = ev.pageX; state.pY = ev.pageY;
120                // update "current" X and Y position based on mousemove
121                $el.off(mousemove,track).on(mousemove,track);
122                // start polling interval (self-calling timeout) to compare mouse coordinates over time
123                state.timeoutId = setTimeout( function(){compare(ev,$el,state,cfg);} , cfg.interval );
124            } else { // "mouseleave"
125                // do nothing if not already active
126                if (!state.isActive) { return; }
127                // unbind expensive mousemove event
128                $el.off(mousemove,track);
129                // if hoverIntent state is true, then call the mouseOut function after the specified delay
130                state.timeoutId = setTimeout( function(){delay(ev,$el,state,cfg.out);} , cfg.timeout );
131            }
132        };
133
134        // listen for mouseenter and mouseleave
135        return this.on({'mouseenter.hoverIntent':handleHover,'mouseleave.hoverIntent':handleHover}, cfg.selector);
136    };
137});

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.