Skip to content

Instantly share code, notes, and snippets.

@genee19
Created May 17, 2011 18:27
Show Gist options
  • Save genee19/977052 to your computer and use it in GitHub Desktop.
Save genee19/977052 to your computer and use it in GitHub Desktop.
Ecwid addon: a drop-in script to make any scripts inserted in product description to work out of the box.
(function(){(function(k,h,M){function H(){var a=l;a.loader={load:N,i:0};return a}function N(a,c,e){var m=c=="c"?O:I;w=0;c=c||"j";x(a)?P(m,a,c,this.i++,y,e):(s.splice(this.i++,0,a),s.length==1&&z());return this}function P(a,c,e,m,n,i){function t(){!f&&(!b.readyState||b.readyState=="loaded"||b.readyState=="complete")&&(g.r=f=1,!w&&o(),b.onload=b.onreadystatechange=null,p(function(){A.removeChild(b)},0))}var b=h.createElement(a),f=0,g={t:e,s:c,e:i};b.src=b.data=c;!B&&(b.style.display="none");b.width=
b.height="0";a!="object"&&(b.type=e);b.onload=b.onreadystatechange=t;a=="img"?b.onerror=t:a=="script"&&(b.onerror=function(){g.e=g.r=1;z()});s.splice(m,0,g);A.insertBefore(b,B?null:v);p(function(){f||(A.removeChild(b),g.r=g.e=f=1,o())},l.errorTimeout)}function z(){var a=s.shift();w=1;a?a.t?p(function(){a.t=="c"?Q(a):R(a)},0):(a(),o()):w=0}function Q(a){var c=h.createElement("link"),e;c.href=a.s;c.rel="stylesheet";c.type="text/css";if(!a.e&&(C||D)){var m=function(n){p(function(){if(!e)try{n.sheet.cssRules.length?
(e=1,o()):m(n)}catch(i){i.code==1E3||i.message=="security"||i.message=="denied"?(e=1,p(function(){o()},0)):m(n)}},0)};m(c)}else{c.onload=function(){e||(e=1,p(function(){o()},0))};a.e&&c.onload()}p(function(){e||(e=1,o())},l.errorTimeout);!a.e&&v.parentNode.insertBefore(c,v)}function R(a){var c=h.createElement("script"),e;c.src=a.s;c.onreadystatechange=c.onload=function(){!e&&(!c.readyState||c.readyState=="loaded"||c.readyState=="complete")&&(e=1,o(),c.onload=c.onreadystatechange=null)};p(function(){e||
(e=1,o())},l.errorTimeout);a.e?c.onload():v.parentNode.insertBefore(c,v)}function o(){for(var a=1,c=-1;s.length-++c;)if(s[c].s&&!(a=s[c].r))break;a&&z()}var y=h.documentElement,p=k.setTimeout,v=h.getElementsByTagName("script")[0],E={}.toString,s=[],w=0,D="MozAppearance"in y.style,B=D&&!!h.createRange().compareNode,A=B?y:v.parentNode,S=k.opera&&E.call(k.opera)=="[object Opera]",C="webkitAppearance"in y.style,T=C&&"async"in h.createElement("script"),I=D?"object":S||T?"img":"script",O=C?"img":I,J=Array.isArray||
function(a){return E.call(a)=="[object Array]"},x=function(a){return typeof a=="string"},F=function(a){return E.call(a)=="[object Function]"},G=[],K={},L,l;l=function(a){function c(b,f){function g(u){if(x(u))e(u,d,f,0,j);else if(Object(u)===u)for(q in u)u.hasOwnProperty(q)&&e(u[q],d,f,q,j)}var j=!!b.test,r=b.load||b.both,d=b.callback,q;g(j?b.yep:b.nope);g(r);b.complete&&f.load(b.complete)}function e(b,f,g,j,r){var d=m(b),q=d.autoCallback;if(!d.bypass){f&&(f=F(f)?f:f[b]||f[j]||f[b.split("/").pop().split("?")[0]]);
if(d.instead)return d.instead(b,f,g,j,r);g.load(d.url,d.forceCSS||!d.forceJS&&/css$/.test(d.url)?"c":M,d.noexec);(F(f)||F(q))&&g.load(function(){H();f&&f(d.origUrl,r,j);q&&q(d.origUrl,r,j)})}}function m(b){b=b.split("!");var f=G.length,g=b.pop(),j=b.length;g={url:g,origUrl:g,prefixes:b};var r,d;for(d=0;d<j;d++)(r=K[b[d]])&&(g=r(g));for(d=0;d<f;d++)g=G[d](g);return g}var n,i,t=this.yepnope.loader;if(x(a))e(a,0,t,0);else if(J(a))for(n=0;n<a.length;n++){i=a[n];x(i)?e(i,0,t,0):J(i)?l(i):Object(i)===i&&
c(i,t)}else Object(a)===a&&c(a,t)};l.addPrefix=function(a,c){K[a]=c};l.addFilter=function(a){G.push(a)};l.errorTimeout=1E4;h.readyState==null&&h.addEventListener&&(h.readyState="loading",h.addEventListener("DOMContentLoaded",L=function(){h.removeEventListener("DOMContentLoaded",L,0);h.readyState="complete"},0));k.yepnope=H()})(window,window.document);yepnope({test:"jQuery"in window,nope:"https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js",callback:function(k,h){if(!h)window.jQuery.noConflict()},
complete:function(){var k;k=window.jQuery;window.Ecwid.OnPageLoaded.add(function(h){if(h.type==="PRODUCT")k(".ecwid-productBrowser-details-descr").find("script").each(function(){k(this).clone().insertAfter(this).end().remove()})})}})}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment