@gobistories/gobi-web-integration
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.gobi=e():t.gobi=e()}(window,function(){return function(n){var i={};function r(t){if(i[t])return i[t].exports;var e=i[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,r),e.l=!0,e.exports}return r.m=n,r.c=i,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=7)}([function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,p,d){"use strict";(function(e){var t=d(2),n=setTimeout;function i(){}function o(t){if(!(this instanceof o))throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],u(t,this)}function r(n,i){for(;3===n._state;)n=n._value;0!==n._state?(n._handled=!0,o._immediateFn(function(){var t=1===n._state?i.onFulfilled:i.onRejected;if(null!==t){var e;try{e=t(n._value)}catch(t){return void a(i.promise,t)}s(i.promise,e)}else(1===n._state?s:a)(i.promise,n._value)})):n._deferreds.push(i)}function s(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if(t instanceof o)return e._state=3,e._value=t,void c(e);if("function"==typeof n)return void u((i=n,r=t,function(){i.apply(r,arguments)}),e)}e._state=1,e._value=t,c(e)}catch(t){a(e,t)}var i,r}function a(t,e){t._state=2,t._value=e,c(t)}function c(t){2===t._state&&0===t._deferreds.length&&o._immediateFn(function(){t._handled||o._unhandledRejectionFn(t._value)});for(var e=0,n=t._deferreds.length;e<n;e++)r(t,t._deferreds[e]);t._deferreds=null}function l(t,e,n){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof e?e:null,this.promise=n}function u(t,e){var n=!1;try{t(function(t){n||(n=!0,s(e,t))},function(t){n||(n=!0,a(e,t))})}catch(t){if(n)return;n=!0,a(e,t)}}o.prototype.catch=function(t){return this.then(null,t)},o.prototype.then=function(t,e){var n=new this.constructor(i);return r(this,new l(t,e,n)),n},o.prototype.finally=t.a,o.all=function(e){return new o(function(i,r){if(!e||void 0===e.length)throw new TypeError("Promise.all accepts an array");var o=Array.prototype.slice.call(e);if(0===o.length)return i([]);var s=o.length;function a(e,t){try{if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if("function"==typeof n)return void n.call(t,function(t){a(e,t)},r)}o[e]=t,0==--s&&i(o)}catch(t){r(t)}}for(var t=0;t<o.length;t++)a(t,o[t])})},o.resolve=function(e){return e&&"object"==typeof e&&e.constructor===o?e:new o(function(t){t(e)})},o.reject=function(n){return new o(function(t,e){e(n)})},o.race=function(r){return new o(function(t,e){for(var n=0,i=r.length;n<i;n++)r[n].then(t,e)})},o._immediateFn="function"==typeof e&&function(t){e(t)}||function(t){n(t,0)},o._unhandledRejectionFn=function(t){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",t)},p.a=o}).call(this,d(4).setImmediate)},function(t,e,n){"use strict";e.a=function(e){var n=this.constructor;return this.then(function(t){return n.resolve(e()).then(function(){return t})},function(t){return n.resolve(e()).then(function(){return n.reject(t)})})}},function(t,e,n){},function(t,r,o){(function(t){var e=void 0!==t&&t||"undefined"!=typeof self&&self||window,n=Function.prototype.apply;function i(t,e){this._id=t,this._clearFn=e}r.setTimeout=function(){return new i(n.call(setTimeout,e,arguments),clearTimeout)},r.setInterval=function(){return new i(n.call(setInterval,e,arguments),clearInterval)},r.clearTimeout=r.clearInterval=function(t){t&&t.close()},i.prototype.unref=i.prototype.ref=function(){},i.prototype.close=function(){this._clearFn.call(e,this._id)},r.enroll=function(t,e){clearTimeout(t._idleTimeoutId),t._idleTimeout=e},r.unenroll=function(t){clearTimeout(t._idleTimeoutId),t._idleTimeout=-1},r._unrefActive=r.active=function(t){clearTimeout(t._idleTimeoutId);var e=t._idleTimeout;0<=e&&(t._idleTimeoutId=setTimeout(function(){t._onTimeout&&t._onTimeout()},e))},o(5),r.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==t&&t.setImmediate||this&&this.setImmediate,r.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==t&&t.clearImmediate||this&&this.clearImmediate}).call(this,o(0))},function(t,e,n){(function(t,f){!function(n,i){"use strict";if(!n.setImmediate){var r,o,e,s,t,a=1,c={},l=!1,u=n.document,p=Object.getPrototypeOf&&Object.getPrototypeOf(n);p=p&&p.setTimeout?p:n,r="[object process]"==={}.toString.call(n.process)?function(t){f.nextTick(function(){h(t)})}:function(){if(n.postMessage&&!n.importScripts){var t=!0,e=n.onmessage;return n.onmessage=function(){t=!1},n.postMessage("","*"),n.onmessage=e,t}}()?(s="setImmediate$"+Math.random()+"$",t=function(t){t.source===n&&"string"==typeof t.data&&0===t.data.indexOf(s)&&h(+t.data.slice(s.length))},n.addEventListener?n.addEventListener("message",t,!1):n.attachEvent("onmessage",t),function(t){n.postMessage(s+t,"*")}):n.MessageChannel?((e=new MessageChannel).port1.onmessage=function(t){h(t.data)},function(t){e.port2.postMessage(t)}):u&&"onreadystatechange"in u.createElement("script")?(o=u.documentElement,function(t){var e=u.createElement("script");e.onreadystatechange=function(){h(t),e.onreadystatechange=null,o.removeChild(e),e=null},o.appendChild(e)}):function(t){setTimeout(h,0,t)},p.setImmediate=function(t){"function"!=typeof t&&(t=new Function(""+t));for(var e=new Array(arguments.length-1),n=0;n<e.length;n++)e[n]=arguments[n+1];var i={callback:t,args:e};return c[a]=i,r(a),a++},p.clearImmediate=d}function d(t){delete c[t]}function h(t){if(l)setTimeout(h,0,t);else{var e=c[t];if(e){l=!0;try{!function(t){var e=t.callback,n=t.args;switch(n.length){case 0:e();break;case 1:e(n[0]);break;case 2:e(n[0],n[1]);break;case 3:e(n[0],n[1],n[2]);break;default:e.apply(i,n)}}(e)}finally{d(t),l=!1}}}}}("undefined"==typeof self?void 0===t?this:t:self)}).call(this,n(0),n(6))},function(t,e){var n,i,r=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(e){if(n===setTimeout)return setTimeout(e,0);if((n===o||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:o}catch(t){n=o}try{i="function"==typeof clearTimeout?clearTimeout:s}catch(t){i=s}}();var c,l=[],u=!1,p=-1;function d(){u&&c&&(u=!1,c.length?l=c.concat(l):p=-1,l.length&&h())}function h(){if(!u){var t=a(d);u=!0;for(var e=l.length;e;){for(c=l,l=[];++p<e;)c&&c[p].run();p=-1,e=l.length}c=null,u=!1,function(e){if(i===clearTimeout)return clearTimeout(e);if((i===s||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(e);try{i(e)}catch(t){try{return i.call(null,e)}catch(t){return i.call(this,e)}}}(t)}}function f(t,e){this.fun=t,this.array=e}function y(){}r.nextTick=function(t){var e=new Array(arguments.length-1);if(1<arguments.length)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];l.push(new f(t,e)),1!==l.length||u||a(h)},f.prototype.run=function(){this.fun.apply(null,this.array)},r.title="browser",r.browser=!0,r.env={},r.argv=[],r.version="",r.versions={},r.on=y,r.addListener=y,r.once=y,r.off=y,r.removeListener=y,r.removeAllListeners=y,r.emit=y,r.prependListener=y,r.prependOnceListener=y,r.listeners=function(t){return[]},r.binding=function(t){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(t){throw new Error("process.chdir is not supported")},r.umask=function(){return 0}},function(t,e,n){"use strict";n.r(e);n(3);var i=function(){function t(){this._eventsCallbacks={}}return t.prototype.on=function(t,e){this._eventsCallbacks.hasOwnProperty(t)||(this._eventsCallbacks[t]=[]);var n=this._eventsCallbacks[t];-1===n.indexOf(e)&&n.push(e)},t.prototype.off=function(t,e){"string"==typeof t?this._eventsCallbacks.hasOwnProperty(t)&&("function"==typeof e?this._removeCallback(t,e):this._eventsCallbacks[t]=[]):this._removeAllCallbacks()},t.prototype.emit=function(t,e,n){if(this._eventsCallbacks.hasOwnProperty(t))for(var i=this._eventsCallbacks[t],r=i.length,o=0;o<r;o++)i[o].call(n||this,e)},t.prototype._removeCallback=function(t,e){var n=this._eventsCallbacks[t],i=n.indexOf(e);-1<i&&n.splice(i,1)},t.prototype._removeAllCallbacks=function(){for(var t in this._eventsCallbacks)this._eventsCallbacks.hasOwnProperty(t)&&delete this._eventsCallbacks[t]},t}();function r(t,e){for(var n,i=t.length,r=0;r<i;r++)(n=t[r]).className=e+n.className}function o(t,e,n){var i=function(t){return n(t)};return t.addEventListener(e,i),function(){return t.removeEventListener(e,i)}}var s={scrollTop:0,bodyOverflow:"",disable:function(){this.isIOS?this.IOSDisable():this.classicDisable()},enable:function(){this.isIOS?this.IOSEnable():this.classicEnable()},classicDisable:function(){this.bodyOverflow=document.body.style.overflow,document.body.style.overflow="hidden"},classicEnable:function(){document.body.style.overflow=this.bodyOverflow},IOSEnable:function(){document.documentElement.classList.remove("disabled-scroll"),document.body.classList.remove("disabled-scroll"),window.scrollTo(0,this.scrollTop)},IOSDisable:function(){this.scrollTop=window.pageYOffset,document.documentElement.classList.add("disabled-scroll"),document.body.classList.add("disabled-scroll")},isIOS:/iPad|iPhone|iPod/.test(navigator.userAgent)};function a(){return(a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}var c=function(){function t(t){var n=this;this._defaultOptions={autoStart:!1,hideOverlay:!1,loop:!1,width:0,height:0,roundedCorners:!0,shadow:!0,checkViewPort:!0},this._eventEmitter=new i,this.on=this._eventEmitter.on.bind(this._eventEmitter),this.off=this._eventEmitter.off.bind(this._eventEmitter),this._removeIsOnScreenChecker=function(){},this._removeIsOutOfScreenChecker=function(){},this._options=a({},this._defaultOptions,t),this.el=this._createIframe(),this._options.container&&this._options.container.appendChild(this.el),window.addEventListener("message",function(t){if(n.el.contentWindow===t.source){var e=t.data;e.event&&(n._eventEmitter.emit(e.event,e.value,n),n._options.checkViewPort&&n._viewPortChecker(e.event))}})}return Object.defineProperty(t.prototype,"storyURL",{get:function(){return"https://live.gobiapp.com/next/story/id/"+this._options.storyName+"?autoStart="+this._options.autoStart+"&addLooping="+this._options.loop+"&hideOverlay="+this._options.hideOverlay+"&roundedCorners="+this._options.roundedCorners},enumerable:!0,configurable:!0}),t.prototype.load=function(t){a(this._options,t),this.el.src=this.storyURL},t.prototype.play=function(){this._callPlayerMethod("play")},t.prototype.pause=function(){this._callPlayerMethod("pause")},t.prototype.reload=function(){this._callPlayerMethod("reset")},t.prototype.setMute=function(t){this._callPlayerMethod("setMute",t)},t.prototype.isInViewport=function(){var t=this.el.getBoundingClientRect(),e=window.innerHeight||document.documentElement.clientHeight,n=window.innerWidth||document.documentElement.clientWidth,i=.8*t.height,r=.8*t.width;return t.top>=0-i&&t.left>=0-r&&t.bottom<=e+i&&t.right<=n+r},t.prototype._callPlayerMethod=function(t,e){void 0===e&&(e=void 0),this._sendMessage({method:t,value:e})},t.prototype._sendMessage=function(t){var e=this.el.contentWindow;e&&e.postMessage(t,"*")},t.prototype._createIframe=function(){var t=document.createElement("iframe"),e=this._calcPlayerSize();return t.src=this.storyURL,t.width=e.width.toString(),t.height=e.height.toString(),t.frameBorder="0",t.scrolling="no",t.style.overflow="hidden",t.style.background="#000",t.style.border="0",this._options.shadow&&t.classList.add("gobi-player-shadow"),this._options.roundedCorners&&(t.style.borderRadius="10px"),t.setAttribute("allow","autoplay;"),t},t.prototype._viewPortChecker=function(t){switch(t){case"play":this._addIsOutOfScreenChecker();break;case"pause":this.isInViewport()&&(this._removeIsOnScreenChecker(),this._removeIsOutOfScreenChecker());break;case"ended":this._removeIsOnScreenChecker(),this._removeIsOutOfScreenChecker()}},t.prototype._addIsOutOfScreenChecker=function(){var t=this;this._removeIsOutOfScreenChecker(),this._removeIsOnScreenChecker(),this._removeIsOutOfScreenChecker=o(window,"scroll",function(){t.isInViewport()||(t.pause(),t._removeIsOutOfScreenChecker(),t._addIsOnScreenChecker())})},t.prototype._addIsOnScreenChecker=function(){var t=this;this._removeIsOnScreenChecker=o(window,"scroll",function(){t.isInViewport()&&(t.play(),t._removeIsOnScreenChecker(),t._addIsOutOfScreenChecker())})},t.prototype._calcPlayerSize=function(){var t=612,e=1088;return this._options.width&&this._options.height?(t=this._options.width,e=this._options.height):this._options.width?e=(t=this._options.width)/.5625:this._options.height&&(t=.5625*(e=this._options.height)),{width:t,height:e}},t}(),u=n(1),l=function(t,e){return(l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function p(t,e){function n(){this.constructor=t}l(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function d(){return(d=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}var h=function(){function n(t){this._listeners=[],this._eventEmitter=new i,this.on=this._eventEmitter.on.bind(this._eventEmitter),this.off=this._eventEmitter.off.bind(this._eventEmitter);var e=d({},n._defaultStoryOptions,t);this.el=this._createTemplate(),this.name=e.name,this._title=e.title,this._description=e.description,this._avatarSrc=e.avatarSrc,this._color=e.color,this._addSelectEmitter(),"function"==typeof e.onSelect&&this._eventEmitter.on("select",e.onSelect),e.container&&e.container.appendChild(this.el)}return n.prototype.destroy=function(){this.el.parentElement&&this.el.parentElement.removeChild(this.el),this._eventEmitter.off();for(var t=this._listeners.length;t--;)this._listeners[t]()},n.prototype._addSelectEmitter=function(){for(var t=this,e=this.el.querySelectorAll("[data-select-area]"),n=function(){t._eventEmitter.emit("select",t)},i=e.length;i--;)this._listeners.push(o(e[i],"click",n))},n.prototype._getElem=function(t){var e="data-"+t,n=this.el.querySelector("["+e+"]");if(n)return n.removeAttribute(e),n;throw new Error("Story does not contain element with name:"+t)},n._defaultStoryOptions={avatarSrc:"",title:"",description:"",color:"",selected:!1,titleColor:"",descriptionColor:""},n}(),f=function(n){function i(t){var e=n.call(this,t)||this;return e._selected=!1,e._elems={title:e._getElem("title"),description:e._getElem("description"),avatar:e._getElem("avatar"),avatarContainer:e._getElem("avatarContainer")},t.titleColor&&(e._elems.title.style.color=t.titleColor),t.descriptionColor&&(e._elems.description.style.color=t.descriptionColor),t.titleSize&&(e._elems.title.style.fontSize=t.titleSize),t.descriptionSize&&(e._elems.description.style.fontSize=t.descriptionSize),t.avatarSize&&(e._elems.avatarContainer.style.width=t.avatarSize),e._selected=!!t.selected,e.title=e._title,e.description=e._description,e.avatarSrc=e._avatarSrc,e.color=e._color,e}return p(i,n),Object.defineProperty(i.prototype,"avatarSrc",{get:function(){return this._avatarSrc},set:function(t){this._avatarSrc=t,this._elems.avatar.style.backgroundImage="url("+t+")"},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"title",{get:function(){return this._title},set:function(t){this._title=t,this._elems.title.textContent=t},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"description",{get:function(){return this._description},set:function(t){this._description=t,this._elems.description.textContent=t},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"color",{get:function(){return this._color},set:function(t){this._color=t,this._elems.avatarContainer.style.borderColor=t},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"selected",{get:function(){return this._selected},set:function(t){t?this.el.classList.add("gobi-story--selected"):this.el.classList.remove("gobi-story--selected"),this._selected=t},enumerable:!0,configurable:!0}),i.prototype._createTemplate=function(){var t="gobi-story",e=document.createElement("div");return e.classList.add(t),e.innerHTML=i._HTML,r(e.querySelectorAll("*"),t+"__"),e},Object.defineProperty(i,"_HTML",{get:function(){return'<div class="avatar-container" data-select-area data-avatarContainer><div class="avatar" data-avatar></div></div><div class="title" data-title></div><div class="description" data-description></div>'},enumerable:!0,configurable:!0}),i}(h);function y(){return(y=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}var v=function(){function i(t){var e=this,n=y({},i._defaultOptions,t);this.el=this._createTemplate(),this._title=n.title,this.title=n.title,this._color=n.color,this._activeColor=n.activeColor,this.stories=this._createStories(n.stories,n),this._currentStory=this.stories[0],this._playerContainer=this.el.querySelector("[data-player]"),this.player=new c(y({storyName:this._currentStory.name,container:this._playerContainer},n.playerOptions)),this._playerContainer.style.maxWidth=Math.min(.53*window.innerHeight,350)+"px",window.addEventListener("resize",function(){e._playerContainer.style.maxWidth=Math.min(.53*window.innerHeight,350)+"px"}),this.currentStory=this._currentStory}return Object.defineProperty(i.prototype,"title",{get:function(){return this._title},set:function(t){var e=this.el.querySelector("[data-title]");e&&(this._title=t,e.textContent=t)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"currentStory",{get:function(){return this._currentStory},set:function(t){this._currentStory.color=this._color,this._currentStory.selected=!1,this._currentStory=t,this._currentStory.selected=!0,this._currentStory.color=this._activeColor,this.player.load({storyName:this._currentStory.name})},enumerable:!0,configurable:!0}),i.prototype.append=function(t){t.appendChild(this.el)},i.prototype.remove=function(){var t=this.el.parentElement;t&&t.removeChild(this.el)},i.prototype._createStories=function(t,e){var n=this,i=this.el.querySelector("[data-stories]");return t.map(function(t){return new f({name:t.name,container:i,avatarSrc:t.avatarSrc,title:t.title,description:t.description,titleColor:t.titleColor,descriptionColor:t.descriptionColor,color:n._color,titleSize:e.titleSize,avatarSize:e.avatarSize,descriptionSize:e.descriptionSize,onSelect:n._onStorySelect.bind(n)})})},i.prototype._onStorySelect=function(t){console.log("_onStorySelect"),this.currentStory=t},i.prototype._createTemplate=function(){var t=document.createElement("div"),e="gobi-module";return t.classList.add(e),t.innerHTML=i._HTML,r(t.querySelectorAll("*"),e+"__"),t},Object.defineProperty(i,"_HTML",{get:function(){return'<div class="player-block"><div class="player" data-player></div></div><div class="stories-block"><div class="title" data-title></div><div class="stories" data-stories></div></div>'},enumerable:!0,configurable:!0}),i._defaultOptions={title:"",color:"",activeColor:"",playerOptions:{}},i}();function _(){return(_=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}var m=function(){function t(t){this._isOpen=!1,this._defaultOptions={classes:"",openers:"",closers:""},this._eventEmitter=new i,this._listeners=[];var e=_({},this._defaultOptions,t);this.el=this._createDiv(e.classes),this.content=this._createDiv("gobi-popup__content"),this.iframeContainer=this._createDiv("gobi-popup__iframe-container"),this._createTemplate(),this.player=e.player,this.appendPlayer(this.player),this._initClosers(e.closers)}return Object.defineProperty(t.prototype,"isOpen",{get:function(){return this._isOpen},enumerable:!0,configurable:!0}),t.prototype.appendPlayer=function(t){this.player=t,this.iframeContainer.insertBefore(this.player.el,this.iframeContainer.lastElementChild)},t.prototype.open=function(){s.disable(),this.el.classList.add("gobi-popup--active"),this._listeners.push(o(window,"keyup",this._onKeyUpClose.bind(this))),this._isOpen=!0,this._eventEmitter.emit("open",this,this)},t.prototype.close=function(){this.el.classList.remove("gobi-popup--active"),this.el.style.padding="",s.enable(),this._removeListeners(),this.player.pause(),this._isOpen=!1,this._eventEmitter.emit("close",this,this)},t.prototype.on=function(t,e){this._eventEmitter.on(t,e)},t.prototype.off=function(t,e){this._eventEmitter.off(t,e)},t.prototype._removeListeners=function(){for(var t=this._listeners.length;t--;)this._listeners[t]()},t.prototype._createTemplate=function(){var t=this._createElement("button","gobi-popup__close-btn");o(t,"click",this.close.bind(this)),this._calcPlayerSize(),this.iframeContainer.appendChild(t),this.content.appendChild(this.iframeContainer),this.el.classList.add("gobi-popup"),this.el.appendChild(this.content),window.addEventListener("resize",this._calcPlayerSize.bind(this))},t.prototype._createDiv=function(t){return this._createElement("div",t)},t.prototype._createElement=function(t,e){var n=document.createElement(t);return n.className=e,n},t.prototype._initClosers=function(t){this.el.addEventListener("click",this._onOutsideClose.bind(this)),this.content.addEventListener("click",this._onOutsideClose.bind(this))},t.prototype._onOutsideClose=function(t){t.target===t.currentTarget&&this.close()},t.prototype._onKeyUpClose=function(t){(void 0!==t.key?"Escape"===t.key||"Esc"===t.key:27===t.keyCode)&&this.close()},t.prototype._calcPlayerSize=function(){var t,e,n=window.innerHeight-100,i=window.innerWidth;e=.5625<i/n?(t=.5625*n,n):(t=i)/.5625,this.iframeContainer.style.width=t+"px",this.iframeContainer.style.height=e+"px"},t}(),b=function(n){function i(t){var e=n.call(this,t)||this;return e._elems={title:e._getElem("title"),description:e._getElem("description"),avatar:e._getElem("avatar"),avatarContainer:e._getElem("avatarContainer")},t.titleColor&&(e._elems.title.style.color=t.titleColor),t.descriptionColor&&(e._elems.description.style.color=t.descriptionColor),e.title=e._title,e.description=e._description,e.avatarSrc=e._avatarSrc,e.color=e._color,e}return p(i,n),Object.defineProperty(i.prototype,"avatarSrc",{get:function(){return this._avatarSrc},set:function(t){this._avatarSrc=t,this._elems.avatar.style.backgroundImage="url("+t+")"},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"title",{get:function(){return this._title},set:function(t){this._title=t,this._elems.title.textContent=t},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"description",{get:function(){return this._description},set:function(t){this._description=t,this._elems.description.textContent=t},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"color",{get:function(){return this._color},set:function(t){this._color=t,this._elems.avatarContainer.style.borderColor=t},enumerable:!0,configurable:!0}),i.prototype._createTemplate=function(){var t="gobi-popup-story",e=document.createElement("div");return e.classList.add(t),e.innerHTML=i._HTML,r(e.querySelectorAll("*"),t+"__"),e},Object.defineProperty(i,"_HTML",{get:function(){return'<div class="avatar-container" data-select-area data-avatarContainer><div class="avatar" data-avatar></div></div><div class="title" data-title></div><div class="description"><div class="description-text" data-description></div></div>'},enumerable:!0,configurable:!0}),i}(h);function g(){return(g=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}var w=function(){function n(t){var e=g({},n._defaultMobileModuleOptions,t);this.el=this._createTemplate(),this._title=e.title,this.title=e.title,this._color=e.color,this.stories=this._createStories(e.stories),this._currentStory=this.stories[0],this.player=new c(g({storyName:this.currentStory.name,checkViewPort:!1},e.playerOptions)),this.popup=new m({player:this.player})}return Object.defineProperty(n.prototype,"title",{get:function(){return this._title},set:function(t){var e=this.el.querySelector("[data-title]");e&&(this._title=t,e.textContent=t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"currentStory",{get:function(){return this._currentStory},set:function(t){this._currentStory=t,this.player.load({storyName:this._currentStory.name})},enumerable:!0,configurable:!0}),n.prototype.append=function(t){document.body.appendChild(this.popup.el),t.appendChild(this.el)},n.prototype.remove=function(){var t=this.el.parentElement;t&&(document.body.removeChild(this.popup.el),t.removeChild(this.el),this.popup.close())},n.prototype._createStories=function(t){var e=this,n=this.el.querySelector("[data-stories]");return t.map(function(t){return new b({name:t.name,container:n,avatarSrc:t.avatarSrc,title:t.title,description:t.description,titleColor:t.titleColor,descriptionColor:t.descriptionColor,color:e._color,onSelect:e._onStorySelect.bind(e)})})},n.prototype._onStorySelect=function(t){this.currentStory=t,this.popup.open()},n.prototype._createTemplate=function(){var t=document.createElement("div"),e="gobi-popup-module";return t.classList.add(e),t.innerHTML=n._HTML,r(t.querySelectorAll("*"),e+"__"),t},Object.defineProperty(n,"_HTML",{get:function(){return'<div class="title" data-title></div>\n <div class="stories" data-stories></div>'},enumerable:!0,configurable:!0}),n._defaultMobileModuleOptions={title:"",color:"",playerOptions:{}},n}();function S(){return(S=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}var O=function(){function l(t){this.load(t)}return l.prototype.load=function(a){var c=this;this._getModule(a.moduleId).then(function(t){var e=S({},l._defaultOptions,a),n=e.container,i=c._decorateResponseStories(t),r=c._mergeStoriesOptions(i,e.stories),o=window.innerWidth<768,s=c._initModules(e,r);window.innerWidth<768&&s.mobile.append(n),767<window.innerWidth&&s.desktop.append(n),window.addEventListener("resize",function(){window.innerWidth<768&&!o&&(s.desktop.remove(),s.mobile.append(n),o=!0),767<window.innerWidth&&o&&(s.mobile.remove(),s.desktop.append(n),o=!1)})})},l.prototype._initModules=function(t,e){return{desktop:new v({title:t.title,color:t.color,activeColor:t.activeColor,stories:e,playerOptions:t.playerOptions,titleSize:t.desktopStoryStyle.titleSize,avatarSize:t.desktopStoryStyle.avatarSize,descriptionSize:t.desktopStoryStyle.descriptionSize}),mobile:new w({title:t.title,color:t.activeColor,stories:e,playerOptions:t.playerOptions})}},l.prototype._getModule=function(r){return new u.a(function(t,e){var n=new XMLHttpRequest,i="https://live.gobiapp.com/projector/player/storyModules/"+r;n.open("GET",i,!0),n.send(),n.onload=function(){this.status<400?t(JSON.parse(this.responseText)):e(Error("Module didn't load successfully; error code:"+n.statusText))},n.onerror=function(){e(Error("There was a network error."))}})},l.prototype._mergeStoriesOptions=function(t,e){var n=[];for(var i in t){var r=t[i];if(e[i]){var o=e[i];n.push(S(r,o))}else n.push(r)}return n},l.prototype._decorateResponseStories=function(t){return t.map(function(t,e){return{title:t.title,avatarSrc:t.thumbnail,description:t.description,name:t.story_id}})},l._defaultOptions={title:"",color:"#999999",activeColor:"#15d6ea",stories:[],desktopStoryStyle:{}},l}();n.d(e,"Module",function(){return C}),n.d(e,"Player",function(){return E});var C=O,E=c}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.gobi=e():t.gobi=e()}(window,function(){return function(n){var i={};function r(t){if(i[t])return i[t].exports;var e=i[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,r),e.l=!0,e.exports}return r.m=n,r.c=i,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=7)}([function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,p,d){"use strict";(function(e){var t=d(2),n=setTimeout;function i(){}function o(t){if(!(this instanceof o))throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],u(t,this)}function r(n,i){for(;3===n._state;)n=n._value;0!==n._state?(n._handled=!0,o._immediateFn(function(){var t=1===n._state?i.onFulfilled:i.onRejected;if(null!==t){var e;try{e=t(n._value)}catch(t){return void a(i.promise,t)}s(i.promise,e)}else(1===n._state?s:a)(i.promise,n._value)})):n._deferreds.push(i)}function s(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if(t instanceof o)return e._state=3,e._value=t,void c(e);if("function"==typeof n)return void u((i=n,r=t,function(){i.apply(r,arguments)}),e)}e._state=1,e._value=t,c(e)}catch(t){a(e,t)}var i,r}function a(t,e){t._state=2,t._value=e,c(t)}function c(t){2===t._state&&0===t._deferreds.length&&o._immediateFn(function(){t._handled||o._unhandledRejectionFn(t._value)});for(var e=0,n=t._deferreds.length;e<n;e++)r(t,t._deferreds[e]);t._deferreds=null}function l(t,e,n){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof e?e:null,this.promise=n}function u(t,e){var n=!1;try{t(function(t){n||(n=!0,s(e,t))},function(t){n||(n=!0,a(e,t))})}catch(t){if(n)return;n=!0,a(e,t)}}o.prototype.catch=function(t){return this.then(null,t)},o.prototype.then=function(t,e){var n=new this.constructor(i);return r(this,new l(t,e,n)),n},o.prototype.finally=t.a,o.all=function(e){return new o(function(i,r){if(!e||void 0===e.length)throw new TypeError("Promise.all accepts an array");var o=Array.prototype.slice.call(e);if(0===o.length)return i([]);var s=o.length;function a(e,t){try{if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if("function"==typeof n)return void n.call(t,function(t){a(e,t)},r)}o[e]=t,0==--s&&i(o)}catch(t){r(t)}}for(var t=0;t<o.length;t++)a(t,o[t])})},o.resolve=function(e){return e&&"object"==typeof e&&e.constructor===o?e:new o(function(t){t(e)})},o.reject=function(n){return new o(function(t,e){e(n)})},o.race=function(r){return new o(function(t,e){for(var n=0,i=r.length;n<i;n++)r[n].then(t,e)})},o._immediateFn="function"==typeof e&&function(t){e(t)}||function(t){n(t,0)},o._unhandledRejectionFn=function(t){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",t)},p.a=o}).call(this,d(4).setImmediate)},function(t,e,n){"use strict";e.a=function(e){var n=this.constructor;return this.then(function(t){return n.resolve(e()).then(function(){return t})},function(t){return n.resolve(e()).then(function(){return n.reject(t)})})}},function(t,e,n){},function(t,r,o){(function(t){var e=void 0!==t&&t||"undefined"!=typeof self&&self||window,n=Function.prototype.apply;function i(t,e){this._id=t,this._clearFn=e}r.setTimeout=function(){return new i(n.call(setTimeout,e,arguments),clearTimeout)},r.setInterval=function(){return new i(n.call(setInterval,e,arguments),clearInterval)},r.clearTimeout=r.clearInterval=function(t){t&&t.close()},i.prototype.unref=i.prototype.ref=function(){},i.prototype.close=function(){this._clearFn.call(e,this._id)},r.enroll=function(t,e){clearTimeout(t._idleTimeoutId),t._idleTimeout=e},r.unenroll=function(t){clearTimeout(t._idleTimeoutId),t._idleTimeout=-1},r._unrefActive=r.active=function(t){clearTimeout(t._idleTimeoutId);var e=t._idleTimeout;0<=e&&(t._idleTimeoutId=setTimeout(function(){t._onTimeout&&t._onTimeout()},e))},o(5),r.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==t&&t.setImmediate||this&&this.setImmediate,r.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==t&&t.clearImmediate||this&&this.clearImmediate}).call(this,o(0))},function(t,e,n){(function(t,f){!function(n,i){"use strict";if(!n.setImmediate){var r,o,e,s,t,a=1,c={},l=!1,u=n.document,p=Object.getPrototypeOf&&Object.getPrototypeOf(n);p=p&&p.setTimeout?p:n,r="[object process]"==={}.toString.call(n.process)?function(t){f.nextTick(function(){h(t)})}:function(){if(n.postMessage&&!n.importScripts){var t=!0,e=n.onmessage;return n.onmessage=function(){t=!1},n.postMessage("","*"),n.onmessage=e,t}}()?(s="setImmediate$"+Math.random()+"$",t=function(t){t.source===n&&"string"==typeof t.data&&0===t.data.indexOf(s)&&h(+t.data.slice(s.length))},n.addEventListener?n.addEventListener("message",t,!1):n.attachEvent("onmessage",t),function(t){n.postMessage(s+t,"*")}):n.MessageChannel?((e=new MessageChannel).port1.onmessage=function(t){h(t.data)},function(t){e.port2.postMessage(t)}):u&&"onreadystatechange"in u.createElement("script")?(o=u.documentElement,function(t){var e=u.createElement("script");e.onreadystatechange=function(){h(t),e.onreadystatechange=null,o.removeChild(e),e=null},o.appendChild(e)}):function(t){setTimeout(h,0,t)},p.setImmediate=function(t){"function"!=typeof t&&(t=new Function(""+t));for(var e=new Array(arguments.length-1),n=0;n<e.length;n++)e[n]=arguments[n+1];var i={callback:t,args:e};return c[a]=i,r(a),a++},p.clearImmediate=d}function d(t){delete c[t]}function h(t){if(l)setTimeout(h,0,t);else{var e=c[t];if(e){l=!0;try{!function(t){var e=t.callback,n=t.args;switch(n.length){case 0:e();break;case 1:e(n[0]);break;case 2:e(n[0],n[1]);break;case 3:e(n[0],n[1],n[2]);break;default:e.apply(i,n)}}(e)}finally{d(t),l=!1}}}}}("undefined"==typeof self?void 0===t?this:t:self)}).call(this,n(0),n(6))},function(t,e){var n,i,r=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(e){if(n===setTimeout)return setTimeout(e,0);if((n===o||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:o}catch(t){n=o}try{i="function"==typeof clearTimeout?clearTimeout:s}catch(t){i=s}}();var c,l=[],u=!1,p=-1;function d(){u&&c&&(u=!1,c.length?l=c.concat(l):p=-1,l.length&&h())}function h(){if(!u){var t=a(d);u=!0;for(var e=l.length;e;){for(c=l,l=[];++p<e;)c&&c[p].run();p=-1,e=l.length}c=null,u=!1,function(e){if(i===clearTimeout)return clearTimeout(e);if((i===s||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(e);try{i(e)}catch(t){try{return i.call(null,e)}catch(t){return i.call(this,e)}}}(t)}}function f(t,e){this.fun=t,this.array=e}function y(){}r.nextTick=function(t){var e=new Array(arguments.length-1);if(1<arguments.length)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];l.push(new f(t,e)),1!==l.length||u||a(h)},f.prototype.run=function(){this.fun.apply(null,this.array)},r.title="browser",r.browser=!0,r.env={},r.argv=[],r.version="",r.versions={},r.on=y,r.addListener=y,r.once=y,r.off=y,r.removeListener=y,r.removeAllListeners=y,r.emit=y,r.prependListener=y,r.prependOnceListener=y,r.listeners=function(t){return[]},r.binding=function(t){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(t){throw new Error("process.chdir is not supported")},r.umask=function(){return 0}},function(t,e,n){"use strict";n.r(e);n(3);var i=function(){function t(){this._eventsCallbacks={}}return t.prototype.on=function(t,e){this._eventsCallbacks.hasOwnProperty(t)||(this._eventsCallbacks[t]=[]);var n=this._eventsCallbacks[t];-1===n.indexOf(e)&&n.push(e)},t.prototype.off=function(t,e){"string"==typeof t?this._eventsCallbacks.hasOwnProperty(t)&&("function"==typeof e?this._removeCallback(t,e):this._eventsCallbacks[t]=[]):this._removeAllCallbacks()},t.prototype.emit=function(t,e,n){if(this._eventsCallbacks.hasOwnProperty(t))for(var i=this._eventsCallbacks[t],r=i.length,o=0;o<r;o++)i[o].call(n||this,e)},t.prototype._removeCallback=function(t,e){var n=this._eventsCallbacks[t],i=n.indexOf(e);-1<i&&n.splice(i,1)},t.prototype._removeAllCallbacks=function(){for(var t in this._eventsCallbacks)this._eventsCallbacks.hasOwnProperty(t)&&delete this._eventsCallbacks[t]},t}(),o=n(1);function s(){return(s=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}function r(t,e){for(var n,i=t.length,r=0;r<i;r++)(n=t[r]).className=e+n.className}function l(r){return new o.a(function(t,e){var n=new XMLHttpRequest,i="http://gobi-projector.scrij.com/projector/player/storyModules/"+r;n.open("GET",i,!0),n.send(),n.onload=function(){this.status<400?t(JSON.parse(this.responseText)):e(Error("Module didn't load successfully; error code:"+n.statusText))},n.onerror=function(){e(Error("There was a network error."))}})}function u(t,e){var n=[];for(var i in t){var r=t[i],o=e[i];n.push(o?s(r,o):r)}return n}function p(t){return t.map(function(t){return{title:t.title,avatarSrc:t.thumbnail,description:t.description,name:t.story_id}})}function a(t,e,n){var i=function(t){return n(t)};return t.addEventListener(e,i),function(){return t.removeEventListener(e,i)}}var c={scrollTop:0,bodyOverflow:"",disable:function(){this.isIOS?this.IOSDisable():this.classicDisable()},enable:function(){this.isIOS?this.IOSEnable():this.classicEnable()},classicDisable:function(){this.bodyOverflow=document.body.style.overflow,document.body.style.overflow="hidden"},classicEnable:function(){document.body.style.overflow=this.bodyOverflow},IOSEnable:function(){document.documentElement.classList.remove("disabled-scroll"),document.body.classList.remove("disabled-scroll"),window.scrollTo(0,this.scrollTop)},IOSDisable:function(){this.scrollTop=window.pageYOffset,document.documentElement.classList.add("disabled-scroll"),document.body.classList.add("disabled-scroll")},isIOS:/iPad|iPhone|iPod/.test(navigator.userAgent)};function d(){return(d=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}var h=function(){function t(t){var n=this;this._defaultOptions={autoStart:!1,hideOverlay:!1,loop:!1,width:0,height:0,roundedCorners:!0,shadow:!0,checkViewPort:!0},this._eventEmitter=new i,this.on=this._eventEmitter.on.bind(this._eventEmitter),this.off=this._eventEmitter.off.bind(this._eventEmitter),this._removeIsOnScreenChecker=function(){},this._removeIsOutOfScreenChecker=function(){},this._options=d({},this._defaultOptions,t),this.el=this._createIframe(),this._options.container&&this._options.container.appendChild(this.el),window.addEventListener("message",function(t){if(n.el.contentWindow===t.source){var e=t.data;e.event&&(n._eventEmitter.emit(e.event,e.value,n),n._options.checkViewPort&&n._viewPortChecker(e.event))}})}return Object.defineProperty(t.prototype,"storyURL",{get:function(){return"https://live.gobiapp.com/next/story/id/"+this._options.storyName+"?autoStart="+this._options.autoStart+"&addLooping="+this._options.loop+"&hideOverlay="+this._options.hideOverlay+"&roundedCorners="+this._options.roundedCorners},enumerable:!0,configurable:!0}),t.prototype.load=function(t){d(this._options,t),this.el.src=this.storyURL},t.prototype.play=function(){this._callPlayerMethod("play")},t.prototype.pause=function(){this._callPlayerMethod("pause")},t.prototype.reload=function(){this._callPlayerMethod("reset")},t.prototype.setMute=function(t){this._callPlayerMethod("setMute",t)},t.prototype.isInViewport=function(){var t=this.el.getBoundingClientRect(),e=window.innerHeight||document.documentElement.clientHeight,n=window.innerWidth||document.documentElement.clientWidth,i=.8*t.height,r=.8*t.width;return t.top>=0-i&&t.left>=0-r&&t.bottom<=e+i&&t.right<=n+r},t.prototype._callPlayerMethod=function(t,e){void 0===e&&(e=void 0),this._sendMessage({method:t,value:e})},t.prototype._sendMessage=function(t){var e=this.el.contentWindow;e&&e.postMessage(t,"*")},t.prototype._createIframe=function(){var t=document.createElement("iframe"),e=this._calcPlayerSize();return t.src=this.storyURL,t.width=e.width.toString(),t.height=e.height.toString(),t.frameBorder="0",t.scrolling="no",t.style.overflow="hidden",t.style.background="#000",t.style.border="0",this._options.shadow&&t.classList.add("gobi-player-shadow"),this._options.roundedCorners&&(t.style.borderRadius="10px"),t.setAttribute("allow","autoplay;"),t},t.prototype._viewPortChecker=function(t){switch(t){case"play":this._addIsOutOfScreenChecker();break;case"pause":this.isInViewport()&&(this._removeIsOnScreenChecker(),this._removeIsOutOfScreenChecker());break;case"ended":this._removeIsOnScreenChecker(),this._removeIsOutOfScreenChecker()}},t.prototype._addIsOutOfScreenChecker=function(){var t=this;this._removeIsOutOfScreenChecker(),this._removeIsOnScreenChecker(),this._removeIsOutOfScreenChecker=a(window,"scroll",function(){t.isInViewport()||(t.pause(),t._removeIsOutOfScreenChecker(),t._addIsOnScreenChecker())})},t.prototype._addIsOnScreenChecker=function(){var t=this;this._removeIsOnScreenChecker=a(window,"scroll",function(){t.isInViewport()&&(t.play(),t._removeIsOnScreenChecker(),t._addIsOutOfScreenChecker())})},t.prototype._calcPlayerSize=function(){var t=612,e=1088;return this._options.width&&this._options.height?(t=this._options.width,e=this._options.height):this._options.width?e=(t=this._options.width)/.5625:this._options.height&&(t=.5625*(e=this._options.height)),{width:t,height:e}},t}(),f=function(t,e){return(f=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function y(t,e){function n(){this.constructor=t}f(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function v(){return(v=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}var _=function(){function n(t){this._listeners=[],this._eventEmitter=new i,this.on=this._eventEmitter.on.bind(this._eventEmitter),this.off=this._eventEmitter.off.bind(this._eventEmitter);var e=v({},n._defaultStoryOptions,t);this.el=this._createTemplate(),this.name=e.name,this._title=e.title,this._description=e.description,this._avatarSrc=e.avatarSrc,this._color=e.color,this._addSelectEmitter(),"function"==typeof e.onSelect&&this._eventEmitter.on("select",e.onSelect),e.container&&e.container.appendChild(this.el)}return n.prototype.destroy=function(){this.el.parentElement&&this.el.parentElement.removeChild(this.el),this._eventEmitter.off();for(var t=this._listeners.length;t--;)this._listeners[t]()},n.prototype._addSelectEmitter=function(){for(var t=this,e=this.el.querySelectorAll("[data-select-area]"),n=function(){t._eventEmitter.emit("select",t)},i=e.length;i--;)this._listeners.push(a(e[i],"click",n))},n.prototype._getElem=function(t){var e="data-"+t,n=this.el.querySelector("["+e+"]");if(n)return n.removeAttribute(e),n;throw new Error("Story does not contain element with name:"+t)},n._defaultStoryOptions={avatarSrc:"",title:"",description:"",color:"",selected:!1,titleColor:"",descriptionColor:""},n}(),m=function(n){function i(t){var e=n.call(this,t)||this;return e._selected=!1,e._elems={title:e._getElem("title"),description:e._getElem("description"),avatar:e._getElem("avatar"),avatarContainer:e._getElem("avatarContainer")},t.titleColor&&(e._elems.title.style.color=t.titleColor),t.descriptionColor&&(e._elems.description.style.color=t.descriptionColor),t.titleSize&&(e._elems.title.style.fontSize=t.titleSize),t.descriptionSize&&(e._elems.description.style.fontSize=t.descriptionSize),t.avatarSize&&(e._elems.avatarContainer.style.width=t.avatarSize),e._selected=!!t.selected,e.title=e._title,e.description=e._description,e.avatarSrc=e._avatarSrc,e.color=e._color,e}return y(i,n),Object.defineProperty(i.prototype,"avatarSrc",{get:function(){return this._avatarSrc},set:function(t){this._avatarSrc=t,this._elems.avatar.style.backgroundImage="url("+t+")"},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"title",{get:function(){return this._title},set:function(t){this._title=t,this._elems.title.textContent=t},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"description",{get:function(){return this._description},set:function(t){this._description=t,this._elems.description.textContent=t},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"color",{get:function(){return this._color},set:function(t){this._color=t,this._elems.avatarContainer.style.borderColor=t},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"selected",{get:function(){return this._selected},set:function(t){t?this.el.classList.add("gobi-story--selected"):this.el.classList.remove("gobi-story--selected"),this._selected=t},enumerable:!0,configurable:!0}),i.prototype._createTemplate=function(){var t="gobi-story",e=document.createElement("div");return e.classList.add(t),e.innerHTML=i._HTML,r(e.querySelectorAll("*"),t+"__"),e},Object.defineProperty(i,"_HTML",{get:function(){return'<div class="avatar-container" data-select-area data-avatarContainer><div class="avatar" data-avatar></div></div><div class="title" data-title></div><div class="description" data-description></div>'},enumerable:!0,configurable:!0}),i}(_);function b(){return(b=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}var g=function(){function i(t){var e=this,n=b({},i._defaultOptions,t);this.el=this._createTemplate(),this._title=n.title,this.title=n.title,this._color=n.color,this._activeColor=n.activeColor,this.stories=this._createStories(n.stories,n),this._currentStory=this.stories[0],this._playerContainer=this.el.querySelector("[data-player]"),this.player=new h(b({storyName:this._currentStory.name,container:this._playerContainer},n.playerOptions)),this._playerContainer.style.maxWidth=Math.min(.53*window.innerHeight,350)+"px",window.addEventListener("resize",function(){e._playerContainer.style.maxWidth=Math.min(.53*window.innerHeight,350)+"px"}),this.currentStory=this._currentStory}return Object.defineProperty(i.prototype,"title",{get:function(){return this._title},set:function(t){var e=this.el.querySelector("[data-title]");e&&(this._title=t,e.textContent=t)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"currentStory",{get:function(){return this._currentStory},set:function(t){this._currentStory.color=this._color,this._currentStory.selected=!1,this._currentStory=t,this._currentStory.selected=!0,this._currentStory.color=this._activeColor,this.player.load({storyName:this._currentStory.name})},enumerable:!0,configurable:!0}),i.prototype.append=function(t){t.appendChild(this.el)},i.prototype.remove=function(){var t=this.el.parentElement;t&&t.removeChild(this.el)},i.prototype._createStories=function(t,e){var n=this,i=this.el.querySelector("[data-stories]");return t.map(function(t){return new m({name:t.name,container:i,avatarSrc:t.avatarSrc,title:t.title,description:t.description,titleColor:t.titleColor,descriptionColor:t.descriptionColor,color:n._color,titleSize:e.titleSize,avatarSize:e.avatarSize,descriptionSize:e.descriptionSize,onSelect:n._onStorySelect.bind(n)})})},i.prototype._onStorySelect=function(t){console.log("_onStorySelect"),this.currentStory=t},i.prototype._createTemplate=function(){var t=document.createElement("div"),e="gobi-module";return t.classList.add(e),t.innerHTML=i._HTML,r(t.querySelectorAll("*"),e+"__"),t},Object.defineProperty(i,"_HTML",{get:function(){return'<div class="player-block"><div class="player" data-player></div></div><div class="stories-block"><div class="title" data-title></div><div class="stories" data-stories></div></div>'},enumerable:!0,configurable:!0}),i._defaultOptions={title:"",color:"",activeColor:"",playerOptions:{}},i}();function w(){return(w=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}var S=function(){function t(t){this._isOpen=!1,this._defaultOptions={classes:"",openers:"",closers:""},this._eventEmitter=new i,this._listeners=[];var e=w({},this._defaultOptions,t);this.el=this._createDiv(e.classes),this.content=this._createDiv("gobi-popup__content"),this.iframeContainer=this._createDiv("gobi-popup__iframe-container"),this._createTemplate(),this.player=e.player,this.appendPlayer(this.player),this._initClosers(e.closers)}return Object.defineProperty(t.prototype,"isOpen",{get:function(){return this._isOpen},enumerable:!0,configurable:!0}),t.prototype.appendPlayer=function(t){this.player=t,this.iframeContainer.insertBefore(this.player.el,this.iframeContainer.lastElementChild)},t.prototype.open=function(){c.disable(),this.el.classList.add("gobi-popup--active"),this._listeners.push(a(window,"keyup",this._onKeyUpClose.bind(this))),this._isOpen=!0,this._eventEmitter.emit("open",this,this)},t.prototype.close=function(){this.el.classList.remove("gobi-popup--active"),this.el.style.padding="",c.enable(),this._removeListeners(),this.player.pause(),this._isOpen=!1,this._eventEmitter.emit("close",this,this)},t.prototype.on=function(t,e){this._eventEmitter.on(t,e)},t.prototype.off=function(t,e){this._eventEmitter.off(t,e)},t.prototype._removeListeners=function(){for(var t=this._listeners.length;t--;)this._listeners[t]()},t.prototype._createTemplate=function(){var t=this._createElement("button","gobi-popup__close-btn");a(t,"click",this.close.bind(this)),this._calcPlayerSize(),this.iframeContainer.appendChild(t),this.content.appendChild(this.iframeContainer),this.el.classList.add("gobi-popup"),this.el.appendChild(this.content),window.addEventListener("resize",this._calcPlayerSize.bind(this))},t.prototype._createDiv=function(t){return this._createElement("div",t)},t.prototype._createElement=function(t,e){var n=document.createElement(t);return n.className=e,n},t.prototype._initClosers=function(t){this.el.addEventListener("click",this._onOutsideClose.bind(this)),this.content.addEventListener("click",this._onOutsideClose.bind(this))},t.prototype._onOutsideClose=function(t){t.target===t.currentTarget&&this.close()},t.prototype._onKeyUpClose=function(t){(void 0!==t.key?"Escape"===t.key||"Esc"===t.key:27===t.keyCode)&&this.close()},t.prototype._calcPlayerSize=function(){var t,e,n=window.innerHeight-100,i=window.innerWidth;e=.5625<i/n?(t=.5625*n,n):(t=i)/.5625,this.iframeContainer.style.width=t+"px",this.iframeContainer.style.height=e+"px"},t}(),O=function(n){function i(t){var e=n.call(this,t)||this;return e._elems={title:e._getElem("title"),description:e._getElem("description"),avatar:e._getElem("avatar"),avatarContainer:e._getElem("avatarContainer")},t.titleColor&&(e._elems.title.style.color=t.titleColor),t.descriptionColor&&(e._elems.description.style.color=t.descriptionColor),e.title=e._title,e.description=e._description,e.avatarSrc=e._avatarSrc,e.color=e._color,e}return y(i,n),Object.defineProperty(i.prototype,"avatarSrc",{get:function(){return this._avatarSrc},set:function(t){this._avatarSrc=t,this._elems.avatar.style.backgroundImage="url("+t+")"},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"title",{get:function(){return this._title},set:function(t){this._title=t,this._elems.title.textContent=t},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"description",{get:function(){return this._description},set:function(t){this._description=t,this._elems.description.textContent=t},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"color",{get:function(){return this._color},set:function(t){this._color=t,this._elems.avatarContainer.style.borderColor=t},enumerable:!0,configurable:!0}),i.prototype._createTemplate=function(){var t="gobi-popup-story",e=document.createElement("div");return e.classList.add(t),e.innerHTML=i._HTML,r(e.querySelectorAll("*"),t+"__"),e},Object.defineProperty(i,"_HTML",{get:function(){return'<div class="avatar-container" data-select-area data-avatarContainer><div class="avatar" data-avatar></div></div><div class="title" data-title></div><div class="description"><div class="description-text" data-description></div></div>'},enumerable:!0,configurable:!0}),i}(_);function C(){return(C=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}var E=function(){function n(t){var e=C({},n._defaultMobileModuleOptions,t);this.el=this._createTemplate(),this._title=e.title,this.title=e.title,this._color=e.color,this.stories=this._createStories(e.stories),this._currentStory=this.stories[0],this.player=new h(C({storyName:this.currentStory.name,checkViewPort:!1},e.playerOptions)),this.popup=new S({player:this.player})}return Object.defineProperty(n.prototype,"title",{get:function(){return this._title},set:function(t){var e=this.el.querySelector("[data-title]");e&&(this._title=t,e.textContent=t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"currentStory",{get:function(){return this._currentStory},set:function(t){this._currentStory=t,this.player.load({storyName:this._currentStory.name})},enumerable:!0,configurable:!0}),n.prototype.append=function(t){document.body.appendChild(this.popup.el),t.appendChild(this.el)},n.prototype.remove=function(){var t=this.el.parentElement;t&&(document.body.removeChild(this.popup.el),t.removeChild(this.el),this.popup.close())},n.prototype._createStories=function(t){var e=this,n=this.el.querySelector("[data-stories]");return t.map(function(t){return new O({name:t.name,container:n,avatarSrc:t.avatarSrc,title:t.title,description:t.description,titleColor:t.titleColor,descriptionColor:t.descriptionColor,color:e._color,onSelect:e._onStorySelect.bind(e)})})},n.prototype._onStorySelect=function(t){this.currentStory=t,this.popup.open()},n.prototype._createTemplate=function(){var t=document.createElement("div"),e="gobi-popup-module";return t.classList.add(e),t.innerHTML=n._HTML,r(t.querySelectorAll("*"),e+"__"),t},Object.defineProperty(n,"_HTML",{get:function(){return'<div class="title" data-title></div>\n <div class="stories" data-stories></div>'},enumerable:!0,configurable:!0}),n._defaultMobileModuleOptions={title:"",color:"",playerOptions:{}},n}();function T(){return(T=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}var k=function(){function c(t){this.load(t)}return c.prototype.load=function(s){var a=this;l(s.moduleId).then(function(t){var e=T({},c._defaultOptions,s),n=e.container,i=u(p(t),e.stories),r=window.innerWidth<768,o=a._initModules(e,i);window.innerWidth<768&&o.mobile.append(n),767<window.innerWidth&&o.desktop.append(n),window.addEventListener("resize",function(){window.innerWidth<768&&!r&&(o.desktop.remove(),o.mobile.append(n),r=!0),767<window.innerWidth&&r&&(o.mobile.remove(),o.desktop.append(n),r=!1)})})},c.prototype._initModules=function(t,e){return{desktop:new g({title:t.title,color:t.color,activeColor:t.activeColor,stories:e,playerOptions:t.playerOptions,titleSize:t.desktopStoryStyle.titleSize,avatarSize:t.desktopStoryStyle.avatarSize,descriptionSize:t.desktopStoryStyle.descriptionSize}),mobile:new E({title:t.title,color:t.activeColor,stories:e,playerOptions:t.playerOptions})}},c._defaultOptions={title:"",color:"#999999",activeColor:"#15d6ea",stories:[],desktopStoryStyle:{}},c}();function P(){return(P=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}var j=function(){function r(t){this.load(t)}return r.prototype.load=function(i){l(i.moduleId).then(function(t){var e=P({},r._defaultOptions,i),n=u(p(t),e.stories);new E({title:i.title,color:i.color,stories:n,playerOptions:i.playerOptions}).append(e.container)})},r._defaultOptions={title:"",color:"#15d6ea",stories:[]},r}();n.d(e,"Module",function(){return I}),n.d(e,"MobileModule",function(){return L}),n.d(e,"Player",function(){return M});var I=k,L=j,M=h}])}); |
{ | ||
"name": "@gobistories/gobi-web-integration", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/gobi-web-integration.js", |
@@ -92,2 +92,40 @@ # Gobi Web Integration | ||
# MobileModule Constructor | ||
Function which create **mobile** module layout with already embedded player. Getting options which allow to customize layout. Doesn't return any interface. | ||
## Create | ||
```html | ||
<head> | ||
<link href="https://unpkg.com/@gobistories/gobi-web-integration/dist/gobi-web-integration.css" rel="stylesheet"> | ||
<script src="https://unpkg.com/@gobistories/gobi-web-integration/dist/gobi-web-integration.js"></script> | ||
</head> | ||
<body> | ||
<div id="container"></div> | ||
<script> | ||
new gobi.MobileModule({ | ||
moduleId: 'some-modul-id', | ||
container: document.getElementById('container'), | ||
}); | ||
</script> | ||
</body> | ||
``` | ||
## Options | ||
option | default | description | ||
----------------------------------| -------- | ----------- | ||
moduleId | | **Required.** String. The id of the module. | ||
container | | **Required.** HTMLElement. Container where the module will be embed. | ||
title | `` | String. Module title. | ||
color |`#15d6ea` | Any valid css color value (#000, rgb(...), rgba(...)). The color of border of story circle. | ||
**playerOptions** | `{}` | Object. Provides interface for customization of player view. | ||
playerOptions.roundedCorners | `true` | Boolean. Remove or add rounded corners to player element. | ||
playerOptions.shadow | `true` | Boolean. Remove or add shadow to player element. | ||
**stories** | `{}` | Object. Allow to change content of each stroy circle. | ||
stories[0...n].title | `` | String. Change title text of specific story. | ||
stories[0...n].description | `` | String. Change description text of specific story. | ||
stories[0...n].avatarSrc | `` | String. Avatar URL of specific story. | ||
stories[0...n].titleColor | `` | Any valid css color value (#000, rgb(...), rgba(...)). Set color of specific story title text. | ||
stories[0...n].descriptionColor | `` | Any valid css color value (#000, rgb(...), rgba(...)). Set color of specific story description text. | ||
# Player Constructor | ||
@@ -94,0 +132,0 @@ |
import './styles.scss'; | ||
import {default as _Player} from "@/GobiPlayer/gobi-player"; | ||
import {default as _Module} from "@/Module/gobi-module"; | ||
import GobiMobileModule from "@/GobiMobileModule/gobi-mobile-module"; | ||
export const Module = _Module; | ||
export const MobileModule = GobiMobileModule; | ||
export const Player = _Player; |
import { | ||
ModuleComingOptions, | ||
ModuleOptions, | ||
ModuleStoriesOptionsObj, | ||
ResponseModuleStory | ||
} from "@/Module/gobi-module.types"; | ||
import Promise from 'promise-polyfill'; | ||
import DesktopModule from "@/Module/DesktopModule/desktop-module"; | ||
import {StoryComingOptions} from "@/Story/story.types"; | ||
import MobileModule from "@/Module/MobileModule/mobile-module"; | ||
import {decorateResponseStories, getModule, mergeStoriesOptions} from "@/utils/utils"; | ||
@@ -27,7 +26,7 @@ export default class Module { | ||
load(options:ModuleComingOptions) { | ||
this._getModule(options.moduleId).then((stories:ResponseModuleStory[]) => { | ||
getModule(options.moduleId).then((stories:ResponseModuleStory[]) => { | ||
const _options:ModuleOptions = Object.assign({}, Module._defaultOptions, options); | ||
const container = _options.container; | ||
const responseStoryOptions = this._decorateResponseStories(stories); | ||
const storiesOptions = this._mergeStoriesOptions(responseStoryOptions, _options.stories); | ||
const responseStoryOptions = decorateResponseStories(stories); | ||
const storiesOptions = mergeStoriesOptions(responseStoryOptions, _options.stories); | ||
let isMobileView = window.innerWidth < 768; | ||
@@ -57,3 +56,3 @@ const module = this._initModules(_options, storiesOptions); | ||
private _initModules(options:ModuleOptions, | ||
storiesOptions:StoryComingOptions[]):{ desktop:DesktopModule, mobile:MobileModule }{ | ||
storiesOptions:StoryComingOptions[]):{ desktop:DesktopModule, mobile:MobileModule } { | ||
return { | ||
@@ -78,48 +77,3 @@ desktop: new DesktopModule({ | ||
} | ||
private _getModule(moduleId:string):Promise<Array<ResponseModuleStory>> { | ||
return new Promise(function(resolve, reject) { | ||
const xhr = new XMLHttpRequest(); | ||
const url = 'https://live.gobiapp.com/projector/player/storyModules/' + moduleId; | ||
xhr.open('GET', url, true); | ||
xhr.send(); | ||
xhr.onload = function() { | ||
if (this.status < 400) { | ||
resolve(JSON.parse(this.responseText)); | ||
} else { | ||
reject(Error('Module didn\'t load successfully; error code:' + xhr.statusText)); | ||
} | ||
}; | ||
xhr.onerror = function() { | ||
reject(Error('There was a network error.')); | ||
}; | ||
}) | ||
} | ||
private _mergeStoriesOptions(responseStoryOptions:StoryComingOptions[], | ||
comingStoryOptions:ModuleStoriesOptionsObj):StoryComingOptions[] { | ||
const mergedOptions:StoryComingOptions[] = []; | ||
for (const key in responseStoryOptions) { | ||
const responseOption = responseStoryOptions[key]; | ||
if (comingStoryOptions[key]) { | ||
const comingOptions = comingStoryOptions[key]; | ||
mergedOptions.push(Object.assign(responseOption, comingOptions)) | ||
} | ||
else { | ||
mergedOptions.push(responseOption); | ||
} | ||
} | ||
return mergedOptions; | ||
} | ||
private _decorateResponseStories(responseStories:ResponseModuleStory[]):Array<StoryComingOptions> { | ||
return responseStories.map((responseStory, index):StoryComingOptions => { | ||
return { | ||
title: responseStory.title, | ||
avatarSrc: responseStory.thumbnail, | ||
description: responseStory.description, | ||
name: responseStory.story_id | ||
}; | ||
}) | ||
} | ||
} |
@@ -0,1 +1,3 @@ | ||
export interface ModuleOptions { | ||
@@ -15,2 +17,18 @@ moduleId: string, | ||
} | ||
export interface GobiMobileModuleOptions { | ||
moduleId: string, | ||
container: HTMLElement, | ||
title: string, | ||
color: string, | ||
stories: ModuleStoriesOptionsObj, | ||
playerOptions?: ModulePlayerOptions, | ||
} | ||
export interface GobiMobileModuleComingOptions { | ||
moduleId: string, | ||
container: HTMLElement, | ||
title?: string, | ||
color?: string, | ||
playerOptions?: ModulePlayerOptions, | ||
stories?: ModuleStoriesOptionsObj, | ||
} | ||
@@ -47,4 +65,4 @@ export interface ModuleComingOptions { | ||
description?: string, | ||
titleColor: string, | ||
descriptionColor:string, | ||
titleColor?: string, | ||
descriptionColor?:string, | ||
} | ||
@@ -51,0 +69,0 @@ |
@@ -0,1 +1,5 @@ | ||
import Promise from "promise-polyfill"; | ||
import {ModuleStoriesOptionsObj, ResponseModuleStory} from "@/Module/gobi-module.types"; | ||
import {StoryComingOptions} from "@/Story/story.types"; | ||
export function forEach<T>(list:ArrayLike<T>, callback:(listItem?:T, index?:number, list?:ArrayLike<T>) => void) { | ||
@@ -17,2 +21,45 @@ const max = list.length; | ||
export function getModule(moduleId:string):Promise<Array<ResponseModuleStory>> { | ||
return new Promise(function (resolve, reject) { | ||
const xhr = new XMLHttpRequest(); | ||
const url = 'http://gobi-projector.scrij.com/projector/player/storyModules/' + moduleId; | ||
xhr.open('GET', url, true); | ||
xhr.send(); | ||
xhr.onload = function () { | ||
if (this.status < 400) { | ||
resolve(JSON.parse(this.responseText)); | ||
} else { | ||
reject(Error('Module didn\'t load successfully; error code:' + xhr.statusText)); | ||
} | ||
}; | ||
xhr.onerror = function () { | ||
reject(Error('There was a network error.')); | ||
}; | ||
}) | ||
} | ||
export function mergeStoriesOptions(responseStories:StoryComingOptions[], | ||
comingStories:ModuleStoriesOptionsObj):StoryComingOptions[] { | ||
const mergedOptions: StoryComingOptions[] = []; | ||
for (const key in responseStories) { | ||
const responseStory = responseStories[key]; | ||
const comingOptions = comingStories[key]; | ||
mergedOptions.push(comingOptions ? | ||
Object.assign(responseStory, comingOptions) : | ||
responseStory); | ||
} | ||
return mergedOptions; | ||
} | ||
export function decorateResponseStories(responseStories:ResponseModuleStory[]):Array<StoryComingOptions> { | ||
return responseStories.map((responseStory): StoryComingOptions => { | ||
return { | ||
title: responseStory.title, | ||
avatarSrc: responseStory.thumbnail, | ||
description: responseStory.description, | ||
name: responseStory.story_id | ||
}; | ||
}) | ||
} | ||
export function addListener(object:Window | Document | HTMLElement, | ||
@@ -19,0 +66,0 @@ eventName:string, |
116188
36
1305
353