UNPKG

sizeme.js

Version:

Javascript utils for accessing the SizeMe API

1 lines 4 kB
(function(){var t,e={}.hasOwnProperty,n=[].slice;t=function(){function t(t){n=t}var n,r,o,i,s;return t.contextAddress="https://www.sizeme.com",t.version="2.0",n=void 0,r=function(){return!("withCredentials"in XMLHttpRequest.prototype)},o=function(e,o,i,s){var u,a;return a=void 0,u=""+t.contextAddress+o,r()?"undefined"!=typeof XDomainRequest&&null!==XDomainRequest?(a=new XDomainRequest,u=u+"?_tm="+(new Date).getTime(),null!=n&&(u=u+"&authToken="+n),a.onload=function(){return i(a)},a.onerror=function(){return s(a)},a.open(e,u,!0)):console.error("Unsupported browser"):(a=new XMLHttpRequest,a.onreadystatechange=function(){return 4===a.readyState?a.status>=200&&a.status<300?i(a):s(a):void 0},a.open(e,u,!0),null!=n&&a.setRequestHeader("X-AUTH-TOKEN",n)),a},s=function(t,e,n){return window.console&&console.log?console.log("Error: "+n+" ("+e+")"):void 0},t.getAuthToken=function(e,n){var i,u,a;null==n&&(n=s),r()?(u=document.createElement("iframe"),i=function(t){var n;n=JSON.parse(t.data),window.detachEvent("onmessage",i),document.body.removeChild(u),null!=e&&"function"==typeof e&&e(n)},window.attachEvent("onmessage",i),u.setAttribute("src",t.contextAddress+"/api/authToken.html"),u.setAttribute("style","display:none"),document.body.appendChild(u)):(a=o("GET","/api/authToken",function(t){return e(JSON.parse(t.responseText))},function(t){return n(t,t.status,t.statusText)}),a.withCredentials=!0,a.send())},i=function(n){var r,o,i,s;o=JSON.parse(n.responseText),i=new t.Map;for(s in o)e.call(o,s)&&(r=o[s],r.matchMap=t.Map.fromObject(r.matchMap),i.addItem(s,r));return i},t.prototype.fetchProfilesForAccount=function(t,e){return null==e&&(e=s),void o("GET","/api/profiles",function(e){return t(JSON.parse(e.responseText))},function(t){return e(t,t.status,t.statusText)}).send()},t.prototype.match=function(t,e,n){var r,u;return null==n&&(n=s),r=JSON.stringify(t),u=o("POST","/api/compareSizes",function(t){return e(i(t))},function(t){return n(t,t.status,t.statusText)}),null!=u.setRequestHeader&&u.setRequestHeader("Content-Type","application/json"),void u.send(r)},t.prototype.getItemTypes=function(t,e){return null==e&&(e=s),void o("GET","/api/itemTypes",function(e){return t(JSON.parse(e.responseText))},function(t){return e(t,t.status,t.statusText)}).send()},t.loginFrame=function(e){var n,r,o,i;o=t.contextAddress+"/loginframe.html",n="height=375,width=349,left=200,top=200,location=no,menubar=no, resizable=no,scrollbars=no,toolbar=no",i=window.open(o,"",n),r=null!=i?setInterval(function(){return i.closed&&(clearInterval(r),null!=i)?e():void 0},100):void 0},t}(),t.Map=function(){function r(){}return r.prototype.keys=function(){var t,n;n=[];for(t in this)e.call(this,t)&&n.push(t);return n},r.prototype.each=function(t){var n,r;for(n in this)e.call(this,n)&&(r=this[n],t(n,r));return void 0},r.prototype.addItem=function(t,e){return this[t]=e,this},r.prototype.addItems=function(){var t,e,r,o;if(e=1<=arguments.length?n.call(arguments,0):[],e.length%2!==0)throw new Error('Arguments must be "tuples" (example: (key1, value1, key2, value2, ...)');for(t=r=0,o=e.length;o>r;t=r+=2)this.addItem(e[t],e[t+1]);return this},r.fromObject=function(n){var r,o,i;o=new t.Map;for(r in n)e.call(n,r)&&(i=n[r],o.addItem(r,i));return o},r}(),t.FitRequest=function(){function t(t,e){this.profileId=t,this.item=e}return t}(),t.Item=function(){function e(e,n,r,o){this.itemType=e,this.itemLayer=null!=n?n:0,this.itemThickness=null!=r?r:0,this.itemStretch=null!=o?o:0,this.measurements=new t.Map}return e.prototype.addSize=function(t,e){return this.measurements.addItem(t,e),this},e}(),t.FitRange=function(){function t(){}var n;return n={too_small:{start:0,end:1e3},slim:{start:1e3,end:1050},regular:{start:1050,end:1110},loose:{start:1110,end:1170},too_big:{start:1170,end:99990}},t.getFitRangeLabels=function(){return n},t.getFitRangeLabel=function(t){var r,o,i;return i=function(){var i;i=[];for(r in n)e.call(n,r)&&(o=n[r],o.start<=t&&o.end>t&&i.push(r));return i}()},t}(),window.SizeMe=t}).call(this);