diff --git a/admin/admin_ticket.php b/admin/admin_ticket.php index 899d37e6..e377927c 100644 --- a/admin/admin_ticket.php +++ b/admin/admin_ticket.php @@ -1847,22 +1847,15 @@ function hesk_printReplyForm() @@ -2138,8 +2131,8 @@ function hesk_printCanned() if (document.getElementById) { if (document.getElementById('moderep').checked) { if (isHtml) { - tinymce.get("message").setContent(''); - tinymce.get("message").execCommand('mceInsertRawHTML', false, myMsg); + $("#message").summernote('reset'); + $("#message").summernote('editor.insertText', myMsg)); } else { myMsg = $('').html(myMsg).text(); $('#message').val(myMsg).trigger('input'); @@ -2147,9 +2140,9 @@ function hesk_printCanned() } else { if (isHtml) { - var oldMsg = tinymce.get("message").getContent(); - tinymce.get("message").setContent(''); - tinymce.get("message").execCommand('mceInsertRawHTML', false, oldMsg + myMsg); + var oldMsg = $("#message").val(); + $("#message").summernote('reset'); + $("#message").summernote('editor.insertText', oldMsg + myMsg)); } else { var oldMsg = $('#message').val(); var newMsg = $('').html(oldMsg + '\n' + myMsg).text(); diff --git a/admin/edit_post.php b/admin/edit_post.php index ee3a9e19..65211dd3 100644 --- a/admin/edit_post.php +++ b/admin/edit_post.php @@ -642,27 +642,20 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); buildValidatorForTicketSubmission('form1', ""); - + @@ -679,4 +672,4 @@ function hesk_countAttachments($attachments_string) { return count($att); -} // END hesk_countAttachments() \ No newline at end of file +} // END hesk_countAttachments() diff --git a/admin/manage_canned.php b/admin/manage_canned.php index 30ee8e07..b9acc947 100644 --- a/admin/manage_canned.php +++ b/admin/manage_canned.php @@ -74,9 +74,9 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); var msg = ''; - msg = tinymce.get("message").getContent(); - tinymce.get("message").setContent(''); - tinymce.get("message").execCommand('mceInsertRawHTML', false, msg + text_to_insert); + msg = $('#message').val(); + $("#message").summernote('reset'); + $("#message").summernote('editor.insertText', msg + text_to_insert)); msg = document.getElementById('message').value; document.getElementById('message').value = msg + text_to_insert; @@ -202,22 +202,15 @@ $num = hesk_dbNumRows($result); @@ -255,8 +248,7 @@ $num = hesk_dbNumRows($result); if (myMsg == '') { if (useHtmlEditor) { - tinymce.get("message").setContent(''); - tinymce.get("message").execCommand('mceInsertRawHTML', false, ''); + $("#message").summernote("reset"); } else { $('#message').val(''); @@ -266,8 +258,8 @@ $num = hesk_dbNumRows($result); } if (document.getElementById) { if (useHtmlEditor) { - tinymce.get("message").setContent(''); - tinymce.get("message").execCommand('mceInsertRawHTML', false, myMsg); + $("#message").summernote('reset'); + $("#message").summernote('editor.insertText', myMsg)); } else { myMsg = $('').html(myMsg).text(); $('#message').val(myMsg).trigger('input'); diff --git a/admin/manage_email_templates.php b/admin/manage_email_templates.php index 4e690d14..52583be1 100644 --- a/admin/manage_email_templates.php +++ b/admin/manage_email_templates.php @@ -39,26 +39,22 @@ if (isset($_POST['action'])) { require_once(HESK_PATH . 'inc/headerAdmin.inc.php'); if ($modsForHesk_settings['html_emails']) { - echo ''; +?> + + - + /* ]]> */ + diff --git a/admin/manage_ticket_templates.php b/admin/manage_ticket_templates.php index 9208a085..4440e279 100644 --- a/admin/manage_ticket_templates.php +++ b/admin/manage_ticket_templates.php @@ -286,22 +286,15 @@ $num = hesk_dbNumRows($result); @@ -326,8 +319,7 @@ $num = hesk_dbNumRows($result); if (myMsg == '') { if (useHtmlEditor) { - tinymce.get("message").setContent(''); - tinymce.get("message").execCommand('mceInsertRawHTML', false, ''); + $("#message").summernote('reset'); } else { $('#message').val(''); @@ -337,8 +329,8 @@ $num = hesk_dbNumRows($result); } if (document.getElementById) { if (useHtmlEditor) { - tinymce.get("message").setContent(''); - tinymce.get("message").execCommand('mceInsertRawHTML', false, myMsg); + $("#message").summernote('reset'); + $("#message").summernote('editor.insertText', myMsg)); } else { myMsg = $('').html(myMsg).text(); $('#message').val(myMsg).trigger('input'); diff --git a/admin/new_ticket.php b/admin/new_ticket.php index 9233b35b..22ff7534 100644 --- a/admin/new_ticket.php +++ b/admin/new_ticket.php @@ -193,22 +193,15 @@ $show_quick_help = $show['show']; @@ -539,8 +532,7 @@ $show_quick_help = $show['show']; if (myMsg == '') { if (document.form1.mode[1].checked) { if (useHtmlEditor) { - tinymce.get("message").setContent(''); - tinymce.get("message").execCommand('mceInsertRawHTML', false, ''); + $("#message").summernote('reset'); } else { $('#message').val(''); @@ -552,8 +544,8 @@ $show_quick_help = $show['show']; if (document.getElementById) { if (document.getElementById('moderep').checked) { if (useHtmlEditor) { - tinymce.get("message").setContent(''); - tinymce.get("message").execCommand('mceInsertRawHTML', false, myMsg); + $("#message").summernote('reset'); + $("#message").summernote('editor.insertText', myMsg)); } else { myMsg = $('').html(myMsg).text(); $('#message').val(myMsg).trigger('input'); @@ -563,9 +555,9 @@ $show_quick_help = $show['show']; } else { if (useHtmlEditor) { - var oldMsg = tinymce.get("message").getContent(); - tinymce.get("message").setContent(''); - tinymce.get("message").execCommand('mceInsertRawHTML', false, oldMsg + myMsg); + var oldMsg = $("#message").val(); + $("#message").summernote('reset'); + $("#message").summernote('editor.insertText', oldMsg + myMsg)); } else { var oldMsg = document.getElementById('message').value; var theMsg = $('').html(oldMsg + myMsg).text(); @@ -998,8 +990,8 @@ if ($modsForHesk_settings['rich_text_for_tickets']) { $message = hesk_SESSION('as_message', ''); echo " "; } diff --git a/admin/service_messages.php b/admin/service_messages.php index 580d0012..0f941f17 100644 --- a/admin/service_messages.php +++ b/admin/service_messages.php @@ -126,23 +126,18 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php'); if ($hesk_settings['kb_wysiwyg']) { ?> .btn-group,.panel-heading.note-toolbar>.btn-group{margin-top:5px;margin-right:5px;margin-left:0}.note-popover .popover-content .btn-group .note-table,.panel-heading.note-toolbar .btn-group .note-table{min-width:0;padding:5px}.note-popover .popover-content .btn-group .note-table .note-dimension-picker,.panel-heading.note-toolbar .btn-group .note-table .note-dimension-picker{font-size:18px}.note-popover .popover-content .btn-group .note-table .note-dimension-picker .note-dimension-picker-mousecatcher,.panel-heading.note-toolbar .btn-group .note-table .note-dimension-picker .note-dimension-picker-mousecatcher{position:absolute!important;z-index:3;width:10em;height:10em;cursor:pointer}.note-popover .popover-content .btn-group .note-table .note-dimension-picker .note-dimension-picker-unhighlighted,.panel-heading.note-toolbar .btn-group .note-table .note-dimension-picker .note-dimension-picker-unhighlighted{position:relative!important;z-index:1;width:5em;height:5em;background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASAgMAAAAroGbEAAAACVBMVEUAAIj4+Pjp6ekKlAqjAAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfYAR0BKhmnaJzPAAAAG0lEQVQI12NgAAOtVatWMTCohoaGUY+EmIkEAEruEzK2J7tvAAAAAElFTkSuQmCC') repeat}.note-popover .popover-content .btn-group .note-table .note-dimension-picker .note-dimension-picker-highlighted,.panel-heading.note-toolbar .btn-group .note-table .note-dimension-picker .note-dimension-picker-highlighted{position:absolute!important;z-index:2;width:1em;height:1em;background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASAgMAAAAroGbEAAAACVBMVEUAAIjd6vvD2f9LKLW+AAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfYAR0BKwNDEVT0AAAAG0lEQVQI12NgAAOtVatWMTCohoaGUY+EmIkEAEruEzK2J7tvAAAAAElFTkSuQmCC') repeat}.note-popover .popover-content .note-style h1,.panel-heading.note-toolbar .note-style h1,.note-popover .popover-content .note-style h2,.panel-heading.note-toolbar .note-style h2,.note-popover .popover-content .note-style h3,.panel-heading.note-toolbar .note-style h3,.note-popover .popover-content .note-style h4,.panel-heading.note-toolbar .note-style h4,.note-popover .popover-content .note-style h5,.panel-heading.note-toolbar .note-style h5,.note-popover .popover-content .note-style h6,.panel-heading.note-toolbar .note-style h6,.note-popover .popover-content .note-style blockquote,.panel-heading.note-toolbar .note-style blockquote{margin:0}.note-popover .popover-content .note-color .dropdown-toggle,.panel-heading.note-toolbar .note-color .dropdown-toggle{width:20px;padding-left:5px}.note-popover .popover-content .note-color .dropdown-menu,.panel-heading.note-toolbar .note-color .dropdown-menu{min-width:340px}.note-popover .popover-content .note-color .dropdown-menu .btn-group,.panel-heading.note-toolbar .note-color .dropdown-menu .btn-group{margin:0}.note-popover .popover-content .note-color .dropdown-menu .btn-group:first-child,.panel-heading.note-toolbar .note-color .dropdown-menu .btn-group:first-child{margin:0 5px}.note-popover .popover-content .note-color .dropdown-menu .btn-group .note-palette-title,.panel-heading.note-toolbar .note-color .dropdown-menu .btn-group .note-palette-title{margin:2px 7px;font-size:12px;text-align:center;border-bottom:1px solid #eee}.note-popover .popover-content .note-color .dropdown-menu .btn-group .note-color-reset,.panel-heading.note-toolbar .note-color .dropdown-menu .btn-group .note-color-reset{width:100%;padding:0 3px;margin:3px;font-size:11px;cursor:pointer;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}.note-popover .popover-content .note-color .dropdown-menu .btn-group .note-color-row,.panel-heading.note-toolbar .note-color .dropdown-menu .btn-group .note-color-row{height:20px}.note-popover .popover-content .note-color .dropdown-menu .btn-group .note-color-reset:hover,.panel-heading.note-toolbar .note-color .dropdown-menu .btn-group .note-color-reset:hover{background:#eee}.note-popover .popover-content .note-para .dropdown-menu,.panel-heading.note-toolbar .note-para .dropdown-menu{min-width:216px;padding:5px}.note-popover .popover-content .note-para .dropdown-menu>div:first-child,.panel-heading.note-toolbar .note-para .dropdown-menu>div:first-child{margin-right:5px}.note-popover .popover-content .dropdown-menu,.panel-heading.note-toolbar .dropdown-menu{min-width:90px}.note-popover .popover-content .dropdown-menu.right,.panel-heading.note-toolbar .dropdown-menu.right{right:0;left:auto}.note-popover .popover-content .dropdown-menu.right::before,.panel-heading.note-toolbar .dropdown-menu.right::before{right:9px;left:auto!important}.note-popover .popover-content .dropdown-menu.right::after,.panel-heading.note-toolbar .dropdown-menu.right::after{right:10px;left:auto!important}.note-popover .popover-content .dropdown-menu.note-check li a i,.panel-heading.note-toolbar .dropdown-menu.note-check li a i{color:deepskyblue;visibility:hidden}.note-popover .popover-content .dropdown-menu.note-check li a.checked i,.panel-heading.note-toolbar .dropdown-menu.note-check li a.checked i{visibility:visible}.note-popover .popover-content .note-fontsize-10,.panel-heading.note-toolbar .note-fontsize-10{font-size:10px}.note-popover .popover-content .note-color-palette,.panel-heading.note-toolbar .note-color-palette{line-height:1}.note-popover .popover-content .note-color-palette div .note-color-btn,.panel-heading.note-toolbar .note-color-palette div .note-color-btn{width:20px;height:20px;padding:0;margin:0;border:1px solid #fff}.note-popover .popover-content .note-color-palette div .note-color-btn:hover,.panel-heading.note-toolbar .note-color-palette div .note-color-btn:hover{border:1px solid #000}.note-dialog>div{display:none}.note-dialog .form-group{margin-right:0;margin-left:0}.note-dialog .note-modal-form{margin:0}.note-dialog .note-image-dialog .note-dropzone{min-height:100px;margin-bottom:10px;font-size:30px;line-height:4;color:lightgray;text-align:center;border:4px dashed lightgray}@-moz-document url-prefix(){.note-image-input{height:auto}}.note-placeholder{position:absolute;display:none;color:gray}.note-handle .note-control-selection{position:absolute;display:none;border:1px solid black}.note-handle .note-control-selection>div{position:absolute}.note-handle .note-control-selection .note-control-selection-bg{width:100%;height:100%;background-color:black;-webkit-opacity:.3;-khtml-opacity:.3;-moz-opacity:.3;opacity:.3;-ms-filter:alpha(opacity=30);filter:alpha(opacity=30)}.note-handle .note-control-selection .note-control-handle{width:7px;height:7px;border:1px solid black}.note-handle .note-control-selection .note-control-holder{width:7px;height:7px;border:1px solid black}.note-handle .note-control-selection .note-control-sizing{width:7px;height:7px;background-color:white;border:1px solid black}.note-handle .note-control-selection .note-control-nw{top:-5px;left:-5px;border-right:0;border-bottom:0}.note-handle .note-control-selection .note-control-ne{top:-5px;right:-5px;border-bottom:0;border-left:none}.note-handle .note-control-selection .note-control-sw{bottom:-5px;left:-5px;border-top:0;border-right:0}.note-handle .note-control-selection .note-control-se{right:-5px;bottom:-5px;cursor:se-resize}.note-handle .note-control-selection .note-control-se.note-control-holder{cursor:default;border-top:0;border-left:none}.note-handle .note-control-selection .note-control-selection-info{right:0;bottom:0;padding:5px;margin:5px;font-size:12px;color:white;background-color:black;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;-webkit-opacity:.7;-khtml-opacity:.7;-moz-opacity:.7;opacity:.7;-ms-filter:alpha(opacity=70);filter:alpha(opacity=70)}.note-hint-popover{min-width:100px;padding:2px}.note-hint-popover .popover-content{max-height:150px;padding:3px;overflow:auto}.note-hint-popover .popover-content .note-hint-group .note-hint-item{display:block!important;padding:3px}.note-hint-popover .popover-content .note-hint-group .note-hint-item.active,.note-hint-popover .popover-content .note-hint-group .note-hint-item:hover{display:block;clear:both;font-weight:400;line-height:1.4;color:white;text-decoration:none;white-space:nowrap;cursor:pointer;background-color:#428bca;outline:0} \ No newline at end of file diff --git a/inc/header.inc.php b/inc/header.inc.php index 192e1580..eb30be2e 100644 --- a/inc/header.inc.php +++ b/inc/header.inc.php @@ -173,10 +173,11 @@ if (is_dir(HESK_PATH . 'install')) { - + + - + + @@ -1601,4 +1594,4 @@ function has_public_kb($use_cache=1) { return $hesk_settings['kb_enable']; -} // End has_public_kb() \ No newline at end of file +} // End has_public_kb() diff --git a/js/summernote.js b/js/summernote.js new file mode 100644 index 00000000..8675c643 --- /dev/null +++ b/js/summernote.js @@ -0,0 +1,7896 @@ +/** + * Super simple wysiwyg editor v0.8.6 + * http://summernote.org/ + * + * summernote.js + * Copyright 2013- Alan Hong. and other contributors + * summernote may be freely distributed under the MIT license./ + * + * Date: 2017-07-16T16:33Z + */ +(function (factory) { + /* global define */ + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['jquery'], factory); + } else if (typeof module === 'object' && module.exports) { + // Node/CommonJS + module.exports = factory(require('jquery')); + } else { + // Browser globals + factory(window.jQuery); + } +}(function ($) { + 'use strict'; + + var isSupportAmd = typeof define === 'function' && define.amd; + + /** + * returns whether font is installed or not. + * + * @param {String} fontName + * @return {Boolean} + */ + var isFontInstalled = function (fontName) { + var testFontName = fontName === 'Comic Sans MS' ? 'Courier New' : 'Comic Sans MS'; + var $tester = $('
] + var ancestors = listAncestor(point.node, func.eq(root)); + + if (!ancestors.length) { + return null; + } else if (ancestors.length === 1) { + return splitNode(point, options); + } + + return ancestors.reduce(function (node, parent) { + if (node === point.node) { + node = splitNode(point, options); + } + + return splitNode({ + node: parent, + offset: node ? dom.position(node) : nodeLength(parent) + }, options); + }); + }; + + /** + * split point + * + * @param {Point} point + * @param {Boolean} isInline + * @return {Object} + */ + var splitPoint = function (point, isInline) { + // find splitRoot, container + // - inline: splitRoot is a child of paragraph + // - block: splitRoot is a child of bodyContainer + var pred = isInline ? isPara : isBodyContainer; + var ancestors = listAncestor(point.node, pred); + var topAncestor = list.last(ancestors) || point.node; + + var splitRoot, container; + if (pred(topAncestor)) { + splitRoot = ancestors[ancestors.length - 2]; + container = topAncestor; + } else { + splitRoot = topAncestor; + container = splitRoot.parentNode; + } + + // if splitRoot is exists, split with splitTree + var pivot = splitRoot && splitTree(splitRoot, point, { + isSkipPaddingBlankHTML: isInline, + isNotSplitEdgePoint: isInline + }); + + // if container is point.node, find pivot with point.offset + if (!pivot && container === point.node) { + pivot = point.node.childNodes[point.offset]; + } + + return { + rightNode: pivot, + container: container + }; + }; + + var create = function (nodeName) { + return document.createElement(nodeName); + }; + + var createText = function (text) { + return document.createTextNode(text); + }; + + /** + * @method remove + * + * remove node, (isRemoveChild: remove child or not) + * + * @param {Node} node + * @param {Boolean} isRemoveChild + */ + var remove = function (node, isRemoveChild) { + if (!node || !node.parentNode) { return; } + if (node.removeNode) { return node.removeNode(isRemoveChild); } + + var parent = node.parentNode; + if (!isRemoveChild) { + var nodes = []; + var i, len; + for (i = 0, len = node.childNodes.length; i < len; i++) { + nodes.push(node.childNodes[i]); + } + + for (i = 0, len = nodes.length; i < len; i++) { + parent.insertBefore(nodes[i], node); + } + } + + parent.removeChild(node); + }; + + /** + * @method removeWhile + * + * @param {Node} node + * @param {Function} pred + */ + var removeWhile = function (node, pred) { + while (node) { + if (isEditable(node) || !pred(node)) { + break; + } + + var parent = node.parentNode; + remove(node); + node = parent; + } + }; + + /** + * @method replace + * + * replace node with provided nodeName + * + * @param {Node} node + * @param {String} nodeName + * @return {Node} - new node + */ + var replace = function (node, nodeName) { + if (node.nodeName.toUpperCase() === nodeName.toUpperCase()) { + return node; + } + + var newNode = create(nodeName); + + if (node.style.cssText) { + newNode.style.cssText = node.style.cssText; + } + + appendChildNodes(newNode, list.from(node.childNodes)); + insertAfter(newNode, node); + remove(node); + + return newNode; + }; + + var isTextarea = makePredByNodeName('TEXTAREA'); + + /** + * @param {jQuery} $node + * @param {Boolean} [stripLinebreaks] - default: false + */ + var value = function ($node, stripLinebreaks) { + var val = isTextarea($node[0]) ? $node.val() : $node.html(); + if (stripLinebreaks) { + return val.replace(/[\n\r]/g, ''); + } + return val; + }; + + /** + * @method html + * + * get the HTML contents of node + * + * @param {jQuery} $node + * @param {Boolean} [isNewlineOnBlock] + */ + var html = function ($node, isNewlineOnBlock) { + var markup = value($node); + + if (isNewlineOnBlock) { + var regexTag = /<(\/?)(\b(?!!)[^>\s]*)(.*?)(\s*\/?>)/g; + markup = markup.replace(regexTag, function (match, endSlash, name) { + name = name.toUpperCase(); + var isEndOfInlineContainer = /^DIV|^TD|^TH|^P|^LI|^H[1-7]/.test(name) && + !!endSlash; + var isBlockNode = /^BLOCKQUOTE|^TABLE|^TBODY|^TR|^HR|^UL|^OL/.test(name); + + return match + ((isEndOfInlineContainer || isBlockNode) ? '\n' : ''); + }); + markup = $.trim(markup); + } + + return markup; + }; + + var posFromPlaceholder = function (placeholder) { + var $placeholder = $(placeholder); + var pos = $placeholder.offset(); + var height = $placeholder.outerHeight(true); // include margin + + return { + left: pos.left, + top: pos.top + height + }; + }; + + var attachEvents = function ($node, events) { + Object.keys(events).forEach(function (key) { + $node.on(key, events[key]); + }); + }; + + var detachEvents = function ($node, events) { + Object.keys(events).forEach(function (key) { + $node.off(key, events[key]); + }); + }; + + /** + * @method isCustomStyleTag + * + * assert if a node contains a "note-styletag" class, + * which implies that's a custom-made style tag node + * + * @param {Node} an HTML DOM node + */ + var isCustomStyleTag = function (node) { + return node && !dom.isText(node) && list.contains(node.classList, 'note-styletag'); + }; + + return { + /** @property {String} NBSP_CHAR */ + NBSP_CHAR: NBSP_CHAR, + /** @property {String} ZERO_WIDTH_NBSP_CHAR */ + ZERO_WIDTH_NBSP_CHAR: ZERO_WIDTH_NBSP_CHAR, + /** @property {String} blank */ + blank: blankHTML, + /** @property {String} emptyPara */ + emptyPara: '
' + blankHTML + '
', + makePredByNodeName: makePredByNodeName, + isEditable: isEditable, + isControlSizing: isControlSizing, + isText: isText, + isElement: isElement, + isVoid: isVoid, + isPara: isPara, + isPurePara: isPurePara, + isHeading: isHeading, + isInline: isInline, + isBlock: func.not(isInline), + isBodyInline: isBodyInline, + isBody: isBody, + isParaInline: isParaInline, + isPre: isPre, + isList: isList, + isTable: isTable, + isData: isData, + isCell: isCell, + isBlockquote: isBlockquote, + isBodyContainer: isBodyContainer, + isAnchor: isAnchor, + isDiv: makePredByNodeName('DIV'), + isLi: isLi, + isBR: makePredByNodeName('BR'), + isSpan: makePredByNodeName('SPAN'), + isB: makePredByNodeName('B'), + isU: makePredByNodeName('U'), + isS: makePredByNodeName('S'), + isI: makePredByNodeName('I'), + isImg: makePredByNodeName('IMG'), + isTextarea: isTextarea, + isEmpty: isEmpty, + isEmptyAnchor: func.and(isAnchor, isEmpty), + isClosestSibling: isClosestSibling, + withClosestSiblings: withClosestSiblings, + nodeLength: nodeLength, + isLeftEdgePoint: isLeftEdgePoint, + isRightEdgePoint: isRightEdgePoint, + isEdgePoint: isEdgePoint, + isLeftEdgeOf: isLeftEdgeOf, + isRightEdgeOf: isRightEdgeOf, + isLeftEdgePointOf: isLeftEdgePointOf, + isRightEdgePointOf: isRightEdgePointOf, + prevPoint: prevPoint, + nextPoint: nextPoint, + isSamePoint: isSamePoint, + isVisiblePoint: isVisiblePoint, + prevPointUntil: prevPointUntil, + nextPointUntil: nextPointUntil, + isCharPoint: isCharPoint, + walkPoint: walkPoint, + ancestor: ancestor, + singleChildAncestor: singleChildAncestor, + listAncestor: listAncestor, + lastAncestor: lastAncestor, + listNext: listNext, + listPrev: listPrev, + listDescendant: listDescendant, + commonAncestor: commonAncestor, + wrap: wrap, + insertAfter: insertAfter, + appendChildNodes: appendChildNodes, + position: position, + hasChildren: hasChildren, + makeOffsetPath: makeOffsetPath, + fromOffsetPath: fromOffsetPath, + splitTree: splitTree, + splitPoint: splitPoint, + create: create, + createText: createText, + remove: remove, + removeWhile: removeWhile, + replace: replace, + html: html, + value: value, + posFromPlaceholder: posFromPlaceholder, + attachEvents: attachEvents, + detachEvents: detachEvents, + isCustomStyleTag: isCustomStyleTag + }; + })(); + + /** + * @param {jQuery} $note + * @param {Object} options + * @return {Context} + */ + var Context = function ($note, options) { + var self = this; + + var ui = $.summernote.ui; + this.memos = {}; + this.modules = {}; + this.layoutInfo = {}; + this.options = options; + + /** + * create layout and initialize modules and other resources + */ + this.initialize = function () { + this.layoutInfo = ui.createLayout($note, options); + this._initialize(); + $note.hide(); + return this; + }; + + /** + * destroy modules and other resources and remove layout + */ + this.destroy = function () { + this._destroy(); + $note.removeData('summernote'); + ui.removeLayout($note, this.layoutInfo); + }; + + /** + * destory modules and other resources and initialize it again + */ + this.reset = function () { + var disabled = self.isDisabled(); + this.code(dom.emptyPara); + this._destroy(); + this._initialize(); + + if (disabled) { + self.disable(); + } + }; + + this._initialize = function () { + // add optional buttons + var buttons = $.extend({}, this.options.buttons); + Object.keys(buttons).forEach(function (key) { + self.memo('button.' + key, buttons[key]); + }); + + var modules = $.extend({}, this.options.modules, $.summernote.plugins || {}); + + // add and initialize modules + Object.keys(modules).forEach(function (key) { + self.module(key, modules[key], true); + }); + + Object.keys(this.modules).forEach(function (key) { + self.initializeModule(key); + }); + }; + + this._destroy = function () { + // destroy modules with reversed order + Object.keys(this.modules).reverse().forEach(function (key) { + self.removeModule(key); + }); + + Object.keys(this.memos).forEach(function (key) { + self.removeMemo(key); + }); + // trigger custom onDestroy callback + this.triggerEvent('destroy', this); + }; + + this.code = function (html) { + var isActivated = this.invoke('codeview.isActivated'); + + if (html === undefined) { + this.invoke('codeview.sync'); + return isActivated ? this.layoutInfo.codable.val() : this.layoutInfo.editable.html(); + } else { + if (isActivated) { + this.layoutInfo.codable.val(html); + } else { + this.layoutInfo.editable.html(html); + } + $note.val(html); + this.triggerEvent('change', html); + } + }; + + this.isDisabled = function () { + return this.layoutInfo.editable.attr('contenteditable') === 'false'; + }; + + this.enable = function () { + this.layoutInfo.editable.attr('contenteditable', true); + this.invoke('toolbar.activate', true); + this.triggerEvent('disable', false); + }; + + this.disable = function () { + // close codeview if codeview is opend + if (this.invoke('codeview.isActivated')) { + this.invoke('codeview.deactivate'); + } + this.layoutInfo.editable.attr('contenteditable', false); + this.invoke('toolbar.deactivate', true); + + this.triggerEvent('disable', true); + }; + + this.triggerEvent = function () { + var namespace = list.head(arguments); + var args = list.tail(list.from(arguments)); + + var callback = this.options.callbacks[func.namespaceToCamel(namespace, 'on')]; + if (callback) { + callback.apply($note[0], args); + } + $note.trigger('summernote.' + namespace, args); + }; + + this.initializeModule = function (key) { + var module = this.modules[key]; + module.shouldInitialize = module.shouldInitialize || func.ok; + if (!module.shouldInitialize()) { + return; + } + + // initialize module + if (module.initialize) { + module.initialize(); + } + + // attach events + if (module.events) { + dom.attachEvents($note, module.events); + } + }; + + this.module = function (key, ModuleClass, withoutIntialize) { + if (arguments.length === 1) { + return this.modules[key]; + } + + this.modules[key] = new ModuleClass(this); + + if (!withoutIntialize) { + this.initializeModule(key); + } + }; + + this.removeModule = function (key) { + var module = this.modules[key]; + if (module.shouldInitialize()) { + if (module.events) { + dom.detachEvents($note, module.events); + } + + if (module.destroy) { + module.destroy(); + } + } + + delete this.modules[key]; + }; + + this.memo = function (key, obj) { + if (arguments.length === 1) { + return this.memos[key]; + } + this.memos[key] = obj; + }; + + this.removeMemo = function (key) { + if (this.memos[key] && this.memos[key].destroy) { + this.memos[key].destroy(); + } + + delete this.memos[key]; + }; + + /** + *Some buttons need to change their visual style immediately once they get pressed + */ + this.createInvokeHandlerAndUpdateState = function (namespace, value) { + return function (event) { + self.createInvokeHandler(namespace, value)(event); + self.invoke('buttons.updateCurrentStyle'); + }; + }; + + this.createInvokeHandler = function (namespace, value) { + return function (event) { + event.preventDefault(); + var $target = $(event.target); + self.invoke(namespace, value || $target.closest('[data-value]').data('value'), $target); + }; + }; + + this.invoke = function () { + var namespace = list.head(arguments); + var args = list.tail(list.from(arguments)); + + var splits = namespace.split('.'); + var hasSeparator = splits.length > 1; + var moduleName = hasSeparator && list.head(splits); + var methodName = hasSeparator ? list.last(splits) : list.head(splits); + + var module = this.modules[moduleName || 'editor']; + if (!moduleName && this[methodName]) { + return this[methodName].apply(this, args); + } else if (module && module[methodName] && module.shouldInitialize()) { + return module[methodName].apply(module, args); + } + }; + + return this.initialize(); + }; + + $.fn.extend({ + /** + * Summernote API + * + * @param {Object|String} + * @return {this} + */ + summernote: function () { + var type = $.type(list.head(arguments)); + var isExternalAPICalled = type === 'string'; + var hasInitOptions = type === 'object'; + + var options = hasInitOptions ? list.head(arguments) : {}; + + options = $.extend({}, $.summernote.options, options); + + // Update options + options.langInfo = $.extend(true, {}, $.summernote.lang['en-US'], $.summernote.lang[options.lang]); + options.icons = $.extend(true, {}, $.summernote.options.icons, options.icons); + options.tooltip = options.tooltip === 'auto' ? !agent.isSupportTouch : options.tooltip; + + this.each(function (idx, note) { + var $note = $(note); + if (!$note.data('summernote')) { + var context = new Context($note, options); + $note.data('summernote', context); + $note.data('summernote').triggerEvent('init', context.layoutInfo); + } + }); + + var $note = this.first(); + if ($note.length) { + var context = $note.data('summernote'); + if (isExternalAPICalled) { + return context.invoke.apply(context, list.from(arguments)); + } else if (options.focus) { + context.invoke('editor.focus'); + } + } + + return this; + } + }); + + + var Renderer = function (markup, children, options, callback) { + this.render = function ($parent) { + var $node = $(markup); + + if (options && options.contents) { + $node.html(options.contents); + } + + if (options && options.className) { + $node.addClass(options.className); + } + + if (options && options.data) { + $.each(options.data, function (k, v) { + $node.attr('data-' + k, v); + }); + } + + if (options && options.click) { + $node.on('click', options.click); + } + + if (children) { + var $container = $node.find('.note-children-container'); + children.forEach(function (child) { + child.render($container.length ? $container : $node); + }); + } + + if (callback) { + callback($node, options); + } + + if (options && options.callback) { + options.callback($node); + } + + if ($parent) { + $parent.append($node); + } + + return $node; + }; + }; + + var renderer = { + create: function (markup, callback) { + return function () { + var children = $.isArray(arguments[0]) ? arguments[0] : []; + var options = typeof arguments[1] === 'object' ? arguments[1] : arguments[0]; + if (options && options.children) { + children = options.children; + } + return new Renderer(markup, children, options, callback); + }; + } + }; + + var editor = renderer.create(''); + var toolbar = renderer.create(''); + var editingArea = renderer.create(''); + var codable = renderer.create(''); + var editable = renderer.create(''); + var statusbar = renderer.create([ + ' ' + ].join('')); + + var airEditor = renderer.create(''); + var airEditable = renderer.create(''); + + var buttonGroup = renderer.create('