/** * layout 1.5v 2020-01-14 * The tinymce-plugins is used to set up a layout * * https://github.com/Five-great/tinymce-plugins * * Copyright 2020, Five(Li Hailong) The Chengdu, China https://fivecc.cn/ * * Licensed under MIT */ tinymce.PluginManager.add("layout",function(e,l){var w=tinymce.util.Tools.resolve("tinymce.util.Tools"),c=e.getParam("layout_options",{clearStyle:[],filterTags:["table>*"],style:{"text-align":"justify","text-indent":"2em","line-height":1.5},tagsStyle:{}}),g={},h={},m;for(m in c.filterTags)-1!=c.filterTags[m].indexOf(">*")?h[c.filterTags[m].replace(">*","").toUpperCase()]=!0:g[c.filterTags[m].toUpperCase()]=!0;for(var q in c.tagsStyle){l=q.split(",");for(var r in l)-1!=l[r].indexOf(">*")?h[l[r].replace(">*", "").toUpperCase()]=q:g[l[r].toUpperCase()]=q}var v=function(){function t(a,b){return(a=b.match(new RegExp(a+':?(.+?)"?[;}]')))?a[1]:!1}function u(a){var b=a.tagName;if(g[b]||h[b])return c.tagsStyle[g[b]]?n(a,c.tagsStyle[g[b]]):"",!0;for(var d=a.parentNode,k=d.tagName;"BODY"!==k;){b=k+">"+b;if(g[b]||h[k])return c.tagsStyle[h[k]]?n(a,c.tagsStyle[h[k]]):"",c.tagsStyle[g[b]]?n(a,c.tagsStyle[g[b]]):"",!0;d=d.parentNode;k=d.tagName}return!1}function n(a,b){for(var d in b)f.setStyle(a,d,b[d]);b["text-indent"]&& (b="",a&&a.children["0"]&&a.children["0"].attributes&&a.children["0"].attributes.style&&(b=t("font-size",a.children["0"].attributes.style.textContent),d=t("letter-spacing",a.children["0"].attributes.style.textContent),b=b?2*(parseInt(b)+parseInt(d?d:0))+"px":2*(parseInt(d?d:0)+16)+"px"),f.setStyle(a,"text-indent",c.style["text-indent"]&&"2em"!=c.style["text-indent"]?c.style["text-indent"]:b?b:"2em"))}var f=e.dom;e.execCommand("selectAll");var x=e.selection.getSelectedBlocks(),p="";w.each(x,function(a){""== p&&(f.hasClass(a,"layoutFV")?(p="remove",f.removeClass(a,"layoutFV")):(p="add",f.addClass(a,"layoutFV")));if("add"==p)if(u(a)?"":n(a,c.style),c.clearStyle){var b=f.getAttrib(a,"style");for(d in c.clearStyle)b=b.replace(new RegExp(c.clearStyle[d]+':?(.+?)"?[;}]'),"");f.setAttrib(a,"style",b)}else"";else if(u(a))"";else{var d=f.getAttrib(a,"style");for(b in c.style)d=d.replace(new RegExp(b+':?(.+?)"?[;}]'),"");f.setAttrib(a,"style",d)}})};e.ui.registry.getAll().icons.layout||e.ui.registry.addIcon("layout", ''); e.ui.registry.addToggleButton("layout",{icon:"layout",tooltip:"\u4e00\u952e\u5e03\u5c40",onAction:function(){e.undoManager.transact(function(){e.focus();v()})}});e.ui.registry.addMenuItem("layout",{text:"\u4e00\u952e\u5e03\u5c40",onAction:function(){e.undoManager.transact(function(){e.focus();v()})}});return{getMetadata:function(){return{name:"\u4e00\u952e\u5e03\u5c40",url:"https://github.com/Five-great/tinymce-plugins"}}}});