-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.interject.min.js
2 lines (2 loc) · 2.16 KB
/
jquery.interject.min.js
1
2
/** Interject - Inline SVG injector */
;(function(f,c,h){if(!f.Interject){f.Interject={}}var b={_values:false,_keys:[],remove:function(i){var e=this._keys.indexOf(i);if(e>-1){localStorage.removeItem(i);this._keys.splice(e,1)}},exist:function(e){if(this._keys.indexOf(e)>-1){return true}else{if(localStorage.getItem(e)!==null){this._keys.push(e);return true}}return false},get:function(e){if(this._keys.indexOf(e)==-1){this._keys.push(e)}return localStorage.getItem(e)},set:function(i,j,k){if(j instanceof SVGSVGElement){var e=new XMLSerializer().serializeToString(j);localStorage.setItem(i,e);this._keys.push(i);if(k instanceof Function){k(j)}return}throw new Error(j+" is not of type [object SVGSVGElement].")},clear:function(){this._keys.forEach(function(e){localStorage.removeItem(e)});this._keys=[]}},a={_values:[],_keys:[],remove:function(i){var e=this._keys.indexOf(i);if(e>-1){this._values.splice(e,1);this._keys.splice(e,1)}},exist:function(e){return this._keys.indexOf(e)>-1},get:function(i){var e=this._keys.indexOf(i);if(e>-1){return this._values[e]}return null},set:function(e,i,j){this.remove(e);this._keys.push(e);this._values.push(i);if(j instanceof Function){j(i)}},clear:function(){this._keys=[];this._values=[]}},d=false;try{d="localStorage" in c&&c.localStorage!==null}catch(g){}f.Interject.Cache=d?b:a;f.Interject.Svg=function(m,j){var n=this;n.$el=f(m);n.el=m;n.$el.data("Interject.Svg",n);n.init=function(){n.options=f.extend({},f.Interject.Options,j)};n.init();var l=n.$el;var i=l.attr("id");var k=l.attr("class");var e=l.attr("src");f.ajax({url:e,async:true,cache:n.options.cache,success:function(p){var o=f(p).find("svg");if(typeof i!=="undefined"){o=o.attr("id",i)}if(typeof k!=="undefined"){o=o.attr("class",k+" replaced-svg")}o=o.removeAttr("xmlns:a");l.replaceWith(o);if(n.options.cache){f.Interject.Cache.set(e,o[0])}},beforeSend:function(){if(n.options.cache&&f.Interject.Cache.exist(e)){l.replaceWith(f.Interject.Cache.get(e));return false}return true}})};f.Interject.Options={cache:true};f.fn.interject_svg=function(e){return this.each(function(){(new f.Interject.Svg(this,e))})};f.fn.interject_clear_cache=function(){f.Interject.Cache.clear();return this}}(jQuery,window));