/// /** * 此文件的头部注释 */ /*global jquery: false */ (function ($) { 'use strict'; $(function () { var $controls = $('[data-ui-type]'), editors; /** * 过滤控件 * @param {string} type - 对应的控件类型 * @return {jquery} */ function filtercontrols(type) { return $controls.filter('[data-ui-type=' + type + ']'); } editors = filtercontrols('ueditor'); if (editors.length > 0) { editors.each(function (i, n) { if ($(n).attr('disabled') === 'disabled') { return; } var $this = $(n), pattern = $this.data('ueditor-pattern'), simplebuttons = [ 'collapse', 'rarefont', 'source', '|', 'undo', 'redo', '|', 'fontfamily', 'fontsize', 'bold', 'italic', 'underline', 'strikethrough', '|', 'forecolor', 'backcolor', 'removeformat', '|', 'justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'indent', 'insertorderedlist', 'insertunorderedlist', 'inserttable', 'lineheight', 'link' ], normalbuttons = simplebuttons.concat([ '|', 'insertimage', 'qrcodeupload', 'wordconvert', 'attachment', 'insertaudio', 'insertvideo' ]), fullbuttons = [ 'fullscreen', 'collapse', 'rarefont', 'source', '|', 'fontfamily', 'fontsize', 'bold', 'italic', 'underline', '|', 'forecolor', 'backcolor', 'removeformat', 'autoformat', 'typoscheck', '|', 'justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'indent', 'insertorderedlist', 'insertunorderedlist', 'inserttable', 'lineheight', '|', 'wordconvert', 'pdfconvert', 'insertimage', 'qrcodeupload', 'link', 'attachment', 'map', 'insertaudio', 'insertvideo', 'autotypeset', 'fontborder', 'superscript', 'subscript', 'formatmatch', 'blockquote', 'pasteplain', '|', 'selectall', 'cleardoc', '|', 'rowspacingtop', 'rowspacingbottom', '|', 'customstyle', 'paragraph', '|', 'directionalityltr', 'directionalityrtl', '|', 'strikethrough', '|', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|', 'pagebreak', 'template', 'background', '|', 'horizontal', 'date', 'time', 'spechars', 'kityformula', 'wordimage', '|', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|', 'undo', 'redo', '|', 'searchreplace', 'drafts', 'autosave', 'message' ], extremesimplebuttons = [ 'rarefont', 'undo', 'redo', '|', 'fontfamily', 'fontsize', 'bold', '|', 'forecolor', '|', 'justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'insertorderedlist', 'insertunorderedlist' ], weixinbuttons = [ 'rarefont', 'source', 'undo', 'redo', '|', 'fontfamily', 'fontsize', 'bold', '|', 'forecolor', '|', 'justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'insertimage', 'qrcodeupload', 'wordconvert', 'insertvideo' ], microbuttons = [ 'rarefont', 'bold', '|', 'forecolor', '|', 'justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'insertorderedlist', 'insertunorderedlist' ], typobuttons = [ 'rarefont', 'undo', 'redo', '|', 'fontfamily', 'fontsize', 'bold', '|', 'forecolor', '|', 'justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'insertorderedlist', 'insertunorderedlist', 'typoscheck' ], config = { //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个 toolbars: [], initialcontent: '', readonly: $this.attr('readonly') === 'readonly' ? true : false, autoheightenabled: false, initialframewidth: '100%', autofloatenabled: false, serverurl: $this.data('fileupload'), mergeurl: $this.data('mergeurl'), elementpathenabled: false, initialframeheight: $this.data("height"), wordcount: false }, uploadpath = $this.data('uploadpath'), symbol = $this.data('uploadpathreplacesymbol'); switch (pattern.tolowercase()) { case 'simple': config.toolbars = [simplebuttons]; break; case 'full': config.toolbars = [fullbuttons]; config.wordcount = true; break; case 'extremesimple': config.toolbars = [extremesimplebuttons]; break; case 'weixin': config.toolbars = [weixinbuttons]; break; case 'micro': config.toolbars = [microbuttons]; break; case 'typo': config.toolbars = [typobuttons]; break; default: config.toolbars = [normalbuttons]; break; } var editorsetting = $.extend({}, config, $this.data()), editor = new ue.geteditor($this.attr('id'), editorsetting); editor.addlistener("beforepaste", function (type, html) { var $html = $("
" + html.html + "
"); if ($html.length < 1) { return; } var hyperlink = $html.find('a'); if (hyperlink.length > 0) { if (confirm("内容含有超链接,是否去掉超链接?")) { hyperlink.each(function () { $(this).removeattr("href"); $(this).removeattr("_href"); }); } } $html.find('voice').replacewith(function () { var $element = $(this); return $element.text(); }); html.html = $html.html(); //html.html = $('
').append($html).html(); 外部嵌套一层div,在粘贴的时候会报错。 //html.html = html.html.replace(/]*)>([^<>]*)<\/voice>/gi, "$2"); }); editor.options["uploadproviderkey"] = $(this).attr("data-uploadproviderkey"); editor.options["extendfieldid"] = $(this).attr("data-extendfieldid"); editor.options["isextendfield"] = $(this).attr("data-isextendfield"); editor.options["managepath"] = $(this).attr("data-managepath"); editor.options["uploadpath"] = uploadpath; editor.options["uploadpathreplacesymbol"] = symbol; editor.options["pdfconverturl"] = $(this).attr("data-pdfconverturl"); editor.options["insertaudiourl"] = $(this).attr("data-insertaudiourl"); editor.options["wordconverturl"] = $(this).attr("data-wordconverturl"); editor.options["qrcodeuploadurl"] = $(this).attr("data-qrcodeuploadurl"); editor.options["qrcodedialogurl"] = $(this).attr("data-qrcodedialogurl"); editor.options["absolutefrontsiteurl"] = $(this).attr("data-absolutefrontsiteurl"); editor.ready(function () { var $form = $this.parents('form'), pathregex = new regexp('((src|href)\\s*=\\s*(\"|\'))' + uploadpath, 'gi'); $this.data('original', editor.getcontent()); $form.on('reset', function (e) { if (this !== e.target) { return; } editor.setcontent($this.data('original')); }); $form.on('submit', function () { if (editor.querycommandstate('source') === 1) { editor.execcommand('source'); } //var value = $this.val(); 在火狐下获取不到正确值。 var value = editor.getcontent(); $this.val(value.replace(pathregex, "$1" + symbol)); }); }); $this.data('editor', editor); }); }; }); })(jquery); //使用angular的控件,控制器。 $(function () { $('label.control-label') .each(function () { var title = $(this).attr('title'); if (title != '' && title != undefined) { var $i = $(''); $i.attr('data-content', $(this).attr('title')) .attr('data-trigger', 'tooltip') .attr('data-position', 'ne'); $(this).prepend($i); } }); if ($('i[data-trigger=tooltip]').length > 0) { $('i[data-trigger=tooltip]').scojs_tooltip({ position: 'ne', delay: 0 }); } pe.ui.ueditor = { filtertypotag: function () { var contenteditorname = $("[data-ui-type='ueditor']").attr("name"); function filtertypostag(content) { var $content = $($.parsehtml(content)); $content.find('span[data-typos-type]').replacewith(function () { return $(this).text(); }); var $body = $("
"); $content.each(function () { $body.append($(this)); }); return $body.html(); } function addlistenercontentchange() { if (contenteditorname === "content") { var contenteditor = ue.geteditor('content'); contenteditor.addlistener('contentchange', function () { window.pe.typo.typoconfig.contentchanges = true; }); } } addlistenercontentchange(); $('form') .submit(function () { if (contenteditorname === "content") { var contenteditor = ue.geteditor('content'); var filtertypostaghtml = filtertypostag(contenteditor.getcontent()); if (filtertypostaghtml) { contenteditor.setcontent(filtertypostaghtml); } } }); } }; });