(function (window, $) { 'use strict'; var defaultItems = [ 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', '|', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak', 'anchor', 'link', 'unlink', '|', 'about' ]; function getJquery() { return $ || window.jQuery || (window.layui && window.layui.$); } function normalizeSelector(target) { var jq = getJquery(); if (!target) return ''; if (typeof target === 'string') return target; if (jq && target instanceof jq) target = target.get(0); if (target && target.id) return '#' + target.id; return target; } function initRichEditor(target, options) { var jq = getJquery(); var selector = normalizeSelector(target); var $textarea; if (!jq) return null; $textarea = jq(selector).first(); if (!$textarea.length || !window.KindEditor) return null; if (!$textarea.attr('id')) { $textarea.attr('id', 'rich-editor-' + Math.floor(Math.random() * 1000000)); selector = '#' + $textarea.attr('id'); } return window.KindEditor.create(selector, jq.extend({ width: '100%', minWidth: '100%', height: '460px', resizeType: 1, allowPreviewEmoticons: true, allowImageUpload: true, filterMode: false, newlineTag: 'p', items: defaultItems, afterBlur: function () { this.sync(); } }, options || {})); } function initRichEditors(root, options) { var jq = getJquery(); var editors = {}; var $root; if (!jq) return editors; $root = root ? jq(root) : jq(document); $root.find('.js-rich-editor').each(function (index) { var $textarea = jq(this); var id = $textarea.attr('id') || ('rich-editor-' + (index + 1)); $textarea.attr('id', id); editors[id] = initRichEditor('#' + id, options); }); return editors; } window.AppRichEditor = { init: initRichEditor, initAll: initRichEditors }; if (getJquery()) { getJquery()(function () { if (getJquery()('.js-rich-editor').length) { initRichEditors(document); } }); } })(window, window.jQuery || (window.layui && window.layui.$));