|
22 | 22 | if (this.options.hScroll) |
23 | 23 | this.hScrollbar = new Scrollbar(this, new HSizing()); |
24 | 24 | this.$element.data("scrollable", this); |
25 | | - if (window.jQueryCustomScrollbars == undefined) |
26 | | - window.jQueryCustomScrollbars = []; |
27 | | - this.addToScrollbarsHierarchy(); |
28 | 25 | this.initKeyboardScrolling(); |
29 | 26 | this.bindEvents(); |
30 | 27 | } |
|
58 | 55 | addScrollBarComponents: function () { |
59 | 56 | this.assignViewPort(); |
60 | 57 | if (this.$viewPort.length == 0) { |
61 | | - this.$element.wrapInner("<div class=\"viewport\" />") |
| 58 | + this.$element.wrapInner("<div class=\"viewport\" />"); |
62 | 59 | this.assignViewPort(); |
63 | 60 | this.viewPortAdded = true; |
64 | 61 | } |
65 | 62 | this.assignOverview(); |
66 | 63 | if (this.$overview.length == 0) { |
67 | | - this.$viewPort.wrapInner("<div class=\"overview\" />") |
| 64 | + this.$viewPort.wrapInner("<div class=\"overview\" />"); |
68 | 65 | this.assignOverview(); |
69 | 66 | this.overviewAdded = true; |
70 | 67 | } |
|
135 | 132 | this.removeSkinClass(); |
136 | 133 | this.removeScrollbarComponents(); |
137 | 134 | this.$element.data("scrollable", null); |
138 | | - window.jQueryCustomScrollbars = null; |
139 | 135 | this.removeKeyboardScrolling(); |
140 | 136 | if (this.vScrollbar) |
141 | 137 | this.vScrollbar.remove(); |
|
153 | 149 | (elementOffset.left + $element.width() <= wrappingElementOffset.left + $wrappingElement.width()) |
154 | 150 | }, |
155 | 151 |
|
156 | | - addNested: function (otherScrollable) { |
157 | | - if (this.addNestedToOneFromList(this.nestedScrollbars, otherScrollable)) |
158 | | - return true; |
159 | | - else if (this.isInside(otherScrollable.$viewPort, this.$overview)) { |
160 | | - this.nestedScrollbars.push(otherScrollable); |
161 | | - return true; |
162 | | - } |
163 | | - else |
164 | | - return false; |
165 | | - }, |
166 | | - |
167 | | - addToScrollbarsHierarchy: function () { |
168 | | - this.nestedScrollbars = []; |
169 | | - if (!this.addNestedToOneFromList(this, window.jQueryCustomScrollbars)) |
170 | | - window.jQueryCustomScrollbars.push(this); |
171 | | - }, |
172 | | - |
173 | | - addNestedToOneFromList: function (scrollable, list) { |
174 | | - for (var i = 0; i < list.length; i++) { |
175 | | - if (list[i].addNested(scrollable)) |
176 | | - return true; |
177 | | - else if (scrollable.addNested(list[i])) { |
178 | | - list[i] = scrollable; |
179 | | - return true; |
180 | | - } |
181 | | - } |
182 | | - return false; |
183 | | - }, |
184 | | - |
185 | | - isMouseOver: function () { |
186 | | - for (var i = 0; i < this.nestedScrollbars.length; i++) |
187 | | - if (this.nestedScrollbars[i].isMouseOver()) |
188 | | - return false; |
189 | | - var offset = this.$element.offset(); |
190 | | - var w = this.$element.width(); |
191 | | - var h = this.$element.height(); |
192 | | - return this.lastMouseEvent && |
193 | | - (this.lastMouseEvent.pageX >= offset.left) && (this.lastMouseEvent.pageX <= offset.left + w) && |
194 | | - (this.lastMouseEvent.pageY >= offset.top) && (this.lastMouseEvent.pageY <= offset.top + h); |
195 | | - }, |
196 | | - |
197 | 152 | initKeyboardScrolling: function () { |
198 | 153 | var _this = this; |
199 | | - this.documentKeydown = function (event) { |
200 | | - if (_this.isMouseOver()) { |
| 154 | + |
| 155 | + this.elementKeydown = function (event) { |
| 156 | + if (document.activeElement === _this.$element[0]) { |
201 | 157 | if (_this.vScrollbar) |
202 | 158 | _this.vScrollbar.keyScroll(event); |
203 | 159 | if (_this.hScrollbar) |
204 | 160 | _this.hScrollbar.keyScroll(event); |
205 | 161 | } |
206 | 162 | } |
207 | | - $(document).keydown(this.documentKeydown); |
208 | | - this.documentMousemove = function (event) { |
209 | | - _this.lastMouseEvent = event; |
210 | | - } |
211 | | - $(document).mousemove(this.documentMousemove); |
| 163 | + |
| 164 | + this.$element |
| 165 | + .attr('tabindex', '-1') |
| 166 | + .keydown(this.elementKeydown); |
212 | 167 | }, |
213 | 168 |
|
214 | 169 | removeKeyboardScrolling: function () { |
215 | | - $(document).unbind("keydown", this.documentKeydown); |
216 | | - $(document).unbind("mousemove", this.documentMousemove); |
| 170 | + this.$element |
| 171 | + .removeAttr('tabindex') |
| 172 | + .unbind("keydown", this.elementKeydown); |
217 | 173 | }, |
218 | 174 |
|
219 | 175 | bindEvents: function () { |
|
290 | 246 | this.scrollable.$element.mousewheel(function (event, delta, deltaX, deltaY) { |
291 | 247 | if (_this.enabled) { |
292 | 248 | _this.mouseWheelScroll(deltaX, deltaY); |
293 | | - event.preventDefault(); |
294 | | - event.stopPropagation(); |
| 249 | + return false; |
295 | 250 | } |
296 | 251 | }); |
297 | 252 | }, |
|
0 commit comments