|
|
|
;layui.define(["layer","form"],function(t){"use strict";var e=layui.jquery,i=layui.layer,a=layui.form(),l=(layui.hint(),layui.device()),n="layedit",o="layui-show",c="layui-disabled",s=function(){var t=this;t.index=0,t.config={tool:["strong","italic","underline","del","|","left","center","right","|","link","unlink","face","image"],hideTool:[],height:280}};s.prototype.set=function(t){var i=this;return e.extend(!0,i.config,t),i},s.prototype.on=function(t,e){return layui.onevent(n,t,e)},s.prototype.build=function(t,i){i=i||{};var a=this,n=a.config,c="layui-layedit",s=e("#"+t),d="LAY_layedit_"+ ++a.index,u=s.next("."+c),y=e.extend({},n,i),f=function(){var t=[],e={};return layui.each(y.hideTool,function(t,i){e[i]=!0}),layui.each(y.tool,function(i,a){x[a]&&!e[a]&&t.push(x[a])}),t.join("")}(),m=e(['<div class="'+c+'">','<div class="layui-unselect layui-layedit-tool">'+f+"</div>",'<div class="layui-layedit-iframe">','<iframe id="'+d+'" name="'+d+'" frameborder="0"></iframe>',"</div>","</div>"].join(""));return l.ie&&l.ie<8?s.removeClass("layui-hide").addClass(o):(u[0]&&u.remove(),r.call(a,m,s[0],y),s.addClass("layui-hide").after(m),a.index)},s.prototype.getContent=function(t){var i=e("#LAY_layedit_"+t).prop("contentWindow");if(i)return i.document.body.innerHTML},s.prototype.getText=function(t){var i=e("#LAY_layedit_"+t).prop("contentWindow");if(i)return e(i.document.body).text()};var r=function(t,i,a){var l=this,n=t.find("iframe");n.css({height:a.height}).on("load",function(){var o=n.contents(),c=n.prop("contentWindow"),s=o.find("head"),r=e(["<style>","*{margin: 0; padding: 0;}","body{padding: 10px; line-height: 20px; overflow-x: hidden; word-wrap: break-word; font: 14px Helvetica Neue,Helvetica,PingFang SC,Microsoft YaHei,Tahoma,Arial,sans-serif; -webkit-box-sizing: border-box !important; -moz-box-sizing: border-box !important; box-sizing: border-box !important;}","a{color:#01AAED; text-decoration:none;}a:hover{color:#c00}","p{margin-bottom: 10px;}","img{display: inline-block; border: none; vertical-align: middle;}","</style>"].join("")),u=o.find("body");s.append(r),u.attr("contenteditable","true").css({"min-height":a.height}).html(i.value||""),d.apply(l,[c,n,i,a]),p.call(l,c,t,a)})},d=function(t,i,a,l){var n=t.document,o=e(n.body);o.on("keydown",function(t){var e=t.keyCode;13===e&&n.execCommand("formatBlock",!1,"<p>"),a.value=o.html()}),o.on("paste",function(e){n.execCommand("formatBlock",!1,"<p>"),setTimeout(function(){u.call(t,o),a.value=o.html()},100)})},u=function(t){var i=this;i.document;t.find("*[style]").each(function(){var t=this.style.textAlign;this.removeAttribute("style"),e(this).css({"text-align":t||""})}),t.find("table").addClass("layui-table"),t.find("script,link").remove()},y=function(t){return t.selection?t.selection.createRange():t.getSelection().getRangeAt(0)},f=function(t){return t.endContainer||t.parentElement().childNodes[0]},m=function(t,i,a){var l=this.document,n=document.createElement(t);for(var o in i)n.setAttribute(o,i[o]);if(n.removeAttribute("text"),l.selection){var c=a.text||i.text;if("a"===t&&!c)return;c&&(n.innerHTML=c),a.pasteHTML(e(n).prop("outerHTML")),a.select()}else{var c=a.toString()||i.text;if("a"===t&&!c)return;c&&(n.innerHTML=c),a.deleteContents(),a.insertNode(n)}},h=function(t,i){var a=this.document,l="layedit-tool-active",n=f(y(a)),o=function(e){return t.find(".layedit-tool-"+e)};i&&i[i.hasClass(l)?"removeClass":"addClass"](l),t.find(">i").removeClass(l),o("unlink").addClass(c),e(n).parents().each(function(){var t=this.tagName.toLowerCase(),e=this.style.textAlign;"b"!==t&&"strong"!==t||o("b").addClass(l),"i"!==t&&"em"!==t||o("i").addClass(l),"u"===t&&o("u").addClass(l),"strike"===t&&o("d").addClass(l),"p"===t&&("center"===e?o("center").addClass(l):"right"===e?o("right").addClass(l):o("left").addClass(l)),"a"===t&&(o("link").addClass(l),o("unlink").removeClass(c))})},p=function(t,a,l){var n=t.document,o=e(n.body),s={link:function(i){var a=f(i),l=e(a).parent();v.call(o,{href:l.attr("href"),target:l.attr("target")},function(e){var a=l[0];"A"===a.tagName?a.href=e.url:m.call(t,"a",{target:
|