diff src/formats/bbcode.js @ 27:8165b83907af

remove bind()
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 10 Aug 2022 23:48:47 -0600
parents 160be99e1517
children db061869f28f
line wrap: on
line diff
--- 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;
 	};