%PDF- %PDF-
Direktori : /home/bitrix/www/bitrix/js/ui/viewer/ |
Current File : /home/bitrix/www/bitrix/js/ui/viewer/ui.viewer.item.min.js |
(function(){"use strict";BX.namespace("BX.UI.Viewer");BX.UI.Viewer.Item=function(t){t=t||{};this.controller=null;this.title=t.title;this.src=t.src;this.actions=t.actions;this.contentType=t.contentType;this.isLoaded=false;this.isLoading=false;this.sourceNode=null;this.layout={container:null};this.init()};BX.UI.Viewer.Item.prototype={setController:function(t){if(!(t instanceof BX.UI.Viewer.Controller)){throw new Error("BX.UI.Viewer.Item: 'controller' has to be instance of BX.UI.Viewer.Controller.")}this.controller=t},setPropertiesByNode:function(t){this.title=t.dataset.title||t.title||t.alt;this.src=t.dataset.src;this.actions=t.dataset.actions?JSON.parse(t.dataset.actions):undefined},bindSourceNode:function(t){this.sourceNode=t},init:function(){},reload:function(){this.isLoaded=false;this.isLoading=false;return this.load()},load:function(){var t=new BX.Promise;if(this.isLoaded){t.fulfill(this);return t}if(this.isLoading){return this._loadPromise}this.isLoading=true;this._loadPromise=this.loadData().then(function(t){this.isLoaded=true;this.isLoading=false;return t}.bind(this)).catch(function(t){this.isLoaded=false;this.isLoading=false;var e=new BX.Promise;e.reject(t);return e}.bind(this));return this._loadPromise},getTitle:function(){return this.title},getActions:function(){if(typeof this.actions==="undefined"){return[{type:"download"}]}return this.actions},loadData:function(){var t=new BX.Promise;t.setAutoResolve(true);t.fulfill(this);return t},render:function(){},afterRender:function(){}};BX.UI.Viewer.Image=function(t){t=t||{};BX.UI.Viewer.Item.apply(this,arguments);this.resizedSrc=t.resizedSrc;this.width=t.width;this.height=t.height;this.imageNode=null;this.layout={container:null}};BX.UI.Viewer.Image.prototype={__proto__:BX.UI.Viewer.Item.prototype,constructor:BX.UI.Viewer.Item,setPropertiesByNode:function(t){BX.UI.Viewer.Item.prototype.setPropertiesByNode.apply(this,arguments);this.resizedSrc=t.src;this.src=t.dataset.src||t.src;this.width=t.dataset.width;this.height=t.dataset.height},loadData:function(){var t=new BX.Promise;if(!this.resizedSrc){var e=new XMLHttpRequest;e.responseType="blob";e.onreadystatechange=function(){if(e.readyState!==XMLHttpRequest.DONE){return}if((e.status===200||e.status===0)&&e.response){this.resizedSrc=URL.createObjectURL(e.response);this.imageNode=new Image;this.imageNode.src=this.resizedSrc;t.fulfill(this)}else{t.reject({item:this,type:"error"})}}.bind(this);e.open("GET",BX.util.add_url_param(this.src,{ts:"bxviewer"}),true);e.setRequestHeader("BX-Viewer-image","x");e.send()}else{this.imageNode=new Image;this.imageNode.onload=function(){t.fulfill(this)}.bind(this);this.imageNode.onerror=this.imageNode.onabort=function(e){t.reject({item:this,type:"error"})}.bind(this);this.imageNode.src=this.resizedSrc}return t},render:function(){var t=document.createDocumentFragment();t.appendChild(this.imageNode);if(this.title){t.appendChild(BX.create("div",{props:{className:"viewer-inner-fullsize"},children:[BX.create("a",{props:{href:BX.util.add_url_param(this.src,{ts:"bxviewer",ibxShowImage:1}),target:"_blank"},text:BX.message("JS_UI_VIEWER_IMAGE_VIEW_FULL_SIZE")})]}))}this.imageNode.alt=this.title;return t}};BX.UI.Viewer.PlainText=function(t){t=t||{};BX.UI.Viewer.Item.apply(this,arguments);this.content=t.content};BX.UI.Viewer.PlainText.prototype={__proto__:BX.UI.Viewer.Item.prototype,constructor:BX.UI.Viewer.Item,setPropertiesByNode:function(t){BX.UI.Viewer.Item.prototype.setPropertiesByNode.apply(this,arguments);this.content=t.dataset.content},render:function(){var t=BX.create("span",{text:this.content});t.style.fontSize="18px";t.style.color="white";return t}};BX.UI.Viewer.Unknown=function(t){t=t||{};BX.UI.Viewer.Item.apply(this,arguments)};BX.UI.Viewer.Unknown.prototype={__proto__:BX.UI.Viewer.PlainText.prototype,constructor:BX.UI.Viewer.PlainText,setPropertiesByNode:function(t){BX.UI.Viewer.Item.prototype.setPropertiesByNode.apply(this,arguments);this.content="Unknown type"}};BX.UI.Viewer.Video=function(t){t=t||{};BX.UI.Viewer.Item.apply(this,arguments);this.player=null;if(this.src){this.playerId="playerId_"+this.hashCode(this.src)+Math.floor(Math.random()*Math.floor(1e4))}this.sources=[];this.transFormationPromise=null};BX.UI.Viewer.Video.prototype={__proto__:BX.UI.Viewer.Item.prototype,constructor:BX.UI.Viewer.Item,setPropertiesByNode:function(t){BX.UI.Viewer.Item.prototype.setPropertiesByNode.apply(this,arguments);this.playerId="playerId_"+this.hashCode(this.src)+Math.floor(Math.random()*Math.floor(1e4))},hashCode:function(t){var e=0,i=t.length,r=0;if(i>0){while(r<i)e=(e<<5)-e+t.charCodeAt(r++)|0}return e},init:function(){BX.addCustomEvent("onPullEvent",function(t,e,i){if(t==="main"&&e==="transformationComplete"){if(this.transFormationPromise){this.loadData().then(function(){this.transFormationPromise.fulfill(this)}.bind(this))}}}.bind(this));BX.addCustomEvent("PlayerManager.Player:onAfterInit",function(t){if(t.id!==this.playerId){return}if(t.vjsPlayer.error()){console.log("forceTransformation");this.forceTransformation=true;this.controller.reload(this)}}.bind(this))},loadData:function(){var t=new BX.Promise;var e=[{name:"BX-Viewer-src",value:this.src}];e.push({name:this.forceTransformation?"BX-Viewer-force-transformation":"BX-Viewer",value:"video"});var i=BX.ajax.promise({url:BX.util.add_url_param(this.src,{ts:"bxviewer"}),method:"GET",dataType:"json",headers:e});i.then(function(e){if(!e||!e.data){t.reject({item:this,type:"error"});return}if(e.data.pullTag){BX.PULL.extendWatch(e.data.pullTag);this.transFormationPromise=t}else{if(e.data.data){this.width=e.data.data.width;this.height=e.data.data.height;this.sources=e.data.data.sources}if(e.data.html){var i=BX.processHTML(e.data.html);BX.load(i.STYLE,function(){BX.ajax.processScripts(i.SCRIPT,undefined,function(){t.fulfill(this)}.bind(this))}.bind(this))}}}.bind(this));return t},render:function(){this.player=new BX.Fileman.Player(this.playerId,{width:this.width,height:this.height,sources:this.sources});return this.player.createElement()},afterRender:function(){this.player.init()}};BX.UI.Viewer.Document=function(t){BX.UI.Viewer.Item.apply(this,arguments);this.contentNode=null;this.previewHtml=null;this.previewScriptToProcess=null;this.transFormationPromise=null};BX.UI.Viewer.Document.prototype={__proto__:BX.UI.Viewer.Item.prototype,constructor:BX.UI.Viewer.Item,setPropertiesByNode:function(t){BX.UI.Viewer.Item.prototype.setPropertiesByNode.apply(this,arguments)},init:function(){BX.addCustomEvent("onPullEvent",function(t,e,i){if(t==="main"&&e==="transformationComplete"){if(this.transFormationPromise){this.loadData().then(function(){this.transFormationPromise.fulfill(this)}.bind(this))}}}.bind(this))},loadData:function(){var t=new BX.Promise;if(this.previewHtml){this.processPreviewHtml(this.previewHtml);t.fulfill(this);return t}var e=BX.ajax.promise({url:BX.util.add_url_param(this.src,{ts:"bxviewer"}),method:"GET",dataType:"json",headers:[{name:"BX-Viewer-src",value:this.src},{name:"BX-Viewer",value:"document"}]});e.then(function(e){if(!e||!e.data){t.reject({item:this,type:"error"});return}if(e.data.pullTag){BX.PULL.extendWatch(e.data.pullTag);this.transFormationPromise=t}if(e.data.html){this.previewHtml=e.data.html;this.processPreviewHtml(e.data.html);t.fulfill(this)}}.bind(this));return t},processPreviewHtml:function(t){var e=BX.processHTML(t);if(!this.contentNode){this.contentNode=BX.create("div",{html:e.HTML})}if(!!e.SCRIPT){this.previewScriptToProcess=e.SCRIPT}},render:function(){return this.contentNode},afterRender:function(){if(this.previewScriptToProcess){BX.ajax.processScripts(this.previewScriptToProcess)}}}})();