Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added restoration of original style information on removeOverscroll #38

Merged
merged 2 commits into from

2 participants

@coeamyd

Hi Azoff,

I needed to refresh overscroll due to size changes of the content and noticed, that the style attribute is completely removed on removeOverscroll. I changed this behavior to store the original style information in the elements data and the remover now restores this information.

Cheers,
Christoph

@azoff
Owner
@azoff azoff merged commit 3fa323c into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 21, 2011
This page is out of date. Refresh to see the latest.
Showing with 48 additions and 38 deletions.
  1. +48 −38 jquery.overscroll.js
View
86 jquery.overscroll.js
@@ -21,9 +21,9 @@
/*global window, jQuery */
(function (w, m, $, o, touch) {
-
+
"use strict";
-
+
// check for native touch support
touch = "ontouchstart" in w;
@@ -38,7 +38,7 @@
// removes overscroll from a jQuery object
$.fn.removeOverscroll = function (options) {
return this.each(function () {
- var remover = $(this).data(o.removerKey);
+ var remover = $(this).data(o.removerKey);
if ($.isFunction(remover)) {
remover();
}
@@ -61,6 +61,7 @@
// to save a couple bits
div: '<div/>',
removerKey: 'overscroll-remover',
+ origStyleKey: 'overscroll-orig-style',
// constants used to tune scroll-ability and thumbs
constants: {
@@ -89,7 +90,7 @@
data.options = options = $.extend({
showThumbs: true,
persistThumbs: false,
- hoverThumbs: false,
+ hoverThumbs: false,
wheelDirection: 'vertical',
wheelDelta: o.constants.wheelDelta,
scrollDelta: o.constants.scrollDelta,
@@ -108,20 +109,21 @@
// remove any old bindings and set up a deconstructor
target.removeOverscroll();
+ target.data(o.origStyleKey, target.attr('style'));
target.data(o.removerKey, o.remover(target, data));
// no need for emulation, just apply styles if touch supported natively
if (touch) {
-
+
target.css({
'overflow': 'auto',
'-webkit-overflow-scrolling': 'touch',
'-moz-overflow-scrolling': 'touch',
'overflow-scrolling': 'touch'
});
-
+
} else {
-
+
data.target = target.css({
position: 'relative',
overflow: 'hidden',
@@ -147,15 +149,15 @@
.css({ opacity: options.persistThumbs ? o.constants.thumbOpacity : 0 });
target.prepend(data.thumbs.vertical);
}
-
+
if (data.options.hoverThumbs) {
target.on(o.events.hover, data, o.hover);
}
- }
-
+ }
+
}
-
+
// if scroll offsets are defined, apply them here
if (options.scrollLeft) {
target.scrollLeft(options.scrollLeft);
@@ -167,8 +169,8 @@
o.moveThumbs(data, target.scrollLeft(), target.scrollTop());
},
-
- getCursors: function() {
+
+ getCursors: function () {
var cursors = {};
if ($.browser.mozilla) {
cursors.grab = '-moz-grab';
@@ -176,7 +178,7 @@
} else if ($.browser.webkit) {
cursors.grab = '-webkit-grab';
cursors.grabbing = '-webkit-grabbing';
- } else {
+ } else {
cursors.grab = cursors.grabbing = 'move';
}
return cursors;
@@ -184,9 +186,15 @@
remover: function (target, data) {
return function () {
+ var origStyle = target.data(o.origStyleKey);
+ if (!origStyle) {
+ target.removeAttr('style');
+ } else {
+ target.attr('style', origStyle);
+ }
target
- .removeAttr('style')
.removeData(o.removerKey)
+ .removeData(o.origStyleKey)
.off(o.events.wheel, o.wheel)
.off(o.events.start, o.start)
.off(o.events.end, o.stop)
@@ -245,10 +253,11 @@
},
// handles mouse wheel scroll events
- wheel: function (event, delta) { var
-
- data = event.data,
-
+ wheel: function (event, delta) {
+ var
+
+ data = event.data,
+
original = event.originalEvent;
event.preventDefault();
@@ -256,7 +265,7 @@
o.clearInterval(data.target);
if (original.wheelDelta) {
- delta = original.wheelDelta / (w.opera ? - 120 : 120);
+ delta = original.wheelDelta / (w.opera ? -120 : 120);
}
if (original.detail) {
@@ -317,7 +326,7 @@
// starts the drag operation and binds the mouse move handler
start: function (event) {
-
+
var data = event.data, target = data.target, flags = data.flags;
o.clearInterval(data.target);
@@ -346,8 +355,8 @@
if (!flags.dragged) {
o.toggleThumbs(data, true);
}
-
- flags.dragged = true;
+
+ flags.dragged = true;
if (data.options.direction !== 'vertical') {
this.scrollLeft -= (event.pageX - data.position.x);
@@ -387,12 +396,13 @@
},
// ends the drag operation and unbinds the mouse move handler
- stop: function (event) { var
-
- data = event.data,
- target = data.target,
+ stop: function (event) {
+ var
+
+ data = event.data,
+ target = data.target,
flags = data.flags,
- done = function() {
+ done = function () {
if (!data.options.hoverThumbs) {
o.toggleThumbs(data, flags.dragging = false);
}
@@ -400,14 +410,14 @@
target.unbind(o.events.drag, o.drag);
- if (data.position) {
+ if (data.position) {
o.triggerEvent('dragend', data);
if (flags.dragging) {
o.drift(this, event, done);
- } else {
- done();
+ } else {
+ done();
}
// only if we moved, and the mouse down is the same as
@@ -420,14 +430,14 @@
data.capture = data.position = undefined;
}
-
+
data.target.css('cursor', data.cursors.grab);
},
-
+
scroll: function (event) {
var data = event.data, flags = data.flags;
-
+
if (!flags.dragging) {
o.moveThumbs(data, this.scrollLeft, this.scrollTop);
}
@@ -451,14 +461,14 @@
drift: function (target, event, callback) {
var data = event.data, dx, dy, xMod, yMod,
- scrollLeft = target.scrollLeft, scrollTop = target.scrollTop,
+ scrollLeft = target.scrollLeft, scrollTop = target.scrollTop,
decay = o.constants.driftDecay;
// only drift on intended drifts
if ((o.time() - data.capture.time) > o.constants.driftTimeout) {
return callback.call(null, data);
}
-
+
dx = data.options.scrollDelta * (event.pageX - data.capture.x);
dy = data.options.scrollDelta * (event.pageY - data.capture.y);
xMod = dx / o.constants.driftSequences;
@@ -503,8 +513,8 @@
},
// gets sizing for the container and thumbs
- getSizing: function (container) {
-
+ getSizing: function (container) {
+
var sizing = {}, parent = container.get(0);
container = sizing.container = {
width: container.width(),
Something went wrong with that request. Please try again.