Mercurial Hosting > sceditor
changeset 27:8165b83907af
remove bind()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 10 Aug 2022 23:48:47 -0600 |
parents | 160be99e1517 |
children | f227fdfebded |
files | src/formats/bbcode.js src/formats/xhtml.js src/sceditor.js |
diffstat | 3 files changed, 84 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
diff -r 160be99e1517 -r 8165b83907af src/formats/bbcode.js --- a/src/formats/bbcode.js Tue Aug 09 23:30:24 2022 -0600 +++ b/src/formats/bbcode.js Wed Aug 10 23:48:47 2022 -0600 @@ -2522,14 +2522,16 @@ * @param {string} source * @param {boolean} [legacyAsFragment] Used by fromBBCode() method */ - function toHtml(asFragment, source, legacyAsFragment) { - var parser = newBBCodeParser(base.opts.parserOptions); - var html = parser.toHTML( - base.opts.bbcodeTrim ? source.trim() : source - ); + function toHtml(asFragment) { + return function(source, legacyAsFragment) { + var parser = newBBCodeParser(base.opts.parserOptions); + var html = parser.toHTML( + base.opts.bbcodeTrim ? source.trim() : source + ); - return (asFragment || legacyAsFragment) ? - removeFirstLastDiv(html) : html; + return (asFragment || legacyAsFragment) ? + removeFirstLastDiv(html) : html; + }; } /** @@ -2542,59 +2544,61 @@ * @return {string} * @private */ - function toSource(asFragment, html, context, parent) { - context = context || document; + function toSource(asFragment) { + return function(html, context, parent) { + context = context || document; - var bbcode, elements; - var containerParent = context.createElement('div'); - var container = context.createElement('div'); - var parser = newBBCodeParser(base.opts.parserOptions); + var bbcode, elements; + var containerParent = context.createElement('div'); + var container = context.createElement('div'); + var parser = newBBCodeParser(base.opts.parserOptions); - container.innerHTML = html; - css(containerParent, 'visibility', 'hidden'); - containerParent.appendChild(container); - context.body.appendChild(containerParent); + container.innerHTML = html; + css(containerParent, 'visibility', 'hidden'); + containerParent.appendChild(container); + context.body.appendChild(containerParent); - if (asFragment) { - // Add text before and after so removeWhiteSpace doesn't remove - // leading and trailing whitespace - containerParent.insertBefore( - context.createTextNode('#'), - containerParent.firstChild - ); - containerParent.appendChild(context.createTextNode('#')); - } + if (asFragment) { + // Add text before and after so removeWhiteSpace doesn't remove + // leading and trailing whitespace + containerParent.insertBefore( + context.createTextNode('#'), + containerParent.firstChild + ); + containerParent.appendChild(context.createTextNode('#')); + } - // Match parents white-space handling - if (parent) { - css(container, 'whiteSpace', css(parent, 'whiteSpace')); - } + // Match parents white-space handling + if (parent) { + css(container, 'whiteSpace', css(parent, 'whiteSpace')); + } - // Remove all nodes with sceditor-ignore class - elements = container.getElementsByClassName('sceditor-ignore'); - while (elements.length) { - elements[0].parentNode.removeChild(elements[0]); - } + // Remove all nodes with sceditor-ignore class + elements = container.getElementsByClassName('sceditor-ignore'); + while (elements.length) { + elements[0].parentNode.removeChild(elements[0]); + } - dom.removeWhiteSpace(containerParent); + dom.removeWhiteSpace(containerParent); - bbcode = elementToBbcode(container); + bbcode = elementToBbcode(container); - context.body.removeChild(containerParent); + context.body.removeChild(containerParent); - bbcode = parser.toBBCode(bbcode, true); + bbcode = parser.toBBCode(bbcode, true); - if (base.opts.bbcodeTrim) { - bbcode = bbcode.trim(); - } + if (base.opts.bbcodeTrim) { + bbcode = bbcode.trim(); + } - return bbcode; - }; + return bbcode; + }; + } - base.toHtml = toHtml.bind(null, false); - base.fragmentToHtml = toHtml.bind(null, true); - base.toSource = toSource.bind(null, false); - base.fragmentToSource = toSource.bind(null, true); + base.toHtml = toHtml(false); + base.fragmentToHtml = toHtml(true); + base.toSource = toSource(false); + base.fragmentToSource = toSource(true); return base; };
diff -r 160be99e1517 -r 8165b83907af src/formats/xhtml.js --- a/src/formats/xhtml.js Tue Aug 09 23:30:24 2022 -0600 +++ b/src/formats/xhtml.js Wed Aug 10 23:48:47 2022 -0600 @@ -536,32 +536,34 @@ * @return {string} * @memberOf jQuery.sceditor.plugins.xhtml.prototype */ - function toSource(isFragment, html, context) { - var xhtml, - container = context.createElement('div'); - container.innerHTML = html; + function toSource(isFragment) { + return function(html, context) { + var xhtml, + container = context.createElement('div'); + container.innerHTML = html; - css(container, 'visibility', 'hidden'); - context.body.appendChild(container); + css(container, 'visibility', 'hidden'); + context.body.appendChild(container); - convertTags(container); - removeTags(container); - removeAttribs(container); + convertTags(container); + removeTags(container); + removeAttribs(container); - if (!isFragment) { - wrapInlines(container); - } + if (!isFragment) { + wrapInlines(container); + } - xhtml = (new sceditor.XHTMLSerializer()).serialize(container, true); + xhtml = (new sceditor.XHTMLSerializer()).serialize(container, true); + + context.body.removeChild(container); - context.body.removeChild(container); + return xhtml; + }; + } - return xhtml; - }; + base.toSource = toSource(false); - base.toSource = toSource.bind(null, false); - - base.fragmentToSource = toSource.bind(null, true);; + base.fragmentToSource = toSource(true);; /** * Runs all converters for the specified tagName @@ -588,10 +590,10 @@ return; } - converter.conv.call(base, node); + converter.conv(node); }); } else if (converter.conv) { - converter.conv.call(base, node); + converter.conv(node); } }); };
diff -r 160be99e1517 -r 8165b83907af src/sceditor.js --- a/src/sceditor.js Tue Aug 09 23:30:24 2022 -0600 +++ b/src/sceditor.js Wed Aug 10 23:48:47 2022 -0600 @@ -11,29 +11,31 @@ * @param {*} arg * @returns {boolean} */ - function isTypeof(type, arg) { - return typeof arg === type; + function isTypeof(type) { + return function(arg) { + return typeof arg === type; + }; } /** * @type {function(*): boolean} */ - var isString = isTypeof.bind(null, 'string'); + var isString = isTypeof('string'); /** * @type {function(*): boolean} */ - var isUndefined = isTypeof.bind(null, 'undefined'); + var isUndefined = isTypeof('undefined'); /** * @type {function(*): boolean} */ - var isFunction = isTypeof.bind(null, 'function'); + var isFunction = isTypeof('function'); /** * @type {function(*): boolean} */ - var isNumber = isTypeof.bind(null, 'number'); + var isNumber = isTypeof('number'); /** @@ -2464,7 +2466,7 @@ } onEvent(content, 'click', '.button', insertUrl); - onEvent(content, 'keypress', function (target, e) { + onEvent(content, 'keypress', function (e) { // 13 = enter key if (e.which === 13 && linkInput.value) { insertUrl(e);