%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/bitrix/www/bitrix/js/ui/viewer/
Upload File :
Create Path :
Current File : /home/bitrix/www/bitrix/js/ui/viewer/ui.viewer.min.js

(function(){"use strict";BX.namespace("BX.UI.Viewer");BX.UI.Viewer.Controller=function(e){this.items=null;this.currentIndex=null;this.handlers={};this.setItems(e.items||[]);this.actionPanel=new BX.UI.ActionPanel({darkMode:true,autoHide:false,showTotalSelectedBlock:false,showResetAllBlock:false,alignItems:"center",renderTo:function(){return this.getPanelWrapper()}.bind(this)});this.init();this.zIndex=e.zIndex||999999;this.layout={container:null,content:null,inner:null,items:null,next:null,prev:null,close:null,error:null,loader:null,loaderContainer:null,panel:null}};BX.UI.Viewer.Controller.prototype={handleDocumentClick:function(e){var t=BX.getEventTarget(e);if(!t.dataset.hasOwnProperty("viewer")){return}var i=0;var n=BX.UI.Viewer.Instance;if(!t.dataset.viewerGroupBy){n.setItems([BX.UI.Viewer.buildItemByNode(t)])}else{var r=[].slice.call(t.ownerDocument.querySelectorAll("[data-viewer][data-viewer-group-by='"+t.dataset.viewerGroupBy+"']"));var o=r.map(function(e,n){if(e===t){i=n}return BX.UI.Viewer.buildItemByNode(e)});n.setItems(o)}n.open(i);e.preventDefault()},bindEvents:function(){this.handlers.keyPress=this.handleKeyPress.bind(this);this.handlers.touchStart=this.handleTouchStart.bind(this);this.handlers.touchEnd=this.handleTouchEnd.bind(this);this.handlers.resize=this.adjustViewerHeight.bind(this);BX.bind(document,"keydown",this.handlers.keyPress);BX.bind(window,"resize",this.handlers.resize);BX.bind(this.getItemListNode(),"touchstart",this.handlers.touchStart);BX.bind(this.getItemListNode(),"touchend",this.handlers.touchEnd);BX.bind(this.getNextButton(),"click",this.showNext.bind(this));BX.bind(this.getPrevButton(),"click",this.showPrev.bind(this));BX.bind(this.getCloseButton(),"click",this.close.bind(this));BX.addCustomEvent("SidePanel.Slider:onOpen",function(e){if(!this.originalZIndex){this.originalZIndex=this.getZindex()}this.setZindex(e.getSlider().getZindex()-1)}.bind(this));BX.addCustomEvent("SidePanel.Slider:onCloseComplete",function(e){var t=BX.SidePanel.Instance.getTopSlider();if(t){this.setZindex(t.getZindex()-1)}else{this.setZindex(this.originalZIndex);this.originalZIndex=null}}.bind(this))},unbindEvents:function(){BX.unbind(document,"keydown",this.handlers.keyPress);BX.unbind(window,"resize",this.handlers.resize);BX.unbind(this.getItemListNode(),"touchstart",this.handlers.touchStart);BX.unbind(this.getItemListNode(),"touchend",this.handlers.touchEnd)},init:function(){},getZindex:function(){return this.zIndex},setZindex:function(e){this.zIndex=e;this.getViewerContainer().style.zIndex=e},setItems:function(e){if(!BX.type.isArray(e)){throw new Error("BX.UI.Viewer.Controller.setItems: 'items' has to be Array.")}BX.onCustomEvent("BX.UI.Viewer.Controller:onSetItems",[this,e]);this.items=e;this.items.forEach(function(e){e.setController(this)},this)},appendItem:function(e){if(!(e instanceof BX.UI.Viewer.Item)){throw new Error("BX.UI.Viewer.Controller.appendItem: 'item' has to be instance of BX.UI.Viewer.Item.")}e.setController(this);this.items.push(e)},show:function(e,t){if(typeof e==="undefined"){e=0}BX.onCustomEvent("BX.UI.Viewer.Controller:onBeforeShow",[this,e]);var i=this.getItemByIndex(e);if(!i){return}var n=this.getCurrentItem();this.currentIndex=e;this.hideErrorBlock();if(n){this.hideCurrentItem()}this.actionPanel.removeItems();this.actionPanel.addItems(this.refineActions(this.getCurrentItem().getActions(),this.getCurrentItem()));this.showLoading();var r;if(t){r=i.reload()}else{r=i.load()}r.then(function(e){if(this.getCurrentItem()===e){this.processShowItem.call(this,e)}}.bind(this)).catch(function(e){this.processError.call(this,e,i)}.bind(this));this.updateControls();this.lockScroll();this.adjustViewerHeight()},reload:function(e){var t=this.getCurrentItem()===e;if(t){this.show(this.currentIndex,true)}},reloadCurrentItem:function(){return this.reload(this.getCurrentItem())},processShowItem:function(e){BX.cleanNode(this.layout.items);this.hideLoading();var t=BX.create("div",{props:{className:"ui-viewer-inner-content-wrapper"}});var i=document.createDocumentFragment();i.appendChild(e.render());var n=e.getTitle();if(n){i.appendChild(BX.create("div",{props:{className:"viewer-inner-caption"},text:n}))}t.appendChild(i);this.layout.items.appendChild(t);e.afterRender()},processError:function(e,t){this.hideCurrentItem();this.hideLoading();this.layout.container.appendChild(this.getErrorBlock())},hideErrorBlock:function(){if(this.layout.error){BX.remove(this.layout.error)}},getErrorBlock:function(e){e=e||{};var t=e.title||BX.message("JS_UI_VIEWER_DEFAULT_ERROR_TITLE");var i=e.description;this.layout.error=BX.create("div",{props:{className:"ui-viewer-error"},children:[BX.create("div",{props:{className:"ui-viewer-error-title"},text:t}),BX.create("div",{props:{className:"ui-viewer-error-text"},text:i})]});return this.layout.error},refineActions:function(actions,item){var defaultActions={download:{id:"download",type:"download",text:BX.message("JS_UI_VIEWER_ITEM_ACTION_DOWNLOAD"),href:item.src,buttonIconClass:"ui-btn-icon-download"},edit:{id:"edit",type:"edit",text:BX.message("JS_UI_VIEWER_ITEM_ACTION_EDIT"),buttonIconClass:"ui-btn-icon-edit"},share:{id:"share",type:"share",text:BX.message("JS_UI_VIEWER_ITEM_ACTION_SHARE"),buttonIconClass:"ui-btn-icon-share"},info:{id:"info",type:"info",text:"",buttonIconClass:"ui-btn-icon-info ui-action-panel-item-last"},delete:{id:"delete",type:"delete",text:BX.message("JS_UI_VIEWER_ITEM_ACTION_DELETE"),buttonIconClass:"ui-btn-icon-remove"}};return actions.map(function(action){if(defaultActions[action.type]){action=BX.mergeEx(defaultActions[action.type],action)}if(BX.type.isString(action.action)&&typeof eval(action.action)==="function"){var fn=eval(action.action);action.onclick=function(e,t){fn.call(this,item,t)}}return action},this)},getLoader:function(e){if(!this.layout.loader){this.layout.loader=BX.create("div",{props:{className:"ui-viewer-loader"},children:[this.layout.loaderContainer=BX.create("div",{props:{className:"ui-viewer-loader-container"}}),BX.create("div",{props:{className:"ui-viewer-loader-text"},text:""})]});var t=new BX.Loader({size:130});t.show(this.layout.loaderContainer)}return this.layout.loader},getPrevButton:function(){if(!this.layout.prev){this.layout.prev=BX.create("div",{props:{className:"ui-viewer-prev"}})}return this.layout.prev},getNextButton:function(){if(!this.layout.next){this.layout.next=BX.create("div",{props:{className:"ui-viewer-next"}})}return this.layout.next},getCloseButton:function(){if(!this.layout.close){this.layout.close=BX.create("div",{props:{className:"ui-viewer-close"},html:'<div class="ui-viewer-close-icon"></div>'})}return this.layout.close},isOpen:function(){return this._isOpen},open:function(e){document.body.appendChild(this.getViewerContainer());this.show(e);this.showPanel();this.bindEvents();this._isOpen=true},getPanelWrapper:function(){if(!this.layout.panel){this.layout.panel=BX.create("div",{props:{className:"ui-viewer-panel"}})}return this.layout.panel},showPanel:function(){this.actionPanel.layout.container.style.zIndex="9999999";this.actionPanel.layout.container.style.background="none";this.actionPanel.layout.container.style.maxWidth=this.layout.inner.offsetWidth+"px";this.actionPanel.draw();this.actionPanel.showPanel()},hideCurrentItem:function(){BX.cleanNode(this.layout.items)},updateControls:function(){if(this.currentIndex+1>=this.items.length){BX.addClass(this.getNextButton(),"ui-viewer-navigation-hide")}else{BX.removeClass(this.getNextButton(),"ui-viewer-navigation-hide")}if(this.currentIndex===0){BX.addClass(this.getPrevButton(),"ui-viewer-navigation-hide")}else{BX.removeClass(this.getPrevButton(),"ui-viewer-navigation-hide")}},getCurrentItem:function(){return this.getItemByIndex(this.currentIndex)},getItemByIndex:function(e){e=parseInt(e,10);BX.onCustomEvent("BX.UI.Viewer.Controller:onGetItemByIndex",[this,e]);if(e<0||e-1>this.items.length){return null}return this.items[e]},showNext:function(){this.show(this.currentIndex+1)},showPrev:function(){this.show(this.currentIndex-1)},close:function(){this._isOpen=false;BX.onCustomEvent("BX.UI.Viewer.Controller:onClose",[this]);this.layout.container.parentNode.removeChild(this.layout.container);this.actionPanel.hidePanel();this.unLockScroll();this.unbindEvents()},showLoading:function(){this.layout.inner.appendChild(this.getLoader())},hideLoading:function(){BX.remove(this.layout.loader)},lockScroll:function(){document.body.style.overflow="hidden"},unLockScroll:function(){document.body.style.overflow=null},adjustViewerHeight:function(){if(!this.layout.container)return;this.layout.container.style.height=document.documentElement.clientHeight+"px"},getViewerContainer:function(){if(!this.layout.container){this.layout.container=BX.create("div",{props:{className:"ui-viewer"},style:{zIndex:this.zIndex,height:window.clientHeight+"px"},children:[this.layout.inner=BX.create("div",{props:{className:"ui-viewer-inner"},children:[this.getItemListNode()]}),this.getCloseButton(),this.getPrevButton(),this.getNextButton(),this.getPanelWrapper()]})}return this.layout.container},getItemListNode:function(){if(!this.layout.items){this.layout.items=BX.create("div",{props:{className:"ui-viewer-inner-content"}})}return this.layout.items},handleTouchStart:function(e){var t=e.changedTouches[0];this.swipeDirection=null;this.startX=t.pageX;this.startY=t.pageY;this.startTime=(new Date).getTime();e.preventDefault()},handleTouchEnd:function(e){var t=e.changedTouches[0];var i=300;var n=80;var r=100;var o=t.pageX-this.startX;var s=t.pageY-this.startY;var a=(new Date).getTime()-this.startTime;if(a<=i){if(Math.abs(o)>=n&&Math.abs(s)<=r){this.swipeDirection=o<0?"left":"right"}else if(Math.abs(s)>=n&&Math.abs(o)<=r){this.swipeDirection=s<0?"up":"down"}}switch(this.swipeDirection){case"up":case"left":this.showPrev();break;case"down":case"right":this.showNext();break}e.preventDefault()},handleKeyPress:function(e){switch(e.code){case"Space":case"ArrowRight":case"PageDown":case"ArrowDown":this.showNext();e.preventDefault();break;case"ArrowLeft":case"PageUp":case"ArrowUp":this.showPrev();e.preventDefault();break;case"Escape":this.close();e.preventDefault();break}}};BX.UI.Viewer.buildItemByTypeAndNode=function(e,t){var i=new e;i.setPropertiesByNode(t);i.bindSourceNode(t);return i};BX.UI.Viewer.buildItemByNode=function(e){if(!BX.type.isDomNode(e)){throw new Error("BX.UI.Viewer.buildItemByNode: 'node' has to be DomNode.")}var t=e.dataset.viewerType;if(!t){if(e.tagName.toLowerCase()==="img"){t="image"}}switch(t){case"image":return BX.UI.Viewer.buildItemByTypeAndNode(BX.UI.Viewer.Image,e);case"plainText":return BX.UI.Viewer.buildItemByTypeAndNode(BX.UI.Viewer.PlainText,e);case"unknown":return BX.UI.Viewer.buildItemByTypeAndNode(BX.UI.Viewer.Unknown,e);case"video":return BX.UI.Viewer.buildItemByTypeAndNode(BX.UI.Viewer.Video,e);case"document":return BX.UI.Viewer.buildItemByTypeAndNode(BX.UI.Viewer.Document,e)}};BX.UI.Viewer.bind=function(e,t){if(!BX.type.isDomNode(e)){throw new Error("BX.UI.Viewer.bind: 'container' has to be DomNode.")}if(!BX.type.isPlainObject(t)&&!BX.type.isFunction(t)){t=function(e){return BX.type.isElementNode(e)&&e.dataset.hasOwnProperty("viewer")}}BX.bindDelegate(e,"click",t,function(i){var n=new BX.UI.Viewer.Controller({});var r=BX.findChildren(e,t,true);var o=0;var s=BX.getEventTarget(i);var a=r.map(function(e,t){if(e===s){o=t}return BX.UI.Viewer.buildItemByNode(e)});n.setItems(a);n.open(o);i.preventDefault()})};var instance=null;Object.defineProperty(BX.UI.Viewer,"Instance",{enumerable:false,get:function(){if(window.top!==window&&BX.getClass("window.top.BX.UI.Viewer.Instance")){return window.top.BX.UI.Viewer.Instance}if(instance===null){instance=new BX.UI.Viewer.Controller({})}return instance}});window.document.addEventListener("click",function(e){if(window.top!==window&&!BX.getClass("window.top.BX.UI.Viewer.Instance")){window.top.BX.loadExt("ui.viewer").then(function(){top.BX.UI.Viewer.Instance.handleDocumentClick(e)})}else{top.BX.UI.Viewer.Instance.handleDocumentClick(e)}},true);if(window.top!==window&&!BX.getClass("window.top.BX.UI.Viewer.Instance")){window.top.BX.loadExt("ui.viewer")}})();

Zerion Mini Shell 1.0