From 0c41aad1f9aa03ff7ecea4127f8bbd6b30056d32 Mon Sep 17 00:00:00 2001 From: tsaikd Date: Sat, 8 Aug 2015 16:05:48 +0800 Subject: [PATCH 1/5] use _getScroller() in _move() Signed-off-by: tsaikd --- jquery.kinetic.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jquery.kinetic.js b/jquery.kinetic.js index 4f82667..4867ad9 100644 --- a/jquery.kinetic.js +++ b/jquery.kinetic.js @@ -375,8 +375,8 @@ // do the actual kinetic movement Kinetic.prototype._move = function (){ - var $scroller = this.$el; - var scroller = this.el; + var $scroller = this._getScroller(); + var scroller = $scroller[0]; var self = this; var settings = self.settings; From 739e68a9a826dd1e3fbeb4c193528235fcdd4d2b Mon Sep 17 00:00:00 2001 From: tsaikd Date: Sat, 8 Aug 2015 16:38:28 +0800 Subject: [PATCH 2/5] add invert option Signed-off-by: tsaikd --- jquery.kinetic.js | 9 +++++++++ readme.mkd | 1 + test/specs/basic.spec.js | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/jquery.kinetic.js b/jquery.kinetic.js index 4867ad9..ba19160 100644 --- a/jquery.kinetic.js +++ b/jquery.kinetic.js @@ -64,6 +64,7 @@ slowdown: 0.9, maxvelocity: 40, throttleFPS: 60, + invert: false, movingClass: { up: 'kinetic-moving-up', down: 'kinetic-moving-down', @@ -243,6 +244,10 @@ if (this.mouseDown && (this.xpos || this.ypos)){ var movedX = (clientX - this.xpos); var movedY = (clientY - this.ypos); + if (this.settings.invert) { + movedX *= -1; + movedY *= -1; + } if(this.threshold > 0){ var moved = Math.sqrt(movedX * movedX + movedY * movedY); if(this.threshold > moved){ @@ -284,6 +289,10 @@ Kinetic.prototype._calculateVelocities = function (){ this.velocity = this._capVelocity(this.prevXPos - this.xpos, this.settings.maxvelocity); this.velocityY = this._capVelocity(this.prevYPos - this.ypos, this.settings.maxvelocity); + if (this.settings.invert) { + this.velocity *= -1; + this.velocityY *= -1; + } }; Kinetic.prototype._end = function (){ diff --git a/readme.mkd b/readme.mkd index 427d15f..a68f0cf 100644 --- a/readme.mkd +++ b/readme.mkd @@ -71,6 +71,7 @@ $('#wrapper').kinetic({ performance when scrolling triggerHardware {boolean} false This adds css to the wrapper which will trigger iOS to use hardware acceleration + invert {boolean} default: false Invert movement direction filterTarget {function(target)} Return false from this function to prevent capturing the scroll diff --git a/test/specs/basic.spec.js b/test/specs/basic.spec.js index 480727a..44252ce 100644 --- a/test/specs/basic.spec.js +++ b/test/specs/basic.spec.js @@ -186,3 +186,21 @@ test('we can stay within the threshold', function(){ equal(count > 0, false, 'image has not moved'); equal(self.threshold, 50, 'threshold = 50'); }); +test('we can pass the invert option', function(){ + var $wrapper = $('#wrapper').kinetic({ + invert: true, + moved: function(){ + count++; + if (this.velocity > 0) { + countVelocityPositive++; + } + } + }), + img = $wrapper.find('img')[0], + count = 0, + countVelocityPositive = 0, + self = $wrapper.data().kinetic; + dragOver($wrapper, img, [100,100], [131,141]); + equal(count > 0, true, 'image has moved'); + equal(countVelocityPositive > 0, true, 'velocity positive'); +}); From f0bc35605c6e1ce8a226a5c9bba3c4a2f7824a79 Mon Sep 17 00:00:00 2001 From: tsaikd Date: Sat, 8 Aug 2015 17:20:28 +0800 Subject: [PATCH 3/5] move selectStart to _initEvents and test with _useTarget Signed-off-by: tsaikd --- jquery.kinetic.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/jquery.kinetic.js b/jquery.kinetic.js index ba19160..e6716ea 100644 --- a/jquery.kinetic.js +++ b/jquery.kinetic.js @@ -35,9 +35,6 @@ $.extend($.support, { touch: 'ontouchend' in document }); - var selectStart = function (){ - return false; - }; // KINETIC CLASS DEFINITION @@ -227,6 +224,12 @@ if (self._useTarget(e.target, e) && self.elementFocused){ return false; } + }, + // prevent selection when dragging + selectStart: function (e){ + if (self._useTarget(e.target, e)){ + return false; + } } }; @@ -479,7 +482,7 @@ $this .click(settings.events.inputClick) .scroll(settings.events.scroll) - .bind('selectstart', selectStart) // prevent selection when dragging + .bind('selectstart', settings.events.selectStart) .bind('dragstart', settings.events.dragStart); }; @@ -501,7 +504,7 @@ $this .unbind('click', settings.events.inputClick) .unbind('scroll', settings.events.scroll) - .unbind('selectstart', selectStart) // prevent selection when dragging + .unbind('selectstart', settings.events.selectStart) .unbind('dragstart', settings.events.dragStart); }; From 99c179503b24ee34c4a331142fd8330ea53d4fca Mon Sep 17 00:00:00 2001 From: tsaikd Date: Sun, 9 Aug 2015 17:57:43 +0800 Subject: [PATCH 4/5] add option selectStart for customization Signed-off-by: tsaikd --- jquery.kinetic.js | 5 +++-- readme.mkd | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/jquery.kinetic.js b/jquery.kinetic.js index e6716ea..a00a701 100644 --- a/jquery.kinetic.js +++ b/jquery.kinetic.js @@ -227,9 +227,10 @@ }, // prevent selection when dragging selectStart: function (e){ - if (self._useTarget(e.target, e)){ - return false; + if ($.isFunction(self.settings.selectStart)){ + return self.settings.selectStart.apply(self, arguments); } + return false; } }; diff --git a/readme.mkd b/readme.mkd index a68f0cf..3c50334 100644 --- a/readme.mkd +++ b/readme.mkd @@ -94,6 +94,8 @@ $('#wrapper').kinetic({ moved {function()} A function which is called on every move stopped {function()} A function which is called once all movement has stopped + selectStart {function()} A function which is called on user try to drag (select text), + return false to prevent selection when dragging Methods: You can call methods by running the kinetic plugin on an element which has already been activated. From 6ff19d351325306c1a2852a17be1ba87db17d82a Mon Sep 17 00:00:00 2001 From: davetayls Date: Wed, 9 Sep 2015 10:00:23 +0100 Subject: [PATCH 5/5] Release v2.2.0 --- bower.json | 2 +- jquery.kinetic.js | 7 +++++-- jquery.kinetic.min.js | 4 ++-- package.json | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/bower.json b/bower.json index f0498ec..2373cee 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "jquery.kinetic", "main": "jquery.kinetic.js", - "version": "2.1.1", + "version": "2.2.0", "homepage": "http://davetayls.me/jquery.kinetic", "authors": [ "davetayls " diff --git a/jquery.kinetic.js b/jquery.kinetic.js index a00a701..c4378f5 100644 --- a/jquery.kinetic.js +++ b/jquery.kinetic.js @@ -1,5 +1,5 @@ /** - jQuery.kinetic v2.1.1 + jQuery.kinetic v2.2.0 Dave Taylor http://davetayls.me @license The MIT License (MIT) @@ -229,8 +229,11 @@ selectStart: function (e){ if ($.isFunction(self.settings.selectStart)){ return self.settings.selectStart.apply(self, arguments); + } else if (self._useTarget(e.target, e)) { + return false; + } else { + return false; } - return false; } }; diff --git a/jquery.kinetic.min.js b/jquery.kinetic.min.js index 1a5cef2..deac71a 100644 --- a/jquery.kinetic.min.js +++ b/jquery.kinetic.min.js @@ -1,3 +1,3 @@ -/*! jquery.kinetic - v2.1.1 - 2015-07-20 http://the-taylors.org/jquery.kinetic +/*! jquery.kinetic - v2.2.0 - 2015-09-09 http://the-taylors.org/jquery.kinetic * Copyright (c) 2015 Dave Taylor; Licensed MIT */ -!function(a){"use strict";var b="kinetic-active";window.requestAnimationFrame||(window.requestAnimationFrame=function(){return window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(a,1e3/60)}}()),a.support=a.support||{},a.extend(a.support,{touch:"ontouchend"in document});var c=function(){return!1},d=function(b,c){return this.settings=c,this.el=b,this.$el=a(b),this._initElements(),this};d.DATA_KEY="kinetic",d.DEFAULTS={cursor:"move",decelerate:!0,triggerHardware:!1,threshold:0,y:!0,x:!0,slowdown:.9,maxvelocity:40,throttleFPS:60,movingClass:{up:"kinetic-moving-up",down:"kinetic-moving-down",left:"kinetic-moving-left",right:"kinetic-moving-right"},deceleratingClass:{up:"kinetic-decelerating-up",down:"kinetic-decelerating-down",left:"kinetic-decelerating-left",right:"kinetic-decelerating-right"}},d.prototype.start=function(b){this.settings=a.extend(this.settings,b),this.velocity=b.velocity||this.velocity,this.velocityY=b.velocityY||this.velocityY,this.settings.decelerate=!1,this._move()},d.prototype.end=function(){this.settings.decelerate=!0},d.prototype.stop=function(){this.velocity=0,this.velocityY=0,this.settings.decelerate=!0,a.isFunction(this.settings.stopped)&&this.settings.stopped.call(this)},d.prototype.detach=function(){this._detachListeners(),this.$el.removeClass(b).css("cursor","")},d.prototype.attach=function(){this.$el.hasClass(b)||(this._attachListeners(this.$el),this.$el.addClass(b).css("cursor",this.settings.cursor))},d.prototype._initElements=function(){this.$el.addClass(b),a.extend(this,{xpos:null,prevXPos:!1,ypos:null,prevYPos:!1,mouseDown:!1,throttleTimeout:1e3/this.settings.throttleFPS,lastMove:null,elementFocused:null}),this.velocity=0,this.velocityY=0,a(document).mouseup(a.proxy(this._resetMouse,this)).click(a.proxy(this._resetMouse,this)),this._initEvents(),this.$el.css("cursor",this.settings.cursor),this.settings.triggerHardware&&this.$el.css({"-webkit-transform":"translate3d(0,0,0)","-webkit-perspective":"1000","-webkit-backface-visibility":"hidden"})},d.prototype._initEvents=function(){var b=this;this.settings.events={touchStart:function(a){var c;b._useTarget(a.target,a)&&(c=a.originalEvent.touches[0],b.threshold=b._threshold(a.target,a),b._start(c.clientX,c.clientY),a.stopPropagation())},touchMove:function(a){var c;b.mouseDown&&(c=a.originalEvent.touches[0],b._inputmove(c.clientX,c.clientY),a.preventDefault&&a.preventDefault())},inputDown:function(a){b._useTarget(a.target,a)&&(b.threshold=b._threshold(a.target,a),b._start(a.clientX,a.clientY),b.elementFocused=a.target,"IMG"===a.target.nodeName&&a.preventDefault(),a.stopPropagation())},inputEnd:function(a){b._useTarget(a.target,a)&&(b._end(),b.elementFocused=null,a.preventDefault&&a.preventDefault())},inputMove:function(a){b.mouseDown&&(b._inputmove(a.clientX,a.clientY),a.preventDefault&&a.preventDefault())},scroll:function(c){a.isFunction(b.settings.moved)&&b.settings.moved.call(b,b.settings),c.preventDefault&&c.preventDefault()},inputClick:function(a){return Math.abs(b.velocity)>0?(a.preventDefault(),!1):void 0},dragStart:function(a){return b._useTarget(a.target,a)&&b.elementFocused?!1:void 0}},this._attachListeners(this.$el,this.settings)},d.prototype._inputmove=function(b,c){{var d=this.$el;this.el}if((!this.lastMove||new Date>new Date(this.lastMove.getTime()+this.throttleTimeout))&&(this.lastMove=new Date,this.mouseDown&&(this.xpos||this.ypos))){var e=b-this.xpos,f=c-this.ypos;if(this.threshold>0){var g=Math.sqrt(e*e+f*f);if(this.threshold>g)return;this.threshold=0}this.elementFocused&&(a(this.elementFocused).blur(),this.elementFocused=null,d.focus()),this.settings.decelerate=!1,this.velocity=this.velocityY=0;var h=this.scrollLeft(),i=this.scrollTop();this.scrollLeft(this.settings.x?h-e:h),this.scrollTop(this.settings.y?i-f:i),this.prevXPos=this.xpos,this.prevYPos=this.ypos,this.xpos=b,this.ypos=c,this._calculateVelocities(),this._setMoveClasses(this.settings.movingClass),a.isFunction(this.settings.moved)&&this.settings.moved.call(this,this.settings)}},d.prototype._calculateVelocities=function(){this.velocity=this._capVelocity(this.prevXPos-this.xpos,this.settings.maxvelocity),this.velocityY=this._capVelocity(this.prevYPos-this.ypos,this.settings.maxvelocity)},d.prototype._end=function(){this.xpos&&this.prevXPos&&this.settings.decelerate===!1&&(this.settings.decelerate=!0,this._calculateVelocities(),this.xpos=this.prevXPos=this.mouseDown=!1,this._move())},d.prototype._useTarget=function(b,c){return a.isFunction(this.settings.filterTarget)?this.settings.filterTarget.call(this,b,c)!==!1:!0},d.prototype._threshold=function(b,c){return a.isFunction(this.settings.threshold)?this.settings.threshold.call(this,b,c):this.settings.threshold},d.prototype._start=function(a,b){this.mouseDown=!0,this.velocity=this.prevXPos=0,this.velocityY=this.prevYPos=0,this.xpos=a,this.ypos=b},d.prototype._resetMouse=function(){this.xpos=!1,this.ypos=!1,this.mouseDown=!1},d.prototype._decelerateVelocity=function(a,b){return 0===Math.floor(Math.abs(a))?0:a*b},d.prototype._capVelocity=function(a,b){var c=a;return a>0?a>b&&(c=b):0-b>a&&(c=0-b),c},d.prototype._setMoveClasses=function(a){var b=this.settings,c=this.$el;c.removeClass(b.movingClass.up).removeClass(b.movingClass.down).removeClass(b.movingClass.left).removeClass(b.movingClass.right).removeClass(b.deceleratingClass.up).removeClass(b.deceleratingClass.down).removeClass(b.deceleratingClass.left).removeClass(b.deceleratingClass.right),this.velocity>0&&c.addClass(a.right),this.velocity<0&&c.addClass(a.left),this.velocityY>0&&c.addClass(a.down),this.velocityY<0&&c.addClass(a.up)},d.prototype._move=function(){var b=(this.$el,this.el),c=this,d=c.settings;d.x&&b.scrollWidth>0?(this.scrollLeft(this.scrollLeft()+this.velocity),Math.abs(this.velocity)>0&&(this.velocity=d.decelerate?c._decelerateVelocity(this.velocity,d.slowdown):this.velocity)):this.velocity=0,d.y&&b.scrollHeight>0?(this.scrollTop(this.scrollTop()+this.velocityY),Math.abs(this.velocityY)>0&&(this.velocityY=d.decelerate?c._decelerateVelocity(this.velocityY,d.slowdown):this.velocityY)):this.velocityY=0,c._setMoveClasses(d.deceleratingClass),a.isFunction(d.moved)&&d.moved.call(this,d),Math.abs(this.velocity)>0||Math.abs(this.velocityY)>0?this.moving||(this.moving=!0,window.requestAnimationFrame(function(){c.moving=!1,c._move()})):c.stop()},d.prototype._getScroller=function(){var b=this.$el;return(this.$el.is("body")||this.$el.is("html"))&&(b=a(window)),b},d.prototype.scrollLeft=function(a){var b=this._getScroller();return"number"!=typeof a?b.scrollLeft():(b.scrollLeft(a),void(this.settings.scrollLeft=a))},d.prototype.scrollTop=function(a){var b=this._getScroller();return"number"!=typeof a?b.scrollTop():(b.scrollTop(a),void(this.settings.scrollTop=a))},d.prototype._attachListeners=function(){var b=this.$el,d=this.settings;a.support.touch&&b.bind("touchstart",d.events.touchStart).bind("touchend",d.events.inputEnd).bind("touchmove",d.events.touchMove),b.mousedown(d.events.inputDown).mouseup(d.events.inputEnd).mousemove(d.events.inputMove),b.click(d.events.inputClick).scroll(d.events.scroll).bind("selectstart",c).bind("dragstart",d.events.dragStart)},d.prototype._detachListeners=function(){var b=this.$el,d=this.settings;a.support.touch&&b.unbind("touchstart",d.events.touchStart).unbind("touchend",d.events.inputEnd).unbind("touchmove",d.events.touchMove),b.unbind("mousedown",d.events.inputDown).unbind("mouseup",d.events.inputEnd).unbind("mousemove",d.events.inputMove),b.unbind("click",d.events.inputClick).unbind("scroll",d.events.scroll).unbind("selectstart",c).unbind("dragstart",d.events.dragStart)},a.Kinetic=d,a.fn.kinetic=function(b,c){return this.each(function(){var e=a(this),f=e.data(d.DATA_KEY),g=a.extend({},d.DEFAULTS,e.data(),"object"==typeof b&&b);f||e.data(d.DATA_KEY,f=new d(this,g)),"string"==typeof b&&f[b](c)})}}(window.jQuery||window.Zepto); \ No newline at end of file +!function(a){"use strict";var b="kinetic-active";window.requestAnimationFrame||(window.requestAnimationFrame=function(){return window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(a,1e3/60)}}()),a.support=a.support||{},a.extend(a.support,{touch:"ontouchend"in document});var c=function(b,c){return this.settings=c,this.el=b,this.$el=a(b),this._initElements(),this};c.DATA_KEY="kinetic",c.DEFAULTS={cursor:"move",decelerate:!0,triggerHardware:!1,threshold:0,y:!0,x:!0,slowdown:.9,maxvelocity:40,throttleFPS:60,invert:!1,movingClass:{up:"kinetic-moving-up",down:"kinetic-moving-down",left:"kinetic-moving-left",right:"kinetic-moving-right"},deceleratingClass:{up:"kinetic-decelerating-up",down:"kinetic-decelerating-down",left:"kinetic-decelerating-left",right:"kinetic-decelerating-right"}},c.prototype.start=function(b){this.settings=a.extend(this.settings,b),this.velocity=b.velocity||this.velocity,this.velocityY=b.velocityY||this.velocityY,this.settings.decelerate=!1,this._move()},c.prototype.end=function(){this.settings.decelerate=!0},c.prototype.stop=function(){this.velocity=0,this.velocityY=0,this.settings.decelerate=!0,a.isFunction(this.settings.stopped)&&this.settings.stopped.call(this)},c.prototype.detach=function(){this._detachListeners(),this.$el.removeClass(b).css("cursor","")},c.prototype.attach=function(){this.$el.hasClass(b)||(this._attachListeners(this.$el),this.$el.addClass(b).css("cursor",this.settings.cursor))},c.prototype._initElements=function(){this.$el.addClass(b),a.extend(this,{xpos:null,prevXPos:!1,ypos:null,prevYPos:!1,mouseDown:!1,throttleTimeout:1e3/this.settings.throttleFPS,lastMove:null,elementFocused:null}),this.velocity=0,this.velocityY=0,a(document).mouseup(a.proxy(this._resetMouse,this)).click(a.proxy(this._resetMouse,this)),this._initEvents(),this.$el.css("cursor",this.settings.cursor),this.settings.triggerHardware&&this.$el.css({"-webkit-transform":"translate3d(0,0,0)","-webkit-perspective":"1000","-webkit-backface-visibility":"hidden"})},c.prototype._initEvents=function(){var b=this;this.settings.events={touchStart:function(a){var c;b._useTarget(a.target,a)&&(c=a.originalEvent.touches[0],b.threshold=b._threshold(a.target,a),b._start(c.clientX,c.clientY),a.stopPropagation())},touchMove:function(a){var c;b.mouseDown&&(c=a.originalEvent.touches[0],b._inputmove(c.clientX,c.clientY),a.preventDefault&&a.preventDefault())},inputDown:function(a){b._useTarget(a.target,a)&&(b.threshold=b._threshold(a.target,a),b._start(a.clientX,a.clientY),b.elementFocused=a.target,"IMG"===a.target.nodeName&&a.preventDefault(),a.stopPropagation())},inputEnd:function(a){b._useTarget(a.target,a)&&(b._end(),b.elementFocused=null,a.preventDefault&&a.preventDefault())},inputMove:function(a){b.mouseDown&&(b._inputmove(a.clientX,a.clientY),a.preventDefault&&a.preventDefault())},scroll:function(c){a.isFunction(b.settings.moved)&&b.settings.moved.call(b,b.settings),c.preventDefault&&c.preventDefault()},inputClick:function(a){return Math.abs(b.velocity)>0?(a.preventDefault(),!1):void 0},dragStart:function(a){return b._useTarget(a.target,a)&&b.elementFocused?!1:void 0},selectStart:function(c){return a.isFunction(b.settings.selectStart)?b.settings.selectStart.apply(b,arguments):b._useTarget(c.target,c)?!1:!1}},this._attachListeners(this.$el,this.settings)},c.prototype._inputmove=function(b,c){{var d=this.$el;this.el}if((!this.lastMove||new Date>new Date(this.lastMove.getTime()+this.throttleTimeout))&&(this.lastMove=new Date,this.mouseDown&&(this.xpos||this.ypos))){var e=b-this.xpos,f=c-this.ypos;if(this.settings.invert&&(e*=-1,f*=-1),this.threshold>0){var g=Math.sqrt(e*e+f*f);if(this.threshold>g)return;this.threshold=0}this.elementFocused&&(a(this.elementFocused).blur(),this.elementFocused=null,d.focus()),this.settings.decelerate=!1,this.velocity=this.velocityY=0;var h=this.scrollLeft(),i=this.scrollTop();this.scrollLeft(this.settings.x?h-e:h),this.scrollTop(this.settings.y?i-f:i),this.prevXPos=this.xpos,this.prevYPos=this.ypos,this.xpos=b,this.ypos=c,this._calculateVelocities(),this._setMoveClasses(this.settings.movingClass),a.isFunction(this.settings.moved)&&this.settings.moved.call(this,this.settings)}},c.prototype._calculateVelocities=function(){this.velocity=this._capVelocity(this.prevXPos-this.xpos,this.settings.maxvelocity),this.velocityY=this._capVelocity(this.prevYPos-this.ypos,this.settings.maxvelocity),this.settings.invert&&(this.velocity*=-1,this.velocityY*=-1)},c.prototype._end=function(){this.xpos&&this.prevXPos&&this.settings.decelerate===!1&&(this.settings.decelerate=!0,this._calculateVelocities(),this.xpos=this.prevXPos=this.mouseDown=!1,this._move())},c.prototype._useTarget=function(b,c){return a.isFunction(this.settings.filterTarget)?this.settings.filterTarget.call(this,b,c)!==!1:!0},c.prototype._threshold=function(b,c){return a.isFunction(this.settings.threshold)?this.settings.threshold.call(this,b,c):this.settings.threshold},c.prototype._start=function(a,b){this.mouseDown=!0,this.velocity=this.prevXPos=0,this.velocityY=this.prevYPos=0,this.xpos=a,this.ypos=b},c.prototype._resetMouse=function(){this.xpos=!1,this.ypos=!1,this.mouseDown=!1},c.prototype._decelerateVelocity=function(a,b){return 0===Math.floor(Math.abs(a))?0:a*b},c.prototype._capVelocity=function(a,b){var c=a;return a>0?a>b&&(c=b):0-b>a&&(c=0-b),c},c.prototype._setMoveClasses=function(a){var b=this.settings,c=this.$el;c.removeClass(b.movingClass.up).removeClass(b.movingClass.down).removeClass(b.movingClass.left).removeClass(b.movingClass.right).removeClass(b.deceleratingClass.up).removeClass(b.deceleratingClass.down).removeClass(b.deceleratingClass.left).removeClass(b.deceleratingClass.right),this.velocity>0&&c.addClass(a.right),this.velocity<0&&c.addClass(a.left),this.velocityY>0&&c.addClass(a.down),this.velocityY<0&&c.addClass(a.up)},c.prototype._move=function(){var b=this._getScroller(),c=b[0],d=this,e=d.settings;e.x&&c.scrollWidth>0?(this.scrollLeft(this.scrollLeft()+this.velocity),Math.abs(this.velocity)>0&&(this.velocity=e.decelerate?d._decelerateVelocity(this.velocity,e.slowdown):this.velocity)):this.velocity=0,e.y&&c.scrollHeight>0?(this.scrollTop(this.scrollTop()+this.velocityY),Math.abs(this.velocityY)>0&&(this.velocityY=e.decelerate?d._decelerateVelocity(this.velocityY,e.slowdown):this.velocityY)):this.velocityY=0,d._setMoveClasses(e.deceleratingClass),a.isFunction(e.moved)&&e.moved.call(this,e),Math.abs(this.velocity)>0||Math.abs(this.velocityY)>0?this.moving||(this.moving=!0,window.requestAnimationFrame(function(){d.moving=!1,d._move()})):d.stop()},c.prototype._getScroller=function(){var b=this.$el;return(this.$el.is("body")||this.$el.is("html"))&&(b=a(window)),b},c.prototype.scrollLeft=function(a){var b=this._getScroller();return"number"!=typeof a?b.scrollLeft():(b.scrollLeft(a),void(this.settings.scrollLeft=a))},c.prototype.scrollTop=function(a){var b=this._getScroller();return"number"!=typeof a?b.scrollTop():(b.scrollTop(a),void(this.settings.scrollTop=a))},c.prototype._attachListeners=function(){var b=this.$el,c=this.settings;a.support.touch&&b.bind("touchstart",c.events.touchStart).bind("touchend",c.events.inputEnd).bind("touchmove",c.events.touchMove),b.mousedown(c.events.inputDown).mouseup(c.events.inputEnd).mousemove(c.events.inputMove),b.click(c.events.inputClick).scroll(c.events.scroll).bind("selectstart",c.events.selectStart).bind("dragstart",c.events.dragStart)},c.prototype._detachListeners=function(){var b=this.$el,c=this.settings;a.support.touch&&b.unbind("touchstart",c.events.touchStart).unbind("touchend",c.events.inputEnd).unbind("touchmove",c.events.touchMove),b.unbind("mousedown",c.events.inputDown).unbind("mouseup",c.events.inputEnd).unbind("mousemove",c.events.inputMove),b.unbind("click",c.events.inputClick).unbind("scroll",c.events.scroll).unbind("selectstart",c.events.selectStart).unbind("dragstart",c.events.dragStart)},a.Kinetic=c,a.fn.kinetic=function(b,d){return this.each(function(){var e=a(this),f=e.data(c.DATA_KEY),g=a.extend({},c.DEFAULTS,e.data(),"object"==typeof b&&b);f||e.data(c.DATA_KEY,f=new c(this,g)),"string"==typeof b&&f[b](d)})}}(window.jQuery||window.Zepto); \ No newline at end of file diff --git a/package.json b/package.json index 1fa1fc5..737fb4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery.kinetic", - "version": "2.1.1", + "version": "2.2.0", "description": "adds smooth drag scrolling with gradual deceleration to containers", "homepage": "http://the-taylors.org/jquery.kinetic", "author": {