Update api script

This commit is contained in:
Oleg Korshul
2025-05-16 19:29:59 +03:00
parent e9c45d971c
commit b310b78d89
2 changed files with 65 additions and 0 deletions

View File

@ -383,6 +383,26 @@
window.Asc.plugin.executeMethod("AddToolbarMenuItem", [items]);
};
Asc.Buttons.updateToolbarMenu = function(id, name, buttons)
{
let buttonMainToolbar = new Asc.ButtonToolbar(null, id);
buttonMainToolbar.text = name;
let items = {
guid : window.Asc.plugin.guid,
tabs : []
};
buttonMainToolbar.childs = buttons;
for (let i = 0, len = buttons.length; i < len; i++)
buttons[i].parent = buttonMainToolbar;
buttonMainToolbar.toToolbar(items);
if (items.tabs.length > 0)
window.Asc.plugin.executeMethod("UpdateToolbarMenuItem", [items]);
};
Asc.Buttons.registerContentControl = function()
{
window.Asc.plugin.attachEditorEvent("onShowContentControlTrack", function(contentControls) {
@ -462,6 +482,7 @@
this.lockInViewMode = true;
this.enableToggle = false;
this.disabled = false;
this.removed = false;
this.parent = parent ? parent : null;
this.childs = null;
@ -498,6 +519,11 @@
if (this.disabled)
item.disabled = true;
else
item.disabled = false;
if (this.removed)
item.removed = true;
if (this.icons)
item.icons = this.icons;

39
sdkjs-plugins/v1/plugins.dev.min.js vendored Normal file
View File

@ -0,0 +1,39 @@
/**
*
* (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,t){function v(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===t?{}:d;for(var f in c)c.hasOwnProperty(f)&&(d[f]=c[f]&&"object"===typeof c[f]?r(c[f]):c[f]);return d}function n(c){var d=a.location.search,f=c+"=";c=d.indexOf(f);return 0<=c?(c+=f.length,f=d.indexOf("&",c),0>f&&(f=d.length),d.substring(c,f)):t}function m(){var c=n("windowID");c&&(a.Asc.plugin.windowID=c,
a.Asc.plugin.guid||(a.Asc.plugin.guid=decodeURIComponent(n("guid"))));return t!==c?!0:!1}function p(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(f){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};m()&&(d.windowID=a.Asc.plugin.windowID);var f=document.body;f&&!0!==a.Asc.plugin.enableDrops&&(f.ondrop=function(k){k&&k.preventDefault&&k.preventDefault();return!1},f.ondragenter=function(k){k&&k.preventDefault&&k.preventDefault();return!1},f.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&&m()){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",p,!1):a.attachEvent("onmessage",p);a.Asc.plugin._attachCustomMenuClickEvent=function(c,
d,f){this[c]||(this[c]={});this[c][d]=f};a.Asc.plugin._onCustomMenuClick=function(c,d){var f=t,k=d.indexOf("_oo_sep_");-1!==k&&(f=d.substring(k+8),d=d.substring(0,k));this[c]&&this[c][d]&&this[c][d].call(this,f)};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 f=a.Asc.plugin;f._events||(f._events={});f._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 f=a.Asc.plugin;f._events&&f._events[c]&&f._events[c].call(f,d)};a.Asc.plugin.attachEditorEvent=function(c,d){a.Asc.plugin["event_"+c]=d.bind(a.Asc.plugin);v(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];v(JSON.stringify({guid:a.Asc.plugin.guid,type:"detachEvent",name:c}))};a.onunload=function(){a.addEventListener?a.removeEventListener("message",p,!1):a.detachEvent("onmessage",p)}})(window,void 0);
(function(a,t){function v(){function b(){return(65536+e[h++]).toString(16).substring(1)}if(!a.crypto||!a.crypto.getRandomValues){function g(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return g()+g()+"-"+g()+"-"+g()+"-"+g()+"-"+g()+g()+g()}var e=new Uint16Array(8);a.crypto.getRandomValues(e);var h=0;return b()+b()+"-"+b()+"-"+b()+"-"+b()+"-"+b()+b()+b()}function r(b){return a.Asc.plugin.tr(b)}function n(b,e){this.itemType=k.None;this.editors=["word","cell","slide"];this.id=
e===t?v():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 m(b,e){n.call(this,b,e);this.itemType=k.ContextMenu;this.showOnOptionsType=[];d.Buttons.ButtonsContextMenu.push(this)}function p(b,e){n.call(this,b,e);this.itemType=k.Toolbar;this.type=f.BigButton;this.tab="";
d.Buttons.ButtonsToolbar.push(this)}function c(b,e){n.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 h=0,g=d.Buttons.ButtonsContextMenu.length;h<g;h++){let l=d.Buttons.ButtonsContextMenu[h];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,h=d.Buttons.ButtonsToolbar.length;e<h;e++){let g=d.Buttons.ButtonsToolbar[e];null===g.parent&&g.toToolbar(b);if(g.menu)for(item of g.menu)item.onclick&&a.Asc.plugin.attachToolbarMenuClickEvent(item.id,item.onclick)}0<
b.tabs.length&&a.Asc.plugin.executeMethod("AddToolbarMenuItem",[b])};d.Buttons.updateToolbarMenu=function(b,e,h){b=new d.ButtonToolbar(null,b);b.text=e;e={guid:a.Asc.plugin.guid,tabs:[]};b.childs=h;for(let g=0,l=h.length;g<l;g++)h[g].parent=b;b.toToolbar(e);0<e.tabs.length&&a.Asc.plugin.executeMethod("UpdateToolbarMenuItem",[e])};d.Buttons.registerContentControl=function(){a.Asc.plugin.attachEditorEvent("onShowContentControlTrack",function(e){let h={guid:a.Asc.plugin.guid,items:{}},g=[];for(let l=
0,q=d.Buttons.ButtonsContentControl.length;l<q;++l)g.push(d.Buttons.ButtonsContentControl[l].onShowTrack(e,h.items));Promise.all(g).then(function(){for(let l in h.items){a.Asc.plugin.executeMethod("AddContentControlButtons",[h]);break}})});a.Asc.plugin._attachContentControlButtonClickEvent=function(e,h){this.ContentControlButtonEvents||(this.ContentControlButtonEvents={});this.ContentControlButtonEvents[e]=h};let b=a.Asc.plugin;a.Asc.plugin.attachEditorEvent("onContentControlButtonClick",function(e){let h=
e&&e.buttonId?e.buttonId:null;e=e&&e.contentControlId?e.contentControlId:null;h&&e&&b.ContentControlButtonEvents&&b.ContentControlButtonEvents[h]&&b.ContentControlButtonEvents[h].call(b,e)})};var f={Button:"button",BigButton:"big-button"},k={None:0,ContextMenu:1,Toolbar:2,ContentControl:3};n.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};n.prototype.attachOnClick=function(b){};n.prototype.onClick=function(){console.log("BUTTON: "+this.text)};m.prototype=Object.create(n.prototype);m.prototype.constructor=m;m.prototype.copy=function(){let b=
new m(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};m.prototype.addCheckers=function(){let b=arguments.length;this.showOnOptionsType=Array(b);for(let e=0;e<b;e++)this.showOnOptionsType[e]=arguments[e]};m.prototype.attachOnClick=function(b){a.Asc.plugin.attachContextMenuClickEvent(this.id,b)};m.prototype.onContextMenuShowAnalyze=
function(b,e){return!1};m.prototype.onContextMenuShowExtendItem=function(b,e){};m.prototype.onContextMenuShow=function(b,e){if(!this.onContextMenuShowAnalyze(b,e)){var h=!1;for(let g=0,l=this.editors.length;g<l;g++)if(d.plugin.info.editorType===this.editors[g]){h=!0;break}if(h)for(let g=0,l=this.showOnOptionsType.length;g<l;g++)if(b.type===this.showOnOptionsType[g]||"All"===this.showOnOptionsType[g]){e.items||(e.items=[]);h=this.toItem();this.onContextMenuShowExtendItem(b,h);if(this.childs)for(let q=
0,x=this.childs.length;q<x;q++)this.childs[q].onContextMenuShow(b,h);e.items.push(h);break}}};p.prototype=Object.create(n.prototype);p.prototype.constructor=p;p.prototype.attachOnClick=function(b){a.Asc.plugin.attachToolbarMenuClickEvent(this.id,b)};p.prototype.toItem=function(b){b=n.prototype.toItem.call(this);b.type=this.type;return b};p.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 h=0,g=this.childs.length;h<g;h++)this.childs[h].toToolbar(e)};c.prototype=Object.create(n.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 h=this.checker,g=[],l=this.toItem();for(let q=0,x=b.length;q<
x;++q){let w=b[q];g.push((new Promise(function(u){if(h){let y=h(w);y instanceof Promise?y.then(function(z){u(z)}):u(!!y)}else u(!0)})).then(function(u){u&&(e[w]||(e[w]=[]),e[w].push(l))}))}return Promise.all(g)};d.ToolbarButtonType=f;d.ButtonContextMenu=m;d.ButtonToolbar=p;d.ButtonContentControl=c})(window);