diff --git a/dist/plugin.js b/dist/plugin.js index 9dbcbfc..cb43dc2 100644 --- a/dist/plugin.js +++ b/dist/plugin.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var CSSOM=require("cssom"),myClassName="simple-svg",SimpleSVG={render:function(e){return e("div",{class:["simple-svg-wrapper"]})},name:"simple-svg",props:{filepath:String,fill:String,stroke:String,width:String,height:String,id:{type:String,defualt:""}},data:function(){return{isSVGReady:!1}},mounted:function(){this.generateInlineSVG()},watch:{filepath:function(e){this.generateInlineSVG()},fill:function(e){this.updateSVGStyle("fill",e)},stroke:function(e){this.updateSVGStyle("stroke",e)},width:function(e){this.updateSVGStyle("width",e)},height:function(e){this.updateSVGStyle("height",e)}},methods:{isClassSelector:function(e){return!!new RegExp(/^\./,"i").test(e)},removeStyleTag:function(e){for(var t=e.getElementsByTagName("style")[0],s=CSSOM.parse(t.textContent).cssRules,r=e.getElementsByTagName("*"),i=0;i=200&&s.status<400){var t=(new DOMParser).parseFromString(s.responseText,"text/xml").getElementsByTagName("svg")[0];if(!t)return void console.error("No svg element found. Did you pass a valid .svg file?");t.getElementsByTagName("style")[0]&&(t=e.removeStyleTag(t)),e.removeFillStrokeStyles(t),t.removeAttribute("xmlns:a"),t.removeAttribute("width"),t.removeAttribute("height"),t.removeAttribute("x"),t.removeAttribute("y"),t.removeAttribute("enable-background"),t.removeAttribute("xmlns:xlink"),t.removeAttribute("xml:space"),t.removeAttribute("version"),e.id&&(t.id=e.id),t.style.width=e.width,t.style.height=e.height,t.style.fill=e.fill,t.style.stroke=e.stroke,t.classList.add(myClassName),e.$el.appendChild(t),this.isSVGReady=!0,e.$emit("ready")}else console.error("There was an error retrieving the source of the SVG.")},s.onerror=function(){console.error("There was an error connecting to the origin server.")},s.send()},updateSVGStyle:function(e,t){var s=this.$el.getElementsByTagName("svg")[0];s?s.style[e]=t:console.error("No svg element found. Did you pass a valid .svg file?")}}},plugin={install:function(e,t){e.component("simple-svg",SimpleSVG)}};exports.default=plugin,exports.SimpleSVG=SimpleSVG; +"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var CSSOM=require("cssom"),myClassName="simple-svg",SimpleSVG={render:function(e){return e("div",{class:["simple-svg-wrapper"]})},name:"simple-svg",props:{filepath:String,fill:String,stroke:String,width:String,height:String,id:{type:String,defualt:""}},data:function(){return{isSVGReady:!1}},mounted:function(){this.generateInlineSVG()},watch:{filepath:function(e){this.generateInlineSVG()},fill:function(e){this.updateSVGStyle("fill",e)},stroke:function(e){this.updateSVGStyle("stroke",e)},width:function(e){this.updateSVGStyle("width",e)},height:function(e){this.updateSVGStyle("height",e)}},methods:{isClassSelector:function(e){return!!new RegExp("/^./","i").test(e)},removeStyleTag:function(e){for(var t=e.getElementsByTagName("style")[0],r=CSSOM.parse(t.textContent).cssRules,s=e.getElementsByTagName("*"),i=0;i-1){s[i].classList.remove(o);for(var a=r[n].style,u=0;u=200&&r.status<400){var t=(new DOMParser).parseFromString(r.responseText,"text/xml").getElementsByTagName("svg")[0];if(!t)return void console.error("No svg element found. Did you pass a valid .svg file?");t.getElementsByTagName("style")[0]&&(t=e.removeStyleTag(t)),e.removeFillStrokeStyles(t),t.removeAttribute("xmlns:a"),t.removeAttribute("width"),t.removeAttribute("height"),t.removeAttribute("x"),t.removeAttribute("y"),t.removeAttribute("enable-background"),t.removeAttribute("xmlns:xlink"),t.removeAttribute("xml:space"),t.removeAttribute("version"),e.id&&(t.id=e.id),t.style.width=e.width,t.style.height=e.height,t.style.fill=e.fill,t.style.stroke=e.stroke,t.setAttribute("class",myClassName),e.$el.appendChild(t),this.isSVGReady=!0,e.$emit("ready")}else console.error("There was an error retrieving the source of the SVG.")},r.onerror=function(){console.error("There was an error connecting to the origin server.")},r.send()},updateSVGStyle:function(e,t){var r=this.$el.getElementsByTagName("svg")[0];r?r.style[e]=t:console.error("No svg element found. Did you pass a valid .svg file?")}}},plugin={install:function(e,t){e.component("simple-svg",SimpleSVG)}};exports.default=plugin,exports.SimpleSVG=SimpleSVG; diff --git a/src/plugin.js b/src/plugin.js index a89eefb..1a5ac47 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -75,7 +75,7 @@ let SimpleSVG = { // prepare the classname without a dot at the beginning let className = selectorToRemove.substring(1) - if (elements[i].classList.contains(className)) { + if (elements[i].classList.indexOf(className) > -1) { // if an element has a class to be removed // remove the class @@ -169,7 +169,7 @@ let SimpleSVG = { inlinedSVG.style.height = context.height inlinedSVG.style.fill = context.fill inlinedSVG.style.stroke = context.stroke - inlinedSVG.classList.add(myClassName) // add an additional class + inlinedSVG.setAttribute('class', myClassName); // add an additional class context.$el.appendChild(inlinedSVG)