function showToast(n,t="error"){window.top.pe&&window.top.pe&&window.top.pe.ui&&window.top.pe.ui.message?new window.top.pe.ui.message(n,t):alert(n)}function initDialog(n,t){n.addListener("ready",function(){for(var r,f,u,i=0;i0&&r&&r.length&&r.length>0){var s=t.options.uploadpath,h=t.options.uploadpathreplacesymbol,c=n.replace(s,h);i.val(c);r.attr("src",n);i.val()&&r.attr("src")&&(e=$("#file-picker-FeaturedImage").parents("#upload-placeholder"),e.css("position","absolute"),e.css("top","-15000px"),$("#files-FeaturedImage").removeClass("hidden"));var u=$("#photo-FeaturedImage"),f=$("#files-FeaturedImage > li"),o=$.parseHTML('
<\/i><\/div><\/a><\/div>');$(o).click(function(){if(u&&u.length&&u.length==1){var t=u.find("#photo-element");t.attr("src",n);u.modal("show")}});f&&f.length&&f.length==1&&f.append(o)}}function getSelectJsonArr(n,t,i){var o="",f="",r=n.find(t),e,u,s;if(i==="pdf"?f="#pdfToImageUrl":i==="audio"?f="#audioToMp3Url":i==="word"&&(f="#wordConvertToHtml"),e=n.find(f).val(),r.length>0&&r.val()){for(r=JSON.parse(r.val()),u=0;u-1?e+"&filePath="+r[u].url:e+"?filePath="+r[u].url+"&isUploaded=true",$.ajaxPreventCSRF({url:s,type:"post","async":!1,dataType:"json",success:function(n){o+=n.Result}});n.find("#fileName").html(r[0].fileName)}return o}function transImgIntoWrapper(n,t,i,r){var u,f,e,o;return i=i||t.getAttribute("eid"),f=t.cloneNode(),e=findParent(t,"a","")||findParent(t,"span",""),e?(o=e.cloneNode(),o.appendChild(f),u=getImageWrapperNode(o,i,r)):u=getImageWrapperNode(f,i,r),u}function findChildElement(n,t,i){var u=[],e,o,r,f;if(n)for(e=new RegExp(t||"","i"),o=new RegExp(i||"","i"),u.push(n);u.length>0;){if(r=u.pop(),r.children&&r.children.length)for(f=0;f0;){if(u=e.pop(),u.getAttribute&&u.getAttribute("eid")==t){if(i&&!s.test(u.tagName))continue;if(r&&!h.test(u.className))continue;return u}if(u.children&&u.children.length)for(f=0;f-1,h.find("#fileName").html().trim()&&!h.find("#wordContent").html()){alert("word文档还未上传成功,请稍后。");return}if(c=h.find("#wordContent").html(),c){if(u=$($.parseHTML("
"+$.trim(c)+"<\/div>")),$("a",u).each(function(n,t){var i=$(t);i.attr("href")||(i.after(t.innerHTML),i.remove())}),s=$(this.getDom()).parents().find('input[name="Title"]'),s&&s.length==1){if(f="",k=="FirstLine"){if(f=$("h1,h2,h3,h4,h5,h6",u).eq(0).text().trim(),f||(f=$("p:eq(0)",u).text().trim()),f.length<4||f.length>50)return showToast("文章标题不能为空或不符合长度要求!","error"),!1}else y=h.find("#fileName").text().trim(),f=y.substring(0,y.lastIndexOf("."));if(s.val().trim().length>0&&(b=confirm("是否替换已有的标题?")),b&&(s.val(f),d=f.replace(/\s/g,""),i.indexOf("RemoveTitleFromContent")>-1)){var ft=0,et=new RegExp("h[1-3]","i"),l=[],g=u[0];for(e=0;e0){if(o=l.shift(),o.textContent&&o.textContent.replace(/\s/g,"")==d&&et.test(o.tagName)){o.remove();break}if(o.children.length>0)for(e=0;e10)break}}}s&&s.length==1&&i.indexOf("AutoCover")>-1&&(a="",u.find("img").each(function(){if(!a){var n=$(this).attr("src");n&&(a=n)}}),p=!0,v=$(this.getDom()).parents().find('input[name="FeaturedImage"]'),v&&v.length==1&&(v.val().trim().length>0&&(p=confirm("是否替换已有的封面图片?")),p&&setFeaturedImage(a,n)));w&&u.find("a").each(function(n,t){var r=$(t),i=$.parseHTML(t.innerHTML);i&&i.length==1&&i[0].style&&(i=i[0],i.setAttribute("style",""),r.replaceWith(i))});i.indexOf("RemoveImage")>-1&&u.find("img").each(function(n,t){var i=$(t);i.replaceWith(i.html())});c=u.get(0).innerHTML;tt=n.getContent()!=="";n.setContent(c.trim(),tt);(i.indexOf("RemoveFontSize")>-1||i.indexOf("RemoveFontFamily")>-1||i.indexOf("FirstLineIndent")>-1||i.indexOf("RemoveFormat")>-1||i.indexOf("RemoveEmptyLine")>-1)&&(it=JSON.parse(JSON.stringify(n.options.autotypeset)),r=n.options.autotypeset,r.clearFontSize=i.indexOf("RemoveFontSize")>-1,r.clearFontFamily=i.indexOf("RemoveFontFamily")>-1,r.indent=i.indexOf("FirstLineIndent")>-1,r.textAlign="left",r.keepTextAlignCenter="1",r.clearStyle=i.indexOf("RemoveFormat")>-1,r.removeEmptyline=i.indexOf("RemoveEmptyLine")>-1,n.setOpt({autotypeset:r}),n.execCommand("autotypeset"),n.setOpt({autotypeset:it}),r.keepTextAlignCenter="0");n.body.style.overflow="hidden";n.body.style.padding="8px"}rt="importDocSettingEditorUser";ut=JSON.stringify({TitleFrom:k,ImportSetting:i.join(",")});localStorage.setItem(rt,ut);t.close()}},{className:"edui-nobutton",label:"取消",onclick:function(){t.close()}}]}),i=new UE.ui.Button({name:"importword",title:"导入Word/PDF",cssRules:"background-position: -300px 80px;",onclick:function(){var n=$(this.getDom()).parents().find('input[name="Title"]');n.length>0&&(t.iframeUrl=r+"&showTitleCheckBox=true&showCoverCheckBox=true");t.render();t.open()}});return n.addListener("selectionchange",function(t,r,u){if(!u){var f=n.queryCommandState("wordconvert");f===-1?i.setDisabled(!0):i.setDisabled(!1)}}),i});UE.registerUI("typoscheck",function(n){function r(){var i=$($.parseHTML(n.getContent())),t;return i.find("span[data-typos-type]").replaceWith(function(){return $(this).text()}),t="",i.each(function(){t=this.outerHTML?t+this.outerHTML:t+this.nodeValue}),t}var i=new UE.ui.Dialog({iframeUrl:"/content/_common/base/html/typoscheck.html",editor:n,name:"typosCheckUploadDialog",title:"错别字/敏感词/敏感信息检查",cssRules:"width:760px;height:380px;"}),t=new UE.ui.Button({name:"错别字/敏感词/敏感信息检查",title:"错别字/敏感词/敏感信息检查",className:"power-edui-typoscheck hidden",onclick:function(){var t=r();t&&n.setContent(t);i.render();i.open();setTimeout(function(){var t=new window.pe.typo.TypoEditor(n,i.id+"_iframe");t.show()},1e3)}});return n.addListener("selectionchange",function(i,r,u){if(!u){var f=n.queryCommandState("typoscheck");f===-1?t.setDisabled(!0):t.setDisabled(!1)}}),t.label="错别字/敏感词检查",t.showText=!1,t});UE.registerUI("collapse",function(n,t){return new UE.ui.Button({name:t,title:"展开/折叠",showIcon:!1,label:'<\/i>',editor:n,onclick:function(){var t=n.ui.getDom("toolbarbox"),i=this.getDom("icon"),r;t.dataset.collapse==="false"?(t.className="edui-editor-toolbarbox edui-default",t.dataset.collapse="true",i.className="fa fa-angle-double-down"):(t.className="edui-editor-toolbarbox-open edui-default",t.dataset.collapse="false",i.className="fa fa-angle-double-up");window.dispatchEvent&&window.Event&&(r=new Event("resize"),window.dispatchEvent(r))}})});UE.registerUI("rarefont",function(n,t){var i=new UE.ui.Button({name:t,title:"非常见字体检测",showIcon:!1,label:'<\/i>',editor:n,onclick:function(){}});return n.ready(function(){var n=i.getDom();n.style.display="none"}),n.addListener("selectionchange",function(t,r,u){var s,h,c,v,l,y,f,o,p;if(!u){var w=n.getContent(),e=[],a=w.match(/style\s*\=\s*\"(.*?)\"/gi);if(a)for(f=0;f0&&(s=confirm("是否替换已有的标题?")),s&&e.val(o.substring(0,o.lastIndexOf(".")))),r=u?r.trim().replace("0?(n.focus(),n.execCommand("inserthtml",r.trim())):n.setContent(r.trim(),!1);t.close()}},{className:"edui-nobutton",label:"取消",onclick:function(){t.close()}}]}),i=new UE.ui.Button({name:"importpdf",title:"PDF导入",cssRules:"background-position: -280px 80px;",onclick:function(){var n=$(this.getDom()).parents().find('input[name="Title"]');n.length>0&&(t.iframeUrl=r+"&showpdfCheckbox=true");t.render();t.open()}});return n.addListener("selectionchange",function(t,r,u){if(!u){var f=n.queryCommandState("pdfconvert");f===-1?i.setDisabled(!0):i.setDisabled(!1)}}),i});UE.registerUI("insertaudio",function(n){var u=n.options.insertaudiourl,f=n.options.uploadproviderkey,e=n.options.isextendfield,o=n.options.extendfieldid,r=u+"?uploadProviderKey="+f+"&isExtendField="+e+"&extendFieldId="+o+"&propertyName="+n.key,t=new UE.ui.Dialog({iframeUrl:r,editor:n,name:"UploadAudioDialog",title:"导入音频",cssRules:"width:698px;height:385px;",buttons:[{className:"edui-okbutton",label:"确定",onclick:function(){var i=$(this.getDom()).parents(".edui-dialog").find("iframe").contents(),r="",u=i.find("#ueditor_UoloadAudio_Tab").find(".active").attr("id");switch(u){case"uploadAudio":r=i.find("#audioContent").html();break;case"uploadLocalAudio":r=getSelectJsonArr(i,"#localFile_SelectJsonArr","audio");break;case"uploadMaterialAudio":r=getSelectJsonArr(i,"#material_SelectJsonArr","audio")}i.find("#audioContent").html(r);r=i.find("#audioContent").html();n.focus();n.execCommand("inserthtml",r.trim());t.close()}},{className:"edui-nobutton",label:"取消",onclick:function(){t.close()}}]}),i=new UE.ui.Button({name:"importaudio",title:"音频导入",cssRules:"background-position: -18px -40px;",onclick:function(){var n=$(this.getDom()).parents().find('input[name="Title"]');n.length>0&&(t.iframeUrl=r+"&showpdfCheckbox=true");t.render();t.open()}});return n.addListener("selectionchange",function(t,r,u){if(!u){var f=n.queryCommandState("insertaudio");f===-1?i.setDisabled(!0):i.setDisabled(!1)}}),i});UE.registerUI("justifytype",function(n,t){for(var i,r,f=[{name:"左对齐",value:"left",className:"edui-for-justifyleft"},{name:"右对齐",value:"right",className:"edui-for-justifyright"},{name:"居中对齐",value:"center",className:"edui-for-justifycenter"},{name:"两端对齐",value:"justify",className:"edui-for-justifyjustify"},],o=function(){n.execCommand("justify",this.value)},e=[],u=0;u-1)continue;if(v[i.value]&&!n.getOpt("uploadproviderkey"))continue;r.push({label:i.name,value:i.value,type:i.type,className:i.className,onclick:l})}var y=function(){n.execCommand("insertcode",this.value)},s={as3:"ActionScript3",bash:"Bash/Shell",cpp:"C/C++",css:"Css",cf:"CodeFunction","c#":"C#",delphi:"Delphi",diff:"Diff",erlang:"Erlang",groovy:"Groovy",html:"Html",java:"Java",jfx:"JavaFx",js:"Javascript",pl:"Perl",php:"Php",plain:"Plain Text",ps:"PowerShell",python:"Python",ruby:"Ruby",scala:"Scala",sql:"Sql",vb:"Vb",xml:"Xml"},h=[];for(e in s)h.push({label:s[e],value:e,onclick:y});return c=new UE.ui.MenuItem({value:"insertcode",label:"代码",className:"edui-for-code",subMenu:new UE.ui.Menu({editor:n,items:h})}),r.push(c),f=new UE.ui.MenuButton({name:"insertmenulist",editor:n,items:r,className:"edui-for-insertbtn",onbuttonclick:function(){this.showPopup()},title:"插入表格、图片、视频、附件...",showText:!0,label:"",initValue:"插入表格、图片、视频、附件...",Stateful_onMouseOver:function(){this.showPopup()}}),n.addListener("selectionchange",function(t,i,r){if(!r){var u=n.queryCommandState("insertmenu");u===-1?f.setDisabled(!0):f.setDisabled(!1)}}),f});UE.registerUI("linkmenu",function(n,t){var r,o,e,u,i,f;for(n.registerCommand(t,{execCommand:function(t,i){var f,r,u;if(i.type){if(i.type=="dialog")if(f=n.getDialog(i.value),f)f.open();else if(UE.ui[i.value]&&(r=UE.ui[i.value],r&&typeof r.execFn=="function"&&(u=r.execFn(n,i.value),u&&typeof u.onclick=="function"))){u.onclick();return}}else this.execCommand(i.value)}}),r=[{value:"link",name:"超链接",type:"dialog",className:"edui-for-link"},{value:"unlink",name:"取消链接",className:"edui-for-unlink"},{value:"anchor",name:"锚点",type:"dialog",className:"edui-for-anchor"}],initDialog(n,r),o=function(){n.execCommand(t,this)},e=[],u=0;u