openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

svg-injector.min.js (4552B)


      1 (function(e,r){'use strict';var p=e.location.protocol==='file:',h=r.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#BasicStructure','1.1');function g(e){e=e.split(' ');var n={};var t=e.length,r=[];while(t--){if(!n.hasOwnProperty(e[t])){n[e[t]]=1;r.unshift(e[t])}};return r.join(' ')};var o=Array.prototype.forEach||function(e,t){if(this===void 0||this===null||typeof e!=='function'){throw new TypeError()};var r,n=this.length>>>0;for(r=0;r<n;++r){if(r in this){e.call(t,this[r],r,this)}}},t={};var f=0,i=[],n=[],c={};var l=function(e){return e.cloneNode(!0)},s=function(e,t){n[e]=n[e]||[];n[e].push(t)},d=function(e){for(var r=0,i=n[e].length;r<i;r++){(function(r){setTimeout(function(){n[e][r](l(t[e]))},0)})(r)}},v=function(r,i){if(t[r]!==undefined){if(t[r]instanceof SVGSVGElement){i(l(t[r]))}
      2 else{s(r,i)}}
      3 else{if(!e.XMLHttpRequest){i('Browser does not support XMLHttpRequest');return!1};t[r]={};s(r,i);var n=new XMLHttpRequest();n.onreadystatechange=function(){if(n.readyState===4){if(n.status===404||n.responseXML===null){i('Unable to load SVG file: '+r);if(p)i('Note: SVG injection ajax calls do not work locally without adjusting security setting in your browser. Or consider using a local webserver.');i();return!1};if(n.status===200||(p&&n.status===0)){if(n.responseXML instanceof Document){t[r]=n.responseXML.documentElement}
      4 else if(DOMParser&&(DOMParser instanceof Function)){var e;try{var o=new DOMParser();e=o.parseFromString(n.responseText,'text/xml')}catch(a){e=undefined};if(!e||e.getElementsByTagName('parsererror').length){i('Unable to parse SVG file: '+r);return!1}
      5 else{t[r]=e.documentElement}};d(r)}
      6 else{i('There was a problem injecting the SVG: '+n.status+' '+n.statusText);return!1}}};n.open('GET',r);if(n.overrideMimeType)n.overrideMimeType('text/xml');n.send()}},u=function(t,r,l,n){var a=t.getAttribute('data-src')||t.getAttribute('src');if(!(/\.svg/i).test(a)){n('Attempted to inject a file with a non-svg extension: '+a);return};if(!h){var s=t.getAttribute('data-fallback')||t.getAttribute('data-png');if(s){t.setAttribute('src',s);n(null)}
      7 else if(l){t.setAttribute('src',l+'/'+a.split('/').pop().replace('.svg','.png'));n(null)}
      8 else{n('This browser does not support SVG and no PNG fallback was defined.')};return};if(i.indexOf(t)!==-1){return};i.push(t);t.setAttribute('src','');v(a,function(l){if(typeof l==='undefined'||typeof l==='string'){n(l);return!1};var j=t.getAttribute('id');if(j){l.setAttribute('id',j)};var k=t.getAttribute('title');if(k){l.setAttribute('title',k)};var E=[].concat(l.getAttribute('class')||[],'injected-svg',t.getAttribute('class')||[]).join(' ');l.setAttribute('class',g(E));var x=t.getAttribute('style');if(x){l.setAttribute('style',x)};var V=[].filter.call(t.attributes,function(e){return(/^data-\w[\w\-]*$/).test(e.name)});o.call(V,function(e){if(e.name&&e.value){l.setAttribute(e.name,e.value)}});var S={'clipPath':['clip-path'],'color-profile':['color-profile'],'cursor':['cursor'],'filter':['filter'],'linearGradient':['fill','stroke'],'marker':['marker','marker-start','marker-mid','marker-end'],'mask':['mask'],'pattern':['fill','stroke'],'radialGradient':['fill','stroke']};var A,v,w,m,b;Object.keys(S).forEach(function(e){A=e;w=S[e];v=l.querySelectorAll('defs '+A+'[id]');for(var t=0,n=v.length;t<n;t++){m=v[t].id;b=m+'-'+f;var r;o.call(w,function(e){r=l.querySelectorAll('['+e+'*="'+m+'"]');for(var t=0,n=r.length;t<n;t++){r[t].setAttribute(e,'url(#'+b+')')}});v[t].id=b}});l.removeAttribute('xmlns:a');var u=l.querySelectorAll('script'),p=[],y,d;for(var s=0,M=u.length;s<M;s++){d=u[s].getAttribute('type');if(!d||d==='application/ecmascript'||d==='application/javascript'){y=u[s].innerText||u[s].textContent;p.push(y);l.removeChild(u[s])}};if(p.length>0&&(r==='always'||(r==='once'&&!c[a]))){for(var h=0,T=p.length;h<T;h++){new Function(p[h])(e)};c[a]=!0};var G=l.querySelectorAll('style');o.call(G,function(e){e.textContent+=''});t.parentNode.replaceChild(l,t);delete i[i.indexOf(t)];t=null;f++;n(l)})},a=function(e,t,r){t=t||{};var a=t.evalScripts||'always',l=t.pngFallback||!1,n=t.each;if(e.length!==undefined){var i=0;o.call(e,function(t){u(t,a,l,function(t){if(n&&typeof n==='function')n(t);if(r&&e.length===++i)r(i)})})}
      9 else{if(e){u(e,a,l,function(t){if(n&&typeof n==='function')n(t);if(r)r(1);e=null})}
     10 else{if(r)r(0)}}};if(typeof module==='object'&&typeof module.exports==='object'){module.exports=exports=a}
     11 else if(typeof define==='function'&&define.amd){define(function(){return a})}
     12 else if(typeof e==='object'){e.SVGInjector=a}}(window,document));