Mercurial Hosting > sceditor
diff src/formats/bbcode.js @ 36:21090996a131
clean up TokenizeToken
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 16 Aug 2022 13:50:36 -0600 |
parents | cd02cd04bc9d |
children | 0c4e4b5ef40d |
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) {