svg.draggable.js
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -1,2 +0,2 @@ | ||
/*! svg.draggable.js - v2.0.0 - 2015-06-21 | ||
/*! svg.draggable.js - v2.1.0 - 2015-09-16 | ||
* https://github.com/wout/svg.draggable.js | ||
@@ -19,6 +19,17 @@ * Copyright (c) 2015 Wout Fierens; Licensed MIT */ | ||
this.el.on('mousedown.drag', function(e){ _this.start(e) }) | ||
this.el.on('touchstart.drag', function(e){ _this.start(e) }) | ||
} | ||
// transforms one point from screen to user coords | ||
DragHandler.prototype.transformPoint = function(x, y){ | ||
DragHandler.prototype.transformPoint = function(event){ | ||
event = event || window.event | ||
var x, y; | ||
if(event.touches && event.touches.length){ | ||
x = event.touches[0].pageX | ||
y = event.touches[0].pageY | ||
} | ||
else{ | ||
x = event.pageX | ||
y = event.pageY | ||
} | ||
@@ -51,4 +62,6 @@ this.p.x = x | ||
// check for left button | ||
if((e.which || e.buttons) != 1){ | ||
return | ||
if(event.type == 'click'|| event.type == 'mousedown' || event.type == 'mousemove'){ | ||
if((e.which || e.buttons) != 1){ | ||
return | ||
} | ||
} | ||
@@ -73,3 +86,3 @@ | ||
// We take absolute coordinates since we are just using a delta here | ||
mouse: this.transformPoint(e.pageX, e.pageY), | ||
point: this.transformPoint(e), | ||
box: box | ||
@@ -80,3 +93,5 @@ } | ||
SVG.on(window, 'mousemove.drag', function(e){ _this.drag(e) }) | ||
SVG.on(window, 'touchmove.drag', function(e){ _this.drag(e) }) | ||
SVG.on(window, 'mouseup.drag', function(e){ _this.end(e) }) | ||
SVG.on(window, 'touchend.drag', function(e){ _this.end(e) }) | ||
@@ -94,5 +109,5 @@ // fire dragstart event | ||
var box = this.getBBox() | ||
, p = this.transformPoint(e.pageX, e.pageY) | ||
, x = this.startPoints.box.x + p.x - this.startPoints.mouse.x | ||
, y = this.startPoints.box.y + p.y - this.startPoints.mouse.y | ||
, p = this.transformPoint(e) | ||
, x = this.startPoints.box.x + p.x - this.startPoints.point.x | ||
, y = this.startPoints.box.y + p.y - this.startPoints.point.y | ||
, c = this.constraint | ||
@@ -154,3 +169,5 @@ | ||
SVG.off(window, 'mousemove.drag') | ||
SVG.off(window, 'touchmove.drag') | ||
SVG.off(window, 'mouseup.drag') | ||
SVG.off(window, 'touchend.drag') | ||
@@ -177,3 +194,6 @@ } | ||
if(value) dragHandler.init(constraint || {}, value) | ||
else this.off('mousedown.drag') | ||
else { | ||
this.off('mousedown.drag') | ||
this.off('touchstart.drag') | ||
} | ||
@@ -180,0 +200,0 @@ return this |
@@ -1,4 +0,4 @@ | ||
/*! svg.draggable.js - v2.0.0 - 2015-06-21 | ||
/*! svg.draggable.js - v2.1.0 - 2015-09-16 | ||
* https://github.com/wout/svg.draggable.js | ||
* Copyright (c) 2015 Wout Fierens; Licensed MIT */ | ||
(function(){function a(a){a.remember("_draggable",this),this.el=a}a.prototype.init=function(a,b){var c=this;this.constraint=a,this.value=b,this.el.on("mousedown.drag",function(a){c.start(a)})},a.prototype.transformPoint=function(a,b){return this.p.x=a,this.p.y=b,this.p.matrixTransform(this.m)},a.prototype.getBBox=function(){var a=this.el.bbox();return this.el instanceof SVG.Nested&&(a=this.el.rbox()),(this.el instanceof SVG.G||this.el instanceof SVG.Use||this.el instanceof SVG.Nested)&&(a.x=this.el.x(),a.y=this.el.y()),a},a.prototype.start=function(a){if(1==(a.which||a.buttons)){var b=this;this.el.fire("beforedrag",{event:a,handler:this}),this.parent=this.parent||this.el.parent(SVG.Nested)||this.el.parent(SVG.Doc),this.p=this.parent.node.createSVGPoint(),this.m=this.el.node.getScreenCTM().inverse();var c=this.getBBox();this.startPoints={mouse:this.transformPoint(a.pageX,a.pageY),box:c},SVG.on(window,"mousemove.drag",function(a){b.drag(a)}),SVG.on(window,"mouseup.drag",function(a){b.end(a)}),this.el.fire("dragstart",{event:a,p:this.p,m:this.m,handler:this}),a.preventDefault()}},a.prototype.drag=function(a){var b=this.getBBox(),c=this.transformPoint(a.pageX,a.pageY),d=this.startPoints.box.x+c.x-this.startPoints.mouse.x,e=this.startPoints.box.y+c.y-this.startPoints.mouse.y,f=this.constraint;if(this.el.fire("dragmove",{event:a,p:this.p,m:this.m,handler:this}),"function"==typeof f){var g=f.call(this.el,d,e,this.m);"boolean"==typeof g&&(g={x:g,y:g}),g.x===!0?this.el.x(d):g.x!==!1&&this.el.x(g.x),g.y===!0?this.el.y(e):g.y!==!1&&this.el.y(g.y)}else"object"==typeof f&&(null!=f.minX&&d<f.minX?d=f.minX:null!=f.maxX&&d>f.maxX-b.width&&(d=f.maxX-b.width),null!=f.minY&&e<f.minY?e=f.minY:null!=f.maxY&&e>f.maxY-b.height&&(e=f.maxY-b.height),this.el.move(d,e))},a.prototype.end=function(a){this.drag(a),this.el.fire("dragend",{event:a,p:this.p,m:this.m,handler:this}),SVG.off(window,"mousemove.drag"),SVG.off(window,"mouseup.drag")},SVG.extend(SVG.Element,{draggable:function(b,c){("function"==typeof b||"object"==typeof b)&&(c=b,b=!0);var d=this.remember("_draggable")||new a(this);return b="undefined"==typeof b?!0:b,b?d.init(c||{},b):this.off("mousedown.drag"),this}})}).call(this); | ||
(function(){function a(a){a.remember("_draggable",this),this.el=a}a.prototype.init=function(a,b){var c=this;this.constraint=a,this.value=b,this.el.on("mousedown.drag",function(a){c.start(a)}),this.el.on("touchstart.drag",function(a){c.start(a)})},a.prototype.transformPoint=function(a){a=a||window.event;var b,c;return a.touches&&a.touches.length?(b=a.touches[0].pageX,c=a.touches[0].pageY):(b=a.pageX,c=a.pageY),this.p.x=b,this.p.y=c,this.p.matrixTransform(this.m)},a.prototype.getBBox=function(){var a=this.el.bbox();return this.el instanceof SVG.Nested&&(a=this.el.rbox()),(this.el instanceof SVG.G||this.el instanceof SVG.Use||this.el instanceof SVG.Nested)&&(a.x=this.el.x(),a.y=this.el.y()),a},a.prototype.start=function(a){if("click"!=event.type&&"mousedown"!=event.type&&"mousemove"!=event.type||1==(a.which||a.buttons)){var b=this;this.el.fire("beforedrag",{event:a,handler:this}),this.parent=this.parent||this.el.parent(SVG.Nested)||this.el.parent(SVG.Doc),this.p=this.parent.node.createSVGPoint(),this.m=this.el.node.getScreenCTM().inverse();var c=this.getBBox();this.startPoints={point:this.transformPoint(a),box:c},SVG.on(window,"mousemove.drag",function(a){b.drag(a)}),SVG.on(window,"touchmove.drag",function(a){b.drag(a)}),SVG.on(window,"mouseup.drag",function(a){b.end(a)}),SVG.on(window,"touchend.drag",function(a){b.end(a)}),this.el.fire("dragstart",{event:a,p:this.p,m:this.m,handler:this}),a.preventDefault()}},a.prototype.drag=function(a){var b=this.getBBox(),c=this.transformPoint(a),d=this.startPoints.box.x+c.x-this.startPoints.point.x,e=this.startPoints.box.y+c.y-this.startPoints.point.y,f=this.constraint;if(this.el.fire("dragmove",{event:a,p:this.p,m:this.m,handler:this}),"function"==typeof f){var g=f.call(this.el,d,e,this.m);"boolean"==typeof g&&(g={x:g,y:g}),g.x===!0?this.el.x(d):g.x!==!1&&this.el.x(g.x),g.y===!0?this.el.y(e):g.y!==!1&&this.el.y(g.y)}else"object"==typeof f&&(null!=f.minX&&d<f.minX?d=f.minX:null!=f.maxX&&d>f.maxX-b.width&&(d=f.maxX-b.width),null!=f.minY&&e<f.minY?e=f.minY:null!=f.maxY&&e>f.maxY-b.height&&(e=f.maxY-b.height),this.el.move(d,e))},a.prototype.end=function(a){this.drag(a),this.el.fire("dragend",{event:a,p:this.p,m:this.m,handler:this}),SVG.off(window,"mousemove.drag"),SVG.off(window,"touchmove.drag"),SVG.off(window,"mouseup.drag"),SVG.off(window,"touchend.drag")},SVG.extend(SVG.Element,{draggable:function(b,c){("function"==typeof b||"object"==typeof b)&&(c=b,b=!0);var d=this.remember("_draggable")||new a(this);return b="undefined"==typeof b?!0:b,b?d.init(c||{},b):(this.off("mousedown.drag"),this.off("touchstart.drag")),this}})}).call(this); |
{ | ||
"name": "svg.draggable.js", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "An extension for svg.js which allows to drag elements with your mouse", | ||
@@ -5,0 +5,0 @@ "main": "dist/svg.draggable.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13507
153
0