comparison src/sceditor.js @ 12:933a459aa182

allow selector for textarea
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 07 Aug 2022 13:58:27 -0600
parents 9159df67520a
children 8d32537e0ca7
comparison
equal deleted inserted replaced
11:73d62b7a0713 12:933a459aa182
9025 * 9025 *
9026 * @fileoverview SCEditor - A lightweight WYSIWYG BBCode and HTML editor 9026 * @fileoverview SCEditor - A lightweight WYSIWYG BBCode and HTML editor
9027 * @author Sam Clarke 9027 * @author Sam Clarke
9028 */ 9028 */
9029 9029
9030 function getTextarea(textarea) {
9031 if( typeof(textarea) === 'string' )
9032 textarea = document.querySelector(textarea);
9033 return textarea;
9034 }
9030 9035
9031 window.sceditor = { 9036 window.sceditor = {
9032 command: SCEditor.command, 9037 command: SCEditor.command,
9033 commands: defaultCmds, 9038 commands: defaultCmds,
9034 defaultOptions: defaultOptions, 9039 defaultOptions: defaultOptions,
9074 extend: extend 9079 extend: extend
9075 }, 9080 },
9076 plugins: PluginManager.plugins, 9081 plugins: PluginManager.plugins,
9077 formats: SCEditor.formats, 9082 formats: SCEditor.formats,
9078 create: function (textarea, options) { 9083 create: function (textarea, options) {
9084 textarea = getTextarea(textarea);
9079 options = options || {}; 9085 options = options || {};
9080 9086
9081 // Don't allow the editor to be initialised 9087 // Don't allow the editor to be initialised
9082 // on it's own source editor 9088 // on it's own source editor
9083 if (parent(textarea, '.sceditor-container')) { 9089 if (parent(textarea, '.sceditor-container')) {
9087 if (options.runWithoutWysiwygSupport || isWysiwygSupported) { 9093 if (options.runWithoutWysiwygSupport || isWysiwygSupported) {
9088 /*eslint no-new: off*/ 9094 /*eslint no-new: off*/
9089 (new SCEditor(textarea, options)); 9095 (new SCEditor(textarea, options));
9090 } 9096 }
9091 }, 9097 },
9092 instance: function (textarea) { 9098 instance: function(textarea) {
9099 textarea = getTextarea(textarea);
9093 return textarea._sceditor; 9100 return textarea._sceditor;
9094 } 9101 }
9095 }; 9102 };
9096 9103
9097 }()); 9104 }());