Permalink
Browse files

Updated copy, linted, and minified script

  • Loading branch information...
1 parent 3405869 commit 67812cffbd2eb15c372f583849538e009ea337f4 Jonathan Azoff committed Feb 19, 2012
Showing with 32 additions and 41 deletions.
  1. +7 −2 README.md
  2. +7 −7 jquery.overscroll.js
  3. +18 −32 jquery.overscroll.min.js
View
@@ -1,6 +1,6 @@
-Overscroll v1.6.0
+Overscroll v1.6.1
=================
-Sunday, December 24th 2011
+Saturday, February 18th 2012
Overscroll is a jQuery Plugin that emulates the iPhone scrolling experience in a browser. It is intended for use with the latest version of jQuery
<http://code.jquery.com/jquery-latest.js>
@@ -102,6 +102,11 @@ As of 1.4.4 you can call the `overscroll` constructor on a jQuery element as muc
Change Log
----------
+* __1.6.1__
+ - Fixed feature detection and dragging data flag.
+ + <https://github.com/azoff/Overscroll/issues/41>
+ - Don't prevent default until after checking cancel on.
+ + <https://github.com/azoff/Overscroll/issues/42>
* __1.6.0__
- Major re-factor on code structure to improve readability (more modular, added comments)
- Migrated drift function to use requestAnimationFrame
View
@@ -1,5 +1,5 @@
-/**@license
- * Overscroll v1.6.0
+/**
+ * Overscroll v1.6.1
* A jQuery Plugin that emulates the iPhone scrolling experience in a browser.
* http://azoffdesign.com/overscroll
*
@@ -13,12 +13,12 @@
* For API documentation, see the README file
* http://azof.fr/pYCzuM
*
- * Date: Sunday, December 24th 2011
+ * Date: Saturday, February 18th 2012
*/
/*jslint onevar: true, strict: true */
-/*global window, setTimeout, clearTimeout, jQuery */
+/*global window, document, setTimeout, clearTimeout, jQuery */
(function(global, dom, math, wait, cancel, namespace, $, none){
@@ -36,7 +36,7 @@
style = dom.createElement(datakey).style,
prefix = b.webkit ? 'webkit' : (b.mozilla ? 'moz' : (b.msie ? 'ms' : (b.opera ? 'o' : ''))),
cssprefix = prefix ? ['-','-'].join(prefix) : '';
- compat = { overflowScrolling: false };
+ compat = { prefix: prefix, overflowScrolling: false };
$.each(prefix ? [prefix, ''] : [prefix], function(i, prefix){
var animator = prefix ? (prefix + 'RequestAnimationFrame') : 'requestAnimationFrame',
scroller = prefix ? (prefix + 'OverflowScrolling') : 'overflowScrolling';
@@ -52,7 +52,7 @@
if (style[scroller] !== none) {
compat.overflowScrolling = cssprefix + 'overflow-scrolling';
}
- });
+ });
// fallback to set timeout for no animation support
if (!compat.animate) {
@@ -232,7 +232,7 @@
// calculate how much to move the viewport by
// TODO: let's base this on some fact somewhere...
if (original.wheelDelta) {
- delta = original.wheelDelta / (browser.opera ? -120 : 120);
+ delta = original.wheelDelta / (compat.prefix === 'o' ? -120 : 120);
} if (original.detail) {
delta = -original.detail / 3;
} delta *= options.wheelDelta;
@@ -1,32 +1,18 @@
-/*
-
- Overscroll v1.6.0
- A jQuery Plugin that emulates the iPhone scrolling experience in a browser.
- http://azoffdesign.com/overscroll
-
- Intended for use with the latest jQuery
- http://code.jquery.com/jquery-latest.js
-
- Copyright 2011, Jonathan Azoff
- Dual licensed under the MIT or GPL Version 2 licenses.
- http://jquery.org/license
-
- For API documentation, see the README file
- http://azof.fr/pYCzuM
-
- Date: Sunday, December 24th 2011
-*/
-(function(m,r,y,H,o,I,k,z){var n=o.mozilla?"-moz-":o.webkit?"-webkit-":o.opera?"-o-":o.msie&&o.version>9?"-ms-":"",A=m.requestAnimationFrame||m.webkitRequestAnimationFrame||m.mozRequestAnimationFrame||m.oRequestAnimationFrame||m.msRequestAnimationFrame||function(b){y(b,1E3/60)},s={cursorGrab:n?n+"grab":"move",cursorGrabbing:n?n+"grabbing":"move",scrollingProp:n?n+"overflow-scrolling":"overflow-scrolling",touchEnabled:"ontouchstart"in m},l={drag:"mousemove",end:"mouseup mouseleave click",hover:"mouseenter mouseleave",
-ignored:"select dragstart drag",scroll:"scroll",start:"mousedown",wheel:"mousewheel DOMMouseScroll"},h={captureThreshold:3,driftDecay:1.1,driftSequences:22,driftTimeout:100,scrollDelta:15,thumbOpacity:0.7,thumbThickness:6,thumbTimeout:400,wheelDelta:20},J={cancelOn:"",direction:"multi",hoverThumbs:false,scrollDelta:h.scrollDelta,showThumbs:true,persistThumbs:false,wheelDelta:h.wheelDelta,wheelDirection:"vertical",zIndex:999},t=function(b,a){a.trigger("overscroll:"+b)},u=function(b,a,c){a.x=b.pageX;
-a.y=b.pageY;a.time=(new Date).getTime();a.index=c;return a},p=function(b,a,c,e){var d,f;if(b&&b.added){if(b.horizontal){d=c*(1+a.container.width/a.container.scrollWidth);f=e+a.thumbs.horizontal.top;b.horizontal.css("margin",f+"px 0 0 "+d+"px")}if(b.vertical){d=c+a.thumbs.vertical.left;f=e*(1+a.container.height/a.container.scrollHeight);b.vertical.css("margin",f+"px 0 0 "+d+"px")}}},q=function(b,a,c){if(b&&b.added&&!a.persistThumbs)if(c){b.vertical&&b.vertical.stop(true,true).fadeTo("fast",h.thumbOpacity);
-b.horizontal&&b.horizontal.stop(true,true).fadeTo("fast",h.thumbOpacity)}else{b.vertical&&b.vertical.fadeTo("fast",0);b.horizontal&&b.horizontal.fadeTo("fast",0)}},K=function(b){var a=b.data("events"),c=a&&a.click?a.click.slice():[];a&&delete a.click;b.one("mouseup",function(){k.each(c,function(e,d){b.click(d)});return false})},L=function(b){var a=b.data;q(a.thumbs,a.options,b.type==="mouseenter")},M=function(b){b=b.data;b.flags.dragged||p(b.thumbs,b.sizing,this.scrollLeft,this.scrollTop)},B=function(b){b.preventDefault();
-var a=b.data,c=a.options,e=a.sizing,d=a.thumbs,f=a.wheel,g=a.flags,i;b=b.originalEvent;g.drifting=false;if(b.wheelDelta)i=b.wheelDelta/(o.opera?-120:120);if(b.detail)i=-b.detail/3;i*=c.wheelDelta;if(!f){g.dragging=true;a.wheel=f={timeout:null};q(d,c,true)}if(c.wheelDirection==="horizontal")this.scrollLeft-=i;else this.scrollTop-=i;f.timeout&&H(f.timeout);p(d,e,this.scrollLeft,this.scrollTop);f.timeout=y(function(){q(d,c,a.wheel=g.dragging=null)},h.thumbTimeout)},C=function(b){b.preventDefault();var a=
-b.data,c=a.options,e=a.sizing,d=a.thumbs,f=a.position,g=a.flags;g.dragged||q(d,c,true);g.dragged=true;if(c.direction!=="vertical")this.scrollLeft-=b.pageX-f.x;if(a.options.direction!=="horizontal")this.scrollTop-=b.pageY-f.y;u(b,a.position);if(--a.capture.index<=0){g.dragging=true;u(b,a.capture,h.captureThreshold)}p(d,e,this.scrollLeft,this.scrollTop)},Q=function(b,a,c){var e=a.data,d,f,g,i=e.capture,j=e.options,N=e.sizing,O=e.thumbs;d=(new Date).getTime()-i.time;var v=b.scrollLeft,w=b.scrollTop,
-D=h.driftDecay;if(d>h.driftTimeout)return c(e);d=j.scrollDelta*(a.pageX-i.x);a=j.scrollDelta*(a.pageY-i.y);if(j.direction!=="vertical")v-=d;if(j.direction!=="horizontal")w-=a;f=d/h.driftSequences;g=a/h.driftSequences;t("driftstart",e.target);e.drifting=true;A(function P(){if(e.drifting){e.drifting=false;if(g>1&&b.scrollTop>w||g<-1&&b.scrollTop<w){e.drifting=true;b.scrollTop-=g;g/=D}if(f>1&&b.scrollLeft>v||f<-1&&b.scrollLeft<v){e.drifting=true;b.scrollLeft-=f;f/=D}p(O,N,b.scrollLeft,b.scrollTop);A(P)}else{t("driftend",
-e.target);c(e)}})},E=function(b){b.preventDefault();var a=b.data,c=a.target,e=a.start=k(b.target),d=a.flags;d.drifting=false;if(!e.is(a.options.cancelOn)){c.css("cursor",s.cursorGrabbing);d.dragging=d.dragged=false;c.on(l.drag,a,C);a.position=u(b,{});a.capture=u(b,{},h.captureThreshold);t("dragstart",c)}},F=function(b){var a=b.data,c=a.target,e=a.options,d=a.flags,f=a.thumbs,g=function(){f&&!e.hoverThumbs&&q(f,e,false)};c.unbind(l.drag,C);if(a.position){t("dragend",c);d.dragging?Q(this,b,g):g()}d.dragging&&
-a.start.is(b.target)&&K(a.start);a.start=a.capture=a.position=d.dragged=d.dragging=false;c.css("cursor",s.cursorGrab)},x=function(b,a){var c=k(b),e,d=c.data("overscroll")||{},f=c.attr("style"),g=a?function(){d=c.data("overscroll");e=d.thumbs;f?c.attr("style",f):c.removeAttr("style");if(e){e.horizontal&&e.horizontal.remove();e.vertical&&e.vertical.remove()}c.removeData("overscroll").off(l.wheel,B).off(l.start,E).off(l.end,F).off(l.ignored,false)}:k.noop;return k.isFunction(d.remover)?d.remover:g},
-G=function(b,a){return{position:"absolute",opacity:a.persistThumbs?h.thumbOpacity:0,"background-color":"black",width:b.width+"px",height:b.height+"px","border-radius":b.corner+"px",margin:b.top+"px 0 0 "+b.left+"px","z-index":a.zIndex}};m=function(b){return this.removeOverscroll().each(function(){var a=this,c=b,e;c=c;c=k.extend({},J,c);if(c.direction!=="multi"&&c.direction!==c.wheelDirection)c.wheelDirection=c.direction;c.scrollDelta=r.abs(c.scrollDelta);c.wheelDelta=r.abs(c.wheelDelta);c.scrollLeft=
-c.scrollLeft===z?null:r.abs(c.scrollLeft);c.scrollTop=c.scrollTop===z?null:r.abs(c.scrollTop);e=c=c;var d=x(a,true),f=a,g=k(f),i=g.width();g=g.height();var j=i>=f.scrollWidth?i:f.scrollWidth;f=g>=f.scrollHeight?g:f.scrollHeight;d={flags:{dragging:false},options:e,remover:d,sizing:e={container:{width:i,height:g,scrollWidth:j,scrollHeight:f},thumbs:{horizontal:{width:i*i/j,height:h.thumbThickness,corner:h.thumbThickness/2,left:0,top:g-h.thumbThickness},vertical:{width:h.thumbThickness,height:g*g/f,
-corner:h.thumbThickness/2,left:i-h.thumbThickness,top:0}}}};d.target=a=k(a).css({position:"relative",overflow:"hidden",cursor:s.cursorGrab}).on(l.wheel,d,B).on(l.start,d,E).on(l.end,d,F).on(l.scroll,d,M).on(l.ignored,false);c.scrollLeft!==null&&a.scrollLeft(c.scrollLeft);c.scrollTop!==null&&a.scrollTop(c.scrollTop);if(c.showThumbs){i=a;f=c;g={};j=false;if(e.container.scrollWidth>0&&f.direction!=="vertical"){j=G(e.thumbs.horizontal,f);g.horizontal=k("<div/>").css(j).prependTo(i)}if(e.container.scrollHeight>
-0&&f.direction!=="horizontal"){j=G(e.thumbs.vertical,f);g.vertical=k("<div/>").css(j).prependTo(i)}g.added=!!j;d.thumbs=g;if(g.added){p(g,e,a.scrollLeft(),a.scrollTop());c.hoverThumbs&&a.on(l.hover,d,L)}}a.data("overscroll",d)})};var R=function(){return this.removeOverscroll().each(function(){k(this).data("overscroll",{remover:x(this)}).css(n+"overflow-scrolling","touch").css("overflow","auto")})};m.settings=h;k.extend(I,{overscroll:s.touchEnabled?R:m,removeOverscroll:function(){return this.each(function(){x(this)()})}})})(window,
-Math,setTimeout,clearTimeout,jQuery.browser,jQuery.fn,jQuery);
+/**
+ * Overscroll v1.6.1
+ * A jQuery Plugin that emulates the iPhone scrolling experience in a browser.
+ * http://azoffdesign.com/overscroll
+ *
+ * Intended for use with the latest jQuery
+ * http://code.jquery.com/jquery-latest.js
+ *
+ * Copyright 2011, Jonathan Azoff
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
+ *
+ * For API documentation, see the README file
+ * http://azof.fr/pYCzuM
+ *
+ * Date: Saturday, February 18th 2012
+ */
+(function(a,b,c,d,e,f,g,h){"use strict";var i="overscroll",j=function(){var c=g.browser,e,f=b.createElement(i).style,k=c.webkit?"webkit":c.mozilla?"moz":c.msie?"ms":c.opera?"o":"",l=k?["-","-"].join(k):"";return j={prefix:k,overflowScrolling:!1},g.each(k?[k,""]:[k],function(b,c){var d=c?c+"RequestAnimationFrame":"requestAnimationFrame",e=c?c+"OverflowScrolling":"overflowScrolling";a[d]!==h&&(j.animate=function(b){a[d].call(a,b)}),f[e]!==h&&(j.overflowScrolling=l+"overflow-scrolling")}),j.animate||(j.animate=function(a){d(a,1e3/60)}),k==="moz"||k==="webkit"?(j.cursorGrab=l+"grab",j.cursorGrabbing=l+"grabbing"):(e="https://mail.google.com/mail/images/2/",j.cursorGrab="url("+e+"openhand.cur), default",j.cursorGrabbing="url("+e+"closedhand.cur), default"),j}(),k={drag:"mousemove",end:"mouseup mouseleave click",hover:"mouseenter mouseleave",ignored:"select dragstart drag",scroll:"scroll",start:"mousedown",wheel:"mousewheel DOMMouseScroll"},l={captureThreshold:3,driftDecay:1.1,driftSequences:22,driftTimeout:100,scrollDelta:15,thumbOpacity:.7,thumbThickness:6,thumbTimeout:400,wheelDelta:20},m={cancelOn:"",direction:"multi",hoverThumbs:!1,scrollDelta:l.scrollDelta,showThumbs:!0,persistThumbs:!1,wheelDelta:l.wheelDelta,wheelDirection:"vertical",zIndex:999},n=function(a,b){b.trigger("overscroll:"+a)},o=function(){return(new Date).getTime()},p=function(a,b,c){return b.x=a.pageX,b.y=a.pageY,b.time=o(),b.index=c,b},q=function(a,b,c,d){var e,f;a&&a.added&&(a.horizontal&&(e=c*(1+b.container.width/b.container.scrollWidth),f=d+b.thumbs.horizontal.top,a.horizontal.css("margin",f+"px 0 0 "+e+"px")),a.vertical&&(e=c+b.thumbs.vertical.left,f=d*(1+b.container.height/b.container.scrollHeight),a.vertical.css("margin",f+"px 0 0 "+e+"px")))},r=function(a,b,c){a&&a.added&&!b.persistThumbs&&(c?(a.vertical&&a.vertical.stop(!0,!0).fadeTo("fast",l.thumbOpacity),a.horizontal&&a.horizontal.stop(!0,!0).fadeTo("fast",l.thumbOpacity)):(a.vertical&&a.vertical.fadeTo("fast",0),a.horizontal&&a.horizontal.fadeTo("fast",0)))},s=function(a){var b=a.data("events"),c=b&&b.click?b.click.slice():[];b&&delete b.click,a.one("mouseup",function(){return g.each(c,function(b,c){a.click(c)}),!1})},t=function(a){var b=a.data,c=b.thumbs,d=b.options,e=a.type==="mouseenter";r(c,d,e)},u=function(a){var b=a.data;b.flags.dragged||q(b.thumbs,b.sizing,this.scrollLeft,this.scrollTop)},v=function(a){a.preventDefault();var b=a.data,c=b.options,f=b.sizing,g=b.thumbs,h=b.wheel,k=b.flags,m,n=a.originalEvent;k.drifting=!1,n.wheelDelta&&(m=n.wheelDelta/(j.prefix==="o"?-120:120)),n.detail&&(m=-n.detail/3),m*=c.wheelDelta,h||(b.target.data(i).dragging=k.dragging=!0,b.wheel=h={timeout:null},r(g,c,!0)),c.wheelDirection==="horizontal"?this.scrollLeft-=m:this.scrollTop-=m,h.timeout&&e(h.timeout),q(g,f,this.scrollLeft,this.scrollTop),h.timeout=d(function(){b.target.data(i).dragging=k.dragging=!1,r(g,c,b.wheel=null)},l.thumbTimeout)},w=function(a){a.preventDefault();var b=a.data,c=b.options,d=b.sizing,e=b.thumbs,f=b.position,g=b.flags;g.dragged||r(e,c,!0),g.dragged=!0,c.direction!=="vertical"&&(this.scrollLeft-=a.pageX-f.x),b.options.direction!=="horizontal"&&(this.scrollTop-=a.pageY-f.y),p(a,b.position),--b.capture.index<=0&&(b.target.data(i).dragging=g.dragging=!0,p(a,b.capture,l.captureThreshold)),q(e,d,this.scrollLeft,this.scrollTop)},x=function(a,b,c){var d=b.data,e,f,g,h,i=d.capture,k=d.options,m=d.sizing,p=d.thumbs,r=o()-i.time,s=a.scrollLeft,t=a.scrollTop,u=l.driftDecay;if(r>l.driftTimeout)return c(d);e=k.scrollDelta*(b.pageX-i.x),f=k.scrollDelta*(b.pageY-i.y),k.direction!=="vertical"&&(s-=e),k.direction!=="horizontal"&&(t-=f),g=e/l.driftSequences,h=f/l.driftSequences,n("driftstart",d.target),d.drifting=!0,j.animate(function v(){if(d.drifting){var b=1,e=-1;d.drifting=!1;if(h>b&&a.scrollTop>t||h<e&&a.scrollTop<t)d.drifting=!0,a.scrollTop-=h,h/=u;if(g>b&&a.scrollLeft>s||g<e&&a.scrollLeft<s)d.drifting=!0,a.scrollLeft-=g,g/=u;q(p,m,a.scrollLeft,a.scrollTop),j.animate(v)}else n("driftend",d.target),c(d)})},y=function(a){var b=a.data,c=b.target,d=b.start=g(a.target),e=b.flags;e.drifting=!1,d.is(b.options.cancelOn)||(a.preventDefault(),c.css("cursor",j.cursorGrabbing),c.data(i).dragging=e.dragging=e.dragged=!1,c.on(k.drag,b,w),b.position=p(a,{}),b.capture=p(a,{},l.captureThreshold),n("dragstart",c))},z=function(a){var b=a.data,c=b.target,d=b.options,e=b.flags,f=b.thumbs,g=function(){f&&!d.hoverThumbs&&r(f,d,!1)};c.unbind(k.drag,w),b.position&&(n("dragend",c),e.dragging?x(this,a,g):g()),e.dragging&&b.start.is(a.target)&&s(b.start),c.data(i).dragging=b.start=b.capture=b.position=e.dragged=e.dragging=!1,c.css("cursor",j.cursorGrab)},A=function(a){return a=g.extend({},m,a),a.direction!=="multi"&&a.direction!==a.wheelDirection&&(a.wheelDirection=a.direction),a.scrollDelta=c.abs(a.scrollDelta),a.wheelDelta=c.abs(a.wheelDelta),a.scrollLeft=a.scrollLeft===h?null:c.abs(a.scrollLeft),a.scrollTop=a.scrollTop===h?null:c.abs(a.scrollTop),a},B=function(a){var b=g(a),c=b.width(),d=b.height(),e=c>=a.scrollWidth?c:a.scrollWidth,f=d>=a.scrollHeight?d:a.scrollHeight;return{container:{width:c,height:d,scrollWidth:e,scrollHeight:f},thumbs:{horizontal:{width:c*c/e,height:l.thumbThickness,corner:l.thumbThickness/2,left:0,top:d-l.thumbThickness},vertical:{width:l.thumbThickness,height:d*d/f,corner:l.thumbThickness/2,left:c-l.thumbThickness,top:0}}}},C=function(a,b){var c=g(a),d,e=c.data(i)||{},f=c.attr("style"),h=b?function(){e=c.data(i),d=e.thumbs,f?c.attr("style",f):c.removeAttr("style"),d&&(d.horizontal&&d.horizontal.remove(),d.vertical&&d.vertical.remove()),c.removeData(i).off(k.wheel,v).off(k.start,y).off(k.end,z).off(k.ignored,!1)}:g.noop;return g.isFunction(e.remover)?e.remover:h},D=function(a,b){return{position:"absolute",opacity:b.persistThumbs?l.thumbOpacity:0,"background-color":"black",width:a.width+"px",height:a.height+"px","border-radius":a.corner+"px",margin:a.top+"px 0 0 "+a.left+"px","z-index":b.zIndex}},E=function(a,b,c){var d="<div/>",e={},f=!1;return b.container.scrollWidth>0&&c.direction!=="vertical"&&(f=D(b.thumbs.horizontal,c),e.horizontal=g(d).css(f).prependTo(a)),b.container.scrollHeight>0&&c.direction!=="horizontal"&&(f=D(b.thumbs.vertical,c),e.vertical=g(d).css(f).prependTo(a)),e.added=!!f,e},F=function(a,b){var c,d,e={flags:{dragging:!1},options:b=A(b),remover:C(a,!0),sizing:d=B(a)};e.target=a=g(a).css({position:"relative",overflow:"hidden",cursor:j.cursorGrab}).on(k.wheel,e,v).on(k.start,e,y).on(k.end,e,z).on(k.scroll,e,u).on(k.ignored,!1),b.scrollLeft!==null&&a.scrollLeft(b.scrollLeft),b.scrollTop!==null&&a.scrollTop(b.scrollTop),b.showThumbs&&(e.thumbs=c=E(a,d,b),c.added&&(q(c,d,a.scrollLeft(),a.scrollTop()),b.hoverThumbs&&a.on(k.hover,e,t))),a.data(i,e)},G=function(a){C(a)()},H=function(a){return this.removeOverscroll().each(function(){F(this,a)})},I=function(a){return this.removeOverscroll().each(function(){g(this).data(i,{remover:C(this)}).css(j.overflowScrolling,"touch").css("overflow","auto")})},J=function(){return this.each(function(){G(this)})};H.settings=l,g.extend(f,{overscroll:j.overflowScrolling?I:H,removeOverscroll:J})})(window,document,Math,setTimeout,clearTimeout,jQuery.fn,jQuery);

0 comments on commit 67812cf

Please sign in to comment.