changeset 29:ea32a44b5a6e

remove more oo
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 11 Aug 2022 19:54:03 -0600
parents f227fdfebded
children db061869f28f
files src/plugins/alternative-lists.js src/plugins/autosave.js src/plugins/autoyoutube.js src/plugins/dragdrop.js src/plugins/format.js src/plugins/plaintext.js src/plugins/undo.js src/sceditor.js
diffstat 8 files changed, 57 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/alternative-lists.js	Thu Aug 11 00:04:48 2022 -0600
+++ b/src/plugins/alternative-lists.js	Thu Aug 11 19:54:03 2022 -0600
@@ -26,7 +26,7 @@
 	}
 
 	sceditor.plugins['alternative-lists'] = function () {
-		var base = this;
+		var base = {};
 
 		/**
 		 * Private functions
@@ -36,8 +36,8 @@
 		var orderedHandler;
 		var insertListTag;
 
-		base.init = function () {
-			var opts = this.opts;
+		base.init = function (editor) {
+			var opts = editor.opts;
 
 			// Enable for BBCode only
 			if (opts.format && opts.format !== 'bbcode') {
@@ -70,7 +70,7 @@
 					}
 
 					if (isFunction(toHtml)) {
-						return toHtml.call(this, token, attrs, content);
+						return toHtml(token, attrs, content);
 					} else {
 						token.attrs['0'] = content;
 						return sceditor.formats.bbcode.formatBBCodeString(
@@ -142,16 +142,19 @@
 		 * @private
 		 */
 		orderedHandler = function (caller, selected) {
+console.log('a');
 			var editor = this;
 
 			insertListTag(editor, '1', selected);
 		};
 
 		bulletHandler = function (caller, selected) {
+console.log('b');
 			var editor = this;
 
 			insertListTag(editor, '', selected);
 		};
 
+		return base;
 	};
 })(sceditor);
--- a/src/plugins/autosave.js	Thu Aug 11 00:04:48 2022 -0600
+++ b/src/plugins/autosave.js	Thu Aug 11 19:54:03 2022 -0600
@@ -19,7 +19,7 @@
 	}
 
 	sceditor.plugins.autosave = function () {
-		var base = this;
+		var base = {};
 		var editor;
 		var isLoading = false;
 		var storageKey = defaultKey;
@@ -45,8 +45,8 @@
 			}
 		}
 
-		base.init = function () {
-			editor = this;
+		base.init = function (ed) {
+			editor = ed;
 			var opts = editor.opts && editor.opts.autosave || {};
 
 			saveHandler = opts.save || saveHandler;
@@ -57,13 +57,13 @@
 			gc();
 		};
 
-		base.signalReady = function () {
+		base.signalReady = function (editor) {
 			// Add submit event listener to clear autosave
 			var parent = editor.getContentAreaContainer();
 			while (parent) {
 				if (/form/i.test(parent.nodeName)) {
 					parent.addEventListener(
-						'submit', clear.bind(null, storageKey), true
+						'submit', function(){clear(storageKey)}, true
 					);
 					break;
 				}
@@ -86,24 +86,26 @@
 				isLoading = false;
 			} else {
 				saveHandler({
-					caret: this.sourceEditorCaret(),
-					sourceMode: this.sourceMode(),
+					caret: editor.sourceEditorCaret(),
+					sourceMode: editor.sourceMode(),
 					value: editor.val(null, false),
 					time: Date.now()
 				});
 			}
 		};
 
-		base.signalValuechangedEvent = function (e) {
+		base.signalValuechangedEvent = function (editor, e) {
 			if (!isLoading) {
 				saveHandler({
-					caret: this.sourceEditorCaret(),
-					sourceMode: this.sourceMode(),
+					caret: editor.sourceEditorCaret(),
+					sourceMode: editor.sourceMode(),
 					value: e.detail.rawValue,
 					time: Date.now()
 				});
 			}
 		};
+
+		return base;
 	};
 
 	sceditor.plugins.autosave.clear = clear;
--- a/src/plugins/autoyoutube.js	Thu Aug 11 00:04:48 2022 -0600
+++ b/src/plugins/autoyoutube.js	Thu Aug 11 19:54:03 2022 -0600
@@ -84,10 +84,11 @@
 	};
 
 	sceditor.plugins.autoyoutube = function () {
-		this.signalPasteRaw = function (data) {
+		let base = {}
+		base.signalPasteRaw = function (editor, data) {
 			// TODO: Make this tag configurable.
 			// Skip code tags
-			if (dom.closest(this.currentNode(), 'code')) {
+			if (dom.closest(editor.currentNode(), 'code')) {
 				return;
 			}
 
@@ -102,5 +103,6 @@
 				data.html = node.innerHTML;
 			}
 		};
+		return base;
 	};
 })(document, sceditor);
--- a/src/plugins/dragdrop.js	Thu Aug 11 00:04:48 2022 -0600
+++ b/src/plugins/dragdrop.js	Thu Aug 11 19:54:03 2022 -0600
@@ -71,7 +71,7 @@
 			return;
 		}
 
-		var base = this;
+		var base = {};
 		var	opts;
 		var editor;
 		var handleFile;
@@ -174,8 +174,8 @@
 			e.preventDefault();
 		}
 
-		base.signalReady = function () {
-			editor = this;
+		base.signalReady = function (ed) {
+			editor = ed;
 			opts = editor.opts.dragdrop || {};
 			handleFile = opts.handleFile;
 
@@ -218,5 +218,7 @@
 				paste.val = div.innerHTML;
 			}
 		};
+
+		return base;
 	};
 })(sceditor);
--- a/src/plugins/format.js	Thu Aug 11 00:04:48 2022 -0600
+++ b/src/plugins/format.js	Thu Aug 11 19:54:03 2022 -0600
@@ -14,7 +14,7 @@
 	'use strict';
 
 	sceditor.plugins.format = function () {
-		var base = this;
+		var base = {};
 
 		/**
 		 * Default tags
@@ -41,8 +41,8 @@
 			formatCmd;
 
 
-		base.init = function () {
-			var	opts  = this.opts,
+		base.init = function (editor) {
+			var	opts  = editor.opts,
 				pOpts = opts.paragraphformat;
 
 			// Don't enable if the BBCode plugin is enabled.
@@ -62,8 +62,8 @@
 				}
 			}
 
-			if (!this.commands.format) {
-				this.commands.format = {
+			if (!editor.commands.format) {
+				editor.commands.format = {
 					exec: formatCmd,
 					txtExec: formatCmd,
 					tooltip: 'Format Paragraph'
@@ -122,5 +122,7 @@
 
 			editor.createDropDown(caller, 'format', content);
 		};
+
+		return base;
 	};
 })(sceditor);
--- a/src/plugins/plaintext.js	Thu Aug 11 00:04:48 2022 -0600
+++ b/src/plugins/plaintext.js	Thu Aug 11 19:54:03 2022 -0600
@@ -25,11 +25,12 @@
 	 *                     up. Only applies if addButton is enabled.
 	 */
 	sceditor.plugins.plaintext = function () {
+		var base = {};
 		var plainTextEnabled = true;
 
-		this.init = function () {
-			var commands = this.commands;
-			var opts = this.opts;
+		base.init = function (editor) {
+			var commands = editor.commands;
+			var opts = editor.opts;
 
 			if (opts && opts.plaintext && opts.plaintext.addButton) {
 				plainTextEnabled = opts.plaintext.enabled;
@@ -45,7 +46,7 @@
 			}
 		};
 
-		this.signalPasteRaw = function (data) {
+		base.signalPasteRaw = function (data) {
 			if (plainTextEnabled) {
 				if (data.html && !data.text) {
 					var div = document.createElement('div');
@@ -74,5 +75,7 @@
 				data.html = null;
 			}
 		};
+
+		return base;
 	};
 }(sceditor));
--- a/src/plugins/undo.js	Thu Aug 11 00:04:48 2022 -0600
+++ b/src/plugins/undo.js	Thu Aug 11 19:54:03 2022 -0600
@@ -2,7 +2,7 @@
 	'use strict';
 
 	sceditor.plugins.undo = function () {
-		var base = this;
+		var base = {};
 		var sourceEditor;
 		var editor;
 		var body;
@@ -110,11 +110,8 @@
 				editor.getBody().innerHTML;
 		}
 
-		base.init = function () {
-			// The this variable will be set to the instance of the editor
-			// calling it, hence why the plugins "this" is saved to the base
-			// variable.
-			editor = this;
+		base.init = function (ed) {
+			editor = ed;
 
 			undoLimit = editor.undoLimit || undoLimit;
 
@@ -358,5 +355,7 @@
 			}
 			return node;
 		}
+
+		return base;
 	};
 }(sceditor));
--- a/src/sceditor.js	Thu Aug 11 00:04:48 2022 -0600
+++ b/src/sceditor.js	Thu Aug 11 19:54:03 2022 -0600
@@ -2879,14 +2879,14 @@
 		 * @private
 		 */
 		var callHandlers = function (args, returnAtFirst) {
-			args = [].slice.call(args);
+			if( args.length > 3 )  throw 'too many args';
 
 			var	idx, ret,
-				signal = formatSignalName(args.shift());
+				signal = formatSignalName(args[0]);
 
 			for (idx = 0; idx < registeredPlugins.length; idx++) {
 				if (signal in registeredPlugins[idx]) {
-					ret = registeredPlugins[idx][signal].apply(thisObj, args);
+					ret = registeredPlugins[idx][signal](thisObj, args[1], args[2]);
 
 					if (returnAtFirst) {
 						return ret;
@@ -2996,16 +2996,17 @@
 		 * @name register
 		 * @memberOf PluginManager.prototype
 		 */
-		base.register = function (plugin) {
-			if (!base.exists(plugin) || base.isRegistered(plugin)) {
+		base.register = function (pluginName) {
+			if (!base.exists(pluginName) || base.isRegistered(pluginName)) {
 				return false;
 			}
 
-			plugin = new plugins[plugin]();
+			let plugin = plugins[pluginName]();
+			if(!plugin) throw pluginName;
 			registeredPlugins.push(plugin);
 
 			if ('init' in plugin) {
-				plugin.init.call(thisObj);
+				plugin.init(thisObj);
 			}
 
 			return true;
@@ -3035,7 +3036,7 @@
 					removed       = true;
 
 					if ('destroy' in removedPlugin) {
-						removedPlugin.destroy.call(thisObj);
+						removedPlugin.destroy(thisObj);
 					}
 				}
 			}
@@ -3057,7 +3058,7 @@
 
 			while (i--) {
 				if ('destroy' in registeredPlugins[i]) {
-					registeredPlugins[i].destroy.call(thisObj);
+					registeredPlugins[i].destroy(thisObj);
 				}
 			}