-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.draggy.min.js
1 lines (1 loc) · 9.3 KB
/
jquery.draggy.min.js
1
(function(a){"use strict";var b;b=function(){function b(b,c){this.target=b;this.jq_target=a(b).draggy("kill");this.options=c||{};this.setupDefaults();this.init()}b.prototype.setupDefaults=function(){this.CURSOR_DRAGGABLE="move";this.CURSOR_DRAGGING="move";this.options.z_index=999;this.options.draggability=this.options.draggability?this.options.draggability:"none";this.options.mousewheel=this.options.mousewheel?this.options.mousewheel:"none";this.options.arrowkeys=this.options.arrowkeys?this.options.arrowkeys:"none";this.options.scrolls=this.options.scrolls?this.options.scrolls:"auto"};b.prototype.init=function(){var b=this,c=10,d=function(a){b.keydown(a)},e=a("body").bind("keydown",d),f=function(a){b.mousedown(a)},g=this.jq_target.css({position:"relative"}).mousedown(f).data("draggy",this),h=function(a){b.scroll(a)},i=function(a,c,d,e){b.mousewheel(a,c,d,e)},j=g.parent().css({position:"relative",overflow:"hidden","overflow-x":"hidden","overflow-y":"hidden"}).bind("mousewheel",i).scroll(h),k=j.parent(),l=g.width(),m=g.height(),n=g.outerWidth(true),o=g.outerHeight(true),p=j.offset(),q=j.width(),r=j.height(),s=j.outerWidth(true),t=j.outerHeight(true),u=s-q,v=t-r,w=s<n,x=t<o,y,z,A,B,C,D,E,F,G,H,I,J,K,L=function(a){b.mousemoveDoc(a);return false},M=function(a){b.mouseupDoc(a);return false},N=a(document).mousemove(L).mouseup(M),O,P,Q,R,S,T;if(this.options.scrolls==="vertical"||this.options.scrolls==="both"){x=true}else if(this.options.scrolls==="horizontal"||this.options.scrolls==="none"){x=false}if(this.options.scrolls==="horizontal"||this.options.scrolls==="both"){w=true}else if(this.options.scrolls==="vertical"||this.options.scrolls==="none"){w=false}if(this.options.draggability==="horizontal"||this.options.draggability==="vertical"||this.options.draggability==="both"){g=this.jq_target.css({cursor:this.CURSOR_DRAGGABLE})}if(x){j.css({"float":"left"}).width(function(){return a(this).width()-c-2-2});n=g.outerWidth(true);o=g.outerHeight(true);p=j.offset();q=j.width();r=j.height();s=j.outerWidth(true);t=j.outerHeight(true);z=a("<div/>").addClass("__draggy").addClass("__vertical").addClass("__state_1").height(t-2).mouseover(function(a){return b.mouseoverScrollYContainer(a)}).mouseout(function(a){return b.mouseoutScrollYContainer(a)}).insertAfter(j);A=a("<br/>").css({clear:"both"}).insertAfter(z);G=z.offset();H=z.height();I=z.outerHeight(true);J=(o>t?t/o:1)*I-2;K=a("<div/>").mouseover(function(a){return b.mouseoverScrollY(a)}).mouseout(function(a){return b.mouseoutScrollY(a)}).mousedown(function(a){return b.mousedownScrollY(a)}).height(J).appendTo(z);R=K.outerHeight(true);S=K.offset();T=(I-R)/(o-r)}if(w){y=a("<div/>").addClass("__draggy").addClass("__horizontal").addClass("__state_1").width(s-2).mouseover(function(a){return b.mouseoverScrollContainer(a,true)}).mouseout(function(a){return b.mouseoutScrollContainer(a)});if(x){y.insertAfter(A)}else{y.insertAfter(j)}B=y.offset();C=y.width();D=y.outerWidth(true);E=(n>s?s/n:1)*C;F=a("<div/>").width(E).mouseover(function(a){return b.mouseoverScroll(a)}).mouseout(function(a){return b.mouseoutScroll(a)}).mousedown(function(a){return b.mousedownScroll(a)}).appendTo(y);O=F.outerWidth(true);P=F.offset();Q=(C-E)/(l-q)}this.jq_doc=N;this.jq_parent=j;this.jq_scroll_x=F;this.jq_scroll_y=K;this.jq_scroll_container_x=y;this.jq_scroll_container_y=z;this.displacement_factor_x=Q;this.displacement_factor_y=T;this.scroll_x_outer_width=O;this.container_x_outer_width=D;this.__mousedownTargetHandler=f;this.__scrollParentHandler=h;this.__mousewheelParentHandler=i;this.__mousemoveDocHandler=L;this.__mouseupDocHandler=M};b.prototype.mousedown=function(a){this.is_mouse_down=true;this.mouse_down_point={x:a.pageX,y:a.pageY};this.scroll_left=this.jq_parent.scrollLeft();this.scroll_top=this.jq_parent.scrollTop();if(this.options.draggability==="horizontal"||this.options.draggability==="vertical"||this.options.draggability==="both"){var b=this.jq_target.css({cursor:this.CURSOR_DRAGGING})}};b.prototype.mousewheel=function(a,b,c,d){var e=this.jq_parent,f=e.scrollLeft(),g=e.scrollTop();if(this.options.mousewheel==="horizontal"||this.options.mousewheel==="both"){e.scrollLeft(f+c*30)}if(this.options.mousewheel==="vertical"||this.options.mousewheel==="both"){e.scrollTop(g-d*30)}};b.prototype.mouseup=function(a){this.is_mouse_down=false;if(this.options.draggability==="horizontal"||this.options.draggability==="vertical"||this.options.draggability==="both"){var b=this.jq_target.css({cursor:this.CURSOR_DRAGGABLE})}};b.prototype.mousemove=function(a){var b=this.jq_parent,c=this.is_mouse_down,d=this.scroll_left,e=this.scroll_top,f=this.mouse_down_point,g,h,i,j;if(c){g={x:a.pageX,y:a.pageY};h={x:f.x-g.x,y:f.y-g.y};i=d+h.x;j=e+h.y;if(this.options.draggability==="horizontal"||this.options.draggability==="both"){b.scrollLeft(i)}if(this.options.draggability==="vertical"||this.options.draggability==="both"){b.scrollTop(j)}}};b.prototype.keydown=function(a){var b=this.jq_parent,c=a.which?a.which:a.keyCode,d=b.scrollTop(),e=b.scrollLeft(),f=10;if((c===37||c===39)&&(this.options.arrowkeys==="horizontal"||this.options.arrowkeys==="both")){b.scrollLeft(e+f*(c===37?-1:1))}if((c===38||c===40)&&(this.options.arrowkeys==="vertical"||this.options.arrowkeys==="both")){b.scrollTop(d+f*(c===38?-1:1))}};b.prototype.getStateClasses=function(a,b){return(b.match(/\b__state_\d{1}/g)||[]).join(" ")};b.prototype.setState=function(a,b){b=b?b:1;var c="__state_"+b,d=a==="y"?this.jq_scroll_container_y:this.jq_scroll_container_x;d.removeClass(this.getStateClasses).addClass(c)};b.prototype.mouseoverScrollContainer=function(a,b){this.setState("x",2);this.is_mouse_over_scroll_x_container=true;return false};b.prototype.mouseoutScrollContainer=function(a){this.setState("x");this.is_mouse_over_scroll_x_container=false;return false};b.prototype.mouseoverScroll=function(a){if(!this.is_mouse_down_on_scroll_x){this.setState("x",3)}this.is_mouse_over_scroll_x=true;return false};b.prototype.mouseoutScroll=function(a){if(!this.is_mouse_down_on_scroll_x){this.setState("x")}this.is_mouse_over_scroll_x=false;return false};b.prototype.mousedownScroll=function(a){var b=this.jq_scroll_container_x,c=this.jq_scroll_x,d=c.position().left+2,e=c.css("left");this.setState("x",4);e=e.substring(0,e.indexOf("px"));this.is_mouse_down_on_scroll_x=true;this.scroll_left=d;this.mouse_down_point={x:a.pageX,y:a.pageY};return false};b.prototype.mouseupScroll=function(a){if(this.is_mouse_over_scroll_x){this.setState("x",3)}else{this.setState("x")}this.is_mouse_down_on_scroll_x=false};b.prototype.mousemoveScroll=function(a){var b=this.jq_scroll_x,c=this.jq_parent,d=this.scroll_left,e=this.mouse_down_point,f={x:a.pageX,y:a.pageY},g={x:e.x-f.x,y:e.y-f.y},h=this.displacement_factor_x,i=(d-g.x)/h,j=this.scroll_x_outer_width,k=this.container_x_outer_width;c.scrollLeft(i)};b.prototype.mouseoverScrollY=function(a){if(!this.is_mouse_down_on_scroll_y){this.setState("y",3)}this.is_mouse_over_scroll_y=true;return false};b.prototype.mouseoutScrollY=function(a){if(!this.is_mouse_down_on_scroll_y){this.setState("y")}this.is_mouse_over_scroll_y=false;return false};b.prototype.mousedownScrollY=function(a){var b=this.jq_scroll_y,c=b.position().top+2;this.setState("y",4);this.is_mouse_down_on_scroll_y=true;this.scroll_top=c;this.mouse_down_point={x:a.pageX,y:a.pageY};return false};b.prototype.mouseupScrollY=function(a){if(this.is_mouse_over_scroll_y){this.setState("y",3)}else{this.setState("y")}this.is_mouse_down_on_scroll_y=false};b.prototype.mousemoveScrollY=function(a){var b=this.jq_scroll_y,c=this.jq_parent,d=this.scroll_top,e=this.mouse_down_point,f={x:a.pageX,y:a.pageY},g={x:e.x-f.x,y:e.y-f.y},h=this.displacement_factor_y,i=(d-g.y)/h;c.scrollTop(i)};b.prototype.mouseoverScrollYContainer=function(a){this.setState("y",2);this.is_mouse_over_scroll_y_container=true;return false};b.prototype.mouseoutScrollYContainer=function(a){this.setState("y");this.is_mouse_over_scroll_y_container=false;return false};b.prototype.mousemoveDoc=function(a){var b=this.is_mouse_down_on_scroll_x,c=this.is_mouse_down_on_scroll_y,d=this.is_mouse_down;if(d){this.mousemove(a)}else if(b){this.mousemoveScroll(a)}else if(c){this.mousemoveScrollY(a)}};b.prototype.mouseupDoc=function(a){var b=this.is_mouse_down_on_scroll_x,c=this.is_mouse_over_scroll_x,d=this.is_mouse_over_scroll_x_container,e=this.is_mouse_down_on_scroll_y,f=this.is_mouse_over_scroll_y,g=this.is_mouse_over_scroll_x_container,h=this.is_mouse_down;if(b){this.mouseupScroll(a)}if(e){this.mouseupScrollY(a)}if(h){this.mouseup(a)}};b.prototype.scroll=function(a){var b=this.jq_parent,c=b.scrollLeft(),d=b.scrollTop(),e=this.jq_scroll_container_x,f,g,h,i=this.jq_scroll_container_y,j,k,l;if(e){f=e.offset();g=this.displacement_factor_x;h=this.jq_scroll_x.offset({left:f.left+c*g})}if(i){j=i.offset();k=this.displacement_factor_y;l=this.jq_scroll_y.offset({top:j.top+d*k})}};b.prototype.destroy=function(a){var b=this.jq_doc,c=this.jq_parent,d=this.jq_target,e=this.jq_scroll_container_x,f=this.jq_scroll_container_y;if(e){e.remove()}if(f){f.remove()}d.unbind("mousedown",this.__mousedownTargetHandler);c.unbind("scroll",this.__scrollParentHandler).unbind("mousewheel",this.__mousewheelParentHandler);b.unbind("mousemove",this.__mousemoveDocHandler).unbind("mouseup",this.__mouseupDocHandler);d.removeData("draggy")};b.kill=function(b){var c=a(b),d=c.data("draggy");if(d){d.destroy()}};return b}();a.fn.draggy=function(a){return this.each(function(){if(a==="kill"){b.kill(this)}else{return new b(this,a)}})}})(jQuery)