PageSourceSearch

https://raj-pavlovice.cz/modules/mod_jse_megamenu/assets/js/HoverIntent.js

js raj-pavlovice.cz collected 2026-10-08 07:14:33 UTC 3,020 bytes, 108 lines download raw bytes

1/*
2---
3
4name: PictureSlider
5
6description: Animated picture slider. This is a port of jQuery HoverIntent
7
8license: MIT-style
9
10authors:
11- Jakob Holmelund
12
13requires:
14- core/1.4.3: [Class, Event]
15
16provides: HoverIntent, Element.hoverIntent
17
18...
19*/
20var HoverIntent = new Class({
21	Implements:[Options, Events],
22	options:{
23			sensitivity: 7,
24			interval: 100,
25			timeout: 0,
26			over:function(){},
27			out:function(){}
28	},
29	initialize:function(element, options){
30		this.setOptions(options);
31		this.ob = element;
32		var self = this;
33		this.ob.addEvents({
34			mouseenter:function(e){self.handleHover(e);},
35			mouseleave:function(e){self.handleHover(e);}
36		});
37	},
38	track:function(ev){
39		this.cX = ev.page.x;
40		this.cY = ev.page.y;
41	},
42	_compare:function(ev,ob){
43		var self = this;
44		ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
45		// compare mouse positions to see if they've crossed the threshold
46		if ( ( Math.abs(this.pX-this.cX) + Math.abs(this.pY-this.cY) ) < this.options.sensitivity ) {
47			ob.removeEvent("mousemove",self.track);
48			// set hoverIntent state to true (so mouseOut can be called)
49			ob.hoverIntent_s = 1;
50			return this.options.over.apply(ob,[ev]);
51		} else {
52			// set previous coordinates for next time
53			this.pX = this.cX; this.pY = this.cY;
54			// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
55			ob.hoverIntent_t = (function(){self._compare(ev, ob);}).delay(this.options.interval);
56		}
57	},
58	_delay:function(ev, ob){
59		ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
60		ob.hoverIntent_s = 0;
61//		console.log("delayed call");
62		return this.options.out.apply(ob,[ev]);
63	},
64	handleHover:function(e){
65		var ev = e;
66		var self = this;
67		// cancel hoverIntent timer if it exists
68		if (this.ob.hoverIntent_t !== undefined) {
69			this.ob.hoverIntent_t = clearTimeout(self.ob.hoverIntent_t);
70		}
71		// if e.type == "mouseenter"
72		if (e.type == "mouseenter" || e.type == "mouseover") {
73			// set "previous" X and Y position based on initial entry point
74			this.pX = ev.page.x;
75			this.pY = ev.page.y;
76			// update "current" X and Y position based on mousemove
77			this.ob.addEvent("mousemove",function(e){
78				self.track(e);
79			});
80			// start polling interval (self-calling timeout) to compare mouse coordinates over time
81			if (this.ob.hoverIntent_s != 1) {
82				this.ob.hoverIntent_t = (function(){
83					self._compare(ev,self.ob);
84				}).delay(self.options.interval);
85			}
86
87		// else e.type == "mouseleave"
88		} else if (e.type == "mouseleave" || e.type == "mouseout") {
89			// unbind expensive mousemove event
90			this.ob.removeEvent("mousemove",function(e){
91				self.track(e);
92			});
93			// if hoverIntent state is true, then call the mouseOut function after the specified delay
94			if (this.ob.hoverIntent_s == 1) {
95				this.ob.hoverIntent_t = (function(){
96					self._delay(ev, self.ob);
97				}).delay(self.options.interval);
98			}
99		}
100	}
101});
102
103Element.implement({
104  hoverIntent : function(options) {
105    new HoverIntent(this, options);
106    return this;
107  }
108});

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.