From 85651cca0bb391b9529d188a2ab63bad1d15311a Mon Sep 17 00:00:00 2001 From: bumbu Date: Fri, 9 May 2014 18:55:27 +0200 Subject: [PATCH] fix ie bug when an SVGElement is provided as selector --- dist/svg-pan-zoom.js | 2 +- dist/svg-pan-zoom.min.js | 2 +- src/utilities.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/svg-pan-zoom.js b/dist/svg-pan-zoom.js index 41f6ba3..51f61b5 100644 --- a/dist/svg-pan-zoom.js +++ b/dist/svg-pan-zoom.js @@ -951,7 +951,7 @@ module.exports = { */ , isElement: function(o){ return ( - typeof HTMLElement === "object" ? o instanceof HTMLElement : //DOM2 + typeof HTMLElement === "object" ? (o instanceof HTMLElement || o instanceof SVGElement || o instanceof SVGSVGElement) : //DOM2 o && typeof o === "object" && o !== null && o.nodeType === 1 && typeof o.nodeName==="string" ); } diff --git a/dist/svg-pan-zoom.min.js b/dist/svg-pan-zoom.min.js index 8a9ade7..29645c6 100644 --- a/dist/svg-pan-zoom.min.js +++ b/dist/svg-pan-zoom.min.js @@ -1 +1 @@ -!function t(e,n,o){function i(s,a){if(!n[s]){if(!e[s]){var l="function"==typeof require&&require;if(!a&&l)return l(s,!0);if(r)return r(s,!0);throw new Error("Cannot find module '"+s+"'")}var c=n[s]={exports:{}};e[s][0].call(c.exports,function(t){var n=e[s][1][t];return i(n?n:t)},c,c.exports,t,e,n,o)}return n[s].exports}for(var r="function"==typeof require&&require,s=0;sthis.options.maxZoom*this.initialCTM.a&&(l.a=l.d=a.a),l.a!==a.a&&(o.setCTM(this.viewport,l),this._zoom=this.initialCTM.a),this.stateTf||(this.stateTf=l.inverse()),this.stateTf=this.stateTf.multiply(s.inverse()),this.options.onZoom&&this.options.onZoom(l.a)},i.prototype.publicZoomAtPoint=function(t,e,o){if(!("SVGPoint"!==n.getType(e)&&"x"in e&&"y"in e))throw new Error("Given point is invalid");var i=this.svg.createSVGPoint();i.x=e.x,i.y=e.y,e=i,this.zoomAtPoint(this.svg,e,t,o)},i.prototype.getZoom=function(){return this._zoom},i.prototype.resetZoom=function(){o.setCTM(this.viewport,this.initialCTM),this.options.onZoom(this.initialCTM.a),this.options.onPan(this._pan.x,this._pan.y),this._zoom=this.initialCTM.a,this._pan.x=this.initialCTM.e,this._pan.y=this.initialCTM.f},i.prototype.handleMouseMove=function(t){t.preventDefault?t.preventDefault():t.returnValue=!1;var e,n="svg"===t.target.tagName||"SVG"===t.target.tagName?t.target:t.target.ownerSVGElement||t.target.correspondingElement.ownerSVGElement;if("pan"===this.state&&this.options.panEnabled){e=o.getEventPoint(t).matrixTransform(this.stateTf);var i=this.stateTf.inverse().translate(e.x-this.stateOrigin.x,e.y-this.stateOrigin.y);o.setCTM(this.viewport,i),this._pan.x=i.e,this._pan.y=i.f,this.options.onPan(this._pan.x,this._pan.y)}else"drag"===this.state&&this.options.dragEnabled&&(e=o.getEventPoint(t).matrixTransform(this.viewport.getCTM().inverse()),o.setCTM(this.stateTarget,n.createSVGMatrix().translate(e.x-this.stateOrigin.x,e.y-this.stateOrigin.y).multiply(this.viewport.getCTM().inverse()).multiply(this.stateTarget.getCTM())),this.stateOrigin=e)},i.prototype.handleDblClick=function(t){var e=t.target,n="svg"===e.tagName||"SVG"===e.tagName?e:e.ownerSVGElement||e.correspondingElement.ownerSVGElement;if(t.preventDefault?t.preventDefault():t.returnValue=!1,this.options.controlIconsEnabled){var i=e.getAttribute("class")||"";if(i.indexOf("svg-pan-zoom-control")>-1)return!1}var r;r=t.shiftKey?1/(2*(1+this.options.zoomScaleSensitivity)):2*(1+this.options.zoomScaleSensitivity);var s=o.getRelativeMousePoint(n,t);this.zoomAtPoint(n,s,r)},i.prototype.handleMouseDown=function(t){2===t.detail&&this.handleDblClick(t),t.preventDefault?t.preventDefault():t.returnValue=!1;"svg"===t.target.tagName||"SVG"===t.target.tagName?t.target:t.target.ownerSVGElement||t.target.correspondingElement.ownerSVGElement;"svg"!==t.target.tagName&&this.options.dragEnabled?(this.state="drag",this.stateTarget=t.target,this.stateTf=this.viewport.getCTM().inverse(),this.stateOrigin=o.getEventPoint(t).matrixTransform(this.stateTf)):(this.state="pan",this.stateTf=this.viewport.getCTM().inverse(),this.stateOrigin=o.getEventPoint(t).matrixTransform(this.stateTf))},i.prototype.handleMouseUp=function(t){t.preventDefault?t.preventDefault():t.returnValue=!1;"svg"===t.target.tagName||"SVG"===t.target.tagName?t.target:t.target.ownerSVGElement||t.target.correspondingElement.ownerSVGElement;("pan"===this.state||"drag"===this.state)&&(this.state="none")},i.prototype.pan=function(t){var e=this.viewport.getCTM();e.e=t.x,e.f=t.y,o.setCTM(this.viewport,e),this._pan.x=e.e,this._pan.y=e.f,this.options.onPan(this._pan.x,this._pan.y)},i.prototype.panBy=function(t){var e=this.viewport.getCTM();e.e+=t.x,e.f+=t.y,o.setCTM(this.viewport,e),this._pan.x=e.e,this._pan.y=e.f,this.options.onPan(this._pan.x,this._pan.y)},i.prototype.getPan=function(){return{x:this._pan.x,y:this._pan.y}},i.prototype.getPublicInstance=function(){var t=this;return this.publicInstance||(this.publicInstance={enablePan:function(){t.options.panEnabled=!0},disablePan:function(){t.options.panEnabled=!1},isPanEnabled:function(){return!!t.options.panEnabled},pan:function(e){t.pan(e)},panBy:function(e){t.panBy(e)},getPan:function(){return t.getPan()},setOnPan:function(e){t.options.onPan=n.proxy(e,t.publicInstance)},enableDrag:function(){t.options.dragEnabled=!0},disableDrag:function(){t.options.dragEnabled=!1},isDragEnabled:function(){return!!t.options.dragEnabled},enableZoom:function(){t.options.controlIconsEnabled&&!t.options.zoomEnabled&&e.enable(t),t.options.zoomEnabled=!0},disableZoom:function(){t.options.controlIconsEnabled&&t.options.zoomEnabled&&e.disable(t),t.options.zoomEnabled=!1},isZoomEnabled:function(){return!!t.options.zoomEnabled},enableControlIcons:function(){t.options.zoomEnabled&&!t.options.controlIconsEnabled&&(t.options.controlIconsEnabled=!0,e.enable(t))},disableControlIcons:function(){t.options.controlIconsEnabled&&(t.options.controlIconsEnabled=!1,e.disable(t))},isControlIconsEnabled:function(){return!!t.options.controlIconsEnabled},setZoomScaleSensitivity:function(e){t.options.zoomScaleSensitivity=e},setMinZoom:function(e){t.options.minZoom=e},setMaxZoom:function(e){t.options.maxZoom=e},setOnZoom:function(e){t.options.onZoom=n.proxy(e,t.publicInstance)},zoom:function(e){t.zoomAtPoint(t.svg,o.getSvgCenterPoint(t.svg),e,!0)},zoomBy:function(e){t.zoomAtPoint(t.svg,o.getSvgCenterPoint(t.svg),e,!1)},zoomAtPoint:function(e,n){t.publicZoomAtPoint(e,n,!0)},zoomAtPointBy:function(e,n){t.publicZoomAtPoint(e,n,!1)},zoomIn:function(){this.zoomBy(1+t.options.zoomScaleSensitivity)},zoomOut:function(){this.zoomBy(1/(1+t.options.zoomScaleSensitivity))},resetZoom:function(){t.resetZoom()},getZoom:function(){return t.getZoom()}}),this.publicInstance};var s=[];t.svgPanZoom=function(t,e){var o=n.getSvg(t);if(null===o)return null;for(var r=s.length-1;r>=0;r--)if(s[r].svg===o)return s[r].instance.getPublicInstance();return s.push({svg:o,instance:new i(o,e)}),s[s.length-1].instance.getPublicInstance()}}(window,document)},{"./control-icons":1,"./mousewheel":2,"./svg-utilities":4,"./utilities":5}],4:[function(t,e){e.exports={getSvgDimensions:function(t){var e=0,n=0,o=t.getClientRects();if("undefined"!=typeof o&&o.length>0){var i=o[0];e=parseFloat(i.width),n=parseFloat(i.height)}else{var r=t.getBoundingClientRect();if(!r)throw new Error("Cannot determine SVG width and height.");e=parseFloat(r.width),n=parseFloat(r.height)}return{width:e,height:n}},getOrCreateViewport:function(t){var e=t.querySelector("g.viewport");if(!e){var e=document.createElementNS("http://www.w3.org/2000/svg","g");e.setAttribute("class","viewport");var n=t.childNodes||t.children;do e.appendChild(n[0]);while(n.length>0);t.appendChild(e)}return e},setupSvgAttributes:function(t){if(t.setAttribute("xmlns","http://www.w3.org/1999/xlink"),t.setAttributeNS("xmlns","xlink","http://www.w3.org/1999/xlink"),t.setAttributeNS("xmlns","ev","http://www.w3.org/2001/xml-events"),null!==t.parentNode){var e=t.getAttribute("style")||"";-1===e.toLowerCase().indexOf("overflow")&&t.setAttribute("style","overflow: hidden; "+e)}},setCTM:function(t,e){var n="matrix("+e.a+","+e.b+","+e.c+","+e.d+","+e.e+","+e.f+")";t.setAttribute("transform",n)},getScreenCTMCached:function(){var t={};return function(e){var n=Date.now();if(t.hasOwnProperty(e)){var o=t[e];return n-o.time>300&&(o.time=n,o.ctm=e.getScreenCTM()),o.ctm}var i=e.getScreenCTM();return t[e]={time:n,ctm:i},i}}(),getRelativeMousePoint:function(t,e){var n=t.createSVGPoint();return n.x=e.clientX,n.y=e.clientY,n.matrixTransform(this.getScreenCTMCached(t).inverse())},getEventPoint:function(t){var e="svg"===t.target.tagName||"SVG"===t.target.tagName?t.target:t.target.ownerSVGElement||t.target.correspondingElement.ownerSVGElement,n=e.createSVGPoint();return n.x=t.clientX,n.y=t.clientY,n},getSvgCenterPoint:function(t){var e=t.getBoundingClientRect(),n=e.width,o=e.height,i=t.createSVGPoint();return i.x=n/2,i.y=o/2,i}}},{}],5:[function(t,e){e.exports={extend:function(t,e){t=t||{};for(var n in e)t[n]="object"==typeof e[n]?extend(t[n],e[n]):e[n];return t},isElement:function(t){return"object"==typeof HTMLElement?t instanceof HTMLElement:t&&"object"==typeof t&&null!==t&&1===t.nodeType&&"string"==typeof t.nodeName},getSvg:function(t){var e,n;if(this.isElement(t))e=t;else{if(!("string"==typeof t||t instanceof String))throw new Error("Provided selector is not an HTML object nor String");if(e=document.querySelector(t),!e)throw new Error("Provided selector did not find any elements")}if("svg"===e.tagName.toLowerCase())n=e;else if("object"===e.tagName.toLowerCase())n=e.contentDocument.documentElement;else{if("embed"!==e.tagName.toLowerCase())throw new Error("img"===e.tagName.toLowerCase()?'Cannot script an SVG in an "img" element. Please use an "object" element or an in-line SVG.':"Cannot get SVG.");n=e.getSVGDocument().documentElement}return n},proxy:function(t,e){return function(){t.apply(e,arguments)}},getType:function(t){return Object.prototype.toString.apply(t).replace(/^\[object\s/,"").replace(/\]$/,"")}}},{}]},{},[3]); \ No newline at end of file +!function t(e,n,o){function i(s,a){if(!n[s]){if(!e[s]){var l="function"==typeof require&&require;if(!a&&l)return l(s,!0);if(r)return r(s,!0);throw new Error("Cannot find module '"+s+"'")}var c=n[s]={exports:{}};e[s][0].call(c.exports,function(t){var n=e[s][1][t];return i(n?n:t)},c,c.exports,t,e,n,o)}return n[s].exports}for(var r="function"==typeof require&&require,s=0;sthis.options.maxZoom*this.initialCTM.a&&(l.a=l.d=a.a),l.a!==a.a&&(o.setCTM(this.viewport,l),this._zoom=this.initialCTM.a),this.stateTf||(this.stateTf=l.inverse()),this.stateTf=this.stateTf.multiply(s.inverse()),this.options.onZoom&&this.options.onZoom(l.a)},i.prototype.publicZoomAtPoint=function(t,e,o){if(!("SVGPoint"!==n.getType(e)&&"x"in e&&"y"in e))throw new Error("Given point is invalid");var i=this.svg.createSVGPoint();i.x=e.x,i.y=e.y,e=i,this.zoomAtPoint(this.svg,e,t,o)},i.prototype.getZoom=function(){return this._zoom},i.prototype.resetZoom=function(){o.setCTM(this.viewport,this.initialCTM),this.options.onZoom(this.initialCTM.a),this.options.onPan(this._pan.x,this._pan.y),this._zoom=this.initialCTM.a,this._pan.x=this.initialCTM.e,this._pan.y=this.initialCTM.f},i.prototype.handleMouseMove=function(t){t.preventDefault?t.preventDefault():t.returnValue=!1;var e,n="svg"===t.target.tagName||"SVG"===t.target.tagName?t.target:t.target.ownerSVGElement||t.target.correspondingElement.ownerSVGElement;if("pan"===this.state&&this.options.panEnabled){e=o.getEventPoint(t).matrixTransform(this.stateTf);var i=this.stateTf.inverse().translate(e.x-this.stateOrigin.x,e.y-this.stateOrigin.y);o.setCTM(this.viewport,i),this._pan.x=i.e,this._pan.y=i.f,this.options.onPan(this._pan.x,this._pan.y)}else"drag"===this.state&&this.options.dragEnabled&&(e=o.getEventPoint(t).matrixTransform(this.viewport.getCTM().inverse()),o.setCTM(this.stateTarget,n.createSVGMatrix().translate(e.x-this.stateOrigin.x,e.y-this.stateOrigin.y).multiply(this.viewport.getCTM().inverse()).multiply(this.stateTarget.getCTM())),this.stateOrigin=e)},i.prototype.handleDblClick=function(t){var e=t.target,n="svg"===e.tagName||"SVG"===e.tagName?e:e.ownerSVGElement||e.correspondingElement.ownerSVGElement;if(t.preventDefault?t.preventDefault():t.returnValue=!1,this.options.controlIconsEnabled){var i=e.getAttribute("class")||"";if(i.indexOf("svg-pan-zoom-control")>-1)return!1}var r;r=t.shiftKey?1/(2*(1+this.options.zoomScaleSensitivity)):2*(1+this.options.zoomScaleSensitivity);var s=o.getRelativeMousePoint(n,t);this.zoomAtPoint(n,s,r)},i.prototype.handleMouseDown=function(t){2===t.detail&&this.handleDblClick(t),t.preventDefault?t.preventDefault():t.returnValue=!1;"svg"===t.target.tagName||"SVG"===t.target.tagName?t.target:t.target.ownerSVGElement||t.target.correspondingElement.ownerSVGElement;"svg"!==t.target.tagName&&this.options.dragEnabled?(this.state="drag",this.stateTarget=t.target,this.stateTf=this.viewport.getCTM().inverse(),this.stateOrigin=o.getEventPoint(t).matrixTransform(this.stateTf)):(this.state="pan",this.stateTf=this.viewport.getCTM().inverse(),this.stateOrigin=o.getEventPoint(t).matrixTransform(this.stateTf))},i.prototype.handleMouseUp=function(t){t.preventDefault?t.preventDefault():t.returnValue=!1;"svg"===t.target.tagName||"SVG"===t.target.tagName?t.target:t.target.ownerSVGElement||t.target.correspondingElement.ownerSVGElement;("pan"===this.state||"drag"===this.state)&&(this.state="none")},i.prototype.pan=function(t){var e=this.viewport.getCTM();e.e=t.x,e.f=t.y,o.setCTM(this.viewport,e),this._pan.x=e.e,this._pan.y=e.f,this.options.onPan(this._pan.x,this._pan.y)},i.prototype.panBy=function(t){var e=this.viewport.getCTM();e.e+=t.x,e.f+=t.y,o.setCTM(this.viewport,e),this._pan.x=e.e,this._pan.y=e.f,this.options.onPan(this._pan.x,this._pan.y)},i.prototype.getPan=function(){return{x:this._pan.x,y:this._pan.y}},i.prototype.getPublicInstance=function(){var t=this;return this.publicInstance||(this.publicInstance={enablePan:function(){t.options.panEnabled=!0},disablePan:function(){t.options.panEnabled=!1},isPanEnabled:function(){return!!t.options.panEnabled},pan:function(e){t.pan(e)},panBy:function(e){t.panBy(e)},getPan:function(){return t.getPan()},setOnPan:function(e){t.options.onPan=n.proxy(e,t.publicInstance)},enableDrag:function(){t.options.dragEnabled=!0},disableDrag:function(){t.options.dragEnabled=!1},isDragEnabled:function(){return!!t.options.dragEnabled},enableZoom:function(){t.options.controlIconsEnabled&&!t.options.zoomEnabled&&e.enable(t),t.options.zoomEnabled=!0},disableZoom:function(){t.options.controlIconsEnabled&&t.options.zoomEnabled&&e.disable(t),t.options.zoomEnabled=!1},isZoomEnabled:function(){return!!t.options.zoomEnabled},enableControlIcons:function(){t.options.zoomEnabled&&!t.options.controlIconsEnabled&&(t.options.controlIconsEnabled=!0,e.enable(t))},disableControlIcons:function(){t.options.controlIconsEnabled&&(t.options.controlIconsEnabled=!1,e.disable(t))},isControlIconsEnabled:function(){return!!t.options.controlIconsEnabled},setZoomScaleSensitivity:function(e){t.options.zoomScaleSensitivity=e},setMinZoom:function(e){t.options.minZoom=e},setMaxZoom:function(e){t.options.maxZoom=e},setOnZoom:function(e){t.options.onZoom=n.proxy(e,t.publicInstance)},zoom:function(e){t.zoomAtPoint(t.svg,o.getSvgCenterPoint(t.svg),e,!0)},zoomBy:function(e){t.zoomAtPoint(t.svg,o.getSvgCenterPoint(t.svg),e,!1)},zoomAtPoint:function(e,n){t.publicZoomAtPoint(e,n,!0)},zoomAtPointBy:function(e,n){t.publicZoomAtPoint(e,n,!1)},zoomIn:function(){this.zoomBy(1+t.options.zoomScaleSensitivity)},zoomOut:function(){this.zoomBy(1/(1+t.options.zoomScaleSensitivity))},resetZoom:function(){t.resetZoom()},getZoom:function(){return t.getZoom()}}),this.publicInstance};var s=[];t.svgPanZoom=function(t,e){var o=n.getSvg(t);if(null===o)return null;for(var r=s.length-1;r>=0;r--)if(s[r].svg===o)return s[r].instance.getPublicInstance();return s.push({svg:o,instance:new i(o,e)}),s[s.length-1].instance.getPublicInstance()}}(window,document)},{"./control-icons":1,"./mousewheel":2,"./svg-utilities":4,"./utilities":5}],4:[function(t,e){e.exports={getSvgDimensions:function(t){var e=0,n=0,o=t.getClientRects();if("undefined"!=typeof o&&o.length>0){var i=o[0];e=parseFloat(i.width),n=parseFloat(i.height)}else{var r=t.getBoundingClientRect();if(!r)throw new Error("Cannot determine SVG width and height.");e=parseFloat(r.width),n=parseFloat(r.height)}return{width:e,height:n}},getOrCreateViewport:function(t){var e=t.querySelector("g.viewport");if(!e){var e=document.createElementNS("http://www.w3.org/2000/svg","g");e.setAttribute("class","viewport");var n=t.childNodes||t.children;do e.appendChild(n[0]);while(n.length>0);t.appendChild(e)}return e},setupSvgAttributes:function(t){if(t.setAttribute("xmlns","http://www.w3.org/1999/xlink"),t.setAttributeNS("xmlns","xlink","http://www.w3.org/1999/xlink"),t.setAttributeNS("xmlns","ev","http://www.w3.org/2001/xml-events"),null!==t.parentNode){var e=t.getAttribute("style")||"";-1===e.toLowerCase().indexOf("overflow")&&t.setAttribute("style","overflow: hidden; "+e)}},setCTM:function(t,e){var n="matrix("+e.a+","+e.b+","+e.c+","+e.d+","+e.e+","+e.f+")";t.setAttribute("transform",n)},getScreenCTMCached:function(){var t={};return function(e){var n=Date.now();if(t.hasOwnProperty(e)){var o=t[e];return n-o.time>300&&(o.time=n,o.ctm=e.getScreenCTM()),o.ctm}var i=e.getScreenCTM();return t[e]={time:n,ctm:i},i}}(),getRelativeMousePoint:function(t,e){var n=t.createSVGPoint();return n.x=e.clientX,n.y=e.clientY,n.matrixTransform(this.getScreenCTMCached(t).inverse())},getEventPoint:function(t){var e="svg"===t.target.tagName||"SVG"===t.target.tagName?t.target:t.target.ownerSVGElement||t.target.correspondingElement.ownerSVGElement,n=e.createSVGPoint();return n.x=t.clientX,n.y=t.clientY,n},getSvgCenterPoint:function(t){var e=t.getBoundingClientRect(),n=e.width,o=e.height,i=t.createSVGPoint();return i.x=n/2,i.y=o/2,i}}},{}],5:[function(t,e){e.exports={extend:function(t,e){t=t||{};for(var n in e)t[n]="object"==typeof e[n]?extend(t[n],e[n]):e[n];return t},isElement:function(t){return"object"==typeof HTMLElement?t instanceof HTMLElement||t instanceof SVGElement||t instanceof SVGSVGElement:t&&"object"==typeof t&&null!==t&&1===t.nodeType&&"string"==typeof t.nodeName},getSvg:function(t){var e,n;if(this.isElement(t))e=t;else{if(!("string"==typeof t||t instanceof String))throw new Error("Provided selector is not an HTML object nor String");if(e=document.querySelector(t),!e)throw new Error("Provided selector did not find any elements")}if("svg"===e.tagName.toLowerCase())n=e;else if("object"===e.tagName.toLowerCase())n=e.contentDocument.documentElement;else{if("embed"!==e.tagName.toLowerCase())throw new Error("img"===e.tagName.toLowerCase()?'Cannot script an SVG in an "img" element. Please use an "object" element or an in-line SVG.':"Cannot get SVG.");n=e.getSVGDocument().documentElement}return n},proxy:function(t,e){return function(){t.apply(e,arguments)}},getType:function(t){return Object.prototype.toString.apply(t).replace(/^\[object\s/,"").replace(/\]$/,"")}}},{}]},{},[3]); \ No newline at end of file diff --git a/src/utilities.js b/src/utilities.js index 5346df5..37af706 100644 --- a/src/utilities.js +++ b/src/utilities.js @@ -26,7 +26,7 @@ module.exports = { */ , isElement: function(o){ return ( - typeof HTMLElement === "object" ? o instanceof HTMLElement : //DOM2 + typeof HTMLElement === "object" ? (o instanceof HTMLElement || o instanceof SVGElement || o instanceof SVGSVGElement) : //DOM2 o && typeof o === "object" && o !== null && o.nodeType === 1 && typeof o.nodeName==="string" ); }