1 |
- !function(){"use strict";let t=tinymce.util.Tools.resolve("tinymce.PluginManager"),e=("undefined"!=typeof window?window:Function("return this;")(),{}),o={},i=!0,r=!1,n=null,s=0,l=null;class c{constructor(t){if(!(r=t.getParam("cfyun_toolbar_sticky",!1,"bool")))return;i=t.getParam("toolbar_sticky_type",!0,"bool"),n=t.getParam("toolbar_sticky_elem","","string"),l=t.getParam("toolbar_sticky_wrap","","string"),s=t.getParam("toolbar_sticky_elem_height",0,"number"),this.editor=t,o.wrap=window,o.editor=t.$(t.container),o.header=o.editor.find(".tox-editor-header"),o.container=o.editor.find(".tox-editor-container"),o.elemHeight=s,l&&"string"==typeof l&&"body"!=l&&(o.wrap=document.querySelector(l)||window);let e=this;return i?(t.on("focus",()=>{e.bind()}),t.on("blur",()=>{e.restore(),e.unBind()})):this.bind(),this}sticky(){return o.editor.hasClass("tox-fullscreen")?(this.restore(),!1):(this.position(),e.isSticky?(o.container.css("padding-top",o.header[0].clientHeight),o.editor.removeClass("tox-tinymce--toolbar-sticky-off").addClass("tox-tinymce--toolbar-sticky-on"),o.header.css({position:"fixed",width:e.width,left:e.left,top:o.elemHeight||0,borderTop:"1px solid #ccc"}),!1):void this.restore())}position(){let t=o.elemHeight;if(n){var i=document.querySelector(n);if(!i)return this.editor.notificationManager.open({text:"ToolbarSticky未获取到:预留位置DOM节点,请查看配置toolbar_sticky_elem。",type:"info"}),!1;t=i.offsetHeight,o.elemHeight=i.clientHeight}e.width=this.editor.container.clientWidth,e.left=o.editor.offset().left+1,e.isSticky=this.scrollTop()>=this.editor.$(o.container).offset().top-t}bind(){o.wrap.addEventListener("scroll",this.throttle(this.sticky.bind(this),60),!1),o.wrap.addEventListener("resize",this.throttle(this.sticky.bind(this),60),!1),this.sticky()}unBind(){o.wrap.removeEventListener("scroll",this.throttle(this.sticky.bind(this),60)),o.wrap.removeEventListener("resize",this.throttle(this.sticky.bind(this),60))}restore(){o.header.attr("style",""),o.container.css("padding-top",0),o.editor.removeClass("tox-tinymce--toolbar-sticky-on").addClass("tox-tinymce--toolbar-sticky-off")}destroy(){e=o={},this.unBind(),this.restore()}scrollTop(){return document.body.scrollTop||document.documentElement.scrollTop||window.pageYOffset}now(){return Date.now()||(new Date).getTime()}throttle(t,e){let o,i,r,n=this,s=null,l=0;const c=()=>{l=0,s=null,r=t.apply(o,i),s||(o=i=null)};return()=>{let a=n.now();l||(l=a);let d=e-(a-l);return o=this,i=arguments,d<=0||d>e?(s&&(clearTimeout(s),s=null),l=a,r=t.apply(o,i),s||(o=i=null)):s||(s=setTimeout(c,d)),r}}}t.add("toolbarsticky",function(t){t.on("init",function(e){new c(t)})})}();
|