PageSourceSearch

https://ras.ac.uk/modules/admin_toolbar/js/jquery.hoverIntent.js?tjx2ok

js ras.ac.uk collected 2026-10-01 10:15:53 UTC 6,423 bytes, 156 lines download raw bytes

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

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.