1 |
- define(["jquery"],function(e){var t=[],n=function(n,r){var i=[],s=[],o=r||{},u=function(e){var t=0,n;if(e)for(;t<s.length;t++)n=e[s[t][1]],n&&s[t][0](n)};this.addResource=function(t,n){var r=i.length;while(r--)if(i[r]==t)break;!~r&&i.push(t);var s=e.inArray("view",i);s!=-1&&i.length>1&&s!=0&&(i.splice(s,1),i.unshift("view")),s=e.inArray("recommendations",i),s!=-1&&i.length>1&&s!=i.length-1&&(i.splice(s,1),i.push("recommendations")),e.extend(!0,o,n)},this.addCallback=function(e,t){s.push([e,t])},this.addParam=function(e){var t,n;for(t in e||{})n=e[t],typeof n!="object"&&t!="retailerId"&&(o[t]=n)},this.send=function(){if(!i.length)return;var e=n(i.join("/")),r="utf-8",s=window,a=s.JSON,f,l,c,f=new XMLHttpRequest;l=a.stringify(o),t.push({url:e,params:l}),f.open("POST",e,!0),f.onreadystatechange=function(){c=this.responseText?this.responseText.trim():this.responseText,this.readyState==4&&this.status==200&&c&&u(a.parse(c))},f.withCredentials="true",f.setRequestHeader("Content-Type","text/plain;charset="+r),f.send(l)}};return{RESTRequest:n}})
|