svg.select.js
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -1,2 +0,2 @@ | ||
/*! svg.select.js - v2.0.1 - 2016-01-03 | ||
/*! svg.select.js - v2.0.2 - 2016-03-12 | ||
* https://github.com/Fuzzyma/svg.select.js | ||
@@ -10,3 +10,3 @@ * Copyright (c) 2016 Ulrich-Matthias Schäfer; Licensed MIT */ | ||
this.el = el; | ||
this.parent = el.parent(SVG.Nested) || el.parent(SVG.Doc); | ||
this.parent = el.parent(); | ||
el.remember('_selectHandler', this); | ||
@@ -312,2 +312,2 @@ this.pointSelection = {isSelected: false}; | ||
}).call(this); | ||
})(); |
@@ -1,4 +0,4 @@ | ||
/*! svg.select.js - v2.0.1 - 2016-01-03 | ||
/*! svg.select.js - v2.0.2 - 2016-03-12 | ||
* https://github.com/Fuzzyma/svg.select.js | ||
* Copyright (c) 2016 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.selectize.defaults)this.options[e]=this.el.selectize.defaults[e],c[e]!==a&&(this.options[e]=c[e]);this.nested=this.nested||this.parent.group(),this.nested.matrix(new SVG.Matrix(this.el).translate(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.matrix(new SVG.Matrix(this.el).translate(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,{selectize: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.selectize.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(),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.selectize.defaults)this.options[e]=this.el.selectize.defaults[e],c[e]!==a&&(this.options[e]=c[e]);this.nested=this.nested||this.parent.group(),this.nested.matrix(new SVG.Matrix(this.el).translate(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.matrix(new SVG.Matrix(this.el).translate(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,{selectize: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.selectize.defaults={points:!0,classRect:"svg_select_boundingRect",classPoints:"svg_select_points",radius:7,rotationPoint:!0,deepSelect:!1}}(); |
{ | ||
"name": "svg.select.js", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "An extension of svg.js which allows to select elements with mouse", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
23700