{"version":3,"file":"jquery.hoverintent.js","sources":["jquery.hoverintent.js"],"sourcesContent":["\r\n/*!\r\n * hoverIntent v1.10.0 // 2019.02.25 // jQuery v1.7.0+\r\n * http://briancherne.github.io/jquery-hoverIntent/\r\n *\r\n * You may use hoverIntent under the terms of the MIT license. Basically that\r\n * means you are free to use hoverIntent as long as this header is left intact.\r\n * Copyright 2007-2019 Brian Cherne\r\n */\r\n\r\n/**\r\n * hoverIntent is similar to jQuery's built-in \"hover\" method except that\r\n * instead of firing the handlerIn function immediately, hoverIntent checks\r\n * to see if the user's mouse has slowed down (beneath the sensitivity\r\n * threshold) before firing the event. The handlerOut function is only\r\n * called after a matching handlerIn.\r\n *\r\n * // basic usage ... just like .hover()\r\n * .hoverIntent( handlerIn, handlerOut )\r\n * .hoverIntent( handlerInOut )\r\n *\r\n * // basic usage ... with event delegation!\r\n * .hoverIntent( handlerIn, handlerOut, selector )\r\n * .hoverIntent( handlerInOut, selector )\r\n *\r\n * // using a basic configuration object\r\n * .hoverIntent( config )\r\n *\r\n * @param handlerIn function OR configuration object\r\n * @param handlerOut function OR selector for delegation OR undefined\r\n * @param selector selector OR undefined\r\n * @author Brian Cherne \r\n */\r\n\r\n; (function (factory) {\r\n\t'use strict';\r\n\tif (typeof define === 'function' && define.amd) {\r\n\t\tdefine(['jquery'], factory);\r\n\t} else if (typeof module === 'object' && module.exports) {\r\n\t\tmodule.exports = factory(require('jquery'));\r\n\t} else if (jQuery && !jQuery.fn.hoverIntent) {\r\n\t\tfactory(jQuery);\r\n\t}\r\n})(function ($) {\r\n\t'use strict';\r\n\r\n\t// default configuration values\r\n\tvar _cfg = {\r\n\t\tinterval: 100,\r\n\t\tsensitivity: 6,\r\n\t\ttimeout: 0\r\n\t};\r\n\r\n\t// counter used to generate an ID for each instance\r\n\tvar INSTANCE_COUNT = 0;\r\n\r\n\t// current X and Y position of mouse, updated during mousemove tracking (shared across instances)\r\n\tvar cX, cY;\r\n\r\n\t// saves the current pointer position coordinates based on the given mousemove event\r\n\tvar track = function (ev) {\r\n\t\tcX = ev.pageX;\r\n\t\tcY = ev.pageY;\r\n\t};\r\n\r\n\t// compares current and previous mouse positions\r\n\tvar compare = function (ev, $el, s, cfg) {\r\n\t\t// compare mouse positions to see if pointer has slowed enough to trigger `over` function\r\n\t\tif (Math.sqrt((s.pX - cX) * (s.pX - cX) + (s.pY - cY) * (s.pY - cY)) < cfg.sensitivity) {\r\n\t\t\t$el.off(s.event, track);\r\n\t\t\tdelete s.timeoutId;\r\n\t\t\t// set hoverIntent state as active for this element (permits `out` handler to trigger)\r\n\t\t\ts.isActive = true;\r\n\t\t\t// overwrite old mouseenter event coordinates with most recent pointer position\r\n\t\t\tev.pageX = cX; ev.pageY = cY;\r\n\t\t\t// clear coordinate data from state object\r\n\t\t\tdelete s.pX; delete s.pY;\r\n\t\t\treturn cfg.over.apply($el[0], [ev]);\r\n\t\t} else {\r\n\t\t\t// set previous coordinates for next comparison\r\n\t\t\ts.pX = cX; s.pY = cY;\r\n\t\t\t// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)\r\n\t\t\ts.timeoutId = setTimeout(function () { compare(ev, $el, s, cfg); }, cfg.interval);\r\n\t\t}\r\n\t};\r\n\r\n\t// triggers given `out` function at configured `timeout` after a mouseleave and clears state\r\n\tvar delay = function (ev, $el, s, out) {\r\n\t\tvar data = $el.data('hoverIntent');\r\n\t\tif (data) {\r\n\t\t\tdelete data[s.id];\r\n\t\t}\r\n\t\treturn out.apply($el[0], [ev]);\r\n\t};\r\n\r\n\t$.fn.hoverIntent = function (handlerIn, handlerOut, selector) {\r\n\t\t// instance ID, used as a key to store and retrieve state information on an element\r\n\t\tvar instanceId = INSTANCE_COUNT++;\r\n\r\n\t\t// extend the default configuration and parse parameters\r\n\t\tvar cfg = $.extend({}, _cfg);\r\n\t\tif ($.isPlainObject(handlerIn)) {\r\n\t\t\tcfg = $.extend(cfg, handlerIn);\r\n\t\t\tif (!$.isFunction(cfg.out)) {\r\n\t\t\t\tcfg.out = cfg.over;\r\n\t\t\t}\r\n\t\t} else if ($.isFunction(handlerOut)) {\r\n\t\t\tcfg = $.extend(cfg, { over: handlerIn, out: handlerOut, selector: selector });\r\n\t\t} else {\r\n\t\t\tcfg = $.extend(cfg, { over: handlerIn, out: handlerIn, selector: handlerOut });\r\n\t\t}\r\n\r\n\t\t// A private function for handling mouse 'hovering'\r\n\t\tvar handleHover = function (e) {\r\n\t\t\t// cloned event to pass to handlers (copy required for event object to be passed in IE)\r\n\t\t\tvar ev = $.extend({}, e);\r\n\r\n\t\t\t// the current target of the mouse event, wrapped in a jQuery object\r\n\t\t\tvar $el = $(this);\r\n\r\n\t\t\t// read hoverIntent data from element (or initialize if not present)\r\n\t\t\tvar hoverIntentData = $el.data('hoverIntent');\r\n\t\t\tif (!hoverIntentData) { $el.data('hoverIntent', (hoverIntentData = {})); }\r\n\r\n\t\t\t// read per-instance state from element (or initialize if not present)\r\n\t\t\tvar state = hoverIntentData[instanceId];\r\n\t\t\tif (!state) { hoverIntentData[instanceId] = state = { id: instanceId }; }\r\n\r\n\t\t\t// state properties:\r\n\t\t\t// id = instance ID, used to clean up data\r\n\t\t\t// timeoutId = timeout ID, reused for tracking mouse position and delaying \"out\" handler\r\n\t\t\t// isActive = plugin state, true after `over` is called just until `out` is called\r\n\t\t\t// pX, pY = previously-measured pointer coordinates, updated at each polling interval\r\n\t\t\t// event = string representing the namespaced event used for mouse tracking\r\n\r\n\t\t\t// clear any existing timeout\r\n\t\t\tif (state.timeoutId) { state.timeoutId = clearTimeout(state.timeoutId); }\r\n\r\n\t\t\t// namespaced event used to register and unregister mousemove tracking\r\n\t\t\tvar mousemove = state.event = 'mousemove.hoverIntent.hoverIntent' + instanceId;\r\n\r\n\t\t\t// handle the event, based on its type\r\n\t\t\tif (e.type === 'mouseenter') {\r\n\t\t\t\t// do nothing if already active\r\n\t\t\t\tif (state.isActive) { return; }\r\n\t\t\t\t// set \"previous\" X and Y position based on initial entry point\r\n\t\t\t\tstate.pX = ev.pageX; state.pY = ev.pageY;\r\n\t\t\t\t// update \"current\" X and Y position based on mousemove\r\n\t\t\t\t$el.off(mousemove, track).on(mousemove, track);\r\n\t\t\t\t// start polling interval (self-calling timeout) to compare mouse coordinates over time\r\n\t\t\t\tstate.timeoutId = setTimeout(function () { compare(ev, $el, state, cfg); }, cfg.interval);\r\n\t\t\t} else { // \"mouseleave\"\r\n\t\t\t\t// do nothing if not already active\r\n\t\t\t\tif (!state.isActive) { return; }\r\n\t\t\t\t// unbind expensive mousemove event\r\n\t\t\t\t$el.off(mousemove, track);\r\n\t\t\t\t// if hoverIntent state is true, then call the mouseOut function after the specified delay\r\n\t\t\t\tstate.timeoutId = setTimeout(function () { delay(ev, $el, state, cfg.out); }, cfg.timeout);\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\t// listen for mouseenter and mouseleave\r\n\t\treturn this.on({ 'mouseenter.hoverIntent': handleHover, 'mouseleave.hoverIntent': handleHover }, cfg.selector);\r\n\t};\r\n});\r\n"],"names":["factory","define","amd","module","exports","require","jQuery","fn","hoverIntent","$","cX","cY","_cfg","interval","sensitivity","timeout","INSTANCE_COUNT","track","ev","pageX","pageY","compare","$el","s","cfg","Math","sqrt","pX","pY","off","event","timeoutId","isActive","over","apply","setTimeout","handlerIn","handlerOut","selector","handleHover","e","extend","this","state","hoverIntentData","data","instanceId","mousemove","id","clearTimeout","type","on","out","isPlainObject","isFunction","mouseenter.hoverIntent","mouseleave.hoverIntent"],"mappings":"AAkCE,CAAA,SAAWA,GACZ,aACsB,YAAlB,OAAOC,QAAyBA,OAAOC,IAC1CD,OAAO,CAAC,UAAWD,CAAO,EACE,UAAlB,OAAOG,QAAuBA,OAAOC,QAC/CD,OAAOC,QAAUJ,EAAQK,QAAQ,QAAQ,CAAC,EAChCC,QAAU,CAACA,OAAOC,GAAGC,aAC/BR,EAAQM,MAAM,CAEf,EAAE,SAAUG,GACZ,aAGA,IAUIC,EAAIC,EAVJC,EAAO,CACVC,SA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