changeset 12:933a459aa182

allow selector for textarea
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 07 Aug 2022 13:58:27 -0600
parents 73d62b7a0713
children 8d32537e0ca7
files src/changes.txt src/examples/min.html src/examples/modified.html src/sceditor.js
diffstat 4 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/changes.txt	Sun Aug 07 01:09:17 2022 -0600
+++ b/src/changes.txt	Sun Aug 07 13:58:27 2022 -0600
@@ -1,6 +1,8 @@
 changes, most recent at top
 
 
+Allow selector for textarea.
+
 CSS cleanup.  Avoiding CSS includes is wrong for the same reason that minification is wrong.
 
 Changing icons required including a javascript file and setting the "icons" option.  This is confusing so I got rid of the "icons" option.  And I added icons/famfamfam.js as an option which is the default.
--- a/src/examples/min.html	Sun Aug 07 01:09:17 2022 -0600
+++ b/src/examples/min.html	Sun Aug 07 13:58:27 2022 -0600
@@ -12,8 +12,7 @@
 		<script src="/formats/bbcode.js"></script>
 		<script>
 			function init() {
-				let textarea = document.querySelector('textarea');
-				sceditor.create(textarea, {
+				sceditor.create('textarea', {
 					format: 'bbcode',
 				});
 			}
--- a/src/examples/modified.html	Sun Aug 07 01:09:17 2022 -0600
+++ b/src/examples/modified.html	Sun Aug 07 13:58:27 2022 -0600
@@ -71,8 +71,7 @@
 
 
 		<script>
-			var textarea = document.getElementById('example');
-			sceditor.create(textarea, {
+			sceditor.create('#example', {
 				format: 'bbcode',
 			});
 
--- a/src/sceditor.js	Sun Aug 07 01:09:17 2022 -0600
+++ b/src/sceditor.js	Sun Aug 07 13:58:27 2022 -0600
@@ -9027,6 +9027,11 @@
 	 * @author Sam Clarke
 	 */
 
+	function getTextarea(textarea) {
+		if( typeof(textarea) === 'string' )
+			textarea = document.querySelector(textarea);
+		return textarea;
+	}
 
 	window.sceditor = {
 		command: SCEditor.command,
@@ -9076,6 +9081,7 @@
 		plugins: PluginManager.plugins,
 		formats: SCEditor.formats,
 		create: function (textarea, options) {
+			textarea = getTextarea(textarea);
 			options = options || {};
 
 			// Don't allow the editor to be initialised
@@ -9089,7 +9095,8 @@
 				(new SCEditor(textarea, options));
 			}
 		},
-		instance: function (textarea) {
+		instance: function(textarea) {
+			textarea = getTextarea(textarea);
 			return textarea._sceditor;
 		}
 	};