##// END OF EJS Templates
Fixed: cursor not positioned correctly when using wiki toolbar buttons under IE (Balazs Dan)....
Jean-Philippe Lang -
r648:f601d5fb9e02
parent child
Show More
@@ -1,464 +1,468
1 /* ***** BEGIN LICENSE BLOCK *****
1 /* ***** BEGIN LICENSE BLOCK *****
2 * This file is part of DotClear.
2 * This file is part of DotClear.
3 * Copyright (c) 2005 Nicolas Martin & Olivier Meunier and contributors. All
3 * Copyright (c) 2005 Nicolas Martin & Olivier Meunier and contributors. All
4 * rights reserved.
4 * rights reserved.
5 *
5 *
6 * DotClear is free software; you can redistribute it and/or modify
6 * DotClear is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
9 * (at your option) any later version.
10 *
10 *
11 * DotClear is distributed in the hope that it will be useful,
11 * DotClear is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
14 * GNU General Public License for more details.
15 *
15 *
16 * You should have received a copy of the GNU General Public License
16 * You should have received a copy of the GNU General Public License
17 * along with DotClear; if not, write to the Free Software
17 * along with DotClear; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
19 *
20 * ***** END LICENSE BLOCK *****
20 * ***** END LICENSE BLOCK *****
21 */
21 */
22
22
23 /* Modified by JP LANG for textile formatting */
23 /* Modified by JP LANG for textile formatting */
24
24
25 function jsToolBar(textarea) {
25 function jsToolBar(textarea) {
26 if (!document.createElement) { return; }
26 if (!document.createElement) { return; }
27
27
28 if (!textarea) { return; }
28 if (!textarea) { return; }
29
29
30 if ((typeof(document["selection"]) == "undefined")
30 if ((typeof(document["selection"]) == "undefined")
31 && (typeof(textarea["setSelectionRange"]) == "undefined")) {
31 && (typeof(textarea["setSelectionRange"]) == "undefined")) {
32 return;
32 return;
33 }
33 }
34
34
35 this.textarea = textarea;
35 this.textarea = textarea;
36
36
37 this.editor = document.createElement('div');
37 this.editor = document.createElement('div');
38 this.editor.className = 'jstEditor';
38 this.editor.className = 'jstEditor';
39
39
40 this.textarea.parentNode.insertBefore(this.editor,this.textarea);
40 this.textarea.parentNode.insertBefore(this.editor,this.textarea);
41 this.editor.appendChild(this.textarea);
41 this.editor.appendChild(this.textarea);
42
42
43 this.toolbar = document.createElement("div");
43 this.toolbar = document.createElement("div");
44 this.toolbar.className = 'jstElements';
44 this.toolbar.className = 'jstElements';
45 this.editor.parentNode.insertBefore(this.toolbar,this.editor);
45 this.editor.parentNode.insertBefore(this.toolbar,this.editor);
46
46
47 // Dragable resizing (only for gecko)
47 // Dragable resizing (only for gecko)
48 if (this.editor.addEventListener)
48 if (this.editor.addEventListener)
49 {
49 {
50 this.handle = document.createElement('div');
50 this.handle = document.createElement('div');
51 this.handle.className = 'jstHandle';
51 this.handle.className = 'jstHandle';
52 var dragStart = this.resizeDragStart;
52 var dragStart = this.resizeDragStart;
53 var This = this;
53 var This = this;
54 this.handle.addEventListener('mousedown',function(event) { dragStart.call(This,event); },false);
54 this.handle.addEventListener('mousedown',function(event) { dragStart.call(This,event); },false);
55 // fix memory leak in Firefox (bug #241518)
55 // fix memory leak in Firefox (bug #241518)
56 window.addEventListener('unload',function() {
56 window.addEventListener('unload',function() {
57 var del = This.handle.parentNode.removeChild(This.handle);
57 var del = This.handle.parentNode.removeChild(This.handle);
58 delete(This.handle);
58 delete(This.handle);
59 },false);
59 },false);
60
60
61 this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling);
61 this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling);
62 }
62 }
63
63
64 this.context = null;
64 this.context = null;
65 this.toolNodes = {}; // lorsque la toolbar est dessinΓ©e , cet objet est garni
65 this.toolNodes = {}; // lorsque la toolbar est dessinΓ©e , cet objet est garni
66 // de raccourcis vers les Γ©lΓ©ments DOM correspondants aux outils.
66 // de raccourcis vers les Γ©lΓ©ments DOM correspondants aux outils.
67 }
67 }
68
68
69 function jsButton(title, fn, scope, className) {
69 function jsButton(title, fn, scope, className) {
70 this.title = title || null;
70 this.title = title || null;
71 this.fn = fn || function(){};
71 this.fn = fn || function(){};
72 this.scope = scope || null;
72 this.scope = scope || null;
73 this.className = className || null;
73 this.className = className || null;
74 }
74 }
75 jsButton.prototype.draw = function() {
75 jsButton.prototype.draw = function() {
76 if (!this.scope) return null;
76 if (!this.scope) return null;
77
77
78 var button = document.createElement('button');
78 var button = document.createElement('button');
79 button.setAttribute('type','button');
79 button.setAttribute('type','button');
80 if (this.className) button.className = this.className;
80 if (this.className) button.className = this.className;
81 button.title = this.title;
81 button.title = this.title;
82 var span = document.createElement('span');
82 var span = document.createElement('span');
83 span.appendChild(document.createTextNode(this.title));
83 span.appendChild(document.createTextNode(this.title));
84 button.appendChild(span);
84 button.appendChild(span);
85
85
86 if (this.icon != undefined) {
86 if (this.icon != undefined) {
87 button.style.backgroundImage = 'url('+this.icon+')';
87 button.style.backgroundImage = 'url('+this.icon+')';
88 }
88 }
89 if (typeof(this.fn) == 'function') {
89 if (typeof(this.fn) == 'function') {
90 var This = this;
90 var This = this;
91 button.onclick = function() { try { This.fn.apply(This.scope, arguments) } catch (e) {} return false; };
91 button.onclick = function() { try { This.fn.apply(This.scope, arguments) } catch (e) {} return false; };
92 }
92 }
93 return button;
93 return button;
94 }
94 }
95
95
96 function jsSpace(id) {
96 function jsSpace(id) {
97 this.id = id || null;
97 this.id = id || null;
98 this.width = null;
98 this.width = null;
99 }
99 }
100 jsSpace.prototype.draw = function() {
100 jsSpace.prototype.draw = function() {
101 var span = document.createElement('span');
101 var span = document.createElement('span');
102 if (this.id) span.id = this.id;
102 if (this.id) span.id = this.id;
103 span.appendChild(document.createTextNode(String.fromCharCode(160)));
103 span.appendChild(document.createTextNode(String.fromCharCode(160)));
104 span.className = 'jstSpacer';
104 span.className = 'jstSpacer';
105 if (this.width) span.style.marginRight = this.width+'px';
105 if (this.width) span.style.marginRight = this.width+'px';
106
106
107 return span;
107 return span;
108 }
108 }
109
109
110 function jsCombo(title, options, scope, fn, className) {
110 function jsCombo(title, options, scope, fn, className) {
111 this.title = title || null;
111 this.title = title || null;
112 this.options = options || null;
112 this.options = options || null;
113 this.scope = scope || null;
113 this.scope = scope || null;
114 this.fn = fn || function(){};
114 this.fn = fn || function(){};
115 this.className = className || null;
115 this.className = className || null;
116 }
116 }
117 jsCombo.prototype.draw = function() {
117 jsCombo.prototype.draw = function() {
118 if (!this.scope || !this.options) return null;
118 if (!this.scope || !this.options) return null;
119
119
120 var select = document.createElement('select');
120 var select = document.createElement('select');
121 if (this.className) select.className = className;
121 if (this.className) select.className = className;
122 select.title = this.title;
122 select.title = this.title;
123
123
124 for (var o in this.options) {
124 for (var o in this.options) {
125 //var opt = this.options[o];
125 //var opt = this.options[o];
126 var option = document.createElement('option');
126 var option = document.createElement('option');
127 option.value = o;
127 option.value = o;
128 option.appendChild(document.createTextNode(this.options[o]));
128 option.appendChild(document.createTextNode(this.options[o]));
129 select.appendChild(option);
129 select.appendChild(option);
130 }
130 }
131
131
132 var This = this;
132 var This = this;
133 select.onchange = function() {
133 select.onchange = function() {
134 try {
134 try {
135 This.fn.call(This.scope, this.value);
135 This.fn.call(This.scope, this.value);
136 } catch (e) { alert(e); }
136 } catch (e) { alert(e); }
137
137
138 return false;
138 return false;
139 }
139 }
140
140
141 return select;
141 return select;
142 }
142 }
143
143
144
144
145 jsToolBar.prototype = {
145 jsToolBar.prototype = {
146 base_url: '',
146 base_url: '',
147 mode: 'wiki',
147 mode: 'wiki',
148 elements: {},
148 elements: {},
149
149
150 getMode: function() {
150 getMode: function() {
151 return this.mode;
151 return this.mode;
152 },
152 },
153
153
154 setMode: function(mode) {
154 setMode: function(mode) {
155 this.mode = mode || 'wiki';
155 this.mode = mode || 'wiki';
156 },
156 },
157
157
158 switchMode: function(mode) {
158 switchMode: function(mode) {
159 mode = mode || 'wiki';
159 mode = mode || 'wiki';
160 this.draw(mode);
160 this.draw(mode);
161 },
161 },
162
162
163 button: function(toolName) {
163 button: function(toolName) {
164 var tool = this.elements[toolName];
164 var tool = this.elements[toolName];
165 if (typeof tool.fn[this.mode] != 'function') return null;
165 if (typeof tool.fn[this.mode] != 'function') return null;
166 var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_'+toolName);
166 var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_'+toolName);
167 if (tool.icon != undefined) b.icon = tool.icon;
167 if (tool.icon != undefined) b.icon = tool.icon;
168 return b;
168 return b;
169 },
169 },
170 space: function(toolName) {
170 space: function(toolName) {
171 var tool = new jsSpace(toolName)
171 var tool = new jsSpace(toolName)
172 if (this.elements[toolName].width !== undefined)
172 if (this.elements[toolName].width !== undefined)
173 tool.width = this.elements[toolName].width;
173 tool.width = this.elements[toolName].width;
174 return tool;
174 return tool;
175 },
175 },
176 combo: function(toolName) {
176 combo: function(toolName) {
177 var tool = this.elements[toolName];
177 var tool = this.elements[toolName];
178 var length = tool[this.mode].list.length;
178 var length = tool[this.mode].list.length;
179
179
180 if (typeof tool[this.mode].fn != 'function' || length == 0) {
180 if (typeof tool[this.mode].fn != 'function' || length == 0) {
181 return null;
181 return null;
182 } else {
182 } else {
183 var options = {};
183 var options = {};
184 for (var i=0; i < length; i++) {
184 for (var i=0; i < length; i++) {
185 var opt = tool[this.mode].list[i];
185 var opt = tool[this.mode].list[i];
186 options[opt] = tool.options[opt];
186 options[opt] = tool.options[opt];
187 }
187 }
188 return new jsCombo(tool.title, options, this, tool[this.mode].fn);
188 return new jsCombo(tool.title, options, this, tool[this.mode].fn);
189 }
189 }
190 },
190 },
191 draw: function(mode) {
191 draw: function(mode) {
192 this.setMode(mode);
192 this.setMode(mode);
193
193
194 // Empty toolbar
194 // Empty toolbar
195 while (this.toolbar.hasChildNodes()) {
195 while (this.toolbar.hasChildNodes()) {
196 this.toolbar.removeChild(this.toolbar.firstChild)
196 this.toolbar.removeChild(this.toolbar.firstChild)
197 }
197 }
198 this.toolNodes = {}; // vide les raccourcis DOM/**/
198 this.toolNodes = {}; // vide les raccourcis DOM/**/
199
199
200 // Draw toolbar elements
200 // Draw toolbar elements
201 var b, tool, newTool;
201 var b, tool, newTool;
202
202
203 for (var i in this.elements) {
203 for (var i in this.elements) {
204 b = this.elements[i];
204 b = this.elements[i];
205
205
206 var disabled =
206 var disabled =
207 b.type == undefined || b.type == ''
207 b.type == undefined || b.type == ''
208 || (b.disabled != undefined && b.disabled)
208 || (b.disabled != undefined && b.disabled)
209 || (b.context != undefined && b.context != null && b.context != this.context);
209 || (b.context != undefined && b.context != null && b.context != this.context);
210
210
211 if (!disabled && typeof this[b.type] == 'function') {
211 if (!disabled && typeof this[b.type] == 'function') {
212 tool = this[b.type](i);
212 tool = this[b.type](i);
213 if (tool) newTool = tool.draw();
213 if (tool) newTool = tool.draw();
214 if (newTool) {
214 if (newTool) {
215 this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur
215 this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur
216 this.toolbar.appendChild(newTool);
216 this.toolbar.appendChild(newTool);
217 }
217 }
218 }
218 }
219 }
219 }
220 },
220 },
221
221
222 singleTag: function(stag,etag) {
222 singleTag: function(stag,etag) {
223 stag = stag || null;
223 stag = stag || null;
224 etag = etag || stag;
224 etag = etag || stag;
225
225
226 if (!stag || !etag) { return; }
226 if (!stag || !etag) { return; }
227
227
228 this.encloseSelection(stag,etag);
228 this.encloseSelection(stag,etag);
229 },
229 },
230
230
231 encloseSelection: function(prefix, suffix, fn) {
231 encloseSelection: function(prefix, suffix, fn) {
232 this.textarea.focus();
232 this.textarea.focus();
233
233
234 prefix = prefix || '';
234 prefix = prefix || '';
235 suffix = suffix || '';
235 suffix = suffix || '';
236
236
237 var start, end, sel, scrollPos, subst, res;
237 var start, end, sel, scrollPos, subst, res;
238
238
239 if (typeof(document["selection"]) != "undefined") {
239 if (typeof(document["selection"]) != "undefined") {
240 sel = document.selection.createRange().text;
240 sel = document.selection.createRange().text;
241 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
241 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
242 start = this.textarea.selectionStart;
242 start = this.textarea.selectionStart;
243 end = this.textarea.selectionEnd;
243 end = this.textarea.selectionEnd;
244 scrollPos = this.textarea.scrollTop;
244 scrollPos = this.textarea.scrollTop;
245 sel = this.textarea.value.substring(start, end);
245 sel = this.textarea.value.substring(start, end);
246 }
246 }
247
247
248 if (sel.match(/ $/)) { // exclude ending space char, if any
248 if (sel.match(/ $/)) { // exclude ending space char, if any
249 sel = sel.substring(0, sel.length - 1);
249 sel = sel.substring(0, sel.length - 1);
250 suffix = suffix + " ";
250 suffix = suffix + " ";
251 }
251 }
252
252
253 if (typeof(fn) == 'function') {
253 if (typeof(fn) == 'function') {
254 res = (sel) ? fn.call(this,sel) : fn('');
254 res = (sel) ? fn.call(this,sel) : fn('');
255 } else {
255 } else {
256 res = (sel) ? sel : '';
256 res = (sel) ? sel : '';
257 }
257 }
258
258
259 subst = prefix + res + suffix;
259 subst = prefix + res + suffix;
260
260
261 if (typeof(document["selection"]) != "undefined") {
261 if (typeof(document["selection"]) != "undefined") {
262 var range = document.selection.createRange().text = subst;
262 document.selection.createRange().text = subst;
263 this.textarea.caretPos -= suffix.length;
263 var range = this.textarea.createTextRange();
264 range.collapse(false);
265 range.move('character', -suffix.length);
266 range.select();
267 // this.textarea.caretPos -= suffix.length;
264 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
268 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
265 this.textarea.value = this.textarea.value.substring(0, start) + subst +
269 this.textarea.value = this.textarea.value.substring(0, start) + subst +
266 this.textarea.value.substring(end);
270 this.textarea.value.substring(end);
267 if (sel) {
271 if (sel) {
268 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
272 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
269 } else {
273 } else {
270 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
274 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
271 }
275 }
272 this.textarea.scrollTop = scrollPos;
276 this.textarea.scrollTop = scrollPos;
273 }
277 }
274 },
278 },
275
279
276 stripBaseURL: function(url) {
280 stripBaseURL: function(url) {
277 if (this.base_url != '') {
281 if (this.base_url != '') {
278 var pos = url.indexOf(this.base_url);
282 var pos = url.indexOf(this.base_url);
279 if (pos == 0) {
283 if (pos == 0) {
280 url = url.substr(this.base_url.length);
284 url = url.substr(this.base_url.length);
281 }
285 }
282 }
286 }
283
287
284 return url;
288 return url;
285 }
289 }
286 };
290 };
287
291
288 /** Resizer
292 /** Resizer
289 -------------------------------------------------------- */
293 -------------------------------------------------------- */
290 jsToolBar.prototype.resizeSetStartH = function() {
294 jsToolBar.prototype.resizeSetStartH = function() {
291 this.dragStartH = this.textarea.offsetHeight + 0;
295 this.dragStartH = this.textarea.offsetHeight + 0;
292 };
296 };
293 jsToolBar.prototype.resizeDragStart = function(event) {
297 jsToolBar.prototype.resizeDragStart = function(event) {
294 var This = this;
298 var This = this;
295 this.dragStartY = event.clientY;
299 this.dragStartY = event.clientY;
296 this.resizeSetStartH();
300 this.resizeSetStartH();
297 document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false);
301 document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false);
298 document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false);
302 document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false);
299 };
303 };
300
304
301 jsToolBar.prototype.resizeDragMove = function(event) {
305 jsToolBar.prototype.resizeDragMove = function(event) {
302 this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px';
306 this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px';
303 };
307 };
304
308
305 jsToolBar.prototype.resizeDragStop = function(event) {
309 jsToolBar.prototype.resizeDragStop = function(event) {
306 document.removeEventListener('mousemove', this.dragMoveHdlr, false);
310 document.removeEventListener('mousemove', this.dragMoveHdlr, false);
307 document.removeEventListener('mouseup', this.dragStopHdlr, false);
311 document.removeEventListener('mouseup', this.dragStopHdlr, false);
308 };
312 };
309
313
310 // Elements definition ------------------------------------
314 // Elements definition ------------------------------------
311
315
312 // strong
316 // strong
313 jsToolBar.prototype.elements.strong = {
317 jsToolBar.prototype.elements.strong = {
314 type: 'button',
318 type: 'button',
315 title: 'Strong emphasis',
319 title: 'Strong emphasis',
316 fn: {
320 fn: {
317 wiki: function() { this.singleTag('*') }
321 wiki: function() { this.singleTag('*') }
318 }
322 }
319 }
323 }
320
324
321 // em
325 // em
322 jsToolBar.prototype.elements.em = {
326 jsToolBar.prototype.elements.em = {
323 type: 'button',
327 type: 'button',
324 title: 'Emphasis',
328 title: 'Emphasis',
325 fn: {
329 fn: {
326 wiki: function() { this.singleTag("_") }
330 wiki: function() { this.singleTag("_") }
327 }
331 }
328 }
332 }
329
333
330 // ins
334 // ins
331 jsToolBar.prototype.elements.ins = {
335 jsToolBar.prototype.elements.ins = {
332 type: 'button',
336 type: 'button',
333 title: 'Inserted',
337 title: 'Inserted',
334 fn: {
338 fn: {
335 wiki: function() { this.singleTag('+') }
339 wiki: function() { this.singleTag('+') }
336 }
340 }
337 }
341 }
338
342
339 // del
343 // del
340 jsToolBar.prototype.elements.del = {
344 jsToolBar.prototype.elements.del = {
341 type: 'button',
345 type: 'button',
342 title: 'Deleted',
346 title: 'Deleted',
343 fn: {
347 fn: {
344 wiki: function() { this.singleTag('-') }
348 wiki: function() { this.singleTag('-') }
345 }
349 }
346 }
350 }
347
351
348 // quote
352 // quote
349 jsToolBar.prototype.elements.quote = {
353 jsToolBar.prototype.elements.quote = {
350 type: 'button',
354 type: 'button',
351 title: 'Inline quote',
355 title: 'Inline quote',
352 fn: {
356 fn: {
353 wiki: function() { this.singleTag('??') }
357 wiki: function() { this.singleTag('??') }
354 }
358 }
355 }
359 }
356
360
357 // code
361 // code
358 jsToolBar.prototype.elements.code = {
362 jsToolBar.prototype.elements.code = {
359 type: 'button',
363 type: 'button',
360 title: 'Code',
364 title: 'Code',
361 fn: {
365 fn: {
362 wiki: function() { this.singleTag('@') }
366 wiki: function() { this.singleTag('@') }
363 }
367 }
364 }
368 }
365
369
366 // spacer
370 // spacer
367 jsToolBar.prototype.elements.space1 = {type: 'space'}
371 jsToolBar.prototype.elements.space1 = {type: 'space'}
368
372
369 // heading
373 // heading
370 jsToolBar.prototype.elements.heading = {
374 jsToolBar.prototype.elements.heading = {
371 type: 'button',
375 type: 'button',
372 title: 'Heading',
376 title: 'Heading',
373 fn: {
377 fn: {
374 wiki: function() {
378 wiki: function() {
375 this.encloseSelection('','',function(str) {
379 this.encloseSelection('','',function(str) {
376 str = str.replace(/\r/g,'');
380 str = str.replace(/\r/g,'');
377 return 'h2. '+str.replace(/\n/g,"\n* ");
381 return 'h2. '+str.replace(/\n/g,"\n* ");
378 });
382 });
379 }
383 }
380 }
384 }
381 }
385 }
382
386
383 // br
387 // br
384 //jsToolBar.prototype.elements.br = {
388 //jsToolBar.prototype.elements.br = {
385 // type: 'button',
389 // type: 'button',
386 // title: 'Line break',
390 // title: 'Line break',
387 // fn: {
391 // fn: {
388 // wiki: function() { this.encloseSelection("%%%\n",'') }
392 // wiki: function() { this.encloseSelection("%%%\n",'') }
389 // }
393 // }
390 //}
394 //}
391
395
392 // spacer
396 // spacer
393 jsToolBar.prototype.elements.space2 = {type: 'space'}
397 jsToolBar.prototype.elements.space2 = {type: 'space'}
394
398
395 // ul
399 // ul
396 jsToolBar.prototype.elements.ul = {
400 jsToolBar.prototype.elements.ul = {
397 type: 'button',
401 type: 'button',
398 title: 'Unordered list',
402 title: 'Unordered list',
399 fn: {
403 fn: {
400 wiki: function() {
404 wiki: function() {
401 this.encloseSelection('','',function(str) {
405 this.encloseSelection('','',function(str) {
402 str = str.replace(/\r/g,'');
406 str = str.replace(/\r/g,'');
403 return '* '+str.replace(/\n/g,"\n* ");
407 return '* '+str.replace(/\n/g,"\n* ");
404 });
408 });
405 }
409 }
406 }
410 }
407 }
411 }
408
412
409 // ol
413 // ol
410 jsToolBar.prototype.elements.ol = {
414 jsToolBar.prototype.elements.ol = {
411 type: 'button',
415 type: 'button',
412 title: 'Ordered list',
416 title: 'Ordered list',
413 fn: {
417 fn: {
414 wiki: function() {
418 wiki: function() {
415 this.encloseSelection('','',function(str) {
419 this.encloseSelection('','',function(str) {
416 str = str.replace(/\r/g,'');
420 str = str.replace(/\r/g,'');
417 return '# '+str.replace(/\n/g,"\n# ");
421 return '# '+str.replace(/\n/g,"\n# ");
418 });
422 });
419 }
423 }
420 }
424 }
421 }
425 }
422
426
423 // spacer
427 // spacer
424 jsToolBar.prototype.elements.space3 = {type: 'space'}
428 jsToolBar.prototype.elements.space3 = {type: 'space'}
425
429
426 // link
430 // link
427 /*
431 /*
428 jsToolBar.prototype.elements.link = {
432 jsToolBar.prototype.elements.link = {
429 type: 'button',
433 type: 'button',
430 title: 'Link',
434 title: 'Link',
431 fn: {},
435 fn: {},
432 href_prompt: 'Please give page URL:',
436 href_prompt: 'Please give page URL:',
433 hreflang_prompt: 'Language of this page:',
437 hreflang_prompt: 'Language of this page:',
434 default_hreflang: '',
438 default_hreflang: '',
435 prompt: function(href,hreflang) {
439 prompt: function(href,hreflang) {
436 href = href || '';
440 href = href || '';
437 hreflang = hreflang || this.elements.link.default_hreflang;
441 hreflang = hreflang || this.elements.link.default_hreflang;
438
442
439 href = window.prompt(this.elements.link.href_prompt,href);
443 href = window.prompt(this.elements.link.href_prompt,href);
440 if (!href) { return false; }
444 if (!href) { return false; }
441
445
442 hreflang = ""
446 hreflang = ""
443
447
444 return { href: this.stripBaseURL(href), hreflang: hreflang };
448 return { href: this.stripBaseURL(href), hreflang: hreflang };
445 }
449 }
446 }
450 }
447
451
448 jsToolBar.prototype.elements.link.fn.wiki = function() {
452 jsToolBar.prototype.elements.link.fn.wiki = function() {
449 var link = this.elements.link.prompt.call(this);
453 var link = this.elements.link.prompt.call(this);
450 if (link) {
454 if (link) {
451 var stag = '"';
455 var stag = '"';
452 var etag = '":'+link.href;
456 var etag = '":'+link.href;
453 this.encloseSelection(stag,etag);
457 this.encloseSelection(stag,etag);
454 }
458 }
455 };
459 };
456 */
460 */
457 // link or wiki page
461 // link or wiki page
458 jsToolBar.prototype.elements.link = {
462 jsToolBar.prototype.elements.link = {
459 type: 'button',
463 type: 'button',
460 title: 'Link',
464 title: 'Link',
461 fn: {
465 fn: {
462 wiki: function() { this.encloseSelection("[[", "]]") }
466 wiki: function() { this.encloseSelection("[[", "]]") }
463 }
467 }
464 }
468 }
General Comments 0
You need to be logged in to leave comments. Login now