/*! wangeditor.js 2017-02-26 */ !function (a) { "function" == typeof window.define ? window.define.amd ? window.define("wangEditor", ["jquery"], a) : window.define.cmd ? window.define(function (b, c, d) { return a }) : a(window.jQuery) : "object" == typeof module && "object" == typeof module.exports ? (require("../css/wangEditor.css"), module.exports = a(require("jquery"))) : a(window.jQuery) }(function (a) { if (!a || !a.fn || !a.fn.jquery) return void alert("在引用wangEditor.js之前,先引用jQuery,否则无法使用 wangEditor"); var b = function (b) { var c = window.wangEditor; c && b(c, a) }; return function (a, b) { if (a.wangEditor) return void alert("一个页面不能重复引用 wangEditor.js 或 wangEditor.min.js !!!"); var c = function (a) { "string" == typeof a && (a = "#" + a); var c = b(a); if (1 === c.length) { var d = c[0].nodeName; "TEXTAREA" !== d && "DIV" !== d || (this.valueNodeName = d.toLowerCase(), this.$valueContainer = c, this.$prev = c.prev(), this.$parent = c.parent(), this.init()) } }; c.fn = c.prototype, c.$body = b("body"), c.$document = b(document), c.$window = b(a), c.userAgent = navigator.userAgent, c.getComputedStyle = a.getComputedStyle, c.w3cRange = "function" == typeof document.createRange, c.hostname = location.hostname.toLowerCase(), c.websiteHost = "wangeditor.github.io|www.wangeditor.com|wangeditor.coding.me", c.isOnWebsite = c.websiteHost.indexOf(c.hostname) >= 0, c.docsite = "http://www.kancloud.cn/wangfupeng/wangeditor2/113961", a.wangEditor = c, c.plugin = function (a) { c._plugins || (c._plugins = []), "function" == typeof a && c._plugins.push(a) } }(window, a), b(function (a, b) { a.fn.init = function () { this.initDefaultConfig(), this.addEditorContainer(), this.addTxt(), this.addMenuContainer(), this.menus = {}, this.commandHooks() } }), b(function (a, b) { a.fn.ready = function (a) { this.readyFns || (this.readyFns = []), this.readyFns.push(a) }, a.fn.readyHeadler = function () { for (var a = this.readyFns; a.length;) a.shift().call(this) }, a.fn.updateValue = function () { var a = this, b = a.$valueContainer, c = a.txt.$txt; if (b !== c) { var d = c.html(); b.val(d) } }, a.fn.getInitValue = function () { var a = this, b = a.$valueContainer, c = "", d = a.valueNodeName; return "div" === d ? c = b.html() : "textarea" === d && (c = b.val()), c }, a.fn.updateMenuStyle = function () { var a = this.menus; b.each(a, function (a, b) { b.updateSelected() }) }, a.fn.enableMenusExcept = function (a) { this._disabled || (a = a || [], "string" == typeof a && (a = [a]), b.each(this.menus, function (b, c) { a.indexOf(b) >= 0 || c.disabled(!1) })) }, a.fn.disableMenusExcept = function (a) { this._disabled || (a = a || [], "string" == typeof a && (a = [a]), b.each(this.menus, function (b, c) { a.indexOf(b) >= 0 || c.disabled(!0) })) }, a.fn.hideDropPanelAndModal = function () { var a = this.menus; b.each(a, function (a, b) { var c = b.dropPanel || b.dropList || b.modal; c && c.hide && c.hide() }) } }), b(function (a, b) { function c() { } var d = !a.w3cRange; a.fn.currentRange = function (a) { return a ? void(this._rangeData = a) : this._rangeData }, a.fn.collapseRange = function (a, b) { b = b || "end", b = "start" === b, a = a || this.currentRange(), a && (a.collapse(b), this.currentRange(a)) }, a.fn.getRangeText = d ? c : function (a) { if (a = a || this.currentRange()) return a.toString() }, a.fn.getRangeElem = d ? c : function (a) { a = a || this.currentRange(); var b = a.commonAncestorContainer; return 1 === b.nodeType ? b : b.parentNode }, a.fn.isRangeEmpty = d ? c : function (a) { return a = a || this.currentRange(), !(!a || !a.startContainer || a.startContainer !== a.endContainer || a.startOffset !== a.endOffset) }, a.fn.saveSelection = d ? c : function (a) { var c, d, e = this, f = e.txt.$txt.get(0); a ? c = a.commonAncestorContainer : (d = document.getSelection(), d.getRangeAt && d.rangeCount && (a = document.getSelection().getRangeAt(0), c = a.commonAncestorContainer)), c && (b.contains(f, c) || f === c) && e.currentRange(a) }, a.fn.restoreSelection = d ? c : function (b) { var c; if (b = b || this.currentRange()) try { c = document.getSelection(), c.removeAllRanges(), c.addRange(b) } catch (d) { a.error("执行 editor.restoreSelection 时,IE可能会有异常,不影响使用") } }, a.fn.restoreSelectionByElem = d ? c : function (a, b) { a && (b = b || "end", this.setRangeByElem(a), "start" === b && this.collapseRange(this.currentRange(), "start"), "end" === b && this.collapseRange(this.currentRange(), "end"), this.restoreSelection()) }, a.fn.initSelection = d ? c : function () { var a = this; if (!a.currentRange()) { var b = a.txt.$txt, c = b.children().first(); c.length && a.restoreSelectionByElem(c.get(0)) } }, a.fn.setRangeByElem = d ? c : function (a) { var c = this, d = c.txt.$txt.get(0); if (a && b.contains(d, a)) { for (var e = a.firstChild; e && 3 !== e.nodeType;) e = e.firstChild; for (var f = a.lastChild; f && 3 !== f.nodeType;) f = f.lastChild; var g = document.createRange(); e && f ? (g.setStart(e, 0), g.setEnd(f, f.textContent.length)) : (g.setStart(a, 0), g.setEnd(a, 0)), c.saveSelection(g) } } }), b(function (a, b) { a.w3cRange || (a.fn.getRangeText = function (a) { if (a = a || this.currentRange()) return a.text }, a.fn.getRangeElem = function (a) { if (a = a || this.currentRange()) { var b = a.parentElement(); return 1 === b.nodeType ? b : b.parentNode } }, a.fn.isRangeEmpty = function (a) { return a = a || this.currentRange(), !a || !a.text }, a.fn.saveSelection = function (a) { var c, d = this, e = d.txt.$txt.get(0); a ? c = a.parentElement() : (a = document.selection.createRange(), c = "undefined" == typeof a.parentElement ? null : a.parentElement()), c && (b.contains(e, c) || e === c) && d.currentRange(a) }, a.fn.restoreSelection = function (a) { var b, c = this; if (a = a || c.currentRange()) { b = document.selection.createRange(); try { b.setEndPoint("EndToEnd", a) } catch (d) { } if (0 === a.text.length) try { b.collapse(!1) } catch (d) { } else b.setEndPoint("StartToStart", a); b.select() } }) }), b(function (a, b) { a.fn.commandHooks = function () { var a = this, c = {}; c.insertHtml = function (c) { var d, e = b(c), f = a.getRangeElem(); d = a.getLegalTags(f), d && b(d).after(e) }, a.commandHooks = c } }), b(function (a, b) { a.fn.command = function (a, b, c, d) { function e() { b && (g.queryCommandSupported(b) ? document.execCommand(b, !1, c) : (f = g.commandHooks, b in f && f[b](c))) } var f, g = this; this.customCommand(a, e, d) }, a.fn.commandForElem = function (a, b, c, d, e) { var f, g; "string" == typeof a ? f = a : (f = a.selector, g = a.check); var h = this.getRangeElem(); h = this.getSelfOrParentByName(h, f, g), h && this.setRangeByElem(h), this.command(b, c, d, e) }, a.fn.customCommand = function (a, b, c) { function d() { e.hideDropPanelAndModal() } var e = this, f = e.currentRange(); return f ? (e.undoRecord(), this.restoreSelection(f), b.call(e), this.saveSelection(), this.restoreSelection(), c && "function" == typeof c && c.call(e), e.txt.insertEmptyP(), e.txt.wrapImgAndText(), e.updateValue(), e.updateMenuStyle(), setTimeout(d, 200), void(a && a.preventDefault())) : void(a && a.preventDefault()) }, a.fn.queryCommandValue = function (a) { var b = ""; try { b = document.queryCommandValue(a) } catch (c) { } return b }, a.fn.queryCommandState = function (a) { var b = !1; try { b = document.queryCommandState(a) } catch (c) { } return b }, a.fn.queryCommandSupported = function (a) { var b = !1; try { b = document.queryCommandSupported(a) } catch (c) { } return b } }), b(function (a, b) { function c(a) { var c = this, d = b(a), e = !1; return d.each(function () { if (this === c) return e = !0, !1 }), e } var d; a.fn.getLegalTags = function (b) { var c = this.config.legalTags; return c ? this.getSelfOrParentByName(b, c) : void a.error("配置项中缺少 legalTags 的配置") }, a.fn.getSelfOrParentByName = function (a, e, f) { if (a && e) { d || (d = a.webkitMatchesSelector || a.mozMatchesSelector || a.oMatchesSelector || a.matchesSelector), d || (d = c); for (var g = this.txt.$txt.get(0); a && g !== a && b.contains(g, a);) { if (d.call(a, e)) { if (!f) return a; if (f(a)) return a } a = a.parentNode } } } }), b(function (a, b) { function c(a) { return null == a._redoList && (a._redoList = []), a._redoList } function d(a) { return null == a._undoList && (a._undoList = []), a._undoList } function e(a, b, c) { var d = b.val, e = a.txt.$txt.html(); if (null != d) { if (d === e) return "redo" === c ? void a.redo() : "undo" === c ? void a.undo() : void 0; a.txt.$txt.html(d), a.updateValue(), a.onchange && "function" == typeof a.onchange && a.onchange.call(a) } } var f = 20; a.fn.undoRecord = function () { var a = this, b = a.txt.$txt, e = b.html(), g = d(a), h = c(a), i = g.length ? g[0] : ""; e !== i.val && (h.length && (h = []), g.unshift({range: a.currentRange(), val: e}), g.length > f && g.pop()) }, a.fn.undo = function () { var a = this, b = d(a), f = c(a); if (b.length) { var g = b.shift(); f.unshift(g), e(this, g, "undo") } }, a.fn.redo = function () { var a = this, b = d(a), f = c(a); if (f.length) { var g = f.shift(); b.unshift(g), e(this, g, "redo") } } }), b(function (a, b) { a.fn.create = function () { var c = this; a.$body && 0 !== a.$body.length || (a.$body = b("body"), a.$document = b(document), a.$window = b(window)), c.addMenus(), c.renderMenus(), c.renderMenuContainer(), c.renderTxt(), c.renderEditorContainer(), c.eventMenus(), c.eventMenuContainer(), c.eventTxt(), c.readyHeadler(), c.initSelection(), c.$txt = c.txt.$txt; var d = a._plugins; d && d.length && b.each(d, function (a, b) { b.call(c) }) }, a.fn.disable = function () { this.txt.$txt.removeAttr("contenteditable"), this.disableMenusExcept(), this._disabled = !0 }, a.fn.enable = function () { this._disabled = !1, this.txt.$txt.attr("contenteditable", "true"), this.enableMenusExcept() }, a.fn.destroy = function () { var a = this, b = a.$valueContainer, c = a.$editorContainer, d = a.valueNodeName; "div" === d ? (b.removeAttr("contenteditable"), c.after(b), c.hide()) : (b.show(), c.hide()) }, a.fn.undestroy = function () { var a = this, b = a.$valueContainer, c = a.$editorContainer, d = a.menuContainer.$menuContainer, e = a.valueNodeName; "div" === e ? (b.attr("contenteditable", "true"), d.after(b), c.show()) : (b.hide(), c.show()) }, a.fn.clear = function () { var a = this, b = a.txt.$txt; b.html("
' + i + "
"), a.$body.append(f), h.ready(function () { var a = f.outerWidth() + 5, b = j.outerWidth(), c = parseFloat(j.css("margin-left"), 10); f.remove(), f = null, j.css({width: a, "margin-left": c + (b - a) / 2}), g.tipWidth = a })), j.append(i), c.append(j); var k; c.find("a").on("mouseenter", function (a) { g.active() || g.disabled() || (k = setTimeout(d, 200)) }).on("mouseleave", function (a) { k && clearTimeout(k), e() }).on("click", e) }, c.fn.bindEvent = function () { var b = this, c = b.$domNormal, d = b.$domSelected, e = b.clickEvent; e || (e = function (c) { var d = b.dropPanel || b.dropList || b.modal; if (d && d.show) return void(d.isShowing ? d.hide() : d.show()); var e, f, g = b.editor, h = b.selected; h ? (e = b.commandNameSelected, f = b.commandValueSelected) : (e = b.commandName, f = b.commandValue), e ? g.command(c, e, f) : (a.warn('菜单 "' + b.id + '" 未定义click事件'), c.preventDefault()) }); var f = b.clickEventSelected || e; c.click(function (a) { b.disabled() || (e.call(b, a), b.updateSelected()), a.preventDefault() }), d.click(function (a) { b.disabled() || (f.call(b, a), b.updateSelected()), a.preventDefault() }) }, c.fn.updateSelected = function () { var a = this, b = (a.editor, a.updateSelectedEvent); b || (b = function () { var a = this, b = a.editor, c = a.commandName, d = a.commandValue; if (d) { if (b.queryCommandValue(c).toLowerCase() === d.toLowerCase()) return !0 } else if (b.queryCommandState(c)) return !0; return !1 }); var c = b.call(a); c = !!c, a.changeSelectedState(c) }, c.fn.changeSelectedState = function (a) { var b = this, c = b.selected; if (null != a && "boolean" == typeof a) { if (c === a) return; b.selected = a, a ? (b.$domNormal.hide(), b.$domSelected.show()) : (b.$domNormal.show(), b.$domSelected.hide()) } }, c.fn.active = function (a) { return null == a ? this._activeState : void(this._activeState = a) }, c.fn.activeStyle = function (a) { var b = (this.selected, this.$domNormal), c = this.$domSelected; a ? (b.addClass("active"), c.addClass("active")) : (b.removeClass("active"), c.removeClass("active")), this.active(a) }, c.fn.disabled = function (a) { if (null == a) return !!this._disabled; if (this._disabled !== a) { var b = this.$domNormal, c = this.$domSelected; a ? (b.addClass("disable"), c.addClass("disable")) : (b.removeClass("disable"), c.removeClass("disable")), this._disabled = a } } }), b(function (a, b) { var c = function (a, b, c) { this.editor = a, this.menu = b, this.data = c.data, this.tpl = c.tpl, this.selectorForELemCommand = c.selectorForELemCommand, this.beforeEvent = c.beforeEvent, this.afterEvent = c.afterEvent, this.init() }; c.fn = c.prototype, a.DropList = c }), b(function (a, b) { var c = a.DropList; c.fn.init = function () { var a = this; a.initDOM(), a.bindEvent(), a.initHideEvent() }, c.fn.initDOM = function () { var a, c, d = this, e = d.data, f = d.tpl || "{#title}", g = b(''); b.each(e, function (d, e) { a = f.replace(/{#commandValue}/gi, d).replace(/{#title}/gi, e), c = b(''), c.append(a), g.append(c) }), d.$list = g }, c.fn.bindEvent = function () { var a = this, c = a.editor, d = a.menu, e = d.commandName, f = a.selectorForELemCommand, g = a.$list, h = a.beforeEvent, i = a.afterEvent; g.on("click", "a[commandValue]", function (a) { h && "function" == typeof h && h.call(a); var g = b(a.currentTarget).attr("commandValue"); d.selected && c.isRangeEmpty() && f ? c.commandForElem(f, a, e, g) : c.command(a, e, g), i && "function" == typeof i && i.call(a) }) }, c.fn.initHideEvent = function () { var c = this, d = c.$list.get(0); a.$body.on("click", function (a) { if (c.isShowing) { var e, f = a.target, g = c.menu; e = g.selected ? g.$domSelected.get(0) : g.$domNormal.get(0), e === f || b.contains(e, f) || d === f || b.contains(d, f) || c.hide() } }), a.$window.scroll(function () { c.hide() }), a.$window.on("resize", function () { c.hide() }) } }), b(function (a, b) { var c = a.DropList; c.fn._render = function () { var a = this, b = a.editor, c = a.$list; b.$editorContainer.append(c), a.rendered = !0 }, c.fn._position = function () { var a = this, b = a.$list, c = a.editor, d = a.menu, e = c.menuContainer.$menuContainer, f = d.selected ? d.$domSelected : d.$domNormal, g = f.offsetParent().position(), h = g.top, i = g.left, j = f.offsetParent().height(), k = f.offsetParent().width(), l = b.outerWidth(), m = c.txt.$txt.outerWidth(), n = h + j, o = i + k / 2, p = 0 - k / 2, q = o + l - m; q > -10 && (p = p - q - 10), b.css({ top: n, left: o, "margin-left": p }), c._isMenufixed && (n += e.offset().top + e.outerHeight() - b.offset().top, b.css({top: n})) }, c.fn.show = function () { var a = this, b = a.menu; if (a.rendered || a._render(), !a.isShowing) { var c = a.$list; c.show(), a._position(), a.isShowing = !0, b.activeStyle(!0) } }, c.fn.hide = function () { var a = this, b = a.menu; if (a.isShowing) { var c = a.$list; c.hide(), a.isShowing = !1, b.activeStyle(!1) } } }), b(function (a, b) { var c = function (a, b, c) { this.editor = a, this.menu = b, this.$content = c.$content, this.width = c.width || 200, this.height = c.height, this.onRender = c.onRender, this.init() }; c.fn = c.prototype, a.DropPanel = c }), b(function (a, b) { var c = a.DropPanel; c.fn.init = function () { var a = this; a.initDOM(), a.initHideEvent() }, c.fn.initDOM = function () { var a = this, c = a.$content, d = a.width, e = a.height, f = b(''), g = b(''); f.css({width: d, height: e ? e : "auto"}), f.append(g), f.append(c), a.$panel = f, a.$triangle = g }, c.fn.initHideEvent = function () { var c = this, d = c.$panel.get(0); a.$body.on("click", function (a) { if (c.isShowing) { var e, f = a.target, g = c.menu; e = g.selected ? g.$domSelected.get(0) : g.$domNormal.get(0), e === f || b.contains(e, f) || d === f || b.contains(d, f) || c.hide() } }), a.$window.scroll(function (a) { c.hide() }), a.$window.on("resize", function () { c.hide() }) } }), b(function (a, b) { var c = a.DropPanel; c.fn._render = function () { var a = this, b = a.onRender, c = a.editor, d = a.$panel; c.$editorContainer.append(d), b && b.call(a), a.rendered = !0 }, c.fn._position = function () { var a = this, b = a.$panel, c = a.$triangle, d = a.editor, e = d.menuContainer.$menuContainer, f = a.menu, g = f.selected ? f.$domSelected : f.$domNormal, h = g.offsetParent().position(), i = h.top, j = h.left, k = g.offsetParent().height(), l = g.offsetParent().width(), m = b.outerWidth(), n = d.txt.$txt.outerWidth(), o = i + k, p = j + l / 2, q = 0 - m / 2, r = q; 0 - q > p - 10 && (q = 0 - (p - 10)); var s = p + m + q - n; s > -10 && (q = q - s - 10), b.css({ top: o, left: p, "margin-left": q }), d._isMenufixed && (o += e.offset().top + e.outerHeight() - b.offset().top, b.css({top: o})), c.css({"margin-left": r - q - 5}) }, c.fn.focusFirstInput = function () { var a = this, c = a.$panel; c.find("input[type=text],textarea").each(function () { var a = b(this); if (null == a.attr("disabled")) return a.focus(), !1 }) }, c.fn.show = function () { var b = this, c = b.menu; if (b.rendered || b._render(), !b.isShowing) { var d = b.$panel; d.show(), b._position(), b.isShowing = !0, c.activeStyle(!0), a.w3cRange ? b.focusFirstInput() : a.placeholderForIE8(d) } }, c.fn.hide = function () { var a = this, b = a.menu; if (a.isShowing) { var c = a.$panel; c.hide(), a.isShowing = !1, b.activeStyle(!1) } } }), b(function (a, b) { var c = function (a, b, c) { this.editor = a, this.menu = b, this.$content = c.$content, this.init() }; c.fn = c.prototype, a.Modal = c }), b(function (a, b) { var c = a.Modal; c.fn.init = function () { var a = this; a.initDom(), a.initHideEvent() }, c.fn.initDom = function () { var a = this, c = a.$content, d = b(''), e = b('" + d.html() + "
"); d.after(a), d.remove() } } var d, e = (a.config.legalTags, this), f = e.editor, g = e.$txt; g.on("keydown keyup", function (a) { if (13 === a.keyCode) { var e, g, h = f.getRangeElem(), i = f.getLegalTags(h); if (!i) { if (i = f.getSelfOrParentByName(h, "div"), !i) return; e = b(i), "keydown" === a.type && (d = e, setTimeout(c, 0)), "keyup" === a.type && (g = b("" + e.html() + "
"), e.after(g), e.remove(), f.restoreSelectionByElem(g.get(0), "start")) } } }) }, c.fn.bindEnterForText = function () { var a, b = this, c = b.$txt; c.on("keyup", function (c) { 13 === c.keyCode && (a || (a = function () { b.wrapImgAndText() }), setTimeout(a)) }) }, c.fn.bindTabEvent = function () { var a = this, b = a.editor, c = a.$txt; c.on("keydown", function (a) { 9 === a.keyCode && b.queryCommandSupported("insertHtml") && b.command(a, "insertHtml", " ") }) }, c.fn.bindPasteFilter = function () { function a(e) { if (e && e.nodeType && e.nodeName) { var f, h, i = e.nodeName.toLowerCase(), k = e.nodeType; if (3 === k || 1 === k) { if (f = b(e), "div" === i) return h = [], b.each(e.childNodes, function (a, b) { h.push(b) }), void b.each(h, function () { a(this) }); if (j.indexOf(i) >= 0) g += c(e); else if (3 === k) g += "" + e.textContent + "
"; else if ("br" === i) g += "" + h + "
") } else if (k && k.getData) h = k.getData("text/html"), j = h.split("