-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugins.js
More file actions
1 lines (1 loc) · 10.2 KB
/
plugins.js
File metadata and controls
1 lines (1 loc) · 10.2 KB
1
(function(a,t){function v(t){a.Asc.plugin.ie_channel?a.Asc.plugin.ie_channel.postMessage(t):a.parent.postMessage(t,"*")}function r(n,e){if(!n||"object"!=typeof n&&"array"!=typeof n)return n;for(var o in e=e===t?{}:e,n)n.hasOwnProperty(o)&&(e[o]=n[o]&&"object"==typeof n[o]?r(n[o]):n[o]);return e}function p(n){var e=a.location.search,o=n+"=";return 0<=(n=e.indexOf(o))?(n+=o.length,0>(o=e.indexOf("&",n))&&(o=e.length),e.substring(n,o)):t}function m(){var n=p("windowID");return n&&(a.Asc.plugin.windowID=n,a.Asc.plugin.guid||(a.Asc.plugin.guid=decodeURIComponent(p("guid")))),t!==n}function q(c){if(a.Asc&&a.Asc.plugin)if(a.plugin_onMessage)a.Asc.supportOrigins[c.origin]&&a.plugin_onMessage(c);else if(a.Asc.plugin._initInternal&&"string"==typeof c.data){var d={};try{d=JSON.parse(c.data)}catch(t){d={}}"plugin_init"==d.type&&(a.Asc.supportOrigins[c.origin]=!0,a.Asc.plugin.ie_channel_check(c),eval(d.data))}}a.Asc=a.Asc||{},a.Asc.plugin={},a.Asc.plugin.ie_channel=null,a.Asc.plugin.ie_channel_check=function(t){var n=navigator.userAgent.toLowerCase();(-1<n.indexOf("msie")||-1<n.indexOf("trident"))&&t.ports&&t.ports[0]&&(this.ie_channel=t.ports[0])},a.Asc.plugin.tr_init=!1,a.Asc.plugin.tr=function(t){return t},a.Asc.scope={},a.Asc.scope.prototype={clear:function(){for(var t in a.Asc.scope)delete a.Asc.scope[t]}},a.onload=function(){if(a.Asc&&a.Asc.plugin){var t=new XMLHttpRequest;t.open("get","./config.json",!0),t.responseType="json",t.onload=function(){if(a.Asc&&a.Asc.plugin){if(404===t.status)return t.onerror();if(200==t.status||0==t.status&&4==t.readyState){var n=t.response;"string"==typeof n&&(n=JSON.parse(n)),r(n,a.Asc.plugin),n={type:"initialize",guid:a.Asc.plugin.guid},m()&&(n.windowID=a.Asc.plugin.windowID);var e=document.body;e&&!0!==a.Asc.plugin.enableDrops&&(e.ondrop=function(t){return t&&t.preventDefault&&t.preventDefault(),!1},e.ondragenter=function(t){return t&&t.preventDefault&&t.preventDefault(),!1},e.ondragover=function(t){return t&&t.preventDefault&&t.preventDefault(),t&&t.dataTransfer&&(t.dataTransfer.dropEffect="none"),!1}),a.Asc.plugin._initInternal=!0,a.parent.postMessage(JSON.stringify(n),"*")}}},t.onerror=function(){if(a.Asc&&a.Asc.plugin&&m()){var t={type:"initialize",guid:a.Asc.plugin.guid};t.windowID=a.Asc.plugin.windowID,a.Asc.plugin._initInternal=!0,a.parent.postMessage(JSON.stringify(t),"*")}},t.send()}},a.Asc.supportOrigins={},a.Asc.supportOrigins[a.origin]=!0,a.addEventListener?a.addEventListener("message",q,!1):a.attachEvent("onmessage",q),a.Asc.plugin._attachCustomMenuClickEvent=function(t,n,e){this[t]||(this[t]={}),this[t][n]=e},a.Asc.plugin._onCustomMenuClick=function(n,e){var o=t,i=e.indexOf("_oo_sep_");-1!==i&&(o=e.substring(i+8),e=e.substring(0,i)),this[n]&&this[n][e]&&this[n][e].call(this,o)},a.Asc.plugin.attachContextMenuClickEvent=function(t,n){this._attachCustomMenuClickEvent("contextMenuEvents",t,n)},a.Asc.plugin.event_onContextMenuClick=function(t){this._onCustomMenuClick("contextMenuEvents",t)},a.Asc.plugin.attachToolbarMenuClickEvent=function(t,n){this._attachCustomMenuClickEvent("toolbarMenuEvents",t,n)},a.Asc.plugin.event_onToolbarMenuClick=function(t){this._onCustomMenuClick("toolbarMenuEvents",t)},a.Asc.plugin.attachEvent=function(t,n){var e=a.Asc.plugin;e._events||(e._events={}),e._events[t]=n},a.Asc.plugin.detachEvent=function(t){var n=a.Asc.plugin;n._events&&n._events[t]&&delete n._events[t]},a.Asc.plugin.onEvent=function(t,n){var e=a.Asc.plugin;e._events&&e._events[t]&&e._events[t].call(e,n)},a.Asc.plugin.attachEditorEvent=function(t,n){a.Asc.plugin["event_"+t]=n.bind(a.Asc.plugin),v(JSON.stringify({guid:a.Asc.plugin.guid,type:"attachEvent",name:t}))},a.Asc.plugin.detachEditorEvent=function(t){a.Asc.plugin["event_"+t]&&delete a.Asc.plugin["event_"+t],v(JSON.stringify({guid:a.Asc.plugin.guid,type:"detachEvent",name:t}))},a.onunload=function(){a.addEventListener?a.removeEventListener("message",q,!1):a.detachEvent("onmessage",q)}})(window,void 0),function(t,n){function e(n){return t.Asc.plugin.tr(n)}function o(n,e){this.itemType=l.None,this.editors=["word","cell","slide"],this.id=void 0===e?function(){function n(){return(65536+o[i++]).toString(16).substring(1)}if(!t.crypto||!t.crypto.getRandomValues){function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()}var o=new Uint16Array(8);t.crypto.getRandomValues(o);var i=0;return n()+n()+"-"+n()+"-"+n()+"-"+n()+"-"+n()+n()+n()}():e,this.icons=null,this.text="",this.hint=null,this.data="",this.separator=!1,this.lockInViewMode=!0,this.removed=this.disabled=this.enableToggle=!1,this.parent=n||null,this.childs=null,this.parent&&(this.parent.childs||(this.parent.childs=[]),this.parent.childs.push(this))}function i(t,n){o.call(this,t,n),this.itemType=l.ContextMenu,this.showOnOptionsType=[],a.Buttons.ButtonsContextMenu.push(this)}function s(t,n){o.call(this,t,n),this.itemType=l.Toolbar,this.type=r.BigButton,this.tab="",a.Buttons.ButtonsToolbar.push(this)}function u(t,n){o.call(this,t,n),this.itemType=l.ContentControl,this.checker=null,0===a.Buttons.ButtonsContentControl.length&&a.Buttons.registerContentControl(),a.Buttons.ButtonsContentControl.push(this)}t.Asc=t.Asc||{};var a=t.Asc;a.Buttons={},a.Buttons.ButtonsContextMenu=[],a.Buttons.ButtonsToolbar=[],a.Buttons.ButtonsContentControl=[],a.Buttons.registerContextMenu=function(){t.Asc.plugin.attachEvent("onContextMenuShow",function(n){if(n){var e={guid:t.Asc.plugin.guid};for(let t=0,o=a.Buttons.ButtonsContextMenu.length;t<o;t++){let o=a.Buttons.ButtonsContextMenu[t];null===o.parent&&o.onContextMenuShow(n,e)}e.items&&t.Asc.plugin.executeMethod("AddContextMenuItem",[e])}})},a.Buttons.registerToolbarMenu=function(){let n={guid:t.Asc.plugin.guid,tabs:[]};for(let e=0,o=a.Buttons.ButtonsToolbar.length;e<o;e++){let o=a.Buttons.ButtonsToolbar[e];if(null===o.parent&&o.toToolbar(n),o.menu)for(let n in o.menu){let e=o.menu.hasOwnProperty(n)?o.menu[n]:null;e&&e.onclick&&t.Asc.plugin.attachToolbarMenuClickEvent(e.id,e.onclick)}}0<n.tabs.length&&t.Asc.plugin.executeMethod("AddToolbarMenuItem",[n])},a.Buttons.updateToolbarMenu=function(n,e,o){(n=new a.ButtonToolbar(null,n)).text=e,e={guid:t.Asc.plugin.guid,tabs:[]},n.childs=o;for(let t=0,e=o.length;t<e;t++)o[t].parent=n;n.toToolbar(e),0<e.tabs.length&&t.Asc.plugin.executeMethod("UpdateToolbarMenuItem",[e])},a.Buttons.registerContentControl=function(){t.Asc.plugin.attachEditorEvent("onShowContentControlTrack",function(n){let e={guid:t.Asc.plugin.guid,items:{}},o=[];for(let t=0,i=a.Buttons.ButtonsContentControl.length;t<i;++t)o.push(a.Buttons.ButtonsContentControl[t].onShowTrack(n,e.items));Promise.all(o).then(function(){for(let n in e.items){t.Asc.plugin.executeMethod("AddContentControlButtons",[e]);break}})}),t.Asc.plugin._attachContentControlButtonClickEvent=function(t,n){this.ContentControlButtonEvents||(this.ContentControlButtonEvents={}),this.ContentControlButtonEvents[t]=n};let n=t.Asc.plugin;t.Asc.plugin.attachEditorEvent("onContentControlButtonClick",function(t){let e=t&&t.buttonId?t.buttonId:null;t=t&&t.contentControlId?t.contentControlId:null,e&&t&&n.ContentControlButtonEvents&&n.ContentControlButtonEvents[e]&&n.ContentControlButtonEvents[e].call(n,t)})};var r={Button:"button",BigButton:"big-button"},l={None:0,ContextMenu:1,Toolbar:2,ContentControl:3};o.prototype.toItem=function(){let t={id:this.id,text:e(this.text)};return null!==this.hint&&(t.hint=e(""===this.hint?this.hint:this.text)),this.separator&&(t.separator=!0),this.data&&(t.data=this.data),this.lockInViewMode&&(t.lockInViewMode=!0),this.enableToggle&&(t.enableToggle=!0),t.disabled=!!this.disabled,this.removed&&(t.removed=!0),this.icons&&(t.icons=this.icons),this.itemType===l.Toolbar&&(t.type=this.type),this.menu&&(t.items=this.menu.map(function(t){return t.text=e(t.text),t})),this.split&&(t.split=!0),t},o.prototype.attachOnClick=function(t){},o.prototype.onClick=function(){console.log("BUTTON: "+this.text)},i.prototype=Object.create(o.prototype),i.prototype.constructor=i,i.prototype.copy=function(){let t=new i(this.parent,this.id);return t.editors=this.editors,t.separator=this.separator,t.lockInViewMode=this.lockInViewMode,t.enableToggle=this.enableToggle,t.disabled=this.disabled,t.showOnOptionsType=this.showOnOptionsType.slice(),t},i.prototype.addCheckers=function(){let t=arguments.length;this.showOnOptionsType=Array(t);for(let n=0;n<t;n++)this.showOnOptionsType[n]=arguments[n]},i.prototype.attachOnClick=function(n){t.Asc.plugin.attachContextMenuClickEvent(this.id,n)},i.prototype.onContextMenuShowAnalyze=function(t,n){return!1},i.prototype.onContextMenuShowExtendItem=function(t,n){},i.prototype.onContextMenuShow=function(t,n){if(!this.onContextMenuShowAnalyze(t,n)){var e=!1;for(let t=0,n=this.editors.length;t<n;t++)if(a.plugin.info.editorType===this.editors[t]){e=!0;break}if(e)for(let o=0,i=this.showOnOptionsType.length;o<i;o++)if(t.type===this.showOnOptionsType[o]||"All"===this.showOnOptionsType[o]){if(n.items||(n.items=[]),e=this.toItem(),this.onContextMenuShowExtendItem(t,e),this.childs)for(let n=0,o=this.childs.length;n<o;n++)this.childs[n].onContextMenuShow(t,e);n.items.push(e);break}}},s.prototype=Object.create(o.prototype),s.prototype.constructor=s,s.prototype.attachOnClick=function(n){t.Asc.plugin.attachToolbarMenuClickEvent(this.id,n)},s.prototype.toItem=function(t){return(t=o.prototype.toItem.call(this)).type=this.type,t},s.prototype.toToolbar=function(t){if(null===this.parent){var n={id:this.id,text:e(this.text),items:[]};null!==this.hint&&(n.hint=e(""===this.hint?this.hint:this.text)),t.tabs.push(n)}else n=this.toItem(),t.items||(t.items=[]),t.items.push(n);if(this.childs)for(let t=0,e=this.childs.length;t<e;t++)this.childs[t].toToolbar(n)},u.prototype=Object.create(o.prototype),u.prototype.constructor=u,u.prototype.attachOnClick=function(n){t.Asc.plugin._attachContentControlButtonClickEvent(this.id,n)},u.prototype.addChecker=function(t){t&&"function"==typeof t&&(this.checker=t)},u.prototype.onShowTrack=function(t,n){let e=this.checker,o=[],i=this.toItem();for(let s=0,u=t.length;s<u;++s){let u=t[s];o.push(new Promise(function(t){if(e){let n=e(u);n instanceof Promise?n.then(function(n){t(n)}):t(!!n)}else t(!0)}).then(function(t){t&&(n[u]||(n[u]=[]),n[u].push(i))}))}return Promise.all(o)},a.ToolbarButtonType=r,a.ButtonContextMenu=i,a.ButtonToolbar=s,a.ButtonContentControl=u}(window);