-
Notifications
You must be signed in to change notification settings - Fork 8
/
ecomm-bridge-generator-im.min.js
1 lines (1 loc) · 9.77 KB
/
ecomm-bridge-generator-im.min.js
1
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){var d=a("./utilities"),e=a("./dataParser"),f=a("./xmlParser"),g=function(a,b,c){this.cache={},this.queue={},this.fails={},this.xd=b,this.iframe=null,this.method=c,this.local=window.location,this.target=d.parseURL(a)};g.prototype.load=function(a,b,c){this.local.hostname===this.target.hostname?this.loadLocal(a,b,c):this.loadXD(a,b,c)},g.prototype.netCallback=function(a,b,c){var d=this.queue[a];if(d){if(b&&(c=this.parseData(c)),b)c!==!1?this.cache[a]=c:this.fails[a]={status:"error",response:c};else{try{c=f(c)}catch(e){}this.fails[a]={status:"error",response:c}}for(var g=0;g<d.success.length;g++)d.success[g]&&d.fail[g]&&(b?d.success[g](a,c):d.fail[g](a,{status:"error",response:c}));delete this.queue[a]}},g.prototype.loadXD=function(a,b,c){this.createIframe();var d=this.getOrigin(this.target)+this.parseURLToken(a);if(null==this.xd)return void callback("Origin error, no xd handler",null);var e={type:"xdLoad",url:d,method:this.method,data:{},headers:this.headers,id:a,dest:this.getOrigin(this.target),from:this.getOrigin(this.local)};e.dataString=window.JSON.stringify(e),this.queue[a]?(this.queue[a].success.push(b),this.queue[a].fail.push(c)):this.queue[a]={success:[b],fail:[c]},this.xdLoaded?this.iframe.contentWindow.postMessage(e.dataString,e.dest):this.xdQueue.push(e)},g.prototype.createIframe=function(){if(null==this.iframe){var a=this;this.xdQueue=[],this.xdLoaded=!1;var b=this.iframe=document.createElement("iframe");b.style.visibility="hidden",b.style.width="0px",b.style.heigh="0px",b.style.border="0px";var c=function(){for(var b=0;b<a.xdQueue.length;b++){var c=a.xdQueue[b];a.iframe.contentWindow.postMessage(c.dataString,c.dest)}a.xdLoaded=!0};b.addEventListener?b.addEventListener("load",c,!1):b.attachEvent&&b.attachEvent("onload",c),window.addEventListener?window.addEventListener("message",d.baseClosure(this.xdMessage,this),!1):window.attachEvent&&window.attachEvent("onmessage",d.baseClosure(this.xdMessage,this)),b.src=this.xd,document.body.appendChild(this.iframe)}},g.prototype.loadLocal=function(a,b,c){var d=new XMLHttpRequest,e=this;this.queue[a]?(this.queue[a].success.push(b),this.queue[a].fail.push(c)):this.queue[a]={success:[b],fail:[c]};var f=this.getOrigin(this.target)+this.parseURLToken(a);if(d.open(this.method,f,!0),this.headers)for(var g in this.headers)this.headers.hasOwnProperty(g)&&d.setRequestHeader(g,config.headers[g]);d.onreadystatechange=function(){4==d.readyState&&e.netCallback(a,200==d.status,d.responseText)},"POST"==this.method?d.send(null):d.send(null)},g.prototype.parseURLToken=function(a){var b="%7B%7Bsku%7D%7D",c="{{sku}}",d=this.target.pathname+this.target.search,e=d.indexOf(b),f=d.indexOf(c),g="";return-1!==e?g=d.substr(0,e)+a+d.substr(e+b.length):-1!==f&&(g=d.substr(0,f)+a+d.substr(f+c.length)),g},g.prototype.getOrigin=function(a){return a.origin||(a.origin=a.protocol+"//"+a.hostname+"/"),a.origin},g.prototype.parseData=function(a){var b=f(a),c=b?e(b):b;return c},g.prototype.xdMessage=function(a){try{var b=window.JSON.parse(a.data);"object"==typeof b&&"xdLoaded"==b.type&&this.netCallback(b.id,200==b.status,b.data)}catch(c){}},b.exports=g},{"./dataParser":4,"./utilities":6,"./xmlParser":7}],2:[function(a,b,c){var d=a("./utilities"),e=a("./Request"),f=a("./NetworkLoader"),g=function(a){this.requests=[],a.method&&(a.method=a.method.toUpperCase()),this.networkLoader=new f(a.url,a.xd,a.method||"GET")};g.prototype.load=function(a,b){if(!a&&b)return void b("No SKUs");if(!a||!b)return void b("No SKUs or callback");if(d.isArray(a)){if(0===a.length)return void b("No SKUs")}else a=[a];var c=new e(a,b);this.requests.push(c);for(var f=0;f<a.length;f++){var g=a[f].id;if(this.networkLoader.cache[g])c.addCached(g,this.networkLoader.cache[g]);else if(!this.networkLoader.queue[g]){var h=this;this.networkLoader.load(g,function(a,b){h.addSuccess(a,b)},function(a,b){h.addFail(a,b)})}}},g.prototype.addSuccess=function(a,b){for(var c=0;c<this.requests.length;c++)this.requests[c].requesting(a)&&this.requests[c].addSuccess(a,b)},g.prototype.addFail=function(a,b){for(var c=0;c<this.requests.length;c++)this.requests[c].requesting(a)&&this.requests[c].addFail(a,b)},b.exports=g},{"./NetworkLoader":1,"./Request":3,"./utilities":6}],3:[function(a,b,c){var d=a("./utilities"),e=function(a,b){this.cached={},this.failed={},this.success={},this.done=[],this.skus=a,this.cb=b,this.finished=!1};e.prototype.completeRequest=function(){if(!this.finished){for(var a=[],b=0;b<this.skus.length;b++){var c=this.skus[b].id;this.cached[c]?a.push(this.cached[c]):this.failed[c]?a.push(this.failed[c]):this.success[c]&&a.push(this.success[c])}this.cb(null,a),this.finished=!0}},e.prototype.checkLoaded=function(){this.finished||this.done.length>=this.skus.length&&this.completeRequest()},e.prototype.addCached=function(a,b){-1===d.indexOf(this.done,a)&&(this.done.push(a),this.cached[a]=b,this.checkLoaded())},e.prototype.requesting=function(a){for(var b=0;b<this.skus.length;b++)if(this.skus[b].id==a)return!0;return!1},e.prototype.addFail=function(a,b){-1===d.indexOf(this.done,a)&&(this.done.push(a),this.failed[a]=b,this.checkLoaded())},e.prototype.addSuccess=function(a,b){-1===d.indexOf(this.done,a)&&(this.success[a]=b,this.done.push(a),this.checkLoaded())},b.exports=e},{"./utilities":6}],4:[function(a,b,c){function d(a){function b(a){function b(a){return a?a._body:void 0}function c(a){return"true"===a.toLowerCase()?!0:"false"===a.toLowerCase()?!1:"[object Boolean]"===Object.prototype.toString.call(a)?a:void 0}function d(a){var b=c(a);return void 0===b?"":b?"In Stock":"Out of stock"}function e(a){var c=b(a.images.large),d=b(a.images.medium),e=b(a.images.small);return c?c:d?d:e?e:""}function f(a){var c=b(a.images.large),d=b(a.images.medium),e=b(a.images.small);return e?e:d?d:c?c:""}return{productID:b(a.sku),sku:b(a.sku),name:b(a.name),description:b(a.description),descriptionLong:null,url:b(a.link),image:e(a),thumbnail:f(a),ratingValue:null,ratingsImage:null,price:b(a.price),priceWas:b(a.wasprice),priceCurrency:null,availability:d(b(a.instock)),custom:{}}}if("products"==a._name){for(var c=[],d=0;d<a.length;d++)c.push(b(a[d]));return c}return b(a)}b.exports=d},{}],5:[function(a,b,c){!function(){function b(a){var b=new c(a);window.ecommBridge.site||(window.ecommBridge.site={}),window.ecommBridge.site.getProduct=d.baseClosure(b.load,b),window.ecommBridge.capability||(window.ecommBridge.capability={}),window.ecommBridge.site.getProduct&&"function"==typeof window.ecommBridge.site.getProduct&&(window.ecommBridge.capability.getProduct=!0)}var c=a("./ProductLoader"),d=a("./utilities");window.ecommBridge||(window.ecommBridge={}),window.ecommBridge.IMGenerator=b}()},{"./ProductLoader":2,"./utilities":6}],6:[function(a,b,c){function d(a){function b(a,b){try{if(a=cssRemap[a]||a,!b&&0!==b)return this.style[a];this.style[a]=b}catch(c){}}var c=document.createElement(a);return c.css=b,c}function e(a){var b=document.createElement("a");b.href=a;var c={hash:b.hash,host:b.host,hostname:b.hostname,href:b.href,origin:b.origin,pathname:b.pathname,port:b.port,protocol:b.protocol,search:b.search};return b=null,c}function f(a){return"[object Array]"===Object.prototype.toString.call(a)}function g(a,b,c){return function(){for(var d=[],e=0;e<arguments.length;e++)d.push(arguments[e]);return d.push(c),a.apply(b,d)}}var h=function(a,b){if(null==a)throw new TypeError;var c=Object(a),d=c.length>>>0;if(0===d)return-1;var e=0;if(arguments.length>1&&(e=Number(arguments[2]),e!=e?e=0:0!=e&&e!=1/0&&e!=-(1/0)&&(e=(e>0||-1)*Math.floor(Math.abs(e)))),e>=d)return-1;for(var f=e>=0?e:Math.max(d-Math.abs(e),0);d>f;f++)if(f in c&&c[f]===b)return f;return-1};b.exports={isArray:f,createElement:d,parseURL:e,baseClosure:g,indexOf:h}},{}],7:[function(a,b,c){function d(a,b){if(b||(b=this.root||this),a){a.root=b,a.nodeText=g;for(var c in a)"root"!=c&&"_parent"!=c&&"object"==typeof a[c]&&d(a[c],b);return a}}function e(a){var b,c=/^<\?xml\sversion=(.*)\?>/.test(a);return c?window.DOMParser?b=(new DOMParser).parseFromString(a,"application/xhtml+xml"):window.ActiveXObject&&(b=new ActiveXObject("Microsoft.XMLDOM"),b.async="false",b.loadXML(a)):b=!1,b}function f(a){if("string"==typeof a)a=e(a);else if(!a.root&&!a.childNodes)return h(a,a,null),a;if(a){if(!a.childNodes)return a;for(var b=0;b<a.childNodes.length;b++)return 1==a.childNodes[b].nodeType?i(a.childNodes[b]):!1}}function g(a){var b=a?this[a]:this;return b?"string"==typeof b?k.trim(b):b._body?k.trim(b._body):null:null}function h(a,b,c){a.root=b,a._parent=c,a.importNode=d,a.nodeText=g;for(var e=0;e<a.length;e++){var f=a[e];h(f,b,a);var i=f._name,j=i.indexOf(":");-1!=j&&(i=i.slice(j+1)),j=i.indexOf("."),-1!=i&&(i=i.slice(j+1)),a[i]=f}for(var e in a)f=a[e],"true"==f&&(f=!0),"false"==f&&(f=!1),a[e]=f}function i(a,b,c){var e={length:0};if(e._name=a.nodeName,e.root=b,e._parent=c,e.importNode=d,e.nodeText=g,b||(e.root=e),null!=a.attributes)for(var f=0;f<a.attributes.length;f++){var h=a.attributes[f],j=h.value.toString();"true"==j&&(j=!0),"false"==j&&(j=!1),e[h.nodeName]=j}for(var k=a.childNodes,f=0;f<k.length;f++){var l=k[f];if(1==l.nodeType){var m=l.nodeName,n=m.indexOf(":");-1!=n&&(m=m.slice(n+1)),n=m.indexOf("."),-1!=m&&(m=m.slice(n+1));var o=i(l,e.root,e),p=e.length;e[p]=o,e.length++,e[m]=o}}return a.childNodes.length>0&&(e._body=a.childNodes[0].nodeValue),e}function j(a){var b=e(a);if(b===!1)return!1;var c=f(b);return c}var k=this;k.getNodeByName=function(a,b){b=b.toLowerCase();for(var c=0;c<a.length;c++)if(a[c]&&a[c]._name&&a[c]._name.toLowerCase()==b)return a[c];return null},b.exports=j},{}]},{},[5]);