-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
1 lines (1 loc) · 12.6 KB
/
app.js
1
(function(){var e,t,n,r;window._Shopify=window._Shopify||{},t=["Shopify.API.reportScroll"],n=function(e,n){var r,i,o;if(("undefined"!=typeof console&&null!==console?console.log:void 0)&&(("undefined"!=typeof ShopifyApp&&null!==ShopifyApp?ShopifyApp.debug:void 0)||("undefined"!=typeof ShopifyPOS&&null!==ShopifyPOS?ShopifyPOS.debug:void 0)||n)&&!window.Teaspoon){for(i=0,o=t.length;o>i;i++)if(r=t[i],e.indexOf(r)>0)return;return console.log("ShopifyApp "+e)}},r=function(e){return("undefined"!=typeof console&&null!==console?console.warn:void 0)&&!window.Teaspoon?console.warn("ShopifyApp "+e):n(e,!0)},_Shopify.messageSlug=function(e){var t,n;for(t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e=(e||"message")+"_",n=0;16>n;n++)e+=t.charAt(Math.floor(Math.random()*t.length));return e},null==_Shopify.Messenger&&(_Shopify.Messenger={modalMessages:[],messageHandlers:{},callbackPrefix:"onetime_callback",reset:function(){return this.messageHandlers={},this.modalMessages=[]},handlersFor:function(e){return this.messageHandlers[e]||[]},addHandler:function(e,t,n){return this.messageHandlers[e]||(this.messageHandlers[e]=[]),n&&this.modalMessages.push(e),this.messageHandlers[e].push(t)},setHandler:function(e,t){return this.messageHandlers[e]=[t]},invokeHandlers:function(e,t){var n,r,i,o,a,s;for(s=e.substring(0,this.callbackPrefix.length)===this.callbackPrefix,o=this.handlersFor(e),a=[],r=0,i=o.length;i>r;r++)n=o[r],n(e,t),s?a.push(this.removeHandler(e,n)):a.push(void 0);return a},addOnetimeHandler:function(e){var t;if(null!=e)return t=_Shopify.messageSlug(this.callbackPrefix),this.addHandler(t,e),t},removeHandler:function(e,t){var n;return n=this.messageHandlers[e].indexOf(t),this.messageHandlers[e].splice(n,1),0===this.messageHandlers[e].length?delete this.messageHandlers[e]:void 0},clearModal:function(){var e,t,n,r;for(r=this.modalMessages,e=0,t=r.length;t>e;e++)n=r[e],delete this.messageHandlers[n];return this.modalMessages=[]}}),_Shopify.AppBase||(_Shopify.AppBase=e=function(){function e(){}return e.reset=function(){return _Shopify.Messenger.reset(),this.debug=!1,this.forceRedirect=!0,this.apiKey="",this.shopOrigin="",this._isReady=!1},e.getWindowLocation=function(){return window.location},e.setWindowLocation=function(e){return window.location=e},e.bindWindowLocation=function(){return _Shopify.Messenger.addHandler("Shopify.API.setWindowLocation",function(e){return function(t,n){return e.setWindowLocation(n)}}(this))},e._isReady=!1,e.initWithData=function(e){return this._isReady=!0},e.ready=function(e){return this._isReady?void setTimeout(e,0):_Shopify.Messenger.addHandler("Shopify.API.initialize",function(t){return function(n,r){return t.initWithData(r),e()}}(this))},e.bindEvents=function(){return _Shopify.Messenger.addHandler("Shopify.API.print",function(e){return function(t,n){return window.focus(),e.print()}}(this)),window.addEventListener("message",this.__addEventMessageCallback.bind(this),!1),window.addEventListener("scroll",_Shopify.Utils.throttle(function(e){return function(){return e.messageScrollPosition()}}(this),200),!1),this.bindWindowLocation()},e.messageScrollPosition=function(){return this.postMessage("Shopify.API.reportScroll",{position:window.pageYOffset})},e.init=function(e){return null==e&&(e={}),this._hasCalledInit?void 0:(this._hasCalledInit=!0,this.reset(),this.loadConfig(e),this.checkFrame(),this.bindEvents(),this.postMessage("Shopify.API.initialize",{debug:this.debug,apiKey:this.apiKey}))},e.checkFrame=function(){var e;return window===window.parent?(e=(this.shopOrigin||"https://myshopify.com")+"/admin/apps/",this.apiKey&&(e=e+this.apiKey+this.getWindowLocation().pathname+(this.getWindowLocation().search||"")),this.forceRedirect?(n("detected that it was not loaded in an iframe and is redirecting to: "+e,!0),this.setWindowLocation(e)):r("detected that it was not loaded in an iframe but redirecting is disabled! Redirect URL would be: "+e)):void 0},e.loadConfig=function(e){return this.apiKey=e.apiKey,this.shopOrigin=e.shopOrigin,this.forceRedirect=e.hasOwnProperty("forceRedirect")?!!e.forceRedirect:this.forceRedirect=!0,this.debug=!!e.debug,this.apiKey||r("warning: apiKey has not been set."),this.shopOrigin||r("warning: shopOrigin has not been set."),this.shopOrigin&&!this.shopOrigin.match(/^http(s)?:\/\//)?r("warning: shopOrigin should include the protocol"):void 0},e.print=function(){return window.print()},e.window=function(){return window.parent.frames["app-iframe"]},e.postMessage=function(e,t){var r;return null==t&&(t={}),r=JSON.stringify({message:e,data:t}),n("client sent "+r+" to "+this.shopOrigin),window.parent.postMessage(r,this.shopOrigin),null!=t?t.callbackId:void 0},e.flashNotice=function(e){return this.postMessage("Shopify.API.flash.notice",{message:e})},e.flashError=function(e){return this.postMessage("Shopify.API.flash.error",{message:e})},e.handlers=function(){return _Shopify.Messenger.messageHandlers},e.__addEventMessageCallback=function(e){var t,i,o,a,s;if(e.origin!==this.shopOrigin)return n("client received "+e.data+" from unknown origin "+e.origin+". Expected "+this.shopOrigin+".");n("client received "+e.data+" from "+e.origin);try{a=JSON.parse(e.data)}catch(o){return i=o,void r("client received invalid JSON and cannot process the message. "+i+" : "+e.data+" : "+JSON.stringify(e.data))}null!=a.data&&this.initWithData(a.data),"Shopify.API.Modal.close"===a.message&&(_Shopify.Messenger.clearModal(),"function"==typeof(t=ShopifyApp.Modal).__callback&&t.__callback(a.data.result,a.data.data)),_Shopify.Messenger.invokeHandlers(a.message,a.data),(s=document.querySelector('form[data-shopify-app-submit="'+a.message+'"]'))&&s.submit()},e}()),null==_Shopify.Utils&&(_Shopify.Utils={throttle:function(e,t,n){var r,i;return null==t&&(t=250),i=r=void 0,function(){var o,a,s;return a=n||this,s=+new Date,o=arguments,i&&i+t>s?(clearTimeout(r),r=setTimeout(function(){return i=s,e.apply(a,o)},t)):(i=s,e.apply(a,o))}}})}).call(this),function(){var e,t,n,r=function(e,t){return function(){return e.apply(t,arguments)}},i=function(e,t){function n(){this.constructor=e}for(var r in t)o.call(t,r)&&(e[r]=t[r]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},o={}.hasOwnProperty;e={build:function(e,t,n){return null==n&&(n={}),this.addCallbacks(this.addMessages(e,t,n),n)},addMessages:function(e,t,n){var r,i,o,a;if(null==t&&(t="button"),null==n&&(n={}),Array.isArray(e))for(i=0,o=e.length;o>i;i++)r=e[i],this.addMessages(r,t,n);else null!=e&&(e.message||(e.message=_Shopify.messageSlug("button_"+t)),e.href&&!e.target&&(e.target="app"),"dropdown"===e.type&&(e.links=function(){var t,n,r,i;for(r=e.links,i=[],t=0,n=r.length;n>t;t++)a=r[t],i.push(this.addMessages(a,"link"));return i}.call(this)));return e},addCallbacks:function(e,t){var r,i,o,a;if(null==t&&(t={}),Array.isArray(e))for(i=0,o=e.length;o>i;i++)r=e[i],this.addCallbacks(r,t);return null!=e&&("app"===e.target&&(e.callback=function(t){return function(t,r){return n.setWindowLocation(e.href)}}(this)),null!=e.callback&&_Shopify.Messenger.setHandler(e.message,e.callback,t.modal),t.dropdown&&"dropdown"===e.type&&(e.links=function(){var t,n,r,i;for(r=e.links,i=[],t=0,n=r.length;n>t;t++)a=r[t],i.push(this.addCallbacks(a,{modal:!1}));return i}.call(this))),e}},t=function(){function e(e){this.CURRENCIES=e,this.getCurrency=r(this.getCurrency,this)}return e.prototype.getCurrency=function(e){var t,n,r,i;for(i=this.CURRENCIES,n=0,r=i.length;r>n;n++)if(t=i[n],t.code===e)return t},e}(),window.ShopifyApp||(window.ShopifyApp=n=function(n){function r(){return r.__super__.constructor.apply(this,arguments)}return i(r,n),r.bindEvents=function(){return _Shopify.Messenger.addHandler("Shopify.API.initialize",function(e){return function(t,n){return e.replaceState(e.getWindowLocation().pathname+e.getWindowLocation().search)}}(this)),r.__super__.constructor.bindEvents.apply(this,arguments)},r.initWithData=function(e){return null!=e.User&&(this.User=e.User),null!=e.CurrencyDB&&(this.CurrencyDB=new t(e.CurrencyDB.CURRENCIES)),r.__super__.constructor.initWithData.apply(this,arguments)},r.pushState=function(e){return r.postMessage("Shopify.API.pushState",{location:e})},r.replaceState=function(e){return r.postMessage("Shopify.API.replaceState",{location:e})},r.redirect=function(e){return r.postMessage("Shopify.API.redirect",{location:e})},r.fetchAnalyticsToken=function(e){var t;return t="Shopify.API.fetchAnalyticsToken",_Shopify.Messenger.addHandler(t,e),r.postMessage(t)},r.Nav={initialize:function(e){return e||(e=[]),r.postMessage("Shopify.API.Nav.initialize",e)},select:function(e){return e?r.postMessage("Shopify.API.Nav.select",e):void 0}},r.Sidebar={setSection:function(e){return e?r.postMessage("Shopify.API.Sidebar.setSection",e):void 0}},r.Bar={initialize:function(t){var n,i,o,a,s,u,l;for(t||(t={}),a=["primary","secondary","tertiary"],i=0,o=a.length;o>i;i++)n=a[i],e.build(null!=(s=t.buttons)?s[n]:void 0,n,{dropdown:!0});return e.build(t.breadcrumb,"breadcrumb"),(null!=(u=t.pagination)?u.next:void 0)&&e.build(t.pagination.next,"pagination_next"),(null!=(l=t.pagination)?l.previous:void 0)&&e.build(t.pagination.previous,"pagination_previous"),r.postMessage("Shopify.API.Bar.initialize",t),document.body.onclick=function(){return r.postMessage("Shopify.API.Bar.closeDropdown")}},loadingOn:function(){return r.postMessage("Shopify.API.Bar.loading.on")},loadingOff:function(){return r.postMessage("Shopify.API.Bar.loading.off")},setIcon:function(e){return r.postMessage("Shopify.API.Bar.icon",{icon:e})},setTitle:function(e){return r.postMessage("Shopify.API.Bar.title",{title:e})},setBreadcrumb:function(t){var n;return n={breadcrumb:e.build(t,"breadcrumb")},r.postMessage("Shopify.API.Bar.breadcrumb",n)},disableAllButtons:function(){return r.postMessage("Shopify.API.Bar.disableAllButtons")},enableAllButtons:function(){return r.postMessage("Shopify.API.Bar.enableAllButtons")},setPagination:function(t){var n,i,o;return n={pagination:t},(null!=(i=n.pagination)?i.next:void 0)&&e.build(n.pagination.next,"pagination_next"),(null!=(o=n.pagination)?o.previous:void 0)&&e.build(n.pagination.previous,"pagination_previous"),r.postMessage("Shopify.API.Bar.pagination",n)}},r.Modal={__callback:void 0,window:function(){return window.parent.frames["app-modal-iframe"]},open:function(t,n){var i,o,a,s,u;for(s=["primary","secondary","tertiary"],o=0,a=s.length;a>o;o++)i=s[o],e.build(null!=(u=t.buttons)?u[i]:void 0,i,{dropdown:!0,modal:!0});return r.Modal.__callback=n,r.postMessage("Shopify.API.Modal.open",t)},alert:function(e,t){return r.Modal.__callback=t,r.postMessage("Shopify.API.Modal.alert",{message:e})},confirm:function(e,t){return r.Modal.__callback=t,r.postMessage("Shopify.API.Modal.confirm",{message:e})},input:function(e,t){return r.Modal.__callback=t,r.postMessage("Shopify.API.Modal.input",{message:e})},close:function(e,t){return r.postMessage("Shopify.API.Modal.close",{result:e,data:t})},productPicker:function(e,t){return r.Modal.__callback=t,r.postMessage("Shopify.API.Modal.productPicker",e)},collectionPicker:function(e,t){return r.Modal.__callback=t,r.postMessage("Shopify.API.Modal.collectionPicker",e)},setHeight:function(e){return r.postMessage("Shopify.API.Modal.setHeight",{height:e})},togglePrimaryButton:function(e){return r.postMessage("Shopify.API.Modal.togglePrimaryButton",e)}},r}(_Shopify.AppBase))}.call(this),function(){var e,t,n,r,i,o,a;t={},e="https://analytics.shopify.com",ShopifyApp.Analytics={fetch:function(e){if(!e.query)throw new Error("Shopify Analytics: You must provide a shopifyQl `query` to fetch.");if(!e.success)throw new Error("Shopify Analytics: You must provide a `success` callback to fetch.");if(!e.error)throw new Error("Shopify Analytics: You must provide an `error` callback to fetch.");return Boolean(t.token)?i(e):o(e)},clear:function(){return t={}}},o=function(e){return ShopifyApp.fetchAnalyticsToken(function(n,r){return r.error?e.error(r.error):(t={token:r.token,userId:r.userId,source:"analytics-sdk"},i(e))})},i=function(e){var i;if(Boolean(XMLHttpRequest)&&Boolean(JSON)&&Boolean(encodeURIComponent))return i=new XMLHttpRequest,i.open("GET",n(e.query),!0),i.onreadystatechange=function(){var n;if(4===i.readyState)return 200===i.status&&Boolean(i.responseText)?(n=r(i.responseText),e.success(n)):i.responseText.match(/token signature invalid/)?(t.token=null,ShopifyApp.Analytics.fetch(shopifyQl,e)):e.error(i.responseText)},i.send()},r=function(e){var t,n,r;return t=JSON.parse(e),{result:{columns:(null!=t&&null!=(n=t.result)?n.columns:void 0)||[],data:(null!=t&&null!=(r=t.result)?r.data:void 0)||[]}}},n=function(n){return e+"/query?"+a({q:n,token:t.token,user_id:t.userId||"",source:t.source||"analytics-api"})},a=function(e){var t;return t=function(t){return[t,e[t]].map(encodeURIComponent).join("=")},Object.keys(e).map(t).join("&")}}.call(this),function(){}.call(this);