From 4e1e5985a1a6763d5413ccd0524213d8cd3dc4a7 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 13 Jan 2008 18:39:37 +0000 Subject: [PATCH] Wiki toolbar improvements (mainly for Firefox). git-svn-id: http://redmine.rubyforge.org/svn/trunk@1063 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- public/images/jstoolbar/bt_h1.png | Bin 0 -> 995 bytes public/images/jstoolbar/bt_h2.png | Bin 0 -> 994 bytes public/images/jstoolbar/bt_h3.png | Bin 0 -> 993 bytes public/images/jstoolbar/bt_heading.png | Bin 415 -> 0 bytes public/images/jstoolbar/bt_img.png | Bin 0 -> 566 bytes public/images/jstoolbar/bt_pre.png | Bin 0 -> 224 bytes public/javascripts/jstoolbar.js | 161 ++++++++++++++++--------- public/stylesheets/jstoolbar.css | 16 ++- 8 files changed, 121 insertions(+), 56 deletions(-) create mode 100644 public/images/jstoolbar/bt_h1.png create mode 100644 public/images/jstoolbar/bt_h2.png create mode 100644 public/images/jstoolbar/bt_h3.png delete mode 100644 public/images/jstoolbar/bt_heading.png create mode 100644 public/images/jstoolbar/bt_img.png create mode 100644 public/images/jstoolbar/bt_pre.png diff --git a/public/images/jstoolbar/bt_h1.png b/public/images/jstoolbar/bt_h1.png new file mode 100644 index 0000000000000000000000000000000000000000..01f3eec0da09b79d6f034e68cfd31179826f7f17 GIT binary patch literal 995 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc3?z4jzqJQa`X#OrCC){ui6xo&c?uz!xv2~( znYnrjhQgdOUMOd?Xt6_lB;h-mn#I!Y+$cyQk~WcB0_ cNMe#?U^&QWnY-YWH&7dcr>mdKI;Vst0GR|Z`2YX_ literal 0 HcmV?d00001 diff --git a/public/images/jstoolbar/bt_h2.png b/public/images/jstoolbar/bt_h2.png new file mode 100644 index 0000000000000000000000000000000000000000..36b15048e67810f070655de8d1c67fa7d2d3b04a GIT binary patch literal 994 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc3?z4jzqJQa`X#OrCC){ui6xo&c?uz!xv2~( znYnrjhQgd21s-(chw)Z}tG zQe_Ji;wgd2rgGX-q}Lj!}t>8refI@wD+eO=kFGjnqrD?XQe zmNn{1`zj(ShhE&`-8e+)RVjy7C zZ_<>Yn34FB|4(~w!pm+Q-I}%umoE9$H1l6L<>ZlE$joi&bM3K6-|eKEb5rJ=<$IyA zRIdDS0YR-q^Cl=KR6)o8DZ$)#LeVpZcEH zR$GF+vKntE&wjEY&#gh=H$Mkc-My2ANS8c$bC9M+pTD)Q#H{444$rjF6*2U Fng9-Op=SU9 diff --git a/public/images/jstoolbar/bt_img.png b/public/images/jstoolbar/bt_img.png new file mode 100644 index 0000000000000000000000000000000000000000..91c9a8a87caa26e20c36a13412c39b7ba9bda2fc GIT binary patch literal 566 zcmV-60?GY}P)WdLMpZ7v`&GazbVZgwspGB7YWATc;PFfckWF(4~2F)%RvFe$SD000Mc zNliru*Z~a@HZeGroreGb010qNS#tmY3h)2`3h)6!tTdPa000DMK}|sb0I`n?{9y$E z00D|gL_t(|+QpN-PQx%1g>A=95NQYqkf!O(?ISJ#=OC7e z6HCkiQGx*yNev(aaC&_T5BB#a;ehKExdq@~Z?Yg39j}^^OfW(?$$`lN)7;SXL!JTa z7-4Lr@BI=}E5MM+Oc-iJ9|OkZ@PP^~1IC(y4THRH=bwo7rJSOB5wbHScvNSsW|&71 zqA1RSncy31cRTsI3gMC}=VbH#y>y$v9kOaUT~B`EE3|+!V2aD@)?24f84vuhnQRr0 zRxI@+pv!vYYC|WciEb#m1mJjTt600+{AhYbpSGn;x}pXslT(Bs@e%Kpmu=H=a&bm- z+jrf@ix4~k(~c@3rAP%;{nB!+O09LiYiE77C*t^!#w92`3FHr)&ZQ&P!J-WuJ3m7H zb++N?K6{>*rVVSL2U7!wG1m9}CCe%l3X|{*HNX4(4Q#Z$hI?fv$p8QV07*qoM6N<$ Eg0*1dWdHyG literal 0 HcmV?d00001 diff --git a/public/images/jstoolbar/bt_pre.png b/public/images/jstoolbar/bt_pre.png new file mode 100644 index 0000000000000000000000000000000000000000..df3f917d0eebb3d8ddcb46a2eee079aae81b2a20 GIT binary patch literal 224 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAj3?#R^_xk}Uu@cva66d1S#FEVXJcW?V+*Aew zLwy4aeFKxKVg@Ck3ic9DUsv`UjJ!O|R+1gtW&wpb3p^r=85p=efH0%e8j~47L6&q! zUq=Rpjs4tz5?O(Kwg8_HS0Mf7)x86$CHsIZrjj7P;QtIyw;Ol?dAgo1jv*Ddl7IaF z&&;e>6S2JE;hHCGZJVb#QJpKp9+V7RJk_(rq0_#jXtgQu&X J%Q~loCIFC%L`nbv literal 0 HcmV?d00001 diff --git a/public/javascripts/jstoolbar.js b/public/javascripts/jstoolbar.js index fd4611e2d..b94a4ed80 100644 --- a/public/javascripts/jstoolbar.js +++ b/public/javascripts/jstoolbar.js @@ -228,6 +228,58 @@ jsToolBar.prototype = { this.encloseSelection(stag,etag); }, + encloseLineSelection: function(prefix, suffix, fn) { + this.textarea.focus(); + + prefix = prefix || ''; + suffix = suffix || ''; + + var start, end, sel, scrollPos, subst, res; + + if (typeof(document["selection"]) != "undefined") { + sel = document.selection.createRange().text; + } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { + start = this.textarea.selectionStart; + end = this.textarea.selectionEnd; + scrollPos = this.textarea.scrollTop; + // go to the start of the line + start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length; + // go to the end of the line + end = this.textarea.value.length - this.textarea.value.substring(end, this.textarea.value.length).replace(/^[^\r\n]*/, '').length; + sel = this.textarea.value.substring(start, end); + } + + if (sel.match(/ $/)) { // exclude ending space char, if any + sel = sel.substring(0, sel.length - 1); + suffix = suffix + " "; + } + + if (typeof(fn) == 'function') { + res = (sel) ? fn.call(this,sel) : fn(''); + } else { + res = (sel) ? sel : ''; + } + + subst = prefix + res + suffix; + + if (typeof(document["selection"]) != "undefined") { + document.selection.createRange().text = subst; + var range = this.textarea.createTextRange(); + range.collapse(false); + range.move('character', -suffix.length); + range.select(); + } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { + this.textarea.value = this.textarea.value.substring(0, start) + subst + + this.textarea.value.substring(end); + if (sel) { + this.textarea.setSelectionRange(start + subst.length, start + subst.length); + } else { + this.textarea.setSelectionRange(start + prefix.length, start + prefix.length); + } + this.textarea.scrollTop = scrollPos; + } + }, + encloseSelection: function(prefix, suffix, fn) { this.textarea.focus(); @@ -370,28 +422,43 @@ jsToolBar.prototype.elements.code = { // spacer jsToolBar.prototype.elements.space1 = {type: 'space'} -// heading -jsToolBar.prototype.elements.heading = { +// headings +jsToolBar.prototype.elements.h1 = { type: 'button', - title: 'Heading', + title: 'Heading 1', fn: { - wiki: function() { - this.encloseSelection('','',function(str) { - str = str.replace(/\r/g,''); - return 'h2. '+str.replace(/\n/g,"\n* "); - }); + wiki: function() { + this.encloseLineSelection('h1. ', '',function(str) { + str = str.replace(/^h\d+\.\s+/, '') + return str; + }); + } + } +} +jsToolBar.prototype.elements.h2 = { + type: 'button', + title: 'Heading 2', + fn: { + wiki: function() { + this.encloseLineSelection('h2. ', '',function(str) { + str = str.replace(/^h\d+\.\s+/, '') + return str; + }); + } + } +} +jsToolBar.prototype.elements.h3 = { + type: 'button', + title: 'Heading 3', + fn: { + wiki: function() { + this.encloseLineSelection('h3. ', '',function(str) { + str = str.replace(/^h\d+\.\s+/, '') + return str; + }); } } } - -// br -//jsToolBar.prototype.elements.br = { -// type: 'button', -// title: 'Line break', -// fn: { -// wiki: function() { this.encloseSelection("%%%\n",'') } -// } -//} // spacer jsToolBar.prototype.elements.space2 = {type: 'space'} @@ -402,9 +469,9 @@ jsToolBar.prototype.elements.ul = { title: 'Unordered list', fn: { wiki: function() { - this.encloseSelection('','',function(str) { + this.encloseLineSelection('','',function(str) { str = str.replace(/\r/g,''); - return '* '+str.replace(/\n/g,"\n* "); + return str.replace(/(\n|^)[#-]?\s*/g,"$1* "); }); } } @@ -416,53 +483,39 @@ jsToolBar.prototype.elements.ol = { title: 'Ordered list', fn: { wiki: function() { - this.encloseSelection('','',function(str) { + this.encloseLineSelection('','',function(str) { str = str.replace(/\r/g,''); - return '# '+str.replace(/\n/g,"\n# "); + return str.replace(/(\n|^)[*-]?\s*/g,"$1# "); }); } } } +// pre +jsToolBar.prototype.elements.pre = { + type: 'button', + title: 'Preformatted text', + fn: { + wiki: function() { this.encloseLineSelection('
\n', '\n
') } + } +} + // spacer jsToolBar.prototype.elements.space3 = {type: 'space'} -// link -/* +// wiki page jsToolBar.prototype.elements.link = { type: 'button', - title: 'Link', - fn: {}, - href_prompt: 'Please give page URL:', - hreflang_prompt: 'Language of this page:', - default_hreflang: '', - prompt: function(href,hreflang) { - href = href || ''; - hreflang = hreflang || this.elements.link.default_hreflang; - - href = window.prompt(this.elements.link.href_prompt,href); - if (!href) { return false; } - - hreflang = "" - - return { href: this.stripBaseURL(href), hreflang: hreflang }; - } -} - -jsToolBar.prototype.elements.link.fn.wiki = function() { - var link = this.elements.link.prompt.call(this); - if (link) { - var stag = '"'; - var etag = '":'+link.href; - this.encloseSelection(stag,etag); - } -}; -*/ -// link or wiki page -jsToolBar.prototype.elements.link = { - type: 'button', - title: 'Link', + title: 'Wiki Page Link', fn: { wiki: function() { this.encloseSelection("[[", "]]") } } } +// image +jsToolBar.prototype.elements.img = { + type: 'button', + title: 'Inline image', + fn: { + wiki: function() { this.encloseSelection("!", "!") } + } +} diff --git a/public/stylesheets/jstoolbar.css b/public/stylesheets/jstoolbar.css index 62976e537..df5d2a633 100644 --- a/public/stylesheets/jstoolbar.css +++ b/public/stylesheets/jstoolbar.css @@ -67,8 +67,14 @@ .jstb_br { background-image: url(../images/jstoolbar/bt_br.png); } -.jstb_heading { - background-image: url(../images/jstoolbar/bt_heading.png); +.jstb_h1 { + background-image: url(../images/jstoolbar/bt_h1.png); +} +.jstb_h2 { + background-image: url(../images/jstoolbar/bt_h2.png); +} +.jstb_h3 { + background-image: url(../images/jstoolbar/bt_h3.png); } .jstb_ul { background-image: url(../images/jstoolbar/bt_ul.png); @@ -76,6 +82,12 @@ .jstb_ol { background-image: url(../images/jstoolbar/bt_ol.png); } +.jstb_pre { + background-image: url(../images/jstoolbar/bt_pre.png); +} .jstb_link { background-image: url(../images/jstoolbar/bt_link.png); } +.jstb_img { + background-image: url(../images/jstoolbar/bt_img.png); +}