thedesk/app/js/platform/tj-deck.js

1 line
19 KiB
JavaScript
Raw Permalink Normal View History

2018-09-11 04:59:44 +10:00
"use strict";var _createClass=function(){function a(e,f){for(var h,g=0;g<f.length;g++)h=f[g],h.enumerable=h.enumerable||!1,h.configurable=!0,"value"in h&&(h.writable=!0),Object.defineProperty(e,h.key,h)}return function(e,f,g){return f&&a(e.prototype,f),g&&a(e,g),e}}();function _classCallCheck(a,e){if(!(a instanceof e))throw new TypeError("Cannot call a class as a function")}var TJScrollTask=function(){function a(e,f,g){_classCallCheck(this,a),this.tjDeck=e,this.$t=e.$wrap,this.x=f,this.d=g,this.sl=e.wrapL,this.sTime=Date.now(),this.ended=!1,this._bindAnim=this._anim.bind(this);var h=e.getClms();0>f||f>h[0].offsetWidth*(h.length-1)?this.ended=!0:requestAnimationFrame(this._bindAnim)}return _createClass(a,[{key:"stop",value:function stop(){this.ended||(this.ended=!0,cancelAnimationFrame(this._bindAnim))}},{key:"_anim",value:function _anim(){if(!this.ended){var e=(Date.now()-this.sTime)/this.d,f=this.sl,g=this.x-this.sl;1<e&&!this.ended&&(this.stop(),e=1),this.tjDeck.scrollWrap(this._easeOut(e,f,g,1)),1>e&&requestAnimationFrame(this._bindAnim)}}},{key:"_easeOut",value:function _easeOut(e,f,g,h){return e/=h,--e,g*(e*e*e+1)+f}}]),a}(),TJDeck=function(){function a(){_classCallCheck(this,a),this.version="0.0.9",this.$wrap=document.querySelector(".js-app-columns"),this.wrapL=0,this.scrollTask=null,this.options=this.getOptionObj(),this.setOptionFromObj(this.options),this.$options=this.createOptionPanel(),document.body.appendChild(this.$options),this.updateBlur(),this.updateLight()}return _createClass(a,[{key:"getOption",value:function getOption(e,f){var g=localStorage.getItem("tj_deck_"+e);return g?"true"==g:f}},{key:"getOptionObj",value:function getOptionObj(){return{light:this.getOption("light",!0),light_clm:this.getOption("light_clm",!1),blur:this.getOption("blur",!1)}}},{key:"setOption",value:function setOption(e,f){localStorage.setItem("tj_deck_"+e,f)}},{key:"setOptionFromObj",value:function setOptionFromObj(e){for(var f=Object.keys(e),g=0;g<f.length;g++)this.setOption(f[g],e[f[g]])}},{key:"getClms",value:function getClms(){return this.$wrap.querySelectorAll("section.column")}},{key:"back",value:function back(){if("none"!=this.$options.style.display)return this.updateOption(),void this.hideOptionPanel();var e=document.querySelector(".mdl-dismiss");if(e)return void e.click();if(this.isShownDrawer())return void this.hideDrawer();var f=this.getClosestColumn(this.wrapL),g=f.querySelector(".js-column-back");if(g)return void g.click()}},{key:"isShownItem",value:function isShownItem(){return!!document.querySelector(".mdl-dismiss")||this.isShownDrawer()}},{key:"isShownDrawer",value:function isShownDrawer(){return!!document.querySelector(".hide-detail-view-inline")}},{key:"hideDrawer",value:function hideDrawer(){var e=document.querySelector(".js-hide-drawer");e&&e.click()}},{key:"showDrawer",value:function showDrawer(){var e=document.querySelector(".js-show-drawer");e&&e.click()}},{key:"manageBack",value:function manageBack(){history.pushState(null,null,""),window.addEventListener("popstate",function(){this.back(),history.pushState(null,null,"")}.bind(this))}},{key:"observeModals",value:function observeModals(){for(var e=new MutationObserver(function(j){for(var k,l,m=0;m<j.length;m++){k=j[m];for(var o=0;o<k.addedNodes.length;o++)l=k.addedNodes[m],this.stopAnkerFromModal(l)}}.bind(this)),f={attributes:!1,characterData:!0,childList:!0},g=document.querySelectorAll(".js-modals-container, .js-modal"),h=0;h<g.length;h++)e.observe(g[h],f)}},{key:"stopAnkerFromModal",value:function stopAnkerFromModal(e){for(var g,f=e.querySelectorAll("a"),h=function(k){return k.preventDefault(),k.target.removeEventListener("click",h),!1},j=0;j<f.length;j++)g=f[j],g.href&&g.href.match(/#$/)&&g.addEventListener("click",h)}},{key:"observeClms",value:function observeClms(){var e=new MutationObserver(function(g){for(var h,j,k=0;k<g.length;k++)j=g[k],j.addedNodes[0]&&(h=j.addedNodes[0]),j.removedNodes[0]&&(j.nextSibling instanceof Element?h=j.nextSibling:j.previousSibling instanceof Element?h=j.previousSibling:h=this.getClms()[0]);h&&h instanceof Element&&this.sc