Skip to content

Instantly share code, notes, and snippets.

@daniellizik-sc
Created November 22, 2016 20:19
Show Gist options
  • Save daniellizik-sc/451f003e555fc3eb21967de4c1921299 to your computer and use it in GitHub Desktop.
Save daniellizik-sc/451f003e555fc3eb21967de4c1921299 to your computer and use it in GitHub Desktop.
forceshow
!function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}var o=n(1),i=r(o);new i.default(prompt("enter api key",""))},function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),u=n(2),s=r(u),c=function(){function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o(this,t),this.apikey=e,this.eventConfig=n,this.osr=new s.default(this.apikey,this.eventConfig),this.init()}return i(t,[{key:"init",value:function(){var t=this;this.osr.init().then(function(){return t.templates=t.osr.availableTemplates}).catch(function(t){return console.log(t)})}},{key:"switchTemplate",value:function(t){var e=this;this.osr.view.container.remove().then(function(){var n=t||parseInt(prompt("Templates available for this client ID. Enter new filename to get templates for that client. \n\n"+$pretty(e.osr.availableTemplates))),r=(e.osr.availableTemplates.reduce(function(t,e){return e.templates.forEach(function(e){return t.push(e)}),t},[]),new s.default),o=""+r.apiHost+r.routes.litebox+e.osr.clientId+"/"+n;$resource.template(o).then(r.render.bind(r)).then(r.bindTemplateEvents.bind(r))})}},{key:"switchClient",value:function(t){var e=this,n=this.osr.config;n.guid=guid||prompt("Enter another filename"),this.osr.view.container.remove(),this.osr=new s.default(n),this.osr.init().then(function(){e.templates=e.osr.availableTemplates})}}]),t}();e.default=c},function(t,e,n){"use strict";function r(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function o(t){return t&&t.__esModule?t:{default:t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var u=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),s=n(3),c=n(6),a=o(c),l=n(7),f=r(l),d=n(9),h=r(d),p=n(10),v=o(p),y=function(){function t(e,n){i(this,t),this.apikey=e,this.eventConfig=n,this.routes={litebox:"/litebox/template/",osrConfig:"/osr/"},this.eventMap={outsideClick:[".osr-overlay"],closeClick:[".close-sc",".no-thanks-sc",".exit-sc"],continueClick:[".cta-sc"],emailBasketClick:[".send-sc"]},this.apiHost="https://d22j4fzzszoii2.cloudfront.net",this.overlayStyle=v.default}return u(t,[{key:"init",value:function(){var t=this;return new s.Promise(function(e,n){f.osr(t.apiHost+t.routes.osrConfig+t.apikey).then(function(e){return t.clientId=e.clientId,e}).then(t.promptTemplate.bind(t)).then(function(e){return t.availableTemplates=e.available,e.url}).then(f.template).then(t.render.bind(t)).then(function(e){return t.view=e}).then(t.bindTemplateEvents.bind(t)).then(e).catch(function(t){return console.warn(t)})})}},{key:"promptTemplate",value:function(t){var e=this;return new s.Promise(function(n,r){var o=h.reduceOsr(t),i=h.display(o),u=prompt(i),s=e.apiHost+e.routes.litebox+(t.clientId+"/"+u);n({available:o,url:s})})}},{key:"render",value:function(t){var e=this;return new s.Promise(function(n,r){var o=document.querySelector("head"),i=(0,a.default)({el:"style",attrs:{innerHTML:e.overlayStyle}}),u=(0,a.default)({el:"style",attrs:{id:"sc-osr-style",innerHTML:t.stylesheet}}),s=(0,a.default)({el:"div",attrs:{className:"osr-overlay sc-lb"}}),c=(0,a.default)({el:"div",attrs:{className:"osr-content sc-lb",innerHTML:t.html}});i.appendOn(o).then(function(t){return u.appendOn(o)}).then(function(t){return s.appendOn(document.body)}).then(function(t){return c.appendOn(t)}).then(function(t){return n({overlayStyle:i,osrStyle:u,overlay:s,container:c})})})}},{key:"show",value:function(){this.view.overlay.el.classList.remove("sc-hidden")}},{key:"hide",value:function(){this.view.overlay.el.classList.add("sc-hidden")}},{key:"bindTemplateEvents",value:function(t){var e=this;return new s.Promise(function(t,n){var r=function(t,e,n){return n()},o=function(t){return t.reduce(function(t,e){var n=document.querySelectorAll(e);return t=[].concat.apply(t,[].slice.call(n))},[])},i={outside:{selectors:o(e.eventMap.outsideClick),onClick:function(t){t.target.className.indexOf("osr-overlay sc-lb")>-1&&e.hide()}},exit:{selectors:o(e.eventMap.closeClick),onClick:function(t){return(e.eventConfig.closeClick||r)("CLOSE_CLICK",t,e.hide.bind(e))}},continue:{selectors:o(e.eventMap.continueClick),onClick:function(t){return(e.eventConfig.continueClick||r)("CONTINUE_CLICK",t,e.hide.bind(e))}},emb:{selectors:o(e.eventMap.emailBasketClick),onClick:function(t){return(e.eventConfig.emailBasketClick||r)("EMAIL_BASKET_CLICK",t,e.hide.bind(e))}}},u=function(t){i[t].selectors.forEach(function(e){return e.addEventListener("click",i[t].onClick,!1)})};for(var s in i)u(s);t()})}}]),t}();e.default=y},function(t,e,n){var r,o;(function(i,u){"use strict";var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function(i,u){"object"===s(e)&&"undefined"!=typeof t?t.exports=u():(r=u,o="function"==typeof r?r.call(e,n,e,t):r,!(void 0!==o&&(t.exports=o)))}(void 0,function(){function t(t){return"function"==typeof t||"object"===("undefined"==typeof t?"undefined":s(t))&&null!==t}function e(t){return"function"==typeof t}function r(t){W=t}function o(t){Q=t}function c(){return function(){return i.nextTick(h)}}function a(){return"undefined"!=typeof $?function(){$(h)}:d()}function l(){var t=0,e=new tt(h),n=document.createTextNode("");return e.observe(n,{characterData:!0}),function(){n.data=t=++t%2}}function f(){var t=new MessageChannel;return t.port1.onmessage=h,function(){return t.port2.postMessage(0)}}function d(){var t=setTimeout;return function(){return t(h,1)}}function h(){for(var t=0;t<X;t+=2){var e=rt[t],n=rt[t+1];e(n),rt[t]=void 0,rt[t+1]=void 0}X=0}function p(){try{var t=n(5);return $=t.runOnLoop||t.runOnContext,a()}catch(t){return d()}}function v(t,e){var n=arguments,r=this,o=new this.constructor(m);void 0===o[it]&&H(o);var i=r._state;return i?!function(){var t=n[i-1];Q(function(){return I(i,o,t,r._result)})}():x(r,o,t,e),o}function y(t){var e=this;if(t&&"object"===("undefined"==typeof t?"undefined":s(t))&&t.constructor===e)return t;var n=new e(m);return O(n,t),n}function m(){}function b(){return new TypeError("You cannot resolve a promise with itself")}function _(){return new TypeError("A promises callback cannot return that same promise.")}function w(t){try{return t.then}catch(t){return at.error=t,at}}function g(t,e,n,r){try{t.call(e,n,r)}catch(t){return t}}function T(t,e,n){Q(function(t){var r=!1,o=g(n,e,function(n){r||(r=!0,e!==n?O(t,n):M(t,n))},function(e){r||(r=!0,S(t,e))},"Settle: "+(t._label||" unknown promise"));!r&&o&&(r=!0,S(t,o))},t)}function k(t,e){e._state===st?M(t,e._result):e._state===ct?S(t,e._result):x(e,void 0,function(e){return O(t,e)},function(e){return S(t,e)})}function C(t,n,r){n.constructor===t.constructor&&r===v&&n.constructor.resolve===y?k(t,n):r===at?S(t,at.error):void 0===r?M(t,n):e(r)?T(t,n,r):M(t,n)}function O(e,n){e===n?S(e,b()):t(n)?C(e,n,w(n)):M(e,n)}function E(t){t._onerror&&t._onerror(t._result),A(t)}function M(t,e){t._state===ut&&(t._result=e,t._state=st,0!==t._subscribers.length&&Q(A,t))}function S(t,e){t._state===ut&&(t._state=ct,t._result=e,Q(E,t))}function x(t,e,n,r){var o=t._subscribers,i=o.length;t._onerror=null,o[i]=e,o[i+st]=n,o[i+ct]=r,0===i&&t._state&&Q(A,t)}function A(t){var e=t._subscribers,n=t._state;if(0!==e.length){for(var r=void 0,o=void 0,i=t._result,u=0;u<e.length;u+=3)r=e[u],o=e[u+n],r?I(n,r,o,i):o(i);t._subscribers.length=0}}function j(){this.error=null}function P(t,e){try{return t(e)}catch(t){return lt.error=t,lt}}function I(t,n,r,o){var i=e(r),u=void 0,s=void 0,c=void 0,a=void 0;if(i){if(u=P(r,o),u===lt?(a=!0,s=u.error,u=null):c=!0,n===u)return void S(n,_())}else u=o,c=!0;n._state!==ut||(i&&c?O(n,u):a?S(n,s):t===st?M(n,u):t===ct&&S(n,u))}function L(t,e){try{e(function(e){O(t,e)},function(e){S(t,e)})}catch(e){S(t,e)}}function N(){return ft++}function H(t){t[it]=ft++,t._state=void 0,t._result=void 0,t._subscribers=[]}function F(t,e){this._instanceConstructor=t,this.promise=new t(m),this.promise[it]||H(this.promise),R(e)?(this._input=e,this.length=e.length,this._remaining=e.length,this._result=new Array(this.length),0===this.length?M(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&M(this.promise,this._result))):S(this.promise,K())}function K(){return new Error("Array Methods must be provided an Array")}function z(t){return new F(this,t).promise}function B(t){var e=this;return new e(R(t)?function(n,r){for(var o=t.length,i=0;i<o;i++)e.resolve(t[i]).then(n,r)}:function(t,e){return e(new TypeError("You must pass an array to race."))})}function q(t){var e=this,n=new e(m);return S(n,t),n}function D(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function U(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function Y(t){this[it]=N(),this._result=this._state=void 0,this._subscribers=[],m!==t&&("function"!=typeof t&&D(),this instanceof Y?L(this,t):U())}function G(){var t=void 0;if("undefined"!=typeof u)t=u;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var e=t.Promise;if(e){var n=null;try{n=Object.prototype.toString.call(e.resolve())}catch(t){}if("[object Promise]"===n&&!e.cast)return}t.Promise=Y}var J=void 0;J=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)};var R=J,X=0,$=void 0,W=void 0,Q=function(t,e){rt[X]=t,rt[X+1]=e,X+=2,2===X&&(W?W(h):ot())},V="undefined"!=typeof window?window:void 0,Z=V||{},tt=Z.MutationObserver||Z.WebKitMutationObserver,et="undefined"==typeof self&&"undefined"!=typeof i&&"[object process]"==={}.toString.call(i),nt="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,rt=new Array(1e3),ot=void 0;ot=et?c():tt?l():nt?f():void 0===V?p():d();var it=Math.random().toString(36).substring(16),ut=void 0,st=1,ct=2,at=new j,lt=new j,ft=0;return F.prototype._enumerate=function(){for(var t=this.length,e=this._input,n=0;this._state===ut&&n<t;n++)this._eachEntry(e[n],n)},F.prototype._eachEntry=function(t,e){var n=this._instanceConstructor,r=n.resolve;if(r===y){var o=w(t);if(o===v&&t._state!==ut)this._settledAt(t._state,e,t._result);else if("function"!=typeof o)this._remaining--,this._result[e]=t;else if(n===Y){var i=new n(m);C(i,t,o),this._willSettleAt(i,e)}else this._willSettleAt(new n(function(e){return e(t)}),e)}else this._willSettleAt(r(t),e)},F.prototype._settledAt=function(t,e,n){var r=this.promise;r._state===ut&&(this._remaining--,t===ct?S(r,n):this._result[e]=n),0===this._remaining&&M(r,this._result)},F.prototype._willSettleAt=function(t,e){var n=this;x(t,void 0,function(t){return n._settledAt(st,e,t)},function(t){return n._settledAt(ct,e,t)})},Y.all=z,Y.race=B,Y.resolve=y,Y.reject=q,Y._setScheduler=r,Y._setAsap=o,Y._asap=Q,Y.prototype={constructor:Y,then:v,catch:function(t){return this.then(null,t)}},Y.polyfill=G,Y.Promise=Y,Y})}).call(e,n(4),function(){return this}())},function(t,e){"use strict";function n(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function o(t){if(l===setTimeout)return setTimeout(t,0);if((l===n||!l)&&setTimeout)return l=setTimeout,setTimeout(t,0);try{return l(t,0)}catch(e){try{return l.call(null,t,0)}catch(e){return l.call(this,t,0)}}}function i(t){if(f===clearTimeout)return clearTimeout(t);if((f===r||!f)&&clearTimeout)return f=clearTimeout,clearTimeout(t);try{return f(t)}catch(e){try{return f.call(null,t)}catch(e){return f.call(this,t)}}}function u(){v&&h&&(v=!1,h.length?p=h.concat(p):y=-1,p.length&&s())}function s(){if(!v){var t=o(u);v=!0;for(var e=p.length;e;){for(h=p,p=[];++y<e;)h&&h[y].run();y=-1,e=p.length}h=null,v=!1,i(t)}}function c(t,e){this.fun=t,this.array=e}function a(){}var l,f,d=t.exports={};!function(){try{l="function"==typeof setTimeout?setTimeout:n}catch(t){l=n}try{f="function"==typeof clearTimeout?clearTimeout:r}catch(t){f=r}}();var h,p=[],v=!1,y=-1;d.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];p.push(new c(t,e)),1!==p.length||v||o(s)},c.prototype.run=function(){this.fun.apply(null,this.array)},d.title="browser",d.browser=!0,d.env={},d.argv=[],d.version="",d.versions={},d.on=a,d.addListener=a,d.once=a,d.off=a,d.removeListener=a,d.removeAllListeners=a,d.emit=a,d.binding=function(t){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(t){throw new Error("process.chdir is not supported")},d.umask=function(){return 0}},function(t,e){},function(t,e){"use strict";function n(t){var e=document.createElement(t.el||"div"),n=t.attrs||{};for(var r in n)e[r]=n[r];return{el:e,appendOn:function(t){return new Promise(function(n,r){t.appendChild(e),n(e)})},remove:function(){return new Promise(function(t,n){e.parentNode.removeChild(e),t(e)})}}}Object.defineProperty(e,"__esModule",{value:!0}),e.default=n},function(t,e,n){"use strict";function r(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}Object.defineProperty(e,"__esModule",{value:!0}),e.template=e.osr=void 0;var o=n(8),i=r(o);e.osr=function(t){return i.get(t)},e.template=function(t){return i.get(t).then(function(t){return Object.keys(t).reduce(function(e,n){return e[n]=decodeURIComponent(t[n]),e},{})})}},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.get=function(t){return new Promise(function(e,n){var r=new XMLHttpRequest;r.onreadystatechange=function(){var t=void 0;if(4===r.readyState&&200===r.status&&r.responseText)try{t=JSON.parse(r.responseText)}catch(e){t=r.responseText}finally{e(t)}},r.open("GET",t),r.send()})}},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.find=function(t,e){for(var n=Object.keys(t)[0],r=t[n],o=0;o<e.length;o++)if(e[o][n].toLowerCase()===r.toLowerCase())return e[o]},e.pretty=function(t){return JSON.stringify(t,null,2).replace(/[\[\]\{\}\'\"\,]/gi,"").replace(/^\s{2,}/gm,"")},e.reduceOsr=function(t){var e=t.pageConfigs.reduce(function(t,e){var n=e.pageInstances.reduce(function(t,n){var r=n.filters.map(function(t){return{page:e.name,pages:e.validPages,instance:n.instanceName,keyword:t.keyword,templateId:t.templates.osr}});return t.concat(r)},[]);return t.concat(n)},[]);return{data:e,clientId:t.clientId}},e.display=function(t){return t.data.reduce(function(t,e){return t+=e.templateId+" (keyword: "+e.instance+")\n"},"client id: "+t.clientId+" \n\n")}},function(t,e){t.exports="div.osr-overlay {\r\n background: rgba(0,0,0,0.7);\r\n filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#bf45484d',endColorstr='#bf000000',GradientType=0);\r\n width: 100%;\r\n height: 100%;\r\n z-index: 99999;\r\n top: 0;\r\n left: 0;\r\n position: fixed;\r\n}\r\n\r\ndiv.osr-overlay.sc-hidden {\r\n display: none;\r\n}\r\n\r\ndiv.osr-content {\r\n margin: 0 auto;\r\n position: relative;\r\n background-color: #FFF;\r\n top: 10%;\r\n}"}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment