comparison src/plugins/alternative-lists.js @ 30:db061869f28f

remove sceditor.command, add options.onCreate
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 12 Aug 2022 00:54:39 -0600
parents ea32a44b5a6e
children
comparison
equal deleted inserted replaced
29:ea32a44b5a6e 30:db061869f28f
32 * Private functions 32 * Private functions
33 * @private 33 * @private
34 */ 34 */
35 var bulletHandler; 35 var bulletHandler;
36 var orderedHandler; 36 var orderedHandler;
37 var insertListTag;
38 37
39 base.init = function (editor) { 38 base.init = function (editor) {
40 var opts = editor.opts; 39 var opts = editor.opts;
41 40
42 // Enable for BBCode only 41 // Enable for BBCode only
43 if (opts.format && opts.format !== 'bbcode') { 42 if (opts.format && opts.format !== 'bbcode') {
44 return; 43 return;
45 } 44 }
46 45
47 // Override only txtExec implementation 46 // Override only txtExec implementation
48 sceditor.command.get('orderedlist').txtExec = orderedHandler; 47 editor.commands.orderedlist.txtExec = orderedHandler;
49 sceditor.command.get('bulletlist').txtExec = bulletHandler; 48 editor.commands.bulletlist.txtExec = bulletHandler;
50 49
51 // Override current implementation 50 // Override current implementation
52 sceditor.formats.bbcode.set('list', { 51 sceditor.formats.bbcode.set('list', {
53 breakStart: true, 52 breakStart: true,
54 isInline: false, 53 isInline: false,
117 closedBy: ['/ul', '/ol', '/list', '*', 'li'], 116 closedBy: ['/ul', '/ol', '/list', '*', 'li'],
118 html: '<li>{0}</li>' 117 html: '<li>{0}</li>'
119 }); 118 });
120 }; 119 };
121 120
122 insertListTag = function (editor, listType, selected) { 121 function insertListTag(editor, listType, selected) {
123 var content = ''; 122 let content = '';
124 123
125 utils.each(selected.split(/\r?\n/), function (item) { 124 utils.each(selected.split(/\r?\n/), function (_, item) {
126 content += (content ? '\n' : '') + 125 content += (content ? '\n' : '') +
127 '[*]' + item; 126 '[*]' + item;
128 }); 127 });
129 128
130 if (listType === '') { 129 if (listType === '') {
139 * Function for the txtExec and exec properties 138 * Function for the txtExec and exec properties
140 * 139 *
141 * @param {node} caller 140 * @param {node} caller
142 * @private 141 * @private
143 */ 142 */
144 orderedHandler = function (caller, selected) { 143 orderedHandler = function (editor, caller, selected) {
145 console.log('a');
146 var editor = this;
147
148 insertListTag(editor, '1', selected); 144 insertListTag(editor, '1', selected);
149 }; 145 };
150 146
151 bulletHandler = function (caller, selected) { 147 bulletHandler = function (editor, caller, selected) {
152 console.log('b');
153 var editor = this;
154
155 insertListTag(editor, '', selected); 148 insertListTag(editor, '', selected);
156 }; 149 };
157 150
158 return base; 151 return base;
159 }; 152 };