jquery-hoverIntent-rails 0.0.11 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 805785760419548d1f40e4c7b38d1c0f1652aa42
4
+ data.tar.gz: 8302fc7fcd1f6ef186ee68c7aeb0927aafb11b99
5
+ SHA512:
6
+ metadata.gz: 5ccaf1efb90f9629e8d91b8b6048064353ba19de8437549b81cf162ffd88a4d055cdf203f33a476cec1daaba9ed4be48d55aa1e2e3c8d005815582ed7ea392e8
7
+ data.tar.gz: a0f371198c4d07184cd1f8573faba66095943fa74dee0dd3c1c8566891c4d4784a79e425808a0639bc2c6cff4b0c1a205aedf410635bba1cb82463fbc3601bd7
data/README.md CHANGED
@@ -20,6 +20,13 @@ Or install it yourself as:
20
20
 
21
21
  $ gem install jquery-hoverIntent-rails
22
22
 
23
+ Next, add the following line to your `application.js` file (after jQuery is included):
24
+
25
+ //= require jquery.hoverIntent
26
+
27
+ Restart your server, and you're good to go.
28
+
29
+
23
30
  ## What's included?
24
31
  * jquery.hoverIntent.js
25
32
 
@@ -1,4 +1,4 @@
1
- require "jquery-hoverIntent-rails/version"
1
+ require 'jquery-hoverIntent-rails/version'
2
2
 
3
3
  module Jquery
4
4
  module HoverIntent
@@ -1,7 +1,7 @@
1
1
  module Jquery
2
2
  module HoverIntent
3
3
  module Rails
4
- VERSION = "0.0.11"
4
+ VERSION = '1.8.1'
5
5
  end
6
6
  end
7
7
  end
@@ -1,12 +1,12 @@
1
- /*!
2
- * hoverIntent r7 // 2013.03.11 // jQuery 1.9.1+
1
+ /*!
2
+ * hoverIntent v1.8.1 // 2014.08.11 // jQuery v1.9.1+
3
3
  * http://cherne.net/brian/resources/jquery.hoverIntent.html
4
4
  *
5
5
  * You may use hoverIntent under the terms of the MIT license. Basically that
6
6
  * means you are free to use hoverIntent as long as this header is left intact.
7
- * Copyright 2007, 2013 Brian Cherne
7
+ * Copyright 2007, 2014 Brian Cherne
8
8
  */
9
-
9
+
10
10
  /* hoverIntent is similar to jQuery's built-in "hover" method except that
11
11
  * instead of firing the handlerIn function immediately, hoverIntent checks
12
12
  * to see if the user's mouse has slowed down (beneath the sensitivity
@@ -29,17 +29,68 @@
29
29
  * @param selector selector OR undefined
30
30
  * @author Brian Cherne <brian(at)cherne(dot)net>
31
31
  */
32
- (function($) {
33
- $.fn.hoverIntent = function(handlerIn,handlerOut,selector) {
34
32
 
35
- // default configuration values
36
- var cfg = {
37
- interval: 100,
38
- sensitivity: 7,
39
- timeout: 0
40
- };
33
+ (function(factory) {
34
+ 'use strict';
35
+ if (typeof define === 'function' && define.amd) {
36
+ define(['jquery'], factory);
37
+ } else if (jQuery && !jQuery.fn.hoverIntent) {
38
+ factory(jQuery);
39
+ }
40
+ })(function($) {
41
+ 'use strict';
42
+
43
+ // default configuration values
44
+ var _cfg = {
45
+ interval: 100,
46
+ sensitivity: 6,
47
+ timeout: 60
48
+ };
49
+
50
+ // counter used to generate an ID for each instance
51
+ var INSTANCE_COUNT = 0;
52
+
53
+ // current X and Y position of mouse, updated during mousemove tracking (shared across instances)
54
+ var cX, cY;
41
55
 
42
- if ( typeof handlerIn === "object" ) {
56
+ // saves the current pointer position coordinated based on the given mouse event
57
+ var track = function(ev) {
58
+ cX = ev.pageX;
59
+ cY = ev.pageY;
60
+ };
61
+
62
+ // compares current and previous mouse positions
63
+ var compare = function(ev,$el,s,cfg) {
64
+ // compare mouse positions to see if pointer has slowed enough to trigger `over` function
65
+ if ( Math.sqrt( (s.pX-cX)*(s.pX-cX) + (s.pY-cY)*(s.pY-cY) ) < cfg.sensitivity ) {
66
+ $el.off('mousemove.hoverIntent'+s.namespace,track);
67
+ delete s.timeoutId;
68
+ // set hoverIntent state as active for this element (so `out` handler can eventually be called)
69
+ s.isActive = true;
70
+ // clear coordinate data
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) ) {
43
94
  cfg = $.extend(cfg, handlerIn );
44
95
  } else if ($.isFunction(handlerOut)) {
45
96
  cfg = $.extend(cfg, { over: handlerIn, out: handlerOut, selector: selector } );
@@ -47,69 +98,56 @@
47
98
  cfg = $.extend(cfg, { over: handlerIn, out: handlerIn, selector: handlerOut } );
48
99
  }
49
100
 
50
- // instantiate variables
51
- // cX, cY = current X and Y position of mouse, updated by mousemove event
52
- // pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
53
- var cX, cY, pX, pY;
101
+ // A private function for handling mouse 'hovering'
102
+ var handleHover = function(e) {
103
+ // cloned event to pass to handlers (copy required for event object to be passed in IE)
104
+ var ev = $.extend({},e);
54
105
 
55
- // A private function for getting mouse position
56
- var track = function(ev) {
57
- cX = ev.pageX;
58
- cY = ev.pageY;
59
- };
106
+ // the current target of the mouse event, wrapped in a jQuery object
107
+ var $el = $(this);
60
108
 
61
- // A private function for comparing current and previous mouse position
62
- var compare = function(ev,ob) {
63
- ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
64
- // compare mouse positions to see if they've crossed the threshold
65
- if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
66
- $(ob).off("mousemove.hoverIntent",track);
67
- // set hoverIntent state to true (so mouseOut can be called)
68
- ob.hoverIntent_s = 1;
69
- return cfg.over.apply(ob,[ev]);
70
- } else {
71
- // set previous coordinates for next time
72
- pX = cX; pY = cY;
73
- // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
74
- ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
75
- }
76
- };
109
+ // read hoverIntent data from element (or initialize if not present)
110
+ var hoverIntentData = $el.data('hoverIntent');
111
+ if (!hoverIntentData) { $el.data('hoverIntent', (hoverIntentData = {})); }
77
112
 
78
- // A private function for delaying the mouseOut function
79
- var delay = function(ev,ob) {
80
- ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
81
- ob.hoverIntent_s = 0;
82
- return cfg.out.apply(ob,[ev]);
83
- };
113
+ // read per-instance state from element (or initialize if not present)
114
+ var state = hoverIntentData[instanceId];
115
+ if (!state) { hoverIntentData[instanceId] = state = { id: instanceId }; }
84
116
 
85
- // A private function for handling mouse 'hovering'
86
- var handleHover = function(e) {
87
- // copy objects to be passed into t (required for event object to be passed in IE)
88
- var ev = jQuery.extend({},e);
89
- var ob = this;
117
+ // state properties:
118
+ // id = instance ID, used to clean up data
119
+ // timeoutId = timeout ID, reused for tracking mouse position and delaying "out" handler
120
+ // isActive = plugin state, true after `over` is called just until `out` is called
121
+ // pX, pY = previously-measured pointer coordinates, updated at each polling interval
122
+ // namespace = string used as namespace for per-instance event management
123
+
124
+ // clear any existing timeout
125
+ if (state.timeoutId) { state.timeoutId = clearTimeout(state.timeoutId); }
90
126
 
91
- // cancel hoverIntent timer if it exists
92
- if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }
127
+ // event namespace, used to register and unregister mousemove tracking
128
+ var namespace = state.namespace = '.hoverIntent'+instanceId;
93
129
 
94
- // if e.type == "mouseenter"
95
- if (e.type == "mouseenter") {
130
+ // handle the event, based on its type
131
+ if (e.type === 'mouseenter') {
132
+ // do nothing if already active
133
+ if (state.isActive) { return; }
96
134
  // set "previous" X and Y position based on initial entry point
97
- pX = ev.pageX; pY = ev.pageY;
135
+ state.pX = ev.pageX; state.pY = ev.pageY;
98
136
  // update "current" X and Y position based on mousemove
99
- $(ob).on("mousemove.hoverIntent",track);
137
+ $el.on('mousemove.hoverIntent'+namespace,track);
100
138
  // start polling interval (self-calling timeout) to compare mouse coordinates over time
101
- if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}
102
-
103
- // else e.type == "mouseleave"
104
- } else {
139
+ state.timeoutId = setTimeout( function(){compare(ev,$el,state,cfg);} , cfg.interval );
140
+ } else { // "mouseleave"
141
+ // do nothing if not already active
142
+ if (!state.isActive) { return; }
105
143
  // unbind expensive mousemove event
106
- $(ob).off("mousemove.hoverIntent",track);
144
+ $el.off('mousemove.hoverIntent'+namespace,track);
107
145
  // if hoverIntent state is true, then call the mouseOut function after the specified delay
108
- if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
146
+ state.timeoutId = setTimeout( function(){delay(ev,$el,state,cfg.out);} , cfg.timeout );
109
147
  }
110
148
  };
111
149
 
112
150
  // listen for mouseenter and mouseleave
113
151
  return this.on({'mouseenter.hoverIntent':handleHover,'mouseleave.hoverIntent':handleHover}, cfg.selector);
114
152
  };
115
- })(jQuery);
153
+ });
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-hoverIntent-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
5
- prerelease:
4
+ version: 1.8.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alrick Deillon
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-30 00:00:00.000000000 Z
11
+ date: 2015-11-02 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: A wrapper for jquery hoverIntent plugin
15
14
  email:
@@ -18,7 +17,7 @@ executables: []
18
17
  extensions: []
19
18
  extra_rdoc_files: []
20
19
  files:
21
- - .gitignore
20
+ - ".gitignore"
22
21
  - Gemfile
23
22
  - LICENSE
24
23
  - README.md
@@ -30,27 +29,25 @@ files:
30
29
  homepage: https://github.com/alrick/jquery-hoverIntent-rails
31
30
  licenses:
32
31
  - MIT
32
+ metadata: {}
33
33
  post_install_message:
34
34
  rdoc_options: []
35
35
  require_paths:
36
36
  - lib
37
37
  required_ruby_version: !ruby/object:Gem::Requirement
38
- none: false
39
38
  requirements:
40
- - - ! '>='
39
+ - - ">="
41
40
  - !ruby/object:Gem::Version
42
41
  version: '0'
43
42
  required_rubygems_version: !ruby/object:Gem::Requirement
44
- none: false
45
43
  requirements:
46
- - - ! '>='
44
+ - - ">="
47
45
  - !ruby/object:Gem::Version
48
46
  version: '0'
49
47
  requirements: []
50
48
  rubyforge_project:
51
- rubygems_version: 1.8.24
49
+ rubygems_version: 2.4.5
52
50
  signing_key:
53
- specification_version: 3
51
+ specification_version: 4
54
52
  summary: Jquery Hover improved
55
53
  test_files: []
56
- has_rdoc: