changeset 23:c2a85b2ec677

remove more oo
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 09 Aug 2022 13:25:17 -0600
parents 499f38b5eeff
children 80a86fb8f2b7
files src/sceditor.js
diffstat 1 files changed, 33 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/sceditor.js	Mon Aug 08 23:41:05 2022 -0600
+++ b/src/sceditor.js	Tue Aug 09 13:25:17 2022 -0600
@@ -2840,14 +2840,14 @@
 	 * @class PluginManager
 	 * @name PluginManager
 	 */
-	function PluginManager(thisObj) {
+	function newPluginManager(thisObj) {
 		/**
 		 * Alias of this
 		 *
 		 * @private
 		 * @type {Object}
 		 */
-		var base = this;
+		var base = {};
 
 		/**
 		 * Array of all currently registered plugins
@@ -3065,8 +3065,10 @@
 			registeredPlugins = [];
 			thisObj    = null;
 		};
+
+		return base;
 	}
-	PluginManager.plugins = plugins;
+	//PluginManager.plugins = plugins;
 
 	/**
 	 * Gets the text, start/end node and offset for
@@ -3137,12 +3139,12 @@
 	 * @class RangeHelper
 	 * @name RangeHelper
 	 */
-	function RangeHelper(win, d) {
+	function newRangeHelper(win, d) {
 		var	_createMarker, _prepareInput,
 			doc          = d || win.contentDocument || win.document,
 			startMarker  = 'sceditor-start-marker',
 			endMarker    = 'sceditor-end-marker',
-			base         = this;
+			base         = {};
 
 		/**
 		 * Inserts HTML into the current range replacing any selected
@@ -3854,6 +3856,8 @@
 				}
 			}
 		};
+
+		return base;
 	}
 
 	var USER_AGENT = navigator.userAgent;
@@ -4141,13 +4145,13 @@
 	 * @class SCEditor
 	 * @name SCEditor
 	 */
-	function SCEditor(original, userOptions) {
+	function newSCEditor(original, userOptions) {
 		/**
 		 * Alias of this
 		 *
 		 * @private
 		 */
-		var base = this;
+		var base = {};
 
 		/**
 		 * Editor format like BBCode or HTML
@@ -4489,7 +4493,7 @@
 			isRequired = original.required;
 			original.required = false;
 
-			var FormatCtor = SCEditor.formats[options.format];
+			var FormatCtor = _formats[options.format];
 			format = FormatCtor ? new FormatCtor() : {};
 			/*
 			 * Plugins should be initialized before the formatters since
@@ -4497,7 +4501,7 @@
 			 * since the bbcode format caches its handlers,
 			 * such changes must be done first.
 			 */
-			pluginManager = new PluginManager(base);
+			pluginManager = newPluginManager(base);
 			(options.plugins || '').split(',').forEach(function (plugin) {
 				pluginManager.register(plugin.trim());
 			});
@@ -4549,11 +4553,11 @@
 		initLocale = function () {
 			var lang;
 
-			locale = SCEditor.locale[options.locale];
+			locale = _locale[options.locale];
 
 			if (!locale) {
 				lang   = options.locale.split('-');
-				locale = SCEditor.locale[lang[0]];
+				locale = _locale[lang[0]];
 			}
 
 			// Locale DateTime format overrides any specified in the options
@@ -4631,7 +4635,7 @@
 			attr(sourceEditor, 'tabindex', tabIndex);
 			attr(wysiwygEditor, 'tabindex', tabIndex);
 
-			rangeHelper = new RangeHelper(wysiwygWindow, null);
+			rangeHelper = newRangeHelper(wysiwygWindow, null);
 
 			// load any textarea value into the editor
 			hide(original);
@@ -5903,7 +5907,7 @@
 				sourceEditor.selectionStart = position.start;
 				sourceEditor.selectionEnd = position.end;
 
-				return this;
+				return base;
 			}
 
 			return {
@@ -6300,7 +6304,7 @@
 			if (base.inSourceMode()) {
 				if (cmd.txtExec) {
 					if (Array.isArray(cmd.txtExec)) {
-						base.sourceEditorInsertText.apply(base, cmd.txtExec);
+						base.sourceEditorInsertText(cmd.txtExec[0],cmd.txtExec[1]);
 					} else {
 						cmd.txtExec(base, caller, sourceEditorSelectedText());
 					}
@@ -7277,7 +7281,7 @@
 
 			shortcut = shortcut.join('+');
 			if (shortcutHandlers[shortcut] &&
-				shortcutHandlers[shortcut].call(base) === false) {
+				shortcutHandlers[shortcut](base) === false) {
 
 				e.stopPropagation();
 				e.preventDefault();
@@ -7538,6 +7542,8 @@
 
 		// run the initializer
 		init();
+
+		return base;
 	}
 
 	/**
@@ -7546,9 +7552,9 @@
 	 * @name locale
 	 * @memberOf sceditor
 	 */
-	SCEditor.locale = {};
-
-	SCEditor.formats = {};
+	var _locale = {};
+
+	var _formats = {};
 
 
 	/**
@@ -7556,7 +7562,7 @@
 	 * @class command
 	 * @name sceditor.command
 	 */
-	SCEditor.command =
+	var _command =
 	/** @lends sceditor.command */
 	{
 		/**
@@ -7580,7 +7586,7 @@
 		 * {@link sceditor.execCommand}</p>
 		 *
 		 * @example
-		 * SCEditor.command.set("hello",
+		 * _command.set("hello",
 		 * {
 		 *     exec: function () {
 		 *         alert("Hello World!");
@@ -7601,7 +7607,7 @@
 			cmd = extend(defaultCmds[name] || {}, cmd);
 
 			cmd.remove = function () {
-				SCEditor.command.remove(name);
+				_command.remove(name);
 			};
 
 			defaultCmds[name] = cmd;
@@ -7641,7 +7647,7 @@
 	}
 
 	window.sceditor = {
-		command: SCEditor.command,
+		command: _command,
 		commands: defaultCmds,
 		defaultOptions: defaultOptions,
 
@@ -7678,14 +7684,15 @@
 			getStyle: getStyle,
 			hasStyle: hasStyle
 		},
-		locale: SCEditor.locale,
+		locale: _locale,
 		utils: {
 			each: each,
 			isEmptyObject: isEmptyObject,
 			extend: extend
 		},
-		plugins: PluginManager.plugins,
-		formats: SCEditor.formats,
+		//plugins: PluginManager.plugins,
+		plugins: plugins,
+		formats: _formats,
 		create: function (textarea, options) {
 			textarea = getTextarea(textarea);
 			options = options || {};
@@ -7698,7 +7705,7 @@
 
 			if (options.runWithoutWysiwygSupport || isWysiwygSupported) {
 				/*eslint no-new: off*/
-				(new SCEditor(textarea, options));
+				(newSCEditor(textarea, options));
 			}
 		},
 		instance: function(textarea) {