##// END OF EJS Templates
Wiki toolbar improvements (mainly for Firefox)....
Jean-Philippe Lang -
r1049:4e1e5985a1a6
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: file renamed from public/images/jstoolbar/bt_heading.png to public/images/jstoolbar/bt_img.png, binary diff hidden
@@ -228,6 +228,58 jsToolBar.prototype = {
228 228 this.encloseSelection(stag,etag);
229 229 },
230 230
231 encloseLineSelection: function(prefix, suffix, fn) {
232 this.textarea.focus();
233
234 prefix = prefix || '';
235 suffix = suffix || '';
236
237 var start, end, sel, scrollPos, subst, res;
238
239 if (typeof(document["selection"]) != "undefined") {
240 sel = document.selection.createRange().text;
241 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
242 start = this.textarea.selectionStart;
243 end = this.textarea.selectionEnd;
244 scrollPos = this.textarea.scrollTop;
245 // go to the start of the line
246 start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length;
247 // go to the end of the line
248 end = this.textarea.value.length - this.textarea.value.substring(end, this.textarea.value.length).replace(/^[^\r\n]*/, '').length;
249 sel = this.textarea.value.substring(start, end);
250 }
251
252 if (sel.match(/ $/)) { // exclude ending space char, if any
253 sel = sel.substring(0, sel.length - 1);
254 suffix = suffix + " ";
255 }
256
257 if (typeof(fn) == 'function') {
258 res = (sel) ? fn.call(this,sel) : fn('');
259 } else {
260 res = (sel) ? sel : '';
261 }
262
263 subst = prefix + res + suffix;
264
265 if (typeof(document["selection"]) != "undefined") {
266 document.selection.createRange().text = subst;
267 var range = this.textarea.createTextRange();
268 range.collapse(false);
269 range.move('character', -suffix.length);
270 range.select();
271 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
272 this.textarea.value = this.textarea.value.substring(0, start) + subst +
273 this.textarea.value.substring(end);
274 if (sel) {
275 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
276 } else {
277 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
278 }
279 this.textarea.scrollTop = scrollPos;
280 }
281 },
282
231 283 encloseSelection: function(prefix, suffix, fn) {
232 284 this.textarea.focus();
233 285
@@ -370,28 +422,43 jsToolBar.prototype.elements.code = {
370 422 // spacer
371 423 jsToolBar.prototype.elements.space1 = {type: 'space'}
372 424
373 // heading
374 jsToolBar.prototype.elements.heading = {
425 // headings
426 jsToolBar.prototype.elements.h1 = {
375 427 type: 'button',
376 title: 'Heading',
428 title: 'Heading 1',
377 429 fn: {
378 wiki: function() {
379 this.encloseSelection('','',function(str) {
380 str = str.replace(/\r/g,'');
381 return 'h2. '+str.replace(/\n/g,"\n* ");
382 });
430 wiki: function() {
431 this.encloseLineSelection('h1. ', '',function(str) {
432 str = str.replace(/^h\d+\.\s+/, '')
433 return str;
434 });
435 }
436 }
437 }
438 jsToolBar.prototype.elements.h2 = {
439 type: 'button',
440 title: 'Heading 2',
441 fn: {
442 wiki: function() {
443 this.encloseLineSelection('h2. ', '',function(str) {
444 str = str.replace(/^h\d+\.\s+/, '')
445 return str;
446 });
447 }
448 }
449 }
450 jsToolBar.prototype.elements.h3 = {
451 type: 'button',
452 title: 'Heading 3',
453 fn: {
454 wiki: function() {
455 this.encloseLineSelection('h3. ', '',function(str) {
456 str = str.replace(/^h\d+\.\s+/, '')
457 return str;
458 });
383 459 }
384 460 }
385 461 }
386
387 // br
388 //jsToolBar.prototype.elements.br = {
389 // type: 'button',
390 // title: 'Line break',
391 // fn: {
392 // wiki: function() { this.encloseSelection("%%%\n",'') }
393 // }
394 //}
395 462
396 463 // spacer
397 464 jsToolBar.prototype.elements.space2 = {type: 'space'}
@@ -402,9 +469,9 jsToolBar.prototype.elements.ul = {
402 469 title: 'Unordered list',
403 470 fn: {
404 471 wiki: function() {
405 this.encloseSelection('','',function(str) {
472 this.encloseLineSelection('','',function(str) {
406 473 str = str.replace(/\r/g,'');
407 return '* '+str.replace(/\n/g,"\n* ");
474 return str.replace(/(\n|^)[#-]?\s*/g,"$1* ");
408 475 });
409 476 }
410 477 }
@@ -416,53 +483,39 jsToolBar.prototype.elements.ol = {
416 483 title: 'Ordered list',
417 484 fn: {
418 485 wiki: function() {
419 this.encloseSelection('','',function(str) {
486 this.encloseLineSelection('','',function(str) {
420 487 str = str.replace(/\r/g,'');
421 return '# '+str.replace(/\n/g,"\n# ");
488 return str.replace(/(\n|^)[*-]?\s*/g,"$1# ");
422 489 });
423 490 }
424 491 }
425 492 }
426 493
494 // pre
495 jsToolBar.prototype.elements.pre = {
496 type: 'button',
497 title: 'Preformatted text',
498 fn: {
499 wiki: function() { this.encloseLineSelection('<pre>\n', '\n</pre>') }
500 }
501 }
502
427 503 // spacer
428 504 jsToolBar.prototype.elements.space3 = {type: 'space'}
429 505
430 // link
431 /*
506 // wiki page
432 507 jsToolBar.prototype.elements.link = {
433 508 type: 'button',
434 title: 'Link',
435 fn: {},
436 href_prompt: 'Please give page URL:',
437 hreflang_prompt: 'Language of this page:',
438 default_hreflang: '',
439 prompt: function(href,hreflang) {
440 href = href || '';
441 hreflang = hreflang || this.elements.link.default_hreflang;
442
443 href = window.prompt(this.elements.link.href_prompt,href);
444 if (!href) { return false; }
445
446 hreflang = ""
447
448 return { href: this.stripBaseURL(href), hreflang: hreflang };
509 title: 'Wiki Page Link',
510 fn: {
511 wiki: function() { this.encloseSelection("[[", "]]") }
449 512 }
450 513 }
451
452 jsToolBar.prototype.elements.link.fn.wiki = function() {
453 var link = this.elements.link.prompt.call(this);
454 if (link) {
455 var stag = '"';
456 var etag = '":'+link.href;
457 this.encloseSelection(stag,etag);
458 }
459 };
460 */
461 // link or wiki page
462 jsToolBar.prototype.elements.link = {
514 // image
515 jsToolBar.prototype.elements.img = {
463 516 type: 'button',
464 title: 'Link',
517 title: 'Inline image',
465 518 fn: {
466 wiki: function() { this.encloseSelection("[[", "]]") }
519 wiki: function() { this.encloseSelection("!", "!") }
467 520 }
468 521 }
@@ -67,8 +67,14
67 67 .jstb_br {
68 68 background-image: url(../images/jstoolbar/bt_br.png);
69 69 }
70 .jstb_heading {
71 background-image: url(../images/jstoolbar/bt_heading.png);
70 .jstb_h1 {
71 background-image: url(../images/jstoolbar/bt_h1.png);
72 }
73 .jstb_h2 {
74 background-image: url(../images/jstoolbar/bt_h2.png);
75 }
76 .jstb_h3 {
77 background-image: url(../images/jstoolbar/bt_h3.png);
72 78 }
73 79 .jstb_ul {
74 80 background-image: url(../images/jstoolbar/bt_ul.png);
@@ -76,6 +82,12
76 82 .jstb_ol {
77 83 background-image: url(../images/jstoolbar/bt_ol.png);
78 84 }
85 .jstb_pre {
86 background-image: url(../images/jstoolbar/bt_pre.png);
87 }
79 88 .jstb_link {
80 89 background-image: url(../images/jstoolbar/bt_link.png);
81 90 }
91 .jstb_img {
92 background-image: url(../images/jstoolbar/bt_img.png);
93 }
General Comments 0
You need to be logged in to leave comments. Login now