mirror of
https://github.com/ONLYOFFICE/onlyoffice.github.io.git
synced 2026-02-10 18:05:06 +08:00
40 lines
11 KiB
JavaScript
40 lines
11 KiB
JavaScript
/**
|
|
*
|
|
* (c) Copyright Ascensio System SIA 2021
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
*/
|
|
|
|
(function(a,u){function w(c){a.Asc.plugin.ie_channel?a.Asc.plugin.ie_channel.postMessage(c):a.parent.postMessage(c,"*")}function r(c,d){if(!c||"object"!=typeof c&&"array"!=typeof c)return c;d=d===u?{}:d;for(var h in c)c.hasOwnProperty(h)&&(d[h]=c[h]&&"object"===typeof c[h]?r(c[h]):c[h]);return d}function p(c){var d=a.location.search,h=c+"=";c=d.indexOf(h);return 0<=c?(c+=h.length,h=d.indexOf("&",c),0>h&&(h=d.length),d.substring(c,h)):u}function n(){var c=p("windowID");c&&(a.Asc.plugin.windowID=c,
|
|
a.Asc.plugin.guid||(a.Asc.plugin.guid=decodeURIComponent(p("guid"))));return u!==c?!0:!1}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(h){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(c){var d=navigator.userAgent.toLowerCase();(-1<d.indexOf("msie")||-1<d.indexOf("trident"))&&c.ports&&c.ports[0]&&(this.ie_channel=c.ports[0])};a.Asc.plugin.tr_init=!1;a.Asc.plugin.tr=function(c){return c};a.Asc.scope={};a.Asc.scope.prototype={clear:function(){for(var c in a.Asc.scope)delete a.Asc.scope[c]}};a.onload=function(){if(a.Asc&&a.Asc.plugin){var c=new XMLHttpRequest;c.open("get","./config.json",!0);c.responseType="json";c.onload=function(){if(a.Asc&&a.Asc.plugin){if(404===c.status)return c.onerror();
|
|
if(200==c.status||0==c.status&&4==c.readyState){var d=c.response;"string"==typeof d&&(d=JSON.parse(d));r(d,a.Asc.plugin);d={type:"initialize",guid:a.Asc.plugin.guid};n()&&(d.windowID=a.Asc.plugin.windowID);var h=document.body;h&&!0!==a.Asc.plugin.enableDrops&&(h.ondrop=function(k){k&&k.preventDefault&&k.preventDefault();return!1},h.ondragenter=function(k){k&&k.preventDefault&&k.preventDefault();return!1},h.ondragover=function(k){k&&k.preventDefault&&k.preventDefault();k&&k.dataTransfer&&(k.dataTransfer.dropEffect=
|
|
"none");return!1});a.Asc.plugin._initInternal=!0;a.parent.postMessage(JSON.stringify(d),"*")}}};c.onerror=function(){if(a.Asc&&a.Asc.plugin&&n()){var d={type:"initialize",guid:a.Asc.plugin.guid};d.windowID=a.Asc.plugin.windowID;a.Asc.plugin._initInternal=!0;a.parent.postMessage(JSON.stringify(d),"*")}};c.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(c,
|
|
d,h){this[c]||(this[c]={});this[c][d]=h};a.Asc.plugin._onCustomMenuClick=function(c,d){var h=u,k=d.indexOf("_oo_sep_");-1!==k&&(h=d.substring(k+8),d=d.substring(0,k));this[c]&&this[c][d]&&this[c][d].call(this,h)};a.Asc.plugin.attachContextMenuClickEvent=function(c,d){this._attachCustomMenuClickEvent("contextMenuEvents",c,d)};a.Asc.plugin.event_onContextMenuClick=function(c){this._onCustomMenuClick("contextMenuEvents",c)};a.Asc.plugin.attachToolbarMenuClickEvent=function(c,d){this._attachCustomMenuClickEvent("toolbarMenuEvents",
|
|
c,d)};a.Asc.plugin.event_onToolbarMenuClick=function(c){this._onCustomMenuClick("toolbarMenuEvents",c)};a.Asc.plugin.attachEvent=function(c,d){var h=a.Asc.plugin;h._events||(h._events={});h._events[c]=d};a.Asc.plugin.detachEvent=function(c){var d=a.Asc.plugin;d._events&&d._events[c]&&delete d._events[c]};a.Asc.plugin.onEvent=function(c,d){var h=a.Asc.plugin;h._events&&h._events[c]&&h._events[c].call(h,d)};a.Asc.plugin.attachEditorEvent=function(c,d){a.Asc.plugin["event_"+c]=d.bind(a.Asc.plugin);w(JSON.stringify({guid:a.Asc.plugin.guid,
|
|
type:"attachEvent",name:c}))};a.Asc.plugin.detachEditorEvent=function(c){a.Asc.plugin["event_"+c]&&delete a.Asc.plugin["event_"+c];w(JSON.stringify({guid:a.Asc.plugin.guid,type:"detachEvent",name:c}))};a.onunload=function(){a.addEventListener?a.removeEventListener("message",q,!1):a.detachEvent("onmessage",q)}})(window,void 0);
|
|
(function(a,u){function w(){function b(){return(65536+e[g++]).toString(16).substring(1)}if(!a.crypto||!a.crypto.getRandomValues){function f(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return f()+f()+"-"+f()+"-"+f()+"-"+f()+"-"+f()+f()+f()}var e=new Uint16Array(8);a.crypto.getRandomValues(e);var g=0;return b()+b()+"-"+b()+"-"+b()+"-"+b()+"-"+b()+b()+b()}function r(b){return a.Asc.plugin.tr(b)}function p(b,e){this.itemType=k.None;this.editors=["word","cell","slide"];this.id=
|
|
e===u?w():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=b?b:null;this.childs=null;this.parent&&(this.parent.childs||(this.parent.childs=[]),this.parent.childs.push(this))}function n(b,e){p.call(this,b,e);this.itemType=k.ContextMenu;this.showOnOptionsType=[];d.Buttons.ButtonsContextMenu.push(this)}function q(b,e){p.call(this,b,e);this.itemType=k.Toolbar;this.type=h.BigButton;this.tab="";
|
|
d.Buttons.ButtonsToolbar.push(this)}function c(b,e){p.call(this,b,e);this.itemType=k.ContentControl;this.checker=null;0===d.Buttons.ButtonsContentControl.length&&d.Buttons.registerContentControl();d.Buttons.ButtonsContentControl.push(this)}a.Asc=a.Asc||{};var d=a.Asc;d.Buttons={};d.Buttons.ButtonsContextMenu=[];d.Buttons.ButtonsToolbar=[];d.Buttons.ButtonsContentControl=[];d.Buttons.registerContextMenu=function(){a.Asc.plugin.attachEvent("onContextMenuShow",function(b){if(b){var e={guid:a.Asc.plugin.guid};
|
|
for(let g=0,f=d.Buttons.ButtonsContextMenu.length;g<f;g++){let l=d.Buttons.ButtonsContextMenu[g];if(null===l.parent)l.onContextMenuShow(b,e)}e.items&&a.Asc.plugin.executeMethod("AddContextMenuItem",[e])}})};d.Buttons.registerToolbarMenu=function(){let b={guid:a.Asc.plugin.guid,tabs:[]};for(let e=0,g=d.Buttons.ButtonsToolbar.length;e<g;e++){let f=d.Buttons.ButtonsToolbar[e];null===f.parent&&f.toToolbar(b);if(f.menu)for(let l in f.menu){let m=f.menu.hasOwnProperty(l)?f.menu[l]:null;m&&m.onclick&&a.Asc.plugin.attachToolbarMenuClickEvent(m.id,
|
|
m.onclick)}}0<b.tabs.length&&a.Asc.plugin.executeMethod("AddToolbarMenuItem",[b])};d.Buttons.updateToolbarMenu=function(b,e,g){b=new d.ButtonToolbar(null,b);b.text=e;e={guid:a.Asc.plugin.guid,tabs:[]};b.childs=g;for(let f=0,l=g.length;f<l;f++)g[f].parent=b;b.toToolbar(e);for(let f=0,l=g.length;f<l;f++)if(b=g[f],b.menu)for(let m in b.menu){let t=b.menu.hasOwnProperty(m)?b.menu[m]:null;t&&t.onclick&&a.Asc.plugin.attachToolbarMenuClickEvent(t.id,t.onclick)}0<e.tabs.length&&a.Asc.plugin.executeMethod("UpdateToolbarMenuItem",
|
|
[e])};d.Buttons.registerContentControl=function(){a.Asc.plugin.attachEditorEvent("onShowContentControlTrack",function(e){let g={guid:a.Asc.plugin.guid,items:{}},f=[];for(let l=0,m=d.Buttons.ButtonsContentControl.length;l<m;++l)f.push(d.Buttons.ButtonsContentControl[l].onShowTrack(e,g.items));Promise.all(f).then(function(){for(let l in g.items){a.Asc.plugin.executeMethod("AddContentControlButtons",[g]);break}})});a.Asc.plugin._attachContentControlButtonClickEvent=function(e,g){this.ContentControlButtonEvents||
|
|
(this.ContentControlButtonEvents={});this.ContentControlButtonEvents[e]=g};let b=a.Asc.plugin;a.Asc.plugin.attachEditorEvent("onContentControlButtonClick",function(e){let g=e&&e.buttonId?e.buttonId:null;e=e&&e.contentControlId?e.contentControlId:null;g&&e&&b.ContentControlButtonEvents&&b.ContentControlButtonEvents[g]&&b.ContentControlButtonEvents[g].call(b,e)})};var h={Button:"button",BigButton:"big-button"},k={None:0,ContextMenu:1,Toolbar:2,ContentControl:3};p.prototype.toItem=function(){let b={id:this.id,
|
|
text:r(this.text)};null!==this.hint&&(b.hint=r(""===this.hint?this.hint:this.text));this.separator&&(b.separator=!0);this.data&&(b.data=this.data);this.lockInViewMode&&(b.lockInViewMode=!0);this.enableToggle&&(b.enableToggle=!0);b.disabled=this.disabled?!0:!1;this.removed&&(b.removed=!0);this.icons&&(b.icons=this.icons);this.itemType===k.Toolbar&&(b.type=this.type);this.menu&&(b.items=this.menu.map(function(e){e.text=r(e.text);return e}));this.split&&(b.split=!0);return b};p.prototype.attachOnClick=
|
|
function(b){};p.prototype.onClick=function(){console.log("BUTTON: "+this.text)};n.prototype=Object.create(p.prototype);n.prototype.constructor=n;n.prototype.copy=function(){let b=new n(this.parent,this.id);b.editors=this.editors;b.separator=this.separator;b.lockInViewMode=this.lockInViewMode;b.enableToggle=this.enableToggle;b.disabled=this.disabled;b.showOnOptionsType=this.showOnOptionsType.slice();return b};n.prototype.addCheckers=function(){let b=arguments.length;this.showOnOptionsType=Array(b);
|
|
for(let e=0;e<b;e++)this.showOnOptionsType[e]=arguments[e]};n.prototype.attachOnClick=function(b){a.Asc.plugin.attachContextMenuClickEvent(this.id,b)};n.prototype.onContextMenuShowAnalyze=function(b,e){return!1};n.prototype.onContextMenuShowExtendItem=function(b,e){};n.prototype.onContextMenuShow=function(b,e){if(!this.onContextMenuShowAnalyze(b,e)){var g=!1;for(let f=0,l=this.editors.length;f<l;f++)if(d.plugin.info.editorType===this.editors[f]){g=!0;break}if(g)for(let f=0,l=this.showOnOptionsType.length;f<
|
|
l;f++)if(b.type===this.showOnOptionsType[f]||"All"===this.showOnOptionsType[f]){e.items||(e.items=[]);g=this.toItem();this.onContextMenuShowExtendItem(b,g);if(this.childs)for(let m=0,t=this.childs.length;m<t;m++)this.childs[m].onContextMenuShow(b,g);e.items.push(g);break}}};q.prototype=Object.create(p.prototype);q.prototype.constructor=q;q.prototype.attachOnClick=function(b){a.Asc.plugin.attachToolbarMenuClickEvent(this.id,b)};q.prototype.toItem=function(b){b=p.prototype.toItem.call(this);b.type=
|
|
this.type;return b};q.prototype.toToolbar=function(b){if(null===this.parent){var e={id:this.id,text:r(this.text),items:[]};null!==this.hint&&(e.hint=r(""===this.hint?this.hint:this.text));b.tabs.push(e)}else e=this.toItem(),b.items||(b.items=[]),b.items.push(e);if(this.childs)for(let g=0,f=this.childs.length;g<f;g++)this.childs[g].toToolbar(e)};c.prototype=Object.create(p.prototype);c.prototype.constructor=c;c.prototype.attachOnClick=function(b){a.Asc.plugin._attachContentControlButtonClickEvent(this.id,
|
|
b)};c.prototype.addChecker=function(b){b&&"function"===typeof b&&(this.checker=b)};c.prototype.onShowTrack=function(b,e){let g=this.checker,f=[],l=this.toItem();for(let m=0,t=b.length;m<t;++m){let x=b[m];f.push((new Promise(function(v){if(g){let y=g(x);y instanceof Promise?y.then(function(z){v(z)}):v(!!y)}else v(!0)})).then(function(v){v&&(e[x]||(e[x]=[]),e[x].push(l))}))}return Promise.all(f)};d.ToolbarButtonType=h;d.ButtonContextMenu=n;d.ButtonToolbar=q;d.ButtonContentControl=c})(window);
|