PageSourceSearch

https://resistance-44.fr/wp-content/themes/aravalli-personal/assets/js/jquery.hoverdir.js?ver=7.1.2

js resistance-44.fr collected 2026-10-02 12:18:16 UTC 9,754 bytes, 274 lines download raw bytes

1/**
2 * jquery.hoverdir.js v1.1.2
3 * http://www.codrops.com
4 *
5 * Licensed under the MIT license.
6 * http://www.opensource.org/licenses/mit-license.php
7 *
8 * Copyright 2012, Codrops
9 * http://www.codrops.com
10 */
11(function (factory) {
12    'use strict';
13    if (typeof define === 'function' && define.amd) {
14        define(['jquery'], factory);
15    } else if (typeof exports !== 'undefined') {
16        module.exports = factory(require('jquery'));
17    } else {
18        factory(jQuery);
19    }
20})(function ($) {
21    'use strict';
22
23    function Hoverdir(element, options) {
24        this.$el = $(element);
25        // set options
26        this.options = $.extend(true, {}, this.defaults, options);
27        // initialize visibility to false for show and hide method
28        this.isVisible = false;
29        // get the hover for this element
30        this.$hoverElem = this.$el.find(this.options.hoverElem);
31        // transition properties
32        this.transitionProp = 'all ' + this.options.speed + 'ms ' + this.options.easing;
33        // support for CSS transitions
34        this.support = this._supportsTransitions();
35        // load the events
36        this._loadEvents();
37    }
38
39    Hoverdir.prototype = {
40        defaults: {
41            speed: 300,
42            easing: 'ease',
43            hoverDelay: 0,
44            inverse: false,
45            hoverElem: 'div'
46        },
47        constructor: Hoverdir,
48        /**
49         * Detect if CSS transitions are supported
50         *
51         * @return {Boolean}
52         */
53        _supportsTransitions: function () {
54            if (typeof Modernizr !== 'undefined') {
55                return Modernizr.csstransitions;
56            } else {
57                var b = document.body || document.documentElement,
58                    s = b.style,
59                    p = 'transition';
60
61                if (typeof s[p] === 'string') {
62                    return true;
63                }
64
65                // Tests for vendor specific prop
66                var v = ['Moz', 'webkit', 'Webkit', 'Khtml', 'O', 'ms'];
67                p = p.charAt(0).toUpperCase() + p.substr(1);
68
69                for (var i = 0; i < v.length; i++) {
70                    if (typeof s[v[i] + p] === 'string') {
71                        return true;
72                    }
73                }
74
75                return false;
76            }
77        },
78        /**
79         * Bind the events to the element
80         */
81        _loadEvents: function () {
82            this.$el.on('mouseenter.hoverdir mouseleave.hoverdir', $.proxy(function (event) {
83                this.direction = this._getDir({x: event.pageX, y: event.pageY});
84
85                if (event.type === 'mouseenter') {
86                    this._showHover();
87                }
88                else {
89                    this._hideHover();
90                }
91            }, this));
92        },
93        /**
94         * Show the hover of the element
95         */
96        _showHover: function () {
97            var styleCSS = this._getStyle(this.direction);
98
99            if (this.support) {
100                this.$hoverElem.css('transition', '');
101            }
102
103            this.$hoverElem.hide().css(styleCSS.from);
104            clearTimeout(this.tmhover);
105
106            this.tmhover = setTimeout($.proxy(function () {
107                this.$hoverElem.show(0, $.proxy(function () {
108                    if (this.support) {
109                        this.$hoverElem.css('transition', this.transitionProp);
110                    }
111                    this._applyAnimation(styleCSS.to);
112
113                }, this));
114            }, this), this.options.hoverDelay);
115
116            this.isVisible = true;
117        },
118        /**
119         * Hide the hover to the element
120         */
121        _hideHover: function () {
122            var styleCSS = this._getStyle(this.direction);
123            if (this.support) {
124                this.$hoverElem.css('transition', this.transitionProp);
125            }
126            clearTimeout(this.tmhover);
127            this._applyAnimation(styleCSS.from);
128            this.isVisible = false;
129        },
130        /**
131         * get the direction when the event is triggered
132         * credits : http://stackoverflow.com/a/3647634
133         *
134         * @param {Object} coordinates
135         * @returns {Interger}
136         */
137        _getDir: function (coordinates) {
138            // the width and height of the current div
139            var w = this.$el.width(),
140                h = this.$el.height(),
141                // calculate the x and y to get an angle to the center of the div from that x and y.
142                // gets the x value relative to the center of the DIV and "normalize" it
143                x = (coordinates.x - this.$el.offset().left - (w / 2)) * (w > h ? (h / w) : 1),
144                y = (coordinates.y - this.$el.offset().top - (h / 2)) * (h > w ? (w / h) : 1),
145                // the angle and the direction from where the mouse 
145came in/went out clockwise (TRBL=0123);
146                // first calculate the angle of the point,
147                // add 180 deg to get rid of the negative values
148                // divide by 90 to get the quadrant
149                // add 3 and do a modulo by 4 to shift the quadrants to a proper clockwise TRBL (top/right/bottom/left) **/
150                direction = Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90) + 3) % 4;
151            return direction;
152        },
153        /**
154         * get the style when the event is triggered
155         *
156         * @param {(Interger|String)} direction
157         * @returns {Object}
158         */
159        _getStyle: function (direction) {
160            var fromStyle, toStyle,
161                slideFromTop = {'left': '0', 'top': '-100%'},
162            slideFromBottom = {'left': '0', 'top': '100%'},
163            slideFromLeft = {'left': '-100%', 'top': '0'},
164            slideFromRight = {'left': '100%', 'top': '0'},
165            slideTop = {'top': '0'},
166            slideLeft = {'left': '0'};
167
168            switch (direction) {
169                case 0:
170                case 'top':
171                    // from top
172                    fromStyle = !this.options.inverse ? slideFromTop : slideFromBottom;
173                    toStyle = slideTop;
174                    break;
175                case 1:
176                case 'right':
177                    // from right
178                    fromStyle = !this.options.inverse ? slideFromRight : slideFromLeft;
179                    toStyle = slideLeft;
180                    break;
181                case 2:
182                case 'bottom':
183                    // from bottom
184                    fromStyle = !this.options.inverse ? slideFromBottom : slideFromTop;
185                    toStyle = slideTop;
186                    break;
187                case 3:
188                case 'left':
189                    // from left
190                    fromStyle = !this.options.inverse ? slideFromLeft : slideFromRight;
191                    toStyle = slideLeft;
192                    break;
193            }
194
195            return {from: fromStyle, to: toStyle};
196        },
197        /**
198         * Apply a transition or fallback to jquery animate based on Modernizr.csstransitions support
199         *
200         * @param {Object} styleCSS
201         */
202        _applyAnimation: function (styleCSS) {
203            $.fn.applyStyle = this.support ? $.fn.css : $.fn.animate;
204            this.$hoverElem.stop().applyStyle(styleCSS, $.extend(true, [], {duration: this.options.speed}));
205        },
206        /**
207         * Show $hoverElem from the direction in argument
208         *
209         * @param {String} [direction=top] direction
210         */
211        show: function (direction) {
212            this.$el.off('mouseenter.hoverdir mouseleave.hoverdir');
213            if (!this.isVisible) {
214                this.direction = direction || 'top';
215                this._showHover();
216            }
217        },
218        /**
219         * Hide $hoverElem from the direction in argument
220         *
221         * @param {String} [direction=bottom] direction
222         */
223        hide: function (direction) {
224            this.rebuild();
225            if (this.isVisible) {
226                this.direction = direction || 'bottom';
227                this._hideHover();
228            }
229        },
230        setOptions: function (options) {
231            this.options = $.extend(true, {}, this.defaults, this.options, options);
232        },
233        /**
234         * Unbinds the plugin.
235         */
236        destroy: function () {
237            this.$el.off('mouseenter.hoverdir mouseleave.hoverdir');
238            this.$el.data('hoverdir', null);
239        },
240        /**
241         * Bind the plugin.
242         */
243        rebuild: function (options) {
244            if (typeof options === 'object') {
245                this.setOptions(options);
246            }
247            this._loadEvents();
248        }
249    };
250
251    $.fn.hoverdir = function (option, parameter) {
252        return this.each(function () {
253            var data = $(this).data('hoverdir');
254            var options = typeof option === 'object' && option;
255
256            // Initialize hoverdir.
257            if (!data) {
258                data = new Hoverdir(this, options);
259                $(this).data('hoverdir', data);
260            }
261
262            // Call hoverdir method.
263            if (typeof option === 'string') {
264                data[option](parameter);
265
266                if (option === 'destroy') {
267                    $(this).data('hoverdir', false);
268                }
269            }
270        });
271    };
272
273    $.fn.hoverdir.Constructor = Hoverdir;
274});

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.