Skip to content

Commit 491636c

Browse files
committed
Merge branch 'soulhunter1987-master'
2 parents 0d07f8c + c544ef6 commit 491636c

File tree

3 files changed

+19
-58
lines changed

3 files changed

+19
-58
lines changed

demos/nested.html

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ <h2>This container has a scrollbar and contains other scrollable container</h2>
5454
Phasellus ornare, ante vitae consectetuer consequat, purus sapien ultricies dolor, et mollis pede metus eget
5555
nisi. Praesent sodales velit quis augue. Cras suscipit, urna at aliquam rhoncus, urna quam viverra nisi, in
5656
interdum massa nibh nec erat.
57+
<input type="text" />
58+
<textarea></textarea>
5759
</div>
5860
<p>And some more content...</p>
5961

jquery.custom-scrollbar.css

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
position: relative;
33
}
44

5+
.scrollable:focus {
6+
outline: 0;
7+
}
8+
59
.scrollable .viewport {
610
position: relative;
711
overflow: hidden;

jquery.custom-scrollbar.js

+13-58
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
if (this.options.hScroll)
2323
this.hScrollbar = new Scrollbar(this, new HSizing());
2424
this.$element.data("scrollable", this);
25-
if (window.jQueryCustomScrollbars == undefined)
26-
window.jQueryCustomScrollbars = [];
27-
this.addToScrollbarsHierarchy();
2825
this.initKeyboardScrolling();
2926
this.bindEvents();
3027
}
@@ -58,13 +55,13 @@
5855
addScrollBarComponents: function () {
5956
this.assignViewPort();
6057
if (this.$viewPort.length == 0) {
61-
this.$element.wrapInner("<div class=\"viewport\" />")
58+
this.$element.wrapInner("<div class=\"viewport\" />");
6259
this.assignViewPort();
6360
this.viewPortAdded = true;
6461
}
6562
this.assignOverview();
6663
if (this.$overview.length == 0) {
67-
this.$viewPort.wrapInner("<div class=\"overview\" />")
64+
this.$viewPort.wrapInner("<div class=\"overview\" />");
6865
this.assignOverview();
6966
this.overviewAdded = true;
7067
}
@@ -135,7 +132,6 @@
135132
this.removeSkinClass();
136133
this.removeScrollbarComponents();
137134
this.$element.data("scrollable", null);
138-
window.jQueryCustomScrollbars = null;
139135
this.removeKeyboardScrolling();
140136
if (this.vScrollbar)
141137
this.vScrollbar.remove();
@@ -153,67 +149,27 @@
153149
(elementOffset.left + $element.width() <= wrappingElementOffset.left + $wrappingElement.width())
154150
},
155151

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-
197152
initKeyboardScrolling: function () {
198153
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]) {
201157
if (_this.vScrollbar)
202158
_this.vScrollbar.keyScroll(event);
203159
if (_this.hScrollbar)
204160
_this.hScrollbar.keyScroll(event);
205161
}
206162
}
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);
212167
},
213168

214169
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);
217173
},
218174

219175
bindEvents: function () {
@@ -290,8 +246,7 @@
290246
this.scrollable.$element.mousewheel(function (event, delta, deltaX, deltaY) {
291247
if (_this.enabled) {
292248
_this.mouseWheelScroll(deltaX, deltaY);
293-
event.preventDefault();
294-
event.stopPropagation();
249+
return false;
295250
}
296251
});
297252
},

0 commit comments

Comments
 (0)