diff --git a/jquery.scraggable.js b/jquery.scraggable.js index 7788352..3054473 100644 --- a/jquery.scraggable.js +++ b/jquery.scraggable.js @@ -1,3 +1,14 @@ +/* + jQuery.Scraggable 0.1.0 + + Enables single- and multi-dimensional (depending on browser) + element dragging through the mouse's scroll wheel. For all details + and documentation: https://github.com/borbit/jquery.scraggable + + Copyright (c) 2011-2013 Serge Borbit + + Licensed under the MIT license +*/ (function($, undefined) { $.fn.scraggable = function(options) { @@ -135,8 +146,8 @@ Scraggable.prototype.fixOffset = function(newOffset) { }; Scraggable.prototype.setPosition = function(newOffset) { - var diffTop = newOffset.top - this.offset.top; - var diffLeft = newOffset.left - this.offset.left; + var diffTop = ~~(newOffset.top - this.offset.top); + var diffLeft = ~~(newOffset.left - this.offset.left); if (!this.options.axis || this.options.axis == 'x') { this.position.left += (this.options.inverted ? diffTop : diffLeft); diff --git a/jquery.scraggable.min.js b/jquery.scraggable.min.js index 218ff4c..d5bd67f 100644 --- a/jquery.scraggable.min.js +++ b/jquery.scraggable.min.js @@ -1,9 +1,20 @@ +/* + jQuery.Scraggable 0.1.0 + + Enables single- and multi-dimensional (depending on browser) + element dragging through the mouse's scroll wheel. For all details + and documentation: https://github.com/borbit/jquery.scraggable + + Copyright (c) 2011-2013 Serge Borbit + + Licensed under the MIT license +*/ (function(b,e){function c(a,c){this.element=a;this.options=c;this.enabled=!0;this.dragStarted=!1;this.stopTimer=null;"object"==typeof this.options.parent&&this.options.parent.jquery!==e&&(this.parent=this.options.parent);"object"==typeof this.options.parent&&this.options.parent.tagName!==e&&(this.parent=b(this.options.parent));"string"==typeof this.options.parent&&(this.parent=b(this.options.parent));!1==this.options.parent&&(this.parent=this.element.parent());var d=this;this.onmousewheel=function(a){d.dragStarted|| -d.updateLocation();d.processMouseWheel(a);a.preventDefault?a.preventDefault():a.returnValue=false};this.scaleFactor=2;!~navigator.userAgent.indexOf("Chrome")&&~navigator.userAgent.indexOf("Safari/532.0")?this.scaleFactor=1200:~navigator.userAgent.indexOf("Safari")&&(this.scaleFactor=60);this.updateLocation();this.enableWheelHandling()}b.fn.scraggable=function(a){return this.each(function(){var f=b(this),d=f.data("scraggable");"string"==typeof a&&d&&b.isFunction(b.fn.scraggable.methods[a])?b.fn.scraggable.methods[a].apply(d): +d.updateLocation();d.processMouseWheel(a);a.preventDefault?a.preventDefault():a.returnValue=!1};this.scaleFactor=2;!~navigator.userAgent.indexOf("Chrome")&&~navigator.userAgent.indexOf("Safari/532.0")?this.scaleFactor=1200:~navigator.userAgent.indexOf("Safari")&&(this.scaleFactor=60);this.updateLocation();this.enableWheelHandling()}b.fn.scraggable=function(a){return this.each(function(){var f=b(this),d=f.data("scraggable");"string"==typeof a&&d&&b.isFunction(b.fn.scraggable.methods[a])?b.fn.scraggable.methods[a].apply(d): d||(a=b.extend({},b.fn.scraggable.defaults,a),f.data(new c(f,a)))})};b.fn.scraggable.methods={enable:function(){this.enableWheelHandling()},disable:function(){this.disableWheelHandling()}};b.fn.scraggable.defaults={axis:!1,parent:!1,sensitivity:5,inverted:!1,containment:!1};c.prototype.updateLocation=function(){this.width=this.element.outerWidth();this.height=this.element.outerHeight();this.originalPosition=this.element.position();this.position=this.element.position();this.offset=this.element.offset(); this.bounds=this.getBounds()};c.prototype.enableWheelHandling=function(){this.parent.get(0).addEventListener&&(this.parent.get(0).addEventListener("mousewheel",this.onmousewheel,!1),this.parent.get(0).addEventListener("DOMMouseScroll",this.onmousewheel,!1))};c.prototype.disableWheelHandling=function(){this.parent.get(0).removeEventListener&&(this.parent.get(0).removeEventListener("mousewheel",this.onmousewheel,!1),this.parent.get(0).removeEventListener("DOMMouseScroll",this.onmousewheel,!1))};c.prototype.processMouseWheel= function(a){a=this.getWheelDelta(a);a={left:this.offset.left+a[0]*this.options.sensitivity,top:this.offset.top+a[1]*this.options.sensitivity};this.bounds&&(a=this.fixOffset(a));this.setPosition(a)};c.prototype.fixOffset=function(a){a.leftthis.bounds.right&&(a.left=this.bounds.right-this.width);a.topthis.bounds.bottom&&(a.top=this.bounds.bottom-this.height);return a};c.prototype.setPosition= -function(a){var b=a.top-this.offset.top,c=a.left-this.offset.left;if(!this.options.axis||"x"==this.options.axis)this.position.left+=this.options.inverted?b:c;if(!this.options.axis||"y"==this.options.axis)this.position.top+=this.options.inverted?c:b;this.element.css({top:this.position.top,left:this.position.left});this.offset=a;var g={position:this.position,originalPosition:this.originalPosition};this.dragStarted||(this.element.trigger("dragstart",g),this.dragStarted=!0);this.element.trigger("drag", -g);this.stopTimer&&clearTimeout(this.stopTimer);var e=this;this.stopTimer=setTimeout(function(){e.element.trigger("dragstop",g);e.dragStarted=false},100)};c.prototype.getWheelDelta=function(a){if(null!=a.axis){if(a.axis==a.HORIZONTAL_AXIS)return[-a.detail/this.scaleFactor,0];if(a.axis==a.VERTICAL_AXIS)return[0,-a.detail/this.scaleFactor]}return null!=a.wheelDeltaX&&null!=a.wheelDeltaY?[a.wheelDeltaX/this.scaleFactor,a.wheelDeltaY/this.scaleFactor]:null!=a.detail&&null==a.axis?[0,-a.detail/this.scaleFactor]: +function(a){var b=~~(a.top-this.offset.top),c=~~(a.left-this.offset.left);if(!this.options.axis||"x"==this.options.axis)this.position.left+=this.options.inverted?b:c;if(!this.options.axis||"y"==this.options.axis)this.position.top+=this.options.inverted?c:b;this.element.css({top:this.position.top,left:this.position.left});this.offset=a;var g={position:this.position,originalPosition:this.originalPosition};this.dragStarted||(this.element.trigger("dragstart",g),this.dragStarted=!0);this.element.trigger("drag", +g);this.stopTimer&&clearTimeout(this.stopTimer);var e=this;this.stopTimer=setTimeout(function(){e.element.trigger("dragstop",g);e.dragStarted=!1},100)};c.prototype.getWheelDelta=function(a){if(null!=a.axis){if(a.axis==a.HORIZONTAL_AXIS)return[-a.detail/this.scaleFactor,0];if(a.axis==a.VERTICAL_AXIS)return[0,-a.detail/this.scaleFactor]}return null!=a.wheelDeltaX&&null!=a.wheelDeltaY?[a.wheelDeltaX/this.scaleFactor,a.wheelDeltaY/this.scaleFactor]:null!=a.detail&&null==a.axis?[0,-a.detail/this.scaleFactor]: [0,0]};c.prototype.getBounds=function(){if("document"==this.options.containment)return{left:0,top:0,right:this.parent.width(),bottom:this.parent.height()};if("parent"==this.options.containment){var a=this.parent.offset();return{left:a.left,top:a.top,right:a.left+this.parent.outerWidth(),bottom:a.top+this.parent.outerHeight()}}return b.isArray(this.options.containment)?{left:this.options.containment[0],top:this.options.containment[1],right:this.options.containment[2],bottom:this.options.containment[3]}: !1}})(jQuery); \ No newline at end of file diff --git a/scraggable.jquery.json b/scraggable.jquery.json new file mode 100644 index 0000000..c692441 --- /dev/null +++ b/scraggable.jquery.json @@ -0,0 +1,30 @@ +{ + "name": "scraggable", + "title": "jQuery Scraggable", + "description": "Enables single- and multi-dimensional (depending on browser) element dragging through the mouse's scroll wheel.", + "keywords": [ + "ui", + "drag", + "scroll" + ], + "version": "0.1.0", + "author": { + "name": "Serge Borbit", + "email": "serge.borbit@gmail.com", + "url": "https://github.com/borbit" + }, + "licenses": [ + { + "type": "MIT", + "url": "http://en.wikipedia.org/wiki/MIT_License#License_terms" + } + ], + "dependencies": { + "jquery": ">=1.4.3" + }, + "bugs": "https://github.com/borbit/jquery.scraggable/issues", + "homepage": "https://github.com/borbit/jquery.scraggable", + "download": "https://github.com/borbit/jquery.scraggable", + "demo": "http://borbit.github.com/jquery.viewport/", + "docs": "https://github.com/borbit/jquery.scraggable" +} \ No newline at end of file