Mercurial Hosting > sceditor
changeset 36:21090996a131
clean up TokenizeToken
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 16 Aug 2022 13:50:36 -0600 |
parents | cd02cd04bc9d |
children | 0c4e4b5ef40d |
files | src/formats/bbcode.js src/sceditor.js |
diffstat | 2 files changed, 12 insertions(+), 128 deletions(-) [+] |
line wrap: on
line diff
--- a/src/formats/bbcode.js Mon Aug 15 22:57:06 2022 -0600 +++ b/src/formats/bbcode.js Tue Aug 16 13:50:36 2022 -0600 @@ -970,13 +970,11 @@ * @param {array} children Any children of this token * @param {TokenizeToken} closing This tokens closing tag. * Only set on TOKEN_TYPE_OPEN tokens - * @class {TokenizeToken} * @name {TokenizeToken} - * @memberOf BBCodeParser.prototype */ // eslint-disable-next-line max-params - function TokenizeToken(type, name, val, attrib, children, closing) { - var base = this; + function newTokenizeToken(type, name, val, attrib, children, closing) { + let base = {}; base.type = type; base.name = name; @@ -984,19 +982,9 @@ base.attrib = attrib; base.children = children || []; base.closing = closing || null; - }; - TokenizeToken.prototype = { - /** @lends BBCodeParser.prototype.TokenizeToken */ - /** - * Clones this token - * - * @return {TokenizeToken} - */ - clone: function () { - var base = this; - - return new TokenizeToken( + base.clone = function () { + return newTokenizeToken( base.type, base.name, base.val, @@ -1004,31 +992,24 @@ [], base.closing ? base.closing.clone() : null ); - }, - /** - * Splits this token at the specified child - * - * @param {TokenizeToken} splitAt The child to split at - * @return {TokenizeToken} The right half of the split token or - * empty clone if invalid splitAt lcoation - */ - splitAt: function (splitAt) { - var offsetLength; - var base = this; + }; + + base.splitAt = function (splitAt) { var clone = base.clone(); var offset = base.children.indexOf(splitAt); if (offset > -1) { // Work out how many items are on the right side of the split // to pass to splice() - offsetLength = base.children.length - offset; + let offsetLength = base.children.length - offset; clone.children = base.children.splice(offset, offsetLength); } return clone; - } - }; + }; + return base; + } /** * SCEditor BBCode parser class @@ -1054,7 +1035,6 @@ * * @param {string} str * @return {array} - * @memberOf BBCodeParser.prototype */ base.tokenize = function (str) { var matches, type, i; @@ -1157,7 +1137,7 @@ name = '#'; } - return new TokenizeToken(type, name, val, attrib); + return newTokenizeToken(type, name, val, attrib); } /** @@ -1168,7 +1148,6 @@ * strip any based on the passed * formatting options * @return {array} Array of BBCode objects - * @memberOf BBCodeParser.prototype */ base.parse = function (str, preserveNewLines) { var ret = parseTokens(base.tokenize(str)); @@ -1737,7 +1716,6 @@ * strip any based on the passed * formatting options * @return {string} - * @memberOf BBCodeParser.prototype */ base.toHTML = function (str, preserveNewLines) { return convertToHTML(base.parse(str, preserveNewLines), true); @@ -1856,7 +1834,6 @@ * strip any based on the passed * formatting options * @return {string} - * @memberOf BBCodeParser.prototype */ base.toBBCode = function (str, preserveNewLines) { return convertToBBCode(base.parse(str, preserveNewLines)); @@ -2375,7 +2352,6 @@ * @private * @param {HTMLElement} element * @return {string} BBCode - * @memberOf SCEditor.plugins.bbcode.prototype */ function elementToBbcode(element) { var toBBCode = function (node, vChildren) {
--- a/src/sceditor.js Mon Aug 15 22:57:06 2022 -0600 +++ b/src/sceditor.js Tue Aug 16 13:50:36 2022 -0600 @@ -2907,7 +2907,6 @@ * @param {...string} args * @function * @name call - * @memberOf PluginManager.prototype */ base.call = function () { callHandlers(arguments, false); @@ -2921,7 +2920,6 @@ * @return {*} The result of calling the handler * @function * @name callOnlyFirst - * @memberOf PluginManager.prototype */ base.callOnlyFirst = function () { return callHandlers(arguments, true); @@ -2934,7 +2932,6 @@ * @return {boolean} * @function * @name hasHandler - * @memberOf PluginManager.prototype */ base.hasHandler = function (signal) { var i = registeredPlugins.length; @@ -2956,7 +2953,6 @@ * @return {boolean} * @function * @name exists - * @memberOf PluginManager.prototype */ base.exists = function (plugin) { if (plugin in plugins) { @@ -2976,7 +2972,6 @@ * @return {boolean} * @function * @name isRegistered - * @memberOf PluginManager.prototype */ base.isRegistered = function (plugin) { if (base.exists(plugin)) { @@ -2999,7 +2994,6 @@ * @return {boolean} * @function * @name register - * @memberOf PluginManager.prototype */ base.register = function (pluginName) { if (!base.exists(pluginName) || base.isRegistered(pluginName)) { @@ -3024,7 +3018,6 @@ * @return {boolean} * @function * @name deregister - * @memberOf PluginManager.prototype */ base.deregister = function (plugin) { var removedPlugin, @@ -3056,7 +3049,6 @@ * destroy will cause a JS error. * * @name destroy - * @memberOf PluginManager.prototype */ base.destroy = function () { var i = registeredPlugins.length; @@ -3164,7 +3156,6 @@ * @return False on fail * @function * @name insertHTML - * @memberOf RangeHelper.prototype */ base.insertHTML = function (html, endHTML) { var node, div, @@ -3268,7 +3259,6 @@ * @return {false|undefined} * @function * @name insertNode - * @memberOf RangeHelper.prototype */ base.insertNode = function (node, endNode) { var first, last, @@ -3329,7 +3319,6 @@ * @return {Range} * @function * @name cloneSelected - * @memberOf RangeHelper.prototype */ base.cloneSelected = function () { var range = base.selectedRange(); @@ -3345,7 +3334,6 @@ * @return {Range} * @function * @name selectedRange - * @memberOf RangeHelper.prototype */ base.selectedRange = function () { var range, firstChild, @@ -3385,7 +3373,6 @@ * @function * @name hasSelection * @since 1.4.4 - * @memberOf RangeHelper.prototype */ base.hasSelection = function () { var sel = win.getSelection(); @@ -3399,7 +3386,6 @@ * @return {string} * @function * @name selectedHtml - * @memberOf RangeHelper.prototype */ base.selectedHtml = function () { var div, @@ -3421,7 +3407,6 @@ * @return {HTMLElement} * @function * @name parentNode - * @memberOf RangeHelper.prototype */ base.parentNode = function () { var range = base.selectedRange(); @@ -3438,7 +3423,6 @@ * @return {HTMLElement} * @function * @name getFirstBlockParent - * @memberOf RangeHelper.prototype */ /** * Gets the first block level parent of the selected @@ -3449,7 +3433,6 @@ * @function * @name getFirstBlockParent^2 * @since 1.4.1 - * @memberOf RangeHelper.prototype */ base.getFirstBlockParent = function (node) { var func = function (elm) { @@ -3472,7 +3455,6 @@ * @param {Node} node * @function * @name insertNodeAt - * @memberOf RangeHelper.prototype */ base.insertNodeAt = function (start, node) { var currentRange = base.selectedRange(), @@ -3516,7 +3498,6 @@ * which can be used by restoreRange to re-select the * range. * - * @memberOf RangeHelper.prototype * @function * @name insertMarkers */ @@ -3544,7 +3525,6 @@ * @return {Node} * @function * @name getMarker - * @memberOf RangeHelper.prototype */ base.getMarker = function (id) { return doc.getElementById(id); @@ -3556,7 +3536,6 @@ * @param {string} id * @function * @name removeMarker - * @memberOf RangeHelper.prototype */ base.removeMarker = function (id) { var marker = base.getMarker(id); @@ -3571,7 +3550,6 @@ * * @function * @name removeMarkers - * @memberOf RangeHelper.prototype */ base.removeMarkers = function () { base.removeMarker(startMarker); @@ -3583,7 +3561,6 @@ * * @function * @name saveRage - * @memberOf RangeHelper.prototype */ base.saveRange = function () { base.insertMarkers(); @@ -3595,7 +3572,6 @@ * @param {Range} range * @function * @name selectRange - * @memberOf RangeHelper.prototype */ base.selectRange = function (range) { var lastChild; @@ -3636,7 +3612,6 @@ * * @function * @name restoreRange - * @memberOf RangeHelper.prototype */ base.restoreRange = function () { var isCollapsed, @@ -3670,7 +3645,6 @@ * @since 1.4.3 * @function * @name selectOuterText - * @memberOf RangeHelper.prototype */ base.selectOuterText = function (left, right) { var start, end, @@ -3700,7 +3674,6 @@ * @since 1.4.3 * @function * @name selectOuterText - * @memberOf RangeHelper.prototype */ base.getOuterText = function (before, length) { var range = base.cloneSelected(); @@ -3732,7 +3705,6 @@ * @return {boolean} * @function * @name replaceKeyword - * @memberOf RangeHelper.prototype */ // eslint-disable-next-line max-params base.replaceKeyword = function ( @@ -3827,7 +3799,6 @@ * @return {boolean} * @function * @name compare - * @memberOf RangeHelper.prototype */ base.compare = function (rngA, rngB) { if (!rngB) { @@ -3848,7 +3819,6 @@ * @since 1.4.6 * @function * @name clear - * @memberOf RangeHelper.prototype */ base.clear = function () { var sel = win.getSelection(); @@ -4440,14 +4410,12 @@ /** * All the commands supported by the editor * @name commands - * @memberOf SCEditor.prototype */ base.commands = extendDeep({}, (userOptions.commands || defaultCmds)); /** * Options for this editor instance * @name opts - * @memberOf SCEditor.prototype */ var options = base.opts = extendDeep( {}, defaultOptions, userOptions @@ -5061,7 +5029,6 @@ * * @since 1.3.5 * @function - * @memberOf SCEditor.prototype * @name readOnly * @return {boolean} */ @@ -5071,7 +5038,6 @@ * @param {boolean} readOnly * @since 1.3.5 * @function - * @memberOf SCEditor.prototype * @name readOnly^2 * @return {this} */ @@ -5091,7 +5057,6 @@ * * @since 1.4.1 * @function - * @memberOf SCEditor.prototype * @name rtl * @return {boolean} */ @@ -5101,7 +5066,6 @@ * @param {boolean} rtl * @since 1.4.1 * @function - * @memberOf SCEditor.prototype * @name rtl^2 * @return {this} */ @@ -5141,7 +5105,6 @@ * * @since 1.3.5 * @function - * @memberOf SCEditor.prototype * @name width * @return {number} */ @@ -5151,7 +5114,6 @@ * @param {number} width Width in pixels * @since 1.3.5 * @function - * @memberOf SCEditor.prototype * @name width^2 * @return {this} */ @@ -5165,7 +5127,6 @@ * @param {boolean} [saveWidth=true] If to store the width * @since 1.4.1 * @function - * @memberOf SCEditor.prototype * @name width^3 * @return {this} */ @@ -5183,7 +5144,6 @@ * * @since 1.4.1 * @function - * @memberOf SCEditor.prototype * @name dimensions * @return {object} */ @@ -5196,7 +5156,6 @@ * @param {number} height Height in px * @since 1.4.1 * @function - * @memberOf SCEditor.prototype * @name dimensions^2 * @return {this} */ @@ -5214,7 +5173,6 @@ * @param {boolean} [save=true] If to store the new sizes * @since 1.4.1 * @function - * @memberOf SCEditor.prototype * @name dimensions^3 * @return {this} */ @@ -5249,7 +5207,6 @@ * * @since 1.3.5 * @function - * @memberOf SCEditor.prototype * @name height * @return {number} */ @@ -5259,7 +5216,6 @@ * @param {number} height Height in px * @since 1.3.5 * @function - * @memberOf SCEditor.prototype * @name height^2 * @return {this} */ @@ -5275,7 +5231,6 @@ * @param {boolean} [saveHeight=true] If to store the height * @since 1.4.1 * @function - * @memberOf SCEditor.prototype * @name height^3 * @return {this} */ @@ -5292,7 +5247,6 @@ * * @since 1.4.1 * @function - * @memberOf SCEditor.prototype * @name maximize * @return {boolean} */ @@ -5302,7 +5256,6 @@ * @param {boolean} maximize If to maximise the editor * @since 1.4.1 * @function - * @memberOf SCEditor.prototype * @name maximize^2 * @return {this} */ @@ -5348,7 +5301,6 @@ * @param {boolean} [ignoreMaxHeight=false] * @function * @name expandToContent - * @memberOf SCEditor.prototype * @see #resizeToContent */ base.expandToContent = function (ignoreMaxHeight) { @@ -5389,7 +5341,6 @@ * * @function * @name destroy - * @memberOf SCEditor.prototype */ base.destroy = function () { // Don't destroy if the editor has already been destroyed @@ -5436,7 +5387,6 @@ * @param {HTMLElement} content The HTML content of the dropdown * @function * @name createDropDown - * @memberOf SCEditor.prototype */ base.createDropDown = function (menuItem, name, content) { // first click for create second click for close @@ -5679,7 +5629,6 @@ * after closing the drop down * @function * @name closeDropDown - * @memberOf SCEditor.prototype */ base.closeDropDown = function (focus) { if (dropdown) { @@ -5708,7 +5657,6 @@ * support text. * @function * @name wysiwygEditorInsertHtml - * @memberOf SCEditor.prototype */ base.wysiwygEditorInsertHtml = function ( html, endHtml, overrideCodeBlocking @@ -5765,7 +5713,6 @@ * @param {string} [endText=null] * @function * @name wysiwygEditorInsertText - * @memberOf SCEditor.prototype */ base.wysiwygEditorInsertText = function (text, endText) { base.wysiwygEditorInsertHtml( @@ -5786,7 +5733,6 @@ * @since 1.3.5 * @function * @name insertText - * @memberOf SCEditor.prototype */ base.insertText = function (text, endText) { if (base.inSourceMode()) { @@ -5818,7 +5764,6 @@ * @since 1.4.0 * @function * @name sourceEditorInsertText - * @memberOf SCEditor.prototype */ base.sourceEditorInsertText = function (text, endText) { var scrollTop, currentValue, @@ -5854,7 +5799,6 @@ * @return {RangeHelper} * @function * @name getRangeHelper - * @memberOf SCEditor.prototype */ base.getRangeHelper = function () { return rangeHelper; @@ -5868,7 +5812,6 @@ * @function * @since 1.4.5 * @name sourceEditorCaret - * @memberOf SCEditor.prototype */ base.sourceEditorCaret = function (position) { sourceEditor.focus(); @@ -5898,7 +5841,6 @@ * @return {string} * @function * @name val - * @memberOf SCEditor.prototype */ /** * Sets the value of the editor. @@ -5913,7 +5855,6 @@ * @since 1.3.5 * @function * @name val^2 - * @memberOf SCEditor.prototype */ base.val = function (val, filter) { if (!isString(val)) { @@ -5952,7 +5893,6 @@ * @since 1.3.5 * @function * @name insert - * @memberOf SCEditor.prototype */ /** * Inserts HTML/BBCode into the editor @@ -5977,7 +5917,6 @@ * @since 1.4.3 * @function * @name insert^2 - * @memberOf SCEditor.prototype */ // eslint-disable-next-line max-params base.insert = function ( @@ -6025,7 +5964,6 @@ * @return {string} * @function * @name getWysiwygEditorValue - * @memberOf SCEditor.prototype */ base.getWysiwygEditorValue = function (filter) { var html; @@ -6059,7 +5997,6 @@ * @function * @since 1.4.3 * @name getBody - * @memberOf SCEditor.prototype */ base.getBody = function () { return wysiwygBody; @@ -6072,7 +6009,6 @@ * @function * @since 1.4.3 * @name getContentAreaContainer - * @memberOf SCEditor.prototype */ base.getContentAreaContainer = function () { return wysiwygEditor; @@ -6091,7 +6027,6 @@ * @function * @since 1.4.0 * @name getSourceEditorValue - * @memberOf SCEditor.prototype */ base.getSourceEditorValue = function (filter) { var val = sourceEditor.value; @@ -6110,7 +6045,6 @@ * @param {string} value * @function * @name setWysiwygEditorValue - * @memberOf SCEditor.prototype */ base.setWysiwygEditorValue = function (value) { if (!value) { @@ -6131,7 +6065,6 @@ * @param {string} value * @function * @name setSourceEditorValue - * @memberOf SCEditor.prototype */ base.setSourceEditorValue = function (value) { sourceEditor.value = value; @@ -6146,7 +6079,6 @@ * @function * @name updateOriginal * @since 1.4.0 - * @memberOf SCEditor.prototype */ base.updateOriginal = function () { original.value = base.val(); @@ -6169,7 +6101,6 @@ * @return {boolean} * @function * @name inSourceMode - * @memberOf SCEditor.prototype */ base.inSourceMode = function () { return hasClass(editorContainer, 'sourceMode'); @@ -6181,7 +6112,6 @@ * @return boolean * @function * @name sourceMode - * @memberOf SCEditor.prototype */ /** * Sets if the editor is in sourceMode @@ -6190,7 +6120,6 @@ * @return {this} * @function * @name sourceMode^2 - * @memberOf SCEditor.prototype */ base.sourceMode = function (enable) { var inSourceMode = base.inSourceMode(); @@ -6210,7 +6139,6 @@ * @function * @name toggleSourceMode * @since 1.4.0 - * @memberOf SCEditor.prototype */ base.toggleSourceMode = function () { var isInSourceMode = base.inSourceMode(); @@ -6292,7 +6220,6 @@ * @param {String|Boolean} [param] * @function * @name execCommand - * @memberOf SCEditor.prototype */ base.execCommand = function (command, param) { var executed = false, @@ -6412,7 +6339,6 @@ * @return {?Node} * @function * @name currentNode - * @memberOf SCEditor.prototype */ base.currentNode = function () { return currentNode; @@ -6427,7 +6353,6 @@ * @return {?Node} * @function * @name currentBlockNode - * @memberOf SCEditor.prototype * @since 1.4.4 */ base.currentBlockNode = function () { @@ -6600,7 +6525,6 @@ * @return {string} * @function * @name _ - * @memberOf SCEditor.prototype */ base._ = function () { var undef, @@ -6672,7 +6596,6 @@ * @return {this} * @function * @name bind - * @memberOf SCEditor.prototype * @since 1.4.1 */ base.bind = function (events, handler, excludeWysiwyg, excludeSource) { @@ -6717,7 +6640,6 @@ * @return {this} * @function * @name unbind - * @memberOf SCEditor.prototype * @since 1.4.1 * @see bind */ @@ -6746,7 +6668,6 @@ * @return {this} * @function * @name blur - * @memberOf SCEditor.prototype * @since 1.3.6 */ /** @@ -6760,7 +6681,6 @@ * @return {this} * @function * @name blur^2 - * @memberOf SCEditor.prototype * @since 1.4.1 */ base.blur = function (handler, excludeWysiwyg, excludeSource) { @@ -6779,7 +6699,6 @@ * @return {this} * @function * @name focus - * @memberOf SCEditor.prototype */ /** * Adds an event handler to the focus event @@ -6792,7 +6711,6 @@ * @return {this} * @function * @name focus^2 - * @memberOf SCEditor.prototype * @since 1.4.1 */ base.focus = function (handler, excludeWysiwyg, excludeSource) { @@ -6847,7 +6765,6 @@ * @return {this} * @function * @name keyDown - * @memberOf SCEditor.prototype * @since 1.4.1 */ base.keyDown = function (handler, excludeWysiwyg, excludeSource) { @@ -6865,7 +6782,6 @@ * @return {this} * @function * @name keyPress - * @memberOf SCEditor.prototype * @since 1.4.1 */ base.keyPress = function (handler, excludeWysiwyg, excludeSource) { @@ -6884,7 +6800,6 @@ * @return {this} * @function * @name keyUp - * @memberOf SCEditor.prototype * @since 1.4.1 */ base.keyUp = function (handler, excludeWysiwyg, excludeSource) { @@ -6901,7 +6816,6 @@ * @return {this} * @function * @name nodeChanged - * @memberOf SCEditor.prototype * @since 1.4.1 */ base.nodeChanged = function (handler) { @@ -6917,7 +6831,6 @@ * @return {this} * @function * @name selectionChanged - * @memberOf SCEditor.prototype * @since 1.4.1 */ base.selectionChanged = function (handler) { @@ -6942,7 +6855,6 @@ * @return {this} * @function * @name valueChanged - * @memberOf SCEditor.prototype * @since 1.4.5 */ base.valueChanged = function (handler, excludeWysiwyg, excludeSource) { @@ -7010,7 +6922,6 @@ * @return {boolean} * @function * @name emoticons - * @memberOf SCEditor.prototype * @since 1.4.2 */ /** @@ -7020,7 +6931,6 @@ * @return {this} * @function * @name emoticons^2 - * @memberOf SCEditor.prototype * @since 1.4.2 */ base.emoticons = function (enable) { @@ -7063,7 +6973,6 @@ * @return {string} * @function * @name css - * @memberOf SCEditor.prototype * @since 1.4.3 */ /** @@ -7073,7 +6982,6 @@ * @return {this} * @function * @name css^2 - * @memberOf SCEditor.prototype * @since 1.4.3 */ base.css = function (css) {