svg.select.js
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -1,2 +0,2 @@ | ||
/*! svg.select.js - v1.0.3 - 2015-06-22 | ||
/*! svg.select.js - v1.0.4 - 2015-06-22 | ||
* https://github.com/Fuzzyma/svg.select.js | ||
@@ -152,3 +152,3 @@ * Copyright (c) 2015 Ulrich-Matthias Schäfer; Licensed MIT */ | ||
ev.preventDefault ? ev.preventDefault() : ev.returnValue = false; | ||
_this.el.fire(eventName, {x: ev.pageX, y: ev.pageY}); | ||
_this.el.fire(eventName, {x: ev.pageX, y: ev.pageY, event: ev}); | ||
}; | ||
@@ -186,3 +186,3 @@ } | ||
ev.preventDefault ? ev.preventDefault() : ev.returnValue = false; | ||
_this.el.fire('rot', {x: ev.pageX, y: ev.pageY}); | ||
_this.el.fire('rot', {x: ev.pageX, y: ev.pageY, event: ev}); | ||
})); | ||
@@ -189,0 +189,0 @@ |
@@ -1,4 +0,4 @@ | ||
/*! svg.select.js - v1.0.3 - 2015-06-22 | ||
/*! svg.select.js - v1.0.4 - 2015-06-22 | ||
* https://github.com/Fuzzyma/svg.select.js | ||
* Copyright (c) 2015 Ulrich-Matthias Schäfer; Licensed MIT */ | ||
(function(a){function b(a){this.el=a,this.parent=a.parent(SVG.Nested)||a.parent(SVG.Doc),a.remember("_selectHandler",this),this.pointSelection={isSelected:!1},this.rectSelection={isSelected:!1}}b.prototype.init=function(b,c){var d=this.el.bbox();this.options={};for(var e in this.el.select.defaults)this.options[e]=this.el.select.defaults[e],c[e]!==a&&(this.options[e]=c[e]);this.nested=(this.nested||this.parent.nested()).size(d.width||1,d.height||1).transform(this.el.ctm()).move(d.x,d.y),this.options.deepSelect&&-1!==["line","polyline","polygon"].indexOf(this.el.type)?this.selectPoints(b):this.selectRect(b),this.observe(),this.cleanup()},b.prototype.selectPoints=function(a){return this.pointSelection.isSelected=a,this.pointSelection.set?this:(this.pointSelection.set=this.parent.set(),this.drawCircles(),this)},b.prototype.getPointArray=function(){var a=this.el.bbox();return this.el.array().valueOf().map(function(b){return[b[0]-a.x,b[1]-a.y]})},b.prototype.drawCircles=function(){for(var a=this,b=this.getPointArray(),c=0,d=b.length;d>c;++c)this.pointSelection.set.add(this.nested.circle(this.options.radius).center(b[c][0],b[c][1]).addClass(this.options.classPoints).addClass(this.options.classPoints+"_point").mousedown(function(b){return function(c){c=c||window.event,c.preventDefault?c.preventDefault():c.returnValue=!1,a.el.fire("point",{x:c.pageX,y:c.pageY,i:b,event:c})}}(c)))},b.prototype.updatePointSelection=function(){var a=this.getPointArray();this.pointSelection.set.each(function(b){(this.cx()!==a[b][0]||this.cy()!==a[b][1])&&this.center(a[b][0],a[b][1])})},b.prototype.updateRectSelection=function(){var a=this.el.bbox();this.rectSelection.set.get(0).attr({width:a.width,height:a.height}),this.options.points&&(this.rectSelection.set.get(2).center(a.width,0),this.rectSelection.set.get(3).center(a.width,a.height),this.rectSelection.set.get(4).center(0,a.height),this.rectSelection.set.get(5).center(a.width/2,0),this.rectSelection.set.get(6).center(a.width,a.height/2),this.rectSelection.set.get(7).center(a.width/2,a.height),this.rectSelection.set.get(8).center(0,a.height/2)),this.options.rotationPoint&&this.rectSelection.set.get(9).center(a.width/2,20)},b.prototype.selectRect=function(a){function b(a){return function(b){b=b||window.event,b.preventDefault?b.preventDefault():b.returnValue=!1,c.el.fire(a,{x:b.pageX,y:b.pageY})}}var c=this,d=this.el.bbox();this.rectSelection.isSelected=a,this.rectSelection.set=this.rectSelection.set||this.parent.set(),this.rectSelection.set.get(0)||this.rectSelection.set.add(this.nested.rect(d.width,d.height).addClass(this.options.classRect)),this.options.points&&!this.rectSelection.set.get(1)&&(this.rectSelection.set.add(this.nested.circle(this.options.radius).center(0,0).attr("class",this.options.classPoints+"_lt").mousedown(b("lt"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width,0).attr("class",this.options.classPoints+"_rt").mousedown(b("rt"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width,d.height).attr("class",this.options.classPoints+"_rb").mousedown(b("rb"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(0,d.height).attr("class",this.options.classPoints+"_lb").mousedown(b("lb"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width/2,0).attr("class",this.options.classPoints+"_t").mousedown(b("t"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width,d.height/2).attr("class",this.options.classPoints+"_r").mousedown(b("r"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width/2,d.height).attr("class",this.options.classPoints+"_b").mousedown(b("b"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(0,d.height/2).attr("class",this.options.classPoints+"_l").mousedown(b("l"))),this.rectSelection.set.each(function(){this.addClass(c.options.classPoints)})),this.options.rotationPoint&&!this.rectSelection.set.get(9)&&this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width/2,20).attr("class",this.options.classPoints+"_rot").mousedown(function(a){a=a||window.event,a.preventDefault?a.preventDefault():a.returnValue=!1,c.el.fire("rot",{x:a.pageX,y:a.pageY})}))},b.prototype.handler=function(){var a=this.el.bbox();this.nested.size(a.width||1,a.height||1).transform(this.el.ctm()).move(a.x,a.y),this.rectSelection.isSelected&&this.updateRectSelection(),this.pointSelection.isSelected&&this.updatePointSelection()},b.prototype.observe=function(){var a=this;if(MutationObserver)if(this.rectSelection.isSelected||this.pointSelection.isSelected)this.observerInst=this.observerInst||new MutationObserver(function(){a.handler()}),this.observerInst.observe(this.el.node,{attributes:!0});else try{this.observerInst.disconnect(),delete this.observerInst}catch(b){}else this.el.off("DOMAttrModified.select"),(this.rectSelection.isSelected||this.pointSelection.isSelected)&&this.el.on("DOMAttrModified.select",function(){a.handler()})},b.prototype.cleanup=function(){!this.rectSelection.isSelected&&this.rectSelection.set&&(this.rectSelection.set.each(function(){this.remove()}),this.rectSelection.set.clear(),delete this.rectSelection.set),!this.pointSelection.isSelected&&this.pointSelection.set&&(this.pointSelection.set.each(function(){this.remove()}),this.pointSelection.set.clear(),delete this.pointSelection.set),this.pointSelection.isSelected||this.rectSelection.isSelected||(this.nested.remove(),delete this.nested)},SVG.extend(SVG.Element,{select:function(c,d){"object"==typeof c&&(d=c,c=!0);var e=this.remember("_selectHandler")||new b(this);return e.init(c===a?!0:c,d||{}),this}}),SVG.Element.prototype.select.defaults={points:!0,classRect:"svg_select_boundingRect",classPoints:"svg_select_points",radius:7,rotationPoint:!0,deepSelect:!1}}).call(this); | ||
(function(a){function b(a){this.el=a,this.parent=a.parent(SVG.Nested)||a.parent(SVG.Doc),a.remember("_selectHandler",this),this.pointSelection={isSelected:!1},this.rectSelection={isSelected:!1}}b.prototype.init=function(b,c){var d=this.el.bbox();this.options={};for(var e in this.el.select.defaults)this.options[e]=this.el.select.defaults[e],c[e]!==a&&(this.options[e]=c[e]);this.nested=(this.nested||this.parent.nested()).size(d.width||1,d.height||1).transform(this.el.ctm()).move(d.x,d.y),this.options.deepSelect&&-1!==["line","polyline","polygon"].indexOf(this.el.type)?this.selectPoints(b):this.selectRect(b),this.observe(),this.cleanup()},b.prototype.selectPoints=function(a){return this.pointSelection.isSelected=a,this.pointSelection.set?this:(this.pointSelection.set=this.parent.set(),this.drawCircles(),this)},b.prototype.getPointArray=function(){var a=this.el.bbox();return this.el.array().valueOf().map(function(b){return[b[0]-a.x,b[1]-a.y]})},b.prototype.drawCircles=function(){for(var a=this,b=this.getPointArray(),c=0,d=b.length;d>c;++c)this.pointSelection.set.add(this.nested.circle(this.options.radius).center(b[c][0],b[c][1]).addClass(this.options.classPoints).addClass(this.options.classPoints+"_point").mousedown(function(b){return function(c){c=c||window.event,c.preventDefault?c.preventDefault():c.returnValue=!1,a.el.fire("point",{x:c.pageX,y:c.pageY,i:b,event:c})}}(c)))},b.prototype.updatePointSelection=function(){var a=this.getPointArray();this.pointSelection.set.each(function(b){(this.cx()!==a[b][0]||this.cy()!==a[b][1])&&this.center(a[b][0],a[b][1])})},b.prototype.updateRectSelection=function(){var a=this.el.bbox();this.rectSelection.set.get(0).attr({width:a.width,height:a.height}),this.options.points&&(this.rectSelection.set.get(2).center(a.width,0),this.rectSelection.set.get(3).center(a.width,a.height),this.rectSelection.set.get(4).center(0,a.height),this.rectSelection.set.get(5).center(a.width/2,0),this.rectSelection.set.get(6).center(a.width,a.height/2),this.rectSelection.set.get(7).center(a.width/2,a.height),this.rectSelection.set.get(8).center(0,a.height/2)),this.options.rotationPoint&&this.rectSelection.set.get(9).center(a.width/2,20)},b.prototype.selectRect=function(a){function b(a){return function(b){b=b||window.event,b.preventDefault?b.preventDefault():b.returnValue=!1,c.el.fire(a,{x:b.pageX,y:b.pageY,event:b})}}var c=this,d=this.el.bbox();this.rectSelection.isSelected=a,this.rectSelection.set=this.rectSelection.set||this.parent.set(),this.rectSelection.set.get(0)||this.rectSelection.set.add(this.nested.rect(d.width,d.height).addClass(this.options.classRect)),this.options.points&&!this.rectSelection.set.get(1)&&(this.rectSelection.set.add(this.nested.circle(this.options.radius).center(0,0).attr("class",this.options.classPoints+"_lt").mousedown(b("lt"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width,0).attr("class",this.options.classPoints+"_rt").mousedown(b("rt"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width,d.height).attr("class",this.options.classPoints+"_rb").mousedown(b("rb"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(0,d.height).attr("class",this.options.classPoints+"_lb").mousedown(b("lb"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width/2,0).attr("class",this.options.classPoints+"_t").mousedown(b("t"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width,d.height/2).attr("class",this.options.classPoints+"_r").mousedown(b("r"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width/2,d.height).attr("class",this.options.classPoints+"_b").mousedown(b("b"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(0,d.height/2).attr("class",this.options.classPoints+"_l").mousedown(b("l"))),this.rectSelection.set.each(function(){this.addClass(c.options.classPoints)})),this.options.rotationPoint&&!this.rectSelection.set.get(9)&&this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width/2,20).attr("class",this.options.classPoints+"_rot").mousedown(function(a){a=a||window.event,a.preventDefault?a.preventDefault():a.returnValue=!1,c.el.fire("rot",{x:a.pageX,y:a.pageY,event:a})}))},b.prototype.handler=function(){var a=this.el.bbox();this.nested.size(a.width||1,a.height||1).transform(this.el.ctm()).move(a.x,a.y),this.rectSelection.isSelected&&this.updateRectSelection(),this.pointSelection.isSelected&&this.updatePointSelection()},b.prototype.observe=function(){var a=this;if(MutationObserver)if(this.rectSelection.isSelected||this.pointSelection.isSelected)this.observerInst=this.observerInst||new MutationObserver(function(){a.handler()}),this.observerInst.observe(this.el.node,{attributes:!0});else try{this.observerInst.disconnect(),delete this.observerInst}catch(b){}else this.el.off("DOMAttrModified.select"),(this.rectSelection.isSelected||this.pointSelection.isSelected)&&this.el.on("DOMAttrModified.select",function(){a.handler()})},b.prototype.cleanup=function(){!this.rectSelection.isSelected&&this.rectSelection.set&&(this.rectSelection.set.each(function(){this.remove()}),this.rectSelection.set.clear(),delete this.rectSelection.set),!this.pointSelection.isSelected&&this.pointSelection.set&&(this.pointSelection.set.each(function(){this.remove()}),this.pointSelection.set.clear(),delete this.pointSelection.set),this.pointSelection.isSelected||this.rectSelection.isSelected||(this.nested.remove(),delete this.nested)},SVG.extend(SVG.Element,{select:function(c,d){"object"==typeof c&&(d=c,c=!0);var e=this.remember("_selectHandler")||new b(this);return e.init(c===a?!0:c,d||{}),this}}),SVG.Element.prototype.select.defaults={points:!0,classRect:"svg_select_boundingRect",classPoints:"svg_select_points",radius:7,rotationPoint:!0,deepSelect:!1}}).call(this); |
{ | ||
"name": "svg.select.js", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "An extension of svg.js which allows to select elements with mouse", | ||
@@ -41,4 +41,4 @@ "keywords": [ | ||
"dependencies": { | ||
"svg.js":"1.1.x" | ||
"svg.js":"2.x.x" | ||
} | ||
} |
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
23695
+ Addedsvg.js@2.7.1(transitive)
- Removedsvg.js@1.1.1(transitive)
Updatedsvg.js@2.x.x