##// END OF EJS Templates
Icon for the textile help link....
Jean-Philippe Lang -
r10857:a18f6ffb3752
parent child
Show More
@@ -1,49 +1,46
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 module Redmine
18 module Redmine
19 module WikiFormatting
19 module WikiFormatting
20 module Textile
20 module Textile
21 module Helper
21 module Helper
22 def wikitoolbar_for(field_id)
22 def wikitoolbar_for(field_id)
23 heads_for_wiki_formatter
23 heads_for_wiki_formatter
24 # Is there a simple way to link to a public resource?
24 # Is there a simple way to link to a public resource?
25 url = "#{Redmine::Utils.relative_url_root}/help/wiki_syntax.html"
25 url = "#{Redmine::Utils.relative_url_root}/help/wiki_syntax.html"
26 help_link = link_to(l(:setting_text_formatting), url,
26 javascript_tag("var wikiToolbar = new jsToolBar(document.getElementById('#{field_id}')); wikiToolbar.setHelpLink('#{escape_javascript url}'); wikiToolbar.draw();")
27 :onclick => "window.open(\"#{ url }\", \"\", \"resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes\"); return false;")
28
29 javascript_tag("var wikiToolbar = new jsToolBar(document.getElementById('#{field_id}')); wikiToolbar.setHelpLink('#{escape_javascript help_link}'); wikiToolbar.draw();")
30 end
27 end
31
28
32 def initial_page_content(page)
29 def initial_page_content(page)
33 "h1. #{@page.pretty_title}"
30 "h1. #{@page.pretty_title}"
34 end
31 end
35
32
36 def heads_for_wiki_formatter
33 def heads_for_wiki_formatter
37 unless @heads_for_wiki_formatter_included
34 unless @heads_for_wiki_formatter_included
38 content_for :header_tags do
35 content_for :header_tags do
39 javascript_include_tag('jstoolbar/jstoolbar-textile.min') +
36 javascript_include_tag('jstoolbar/jstoolbar-textile.min') +
40 javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
37 javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
41 stylesheet_link_tag('jstoolbar')
38 stylesheet_link_tag('jstoolbar')
42 end
39 end
43 @heads_for_wiki_formatter_included = true
40 @heads_for_wiki_formatter_included = true
44 end
41 end
45 end
42 end
46 end
43 end
47 end
44 end
48 end
45 end
49 end
46 end
@@ -1,1 +1,2
1 function jsToolBar(e){if(!document.createElement){return}if(!e){return}if(typeof document["selection"]=="undefined"&&typeof e["setSelectionRange"]=="undefined"){return}this.textarea=e;this.editor=document.createElement("div");this.editor.className="jstEditor";this.textarea.parentNode.insertBefore(this.editor,this.textarea);this.editor.appendChild(this.textarea);this.toolbar=document.createElement("div");this.toolbar.className="jstElements";this.editor.parentNode.insertBefore(this.toolbar,this.editor);if(this.editor.addEventListener&&navigator.appVersion.match(/\bMSIE\b/)){this.handle=document.createElement("div");this.handle.className="jstHandle";var t=this.resizeDragStart;var n=this;this.handle.addEventListener("mousedown",function(e){t.call(n,e)},false);window.addEventListener("unload",function(){var e=n.handle.parentNode.removeChild(n.handle);delete n.handle},false);this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling)}this.context=null;this.toolNodes={}}function jsButton(e,t,n,r){if(typeof jsToolBar.strings=="undefined"){this.title=e||null}else{this.title=jsToolBar.strings[e]||e||null}this.fn=t||function(){};this.scope=n||null;this.className=r||null}function jsSpace(e){this.id=e||null;this.width=null}function jsCombo(e,t,n,r,i){this.title=e||null;this.options=t||null;this.scope=n||null;this.fn=r||function(){};this.className=i||null}jsButton.prototype.draw=function(){if(!this.scope)return null;var e=document.createElement("button");e.setAttribute("type","button");e.tabIndex=200;if(this.className)e.className=this.className;e.title=this.title;var t=document.createElement("span");t.appendChild(document.createTextNode(this.title));e.appendChild(t);if(this.icon!=undefined){e.style.backgroundImage="url("+this.icon+")"}if(typeof this.fn=="function"){var n=this;e.onclick=function(){try{n.fn.apply(n.scope,arguments)}catch(e){}return false}}return e};jsSpace.prototype.draw=function(){var e=document.createElement("span");if(this.id)e.id=this.id;e.appendChild(document.createTextNode(String.fromCharCode(160)));e.className="jstSpacer";if(this.width)e.style.marginRight=this.width+"px";return e};jsCombo.prototype.draw=function(){if(!this.scope||!this.options)return null;var e=document.createElement("select");if(this.className)e.className=className;e.title=this.title;for(var t in this.options){var n=document.createElement("option");n.value=t;n.appendChild(document.createTextNode(this.options[t]));e.appendChild(n)}var r=this;e.onchange=function(){try{r.fn.call(r.scope,this.value)}catch(e){alert(e)}return false};return e};jsToolBar.prototype={base_url:"",mode:"wiki",elements:{},help_link:"",getMode:function(){return this.mode},setMode:function(e){this.mode=e||"wiki"},switchMode:function(e){e=e||"wiki";this.draw(e)},setHelpLink:function(e){this.help_link=e},button:function(e){var t=this.elements[e];if(typeof t.fn[this.mode]!="function")return null;var n=new jsButton(t.title,t.fn[this.mode],this,"jstb_"+e);if(t.icon!=undefined)n.icon=t.icon;return n},space:function(e){var t=new jsSpace(e);if(this.elements[e].width!==undefined)t.width=this.elements[e].width;return t},combo:function(e){var t=this.elements[e];var n=t[this.mode].list.length;if(typeof t[this.mode].fn!="function"||n==0){return null}else{var r={};for(var i=0;i<n;i++){var s=t[this.mode].list[i];r[s]=t.options[s]}return new jsCombo(t.title,r,this,t[this.mode].fn)}},draw:function(e){this.setMode(e);while(this.toolbar.hasChildNodes()){this.toolbar.removeChild(this.toolbar.firstChild)}this.toolNodes={};var t=document.createElement("div");t.className="help";t.innerHTML=this.help_link;"<a href=\"/help/wiki_syntax.html\" onclick=\"window.open('/help/wiki_syntax.html', '', 'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes'); return false;\">Aide</a>";this.toolbar.appendChild(t);var n,r,i;for(var s in this.elements){n=this.elements[s];var o=n.type==undefined||n.type==""||n.disabled!=undefined&&n.disabled||n.context!=undefined&&n.context!=null&&n.context!=this.context;if(!o&&typeof this[n.type]=="function"){r=this[n.type](s);if(r)i=r.draw();if(i){this.toolNodes[s]=i;this.toolbar.appendChild(i)}}}},singleTag:function(e,t){e=e||null;t=t||e;if(!e||!t){return}this.encloseSelection(e,t)},encloseLineSelection:function(e,t,n){this.textarea.focus();e=e||"";t=t||"";var r,i,s,o,u,a;if(typeof document["selection"]!="undefined"){s=document.selection.createRange().text}else if(typeof this.textarea["setSelectionRange"]!="undefined"){r=this.textarea.selectionStart;i=this.textarea.selectionEnd;o=this.textarea.scrollTop;r=this.textarea.value.substring(0,r).replace(/[^\r\n]*$/g,"").length;i=this.textarea.value.length-this.textarea.value.substring(i,this.textarea.value.length).replace(/^[^\r\n]*/,"").length;s=this.textarea.value.substring(r,i)}if(s.match(/ $/)){s=s.substring(0,s.length-1);t=t+" "}if(typeof n=="function"){a=s?n.call(this,s):n("")}else{a=s?s:""}u=e+a+t;if(typeof document["selection"]!="undefined"){document.selection.createRange().text=u;var f=this.textarea.createTextRange();f.collapse(false);f.move("character",-t.length);f.select()}else if(typeof this.textarea["setSelectionRange"]!="undefined"){this.textarea.value=this.textarea.value.substring(0,r)+u+this.textarea.value.substring(i);if(s){this.textarea.setSelectionRange(r+u.length,r+u.length)}else{this.textarea.setSelectionRange(r+e.length,r+e.length)}this.textarea.scrollTop=o}},encloseSelection:function(e,t,n){this.textarea.focus();e=e||"";t=t||"";var r,i,s,o,u,a;if(typeof document["selection"]!="undefined"){s=document.selection.createRange().text}else if(typeof this.textarea["setSelectionRange"]!="undefined"){r=this.textarea.selectionStart;i=this.textarea.selectionEnd;o=this.textarea.scrollTop;s=this.textarea.value.substring(r,i)}if(s.match(/ $/)){s=s.substring(0,s.length-1);t=t+" "}if(typeof n=="function"){a=s?n.call(this,s):n("")}else{a=s?s:""}u=e+a+t;if(typeof document["selection"]!="undefined"){document.selection.createRange().text=u;var f=this.textarea.createTextRange();f.collapse(false);f.move("character",-t.length);f.select()}else if(typeof this.textarea["setSelectionRange"]!="undefined"){this.textarea.value=this.textarea.value.substring(0,r)+u+this.textarea.value.substring(i);if(s){this.textarea.setSelectionRange(r+u.length,r+u.length)}else{this.textarea.setSelectionRange(r+e.length,r+e.length)}this.textarea.scrollTop=o}},stripBaseURL:function(e){if(this.base_url!=""){var t=e.indexOf(this.base_url);if(t==0){e=e.substr(this.base_url.length)}}return e}};jsToolBar.prototype.resizeSetStartH=function(){this.dragStartH=this.textarea.offsetHeight+0};jsToolBar.prototype.resizeDragStart=function(e){var t=this;this.dragStartY=e.clientY;this.resizeSetStartH();document.addEventListener("mousemove",this.dragMoveHdlr=function(e){t.resizeDragMove(e)},false);document.addEventListener("mouseup",this.dragStopHdlr=function(e){t.resizeDragStop(e)},false)};jsToolBar.prototype.resizeDragMove=function(e){this.textarea.style.height=this.dragStartH+e.clientY-this.dragStartY+"px"};jsToolBar.prototype.resizeDragStop=function(e){document.removeEventListener("mousemove",this.dragMoveHdlr,false);document.removeEventListener("mouseup",this.dragStopHdlr,false)};jsToolBar.prototype.elements.strong={type:"button",title:"Strong",fn:{wiki:function(){this.singleTag("*")}}};jsToolBar.prototype.elements.em={type:"button",title:"Italic",fn:{wiki:function(){this.singleTag("_")}}};jsToolBar.prototype.elements.ins={type:"button",title:"Underline",fn:{wiki:function(){this.singleTag("+")}}};jsToolBar.prototype.elements.del={type:"button",title:"Deleted",fn:{wiki:function(){this.singleTag("-")}}};jsToolBar.prototype.elements.code={type:"button",title:"Code",fn:{wiki:function(){this.singleTag("@")}}};jsToolBar.prototype.elements.space1={type:"space"};jsToolBar.prototype.elements.h1={type:"button",title:"Heading 1",fn:{wiki:function(){this.encloseLineSelection("h1. ","",function(e){e=e.replace(/^h\d+\.\s+/,"");return e})}}};jsToolBar.prototype.elements.h2={type:"button",title:"Heading 2",fn:{wiki:function(){this.encloseLineSelection("h2. ","",function(e){e=e.replace(/^h\d+\.\s+/,"");return e})}}};jsToolBar.prototype.elements.h3={type:"button",title:"Heading 3",fn:{wiki:function(){this.encloseLineSelection("h3. ","",function(e){e=e.replace(/^h\d+\.\s+/,"");return e})}}};jsToolBar.prototype.elements.space2={type:"space"};jsToolBar.prototype.elements.ul={type:"button",title:"Unordered list",fn:{wiki:function(){this.encloseLineSelection("","",function(e){e=e.replace(/\r/g,"");return e.replace(/(\n|^)[#-]?\s*/g,"$1* ")})}}};jsToolBar.prototype.elements.ol={type:"button",title:"Ordered list",fn:{wiki:function(){this.encloseLineSelection("","",function(e){e=e.replace(/\r/g,"");return e.replace(/(\n|^)[*-]?\s*/g,"$1# ")})}}};jsToolBar.prototype.elements.space3={type:"space"};jsToolBar.prototype.elements.bq={type:"button",title:"Quote",fn:{wiki:function(){this.encloseLineSelection("","",function(e){e=e.replace(/\r/g,"");return e.replace(/(\n|^) *([^\n]*)/g,"$1> $2")})}}};jsToolBar.prototype.elements.unbq={type:"button",title:"Unquote",fn:{wiki:function(){this.encloseLineSelection("","",function(e){e=e.replace(/\r/g,"");return e.replace(/(\n|^) *[>]? *([^\n]*)/g,"$1$2")})}}};jsToolBar.prototype.elements.pre={type:"button",title:"Preformatted text",fn:{wiki:function(){this.encloseLineSelection("<pre>\n","\n</pre>")}}};jsToolBar.prototype.elements.space4={type:"space"};jsToolBar.prototype.elements.link={type:"button",title:"Wiki link",fn:{wiki:function(){this.encloseSelection("[[","]]")}}};jsToolBar.prototype.elements.img={type:"button",title:"Image",fn:{wiki:function(){this.encloseSelection("!","!")}}} No newline at end of file
1 function jsToolBar(e){if(!document.createElement){return}if(!e){return}if(typeof document["selection"]=="undefined"&&typeof e["setSelectionRange"]=="undefined"){return}this.textarea=e;this.editor=document.createElement("div");this.editor.className="jstEditor";this.textarea.parentNode.insertBefore(this.editor,this.textarea);this.editor.appendChild(this.textarea);this.toolbar=document.createElement("div");this.toolbar.className="jstElements";this.editor.parentNode.insertBefore(this.toolbar,this.editor);if(this.editor.addEventListener&&navigator.appVersion.match(/\bMSIE\b/)){this.handle=document.createElement("div");this.handle.className="jstHandle";var t=this.resizeDragStart;var n=this;this.handle.addEventListener("mousedown",function(e){t.call(n,e)},false);window.addEventListener("unload",function(){var e=n.handle.parentNode.removeChild(n.handle);delete n.handle},false);this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling)}this.context=null;this.toolNodes={}}function jsButton(e,t,n,r){if(typeof jsToolBar.strings=="undefined"){this.title=e||null}else{this.title=jsToolBar.strings[e]||e||null}this.fn=t||function(){};this.scope=n||null;this.className=r||null}function jsSpace(e){this.id=e||null;this.width=null}function jsCombo(e,t,n,r,i){this.title=e||null;this.options=t||null;this.scope=n||null;this.fn=r||function(){};this.className=i||null}jsButton.prototype.draw=function(){if(!this.scope)return null;var e=document.createElement("button");e.setAttribute("type","button");e.tabIndex=200;if(this.className)e.className=this.className;e.title=this.title;var t=document.createElement("span");t.appendChild(document.createTextNode(this.title));e.appendChild(t);if(this.icon!=undefined){e.style.backgroundImage="url("+this.icon+")"}if(typeof this.fn=="function"){var n=this;e.onclick=function(){try{n.fn.apply(n.scope,arguments)}catch(e){}return false}}return e};jsSpace.prototype.draw=function(){var e=document.createElement("span");if(this.id)e.id=this.id;e.appendChild(document.createTextNode(String.fromCharCode(160)));e.className="jstSpacer";if(this.width)e.style.marginRight=this.width+"px";return e};jsCombo.prototype.draw=function(){if(!this.scope||!this.options)return null;var e=document.createElement("select");if(this.className)e.className=className;e.title=this.title;for(var t in this.options){var n=document.createElement("option");n.value=t;n.appendChild(document.createTextNode(this.options[t]));e.appendChild(n)}var r=this;e.onchange=function(){try{r.fn.call(r.scope,this.value)}catch(e){alert(e)}return false};return e};jsToolBar.prototype={base_url:"",mode:"wiki",elements:{},help_link:"",getMode:function(){return this.mode},setMode:function(e){this.mode=e||"wiki"},switchMode:function(e){e=e||"wiki";this.draw(e)},setHelpLink:function(e){this.help_link=e},button:function(e){var t=this.elements[e];if(typeof t.fn[this.mode]!="function")return null;var n=new jsButton(t.title,t.fn[this.mode],this,"jstb_"+e);if(t.icon!=undefined)n.icon=t.icon;return n},space:function(e){var t=new jsSpace(e);if(this.elements[e].width!==undefined)t.width=this.elements[e].width;return t},combo:function(e){var t=this.elements[e];var n=t[this.mode].list.length;if(typeof t[this.mode].fn!="function"||n==0){return null}else{var r={};for(var i=0;i<n;i++){var s=t[this.mode].list[i];r[s]=t.options[s]}return new jsCombo(t.title,r,this,t[this.mode].fn)}},draw:function(e){this.setMode(e);while(this.toolbar.hasChildNodes()){this.toolbar.removeChild(this.toolbar.firstChild)}this.toolNodes={};var t,n,r;for(var i in this.elements){t=this.elements[i];var s=t.type==undefined||t.type==""||t.disabled!=undefined&&t.disabled||t.context!=undefined&&t.context!=null&&t.context!=this.context;if(!s&&typeof this[t.type]=="function"){n=this[t.type](i);if(n)r=n.draw();if(r){this.toolNodes[i]=r;this.toolbar.appendChild(r)}}}},singleTag:function(e,t){e=e||null;t=t||e;if(!e||!t){return}this.encloseSelection(e,t)},encloseLineSelection:function(e,t,n){this.textarea.focus();e=e||"";t=t||"";var r,i,s,o,u,a;if(typeof document["selection"]!="undefined"){s=document.selection.createRange().text}else if(typeof this.textarea["setSelectionRange"]!="undefined"){r=this.textarea.selectionStart;i=this.textarea.selectionEnd;o=this.textarea.scrollTop;r=this.textarea.value.substring(0,r).replace(/[^\r\n]*$/g,"").length;i=this.textarea.value.length-this.textarea.value.substring(i,this.textarea.value.length).replace(/^[^\r\n]*/,"").length;s=this.textarea.value.substring(r,i)}if(s.match(/ $/)){s=s.substring(0,s.length-1);t=t+" "}if(typeof n=="function"){a=s?n.call(this,s):n("")}else{a=s?s:""}u=e+a+t;if(typeof document["selection"]!="undefined"){document.selection.createRange().text=u;var f=this.textarea.createTextRange();f.collapse(false);f.move("character",-t.length);f.select()}else if(typeof this.textarea["setSelectionRange"]!="undefined"){this.textarea.value=this.textarea.value.substring(0,r)+u+this.textarea.value.substring(i);if(s){this.textarea.setSelectionRange(r+u.length,r+u.length)}else{this.textarea.setSelectionRange(r+e.length,r+e.length)}this.textarea.scrollTop=o}},encloseSelection:function(e,t,n){this.textarea.focus();e=e||"";t=t||"";var r,i,s,o,u,a;if(typeof document["selection"]!="undefined"){s=document.selection.createRange().text}else if(typeof this.textarea["setSelectionRange"]!="undefined"){r=this.textarea.selectionStart;i=this.textarea.selectionEnd;o=this.textarea.scrollTop;s=this.textarea.value.substring(r,i)}if(s.match(/ $/)){s=s.substring(0,s.length-1);t=t+" "}if(typeof n=="function"){a=s?n.call(this,s):n("")}else{a=s?s:""}u=e+a+t;if(typeof document["selection"]!="undefined"){document.selection.createRange().text=u;var f=this.textarea.createTextRange();f.collapse(false);f.move("character",-t.length);f.select()}else if(typeof this.textarea["setSelectionRange"]!="undefined"){this.textarea.value=this.textarea.value.substring(0,r)+u+this.textarea.value.substring(i);if(s){this.textarea.setSelectionRange(r+u.length,r+u.length)}else{this.textarea.setSelectionRange(r+e.length,r+e.length)}this.textarea.scrollTop=o}},stripBaseURL:function(e){if(this.base_url!=""){var t=e.indexOf(this.base_url);if(t==0){e=e.substr(this.base_url.length)}}return e}};jsToolBar.prototype.resizeSetStartH=function(){this.dragStartH=this.textarea.offsetHeight+0};jsToolBar.prototype.resizeDragStart=function(e){var t=this;this.dragStartY=e.clientY;this.resizeSetStartH();document.addEventListener("mousemove",this.dragMoveHdlr=function(e){t.resizeDragMove(e)},false);document.addEventListener("mouseup",this.dragStopHdlr=function(e){t.resizeDragStop(e)},false)};jsToolBar.prototype.resizeDragMove=function(e){this.textarea.style.height=this.dragStartH+e.clientY-this.dragStartY+"px"};jsToolBar.prototype.resizeDragStop=function(e){document.removeEventListener("mousemove",this.dragMoveHdlr,false);document.removeEventListener("mouseup",this.dragStopHdlr,false)};
2 jsToolBar.prototype.elements.strong={type:"button",title:"Strong",fn:{wiki:function(){this.singleTag("*")}}};jsToolBar.prototype.elements.em={type:"button",title:"Italic",fn:{wiki:function(){this.singleTag("_")}}};jsToolBar.prototype.elements.ins={type:"button",title:"Underline",fn:{wiki:function(){this.singleTag("+")}}};jsToolBar.prototype.elements.del={type:"button",title:"Deleted",fn:{wiki:function(){this.singleTag("-")}}};jsToolBar.prototype.elements.code={type:"button",title:"Code",fn:{wiki:function(){this.singleTag("@")}}};jsToolBar.prototype.elements.space1={type:"space"};jsToolBar.prototype.elements.h1={type:"button",title:"Heading 1",fn:{wiki:function(){this.encloseLineSelection("h1. ","",function(e){e=e.replace(/^h\d+\.\s+/,"");return e})}}};jsToolBar.prototype.elements.h2={type:"button",title:"Heading 2",fn:{wiki:function(){this.encloseLineSelection("h2. ","",function(e){e=e.replace(/^h\d+\.\s+/,"");return e})}}};jsToolBar.prototype.elements.h3={type:"button",title:"Heading 3",fn:{wiki:function(){this.encloseLineSelection("h3. ","",function(e){e=e.replace(/^h\d+\.\s+/,"");return e})}}};jsToolBar.prototype.elements.space2={type:"space"};jsToolBar.prototype.elements.ul={type:"button",title:"Unordered list",fn:{wiki:function(){this.encloseLineSelection("","",function(e){e=e.replace(/\r/g,"");return e.replace(/(\n|^)[#-]?\s*/g,"$1* ")})}}};jsToolBar.prototype.elements.ol={type:"button",title:"Ordered list",fn:{wiki:function(){this.encloseLineSelection("","",function(e){e=e.replace(/\r/g,"");return e.replace(/(\n|^)[*-]?\s*/g,"$1# ")})}}};jsToolBar.prototype.elements.space3={type:"space"};jsToolBar.prototype.elements.bq={type:"button",title:"Quote",fn:{wiki:function(){this.encloseLineSelection("","",function(e){e=e.replace(/\r/g,"");return e.replace(/(\n|^) *([^\n]*)/g,"$1> $2")})}}};jsToolBar.prototype.elements.unbq={type:"button",title:"Unquote",fn:{wiki:function(){this.encloseLineSelection("","",function(e){e=e.replace(/\r/g,"");return e.replace(/(\n|^) *[>]? *([^\n]*)/g,"$1$2")})}}};jsToolBar.prototype.elements.pre={type:"button",title:"Preformatted text",fn:{wiki:function(){this.encloseLineSelection("<pre>\n","\n</pre>")}}};jsToolBar.prototype.elements.space4={type:"space"};jsToolBar.prototype.elements.link={type:"button",title:"Wiki link",fn:{wiki:function(){this.encloseSelection("[[","]]")}}};jsToolBar.prototype.elements.img={type:"button",title:"Image",fn:{wiki:function(){this.encloseSelection("!","!")}}};jsToolBar.prototype.elements.space5={type:"space"};jsToolBar.prototype.elements.help={type:"button",title:"Help",fn:{wiki:function(){window.open(this.help_link,"","resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes")}}}
@@ -1,380 +1,374
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
47 // Dragable resizing
48 if (this.editor.addEventListener && navigator.appVersion.match(/\bMSIE\b/))
48 if (this.editor.addEventListener && navigator.appVersion.match(/\bMSIE\b/))
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 if(typeof jsToolBar.strings == 'undefined') {
70 if(typeof jsToolBar.strings == 'undefined') {
71 this.title = title || null;
71 this.title = title || null;
72 } else {
72 } else {
73 this.title = jsToolBar.strings[title] || title || null;
73 this.title = jsToolBar.strings[title] || title || null;
74 }
74 }
75 this.fn = fn || function(){};
75 this.fn = fn || function(){};
76 this.scope = scope || null;
76 this.scope = scope || null;
77 this.className = className || null;
77 this.className = className || null;
78 }
78 }
79 jsButton.prototype.draw = function() {
79 jsButton.prototype.draw = function() {
80 if (!this.scope) return null;
80 if (!this.scope) return null;
81
81
82 var button = document.createElement('button');
82 var button = document.createElement('button');
83 button.setAttribute('type','button');
83 button.setAttribute('type','button');
84 button.tabIndex = 200;
84 button.tabIndex = 200;
85 if (this.className) button.className = this.className;
85 if (this.className) button.className = this.className;
86 button.title = this.title;
86 button.title = this.title;
87 var span = document.createElement('span');
87 var span = document.createElement('span');
88 span.appendChild(document.createTextNode(this.title));
88 span.appendChild(document.createTextNode(this.title));
89 button.appendChild(span);
89 button.appendChild(span);
90
90
91 if (this.icon != undefined) {
91 if (this.icon != undefined) {
92 button.style.backgroundImage = 'url('+this.icon+')';
92 button.style.backgroundImage = 'url('+this.icon+')';
93 }
93 }
94 if (typeof(this.fn) == 'function') {
94 if (typeof(this.fn) == 'function') {
95 var This = this;
95 var This = this;
96 button.onclick = function() { try { This.fn.apply(This.scope, arguments) } catch (e) {} return false; };
96 button.onclick = function() { try { This.fn.apply(This.scope, arguments) } catch (e) {} return false; };
97 }
97 }
98 return button;
98 return button;
99 }
99 }
100
100
101 function jsSpace(id) {
101 function jsSpace(id) {
102 this.id = id || null;
102 this.id = id || null;
103 this.width = null;
103 this.width = null;
104 }
104 }
105 jsSpace.prototype.draw = function() {
105 jsSpace.prototype.draw = function() {
106 var span = document.createElement('span');
106 var span = document.createElement('span');
107 if (this.id) span.id = this.id;
107 if (this.id) span.id = this.id;
108 span.appendChild(document.createTextNode(String.fromCharCode(160)));
108 span.appendChild(document.createTextNode(String.fromCharCode(160)));
109 span.className = 'jstSpacer';
109 span.className = 'jstSpacer';
110 if (this.width) span.style.marginRight = this.width+'px';
110 if (this.width) span.style.marginRight = this.width+'px';
111
111
112 return span;
112 return span;
113 }
113 }
114
114
115 function jsCombo(title, options, scope, fn, className) {
115 function jsCombo(title, options, scope, fn, className) {
116 this.title = title || null;
116 this.title = title || null;
117 this.options = options || null;
117 this.options = options || null;
118 this.scope = scope || null;
118 this.scope = scope || null;
119 this.fn = fn || function(){};
119 this.fn = fn || function(){};
120 this.className = className || null;
120 this.className = className || null;
121 }
121 }
122 jsCombo.prototype.draw = function() {
122 jsCombo.prototype.draw = function() {
123 if (!this.scope || !this.options) return null;
123 if (!this.scope || !this.options) return null;
124
124
125 var select = document.createElement('select');
125 var select = document.createElement('select');
126 if (this.className) select.className = className;
126 if (this.className) select.className = className;
127 select.title = this.title;
127 select.title = this.title;
128
128
129 for (var o in this.options) {
129 for (var o in this.options) {
130 //var opt = this.options[o];
130 //var opt = this.options[o];
131 var option = document.createElement('option');
131 var option = document.createElement('option');
132 option.value = o;
132 option.value = o;
133 option.appendChild(document.createTextNode(this.options[o]));
133 option.appendChild(document.createTextNode(this.options[o]));
134 select.appendChild(option);
134 select.appendChild(option);
135 }
135 }
136
136
137 var This = this;
137 var This = this;
138 select.onchange = function() {
138 select.onchange = function() {
139 try {
139 try {
140 This.fn.call(This.scope, this.value);
140 This.fn.call(This.scope, this.value);
141 } catch (e) { alert(e); }
141 } catch (e) { alert(e); }
142
142
143 return false;
143 return false;
144 }
144 }
145
145
146 return select;
146 return select;
147 }
147 }
148
148
149
149
150 jsToolBar.prototype = {
150 jsToolBar.prototype = {
151 base_url: '',
151 base_url: '',
152 mode: 'wiki',
152 mode: 'wiki',
153 elements: {},
153 elements: {},
154 help_link: '',
154 help_link: '',
155
155
156 getMode: function() {
156 getMode: function() {
157 return this.mode;
157 return this.mode;
158 },
158 },
159
159
160 setMode: function(mode) {
160 setMode: function(mode) {
161 this.mode = mode || 'wiki';
161 this.mode = mode || 'wiki';
162 },
162 },
163
163
164 switchMode: function(mode) {
164 switchMode: function(mode) {
165 mode = mode || 'wiki';
165 mode = mode || 'wiki';
166 this.draw(mode);
166 this.draw(mode);
167 },
167 },
168
168
169 setHelpLink: function(link) {
169 setHelpLink: function(link) {
170 this.help_link = link;
170 this.help_link = link;
171 },
171 },
172
172
173 button: function(toolName) {
173 button: function(toolName) {
174 var tool = this.elements[toolName];
174 var tool = this.elements[toolName];
175 if (typeof tool.fn[this.mode] != 'function') return null;
175 if (typeof tool.fn[this.mode] != 'function') return null;
176 var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_'+toolName);
176 var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_'+toolName);
177 if (tool.icon != undefined) b.icon = tool.icon;
177 if (tool.icon != undefined) b.icon = tool.icon;
178 return b;
178 return b;
179 },
179 },
180 space: function(toolName) {
180 space: function(toolName) {
181 var tool = new jsSpace(toolName)
181 var tool = new jsSpace(toolName)
182 if (this.elements[toolName].width !== undefined)
182 if (this.elements[toolName].width !== undefined)
183 tool.width = this.elements[toolName].width;
183 tool.width = this.elements[toolName].width;
184 return tool;
184 return tool;
185 },
185 },
186 combo: function(toolName) {
186 combo: function(toolName) {
187 var tool = this.elements[toolName];
187 var tool = this.elements[toolName];
188 var length = tool[this.mode].list.length;
188 var length = tool[this.mode].list.length;
189
189
190 if (typeof tool[this.mode].fn != 'function' || length == 0) {
190 if (typeof tool[this.mode].fn != 'function' || length == 0) {
191 return null;
191 return null;
192 } else {
192 } else {
193 var options = {};
193 var options = {};
194 for (var i=0; i < length; i++) {
194 for (var i=0; i < length; i++) {
195 var opt = tool[this.mode].list[i];
195 var opt = tool[this.mode].list[i];
196 options[opt] = tool.options[opt];
196 options[opt] = tool.options[opt];
197 }
197 }
198 return new jsCombo(tool.title, options, this, tool[this.mode].fn);
198 return new jsCombo(tool.title, options, this, tool[this.mode].fn);
199 }
199 }
200 },
200 },
201 draw: function(mode) {
201 draw: function(mode) {
202 this.setMode(mode);
202 this.setMode(mode);
203
203
204 // Empty toolbar
204 // Empty toolbar
205 while (this.toolbar.hasChildNodes()) {
205 while (this.toolbar.hasChildNodes()) {
206 this.toolbar.removeChild(this.toolbar.firstChild)
206 this.toolbar.removeChild(this.toolbar.firstChild)
207 }
207 }
208 this.toolNodes = {}; // vide les raccourcis DOM/**/
208 this.toolNodes = {}; // vide les raccourcis DOM/**/
209
209
210 var h = document.createElement('div');
211 h.className = 'help'
212 h.innerHTML = this.help_link;
213 '<a href="/help/wiki_syntax.html" onclick="window.open(\'/help/wiki_syntax.html\', \'\', \'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes\'); return false;">Aide</a>';
214 this.toolbar.appendChild(h);
215
216 // Draw toolbar elements
210 // Draw toolbar elements
217 var b, tool, newTool;
211 var b, tool, newTool;
218
212
219 for (var i in this.elements) {
213 for (var i in this.elements) {
220 b = this.elements[i];
214 b = this.elements[i];
221
215
222 var disabled =
216 var disabled =
223 b.type == undefined || b.type == ''
217 b.type == undefined || b.type == ''
224 || (b.disabled != undefined && b.disabled)
218 || (b.disabled != undefined && b.disabled)
225 || (b.context != undefined && b.context != null && b.context != this.context);
219 || (b.context != undefined && b.context != null && b.context != this.context);
226
220
227 if (!disabled && typeof this[b.type] == 'function') {
221 if (!disabled && typeof this[b.type] == 'function') {
228 tool = this[b.type](i);
222 tool = this[b.type](i);
229 if (tool) newTool = tool.draw();
223 if (tool) newTool = tool.draw();
230 if (newTool) {
224 if (newTool) {
231 this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur
225 this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur
232 this.toolbar.appendChild(newTool);
226 this.toolbar.appendChild(newTool);
233 }
227 }
234 }
228 }
235 }
229 }
236 },
230 },
237
231
238 singleTag: function(stag,etag) {
232 singleTag: function(stag,etag) {
239 stag = stag || null;
233 stag = stag || null;
240 etag = etag || stag;
234 etag = etag || stag;
241
235
242 if (!stag || !etag) { return; }
236 if (!stag || !etag) { return; }
243
237
244 this.encloseSelection(stag,etag);
238 this.encloseSelection(stag,etag);
245 },
239 },
246
240
247 encloseLineSelection: function(prefix, suffix, fn) {
241 encloseLineSelection: function(prefix, suffix, fn) {
248 this.textarea.focus();
242 this.textarea.focus();
249
243
250 prefix = prefix || '';
244 prefix = prefix || '';
251 suffix = suffix || '';
245 suffix = suffix || '';
252
246
253 var start, end, sel, scrollPos, subst, res;
247 var start, end, sel, scrollPos, subst, res;
254
248
255 if (typeof(document["selection"]) != "undefined") {
249 if (typeof(document["selection"]) != "undefined") {
256 sel = document.selection.createRange().text;
250 sel = document.selection.createRange().text;
257 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
251 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
258 start = this.textarea.selectionStart;
252 start = this.textarea.selectionStart;
259 end = this.textarea.selectionEnd;
253 end = this.textarea.selectionEnd;
260 scrollPos = this.textarea.scrollTop;
254 scrollPos = this.textarea.scrollTop;
261 // go to the start of the line
255 // go to the start of the line
262 start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length;
256 start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length;
263 // go to the end of the line
257 // go to the end of the line
264 end = this.textarea.value.length - this.textarea.value.substring(end, this.textarea.value.length).replace(/^[^\r\n]*/, '').length;
258 end = this.textarea.value.length - this.textarea.value.substring(end, this.textarea.value.length).replace(/^[^\r\n]*/, '').length;
265 sel = this.textarea.value.substring(start, end);
259 sel = this.textarea.value.substring(start, end);
266 }
260 }
267
261
268 if (sel.match(/ $/)) { // exclude ending space char, if any
262 if (sel.match(/ $/)) { // exclude ending space char, if any
269 sel = sel.substring(0, sel.length - 1);
263 sel = sel.substring(0, sel.length - 1);
270 suffix = suffix + " ";
264 suffix = suffix + " ";
271 }
265 }
272
266
273 if (typeof(fn) == 'function') {
267 if (typeof(fn) == 'function') {
274 res = (sel) ? fn.call(this,sel) : fn('');
268 res = (sel) ? fn.call(this,sel) : fn('');
275 } else {
269 } else {
276 res = (sel) ? sel : '';
270 res = (sel) ? sel : '';
277 }
271 }
278
272
279 subst = prefix + res + suffix;
273 subst = prefix + res + suffix;
280
274
281 if (typeof(document["selection"]) != "undefined") {
275 if (typeof(document["selection"]) != "undefined") {
282 document.selection.createRange().text = subst;
276 document.selection.createRange().text = subst;
283 var range = this.textarea.createTextRange();
277 var range = this.textarea.createTextRange();
284 range.collapse(false);
278 range.collapse(false);
285 range.move('character', -suffix.length);
279 range.move('character', -suffix.length);
286 range.select();
280 range.select();
287 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
281 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
288 this.textarea.value = this.textarea.value.substring(0, start) + subst +
282 this.textarea.value = this.textarea.value.substring(0, start) + subst +
289 this.textarea.value.substring(end);
283 this.textarea.value.substring(end);
290 if (sel) {
284 if (sel) {
291 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
285 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
292 } else {
286 } else {
293 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
287 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
294 }
288 }
295 this.textarea.scrollTop = scrollPos;
289 this.textarea.scrollTop = scrollPos;
296 }
290 }
297 },
291 },
298
292
299 encloseSelection: function(prefix, suffix, fn) {
293 encloseSelection: function(prefix, suffix, fn) {
300 this.textarea.focus();
294 this.textarea.focus();
301
295
302 prefix = prefix || '';
296 prefix = prefix || '';
303 suffix = suffix || '';
297 suffix = suffix || '';
304
298
305 var start, end, sel, scrollPos, subst, res;
299 var start, end, sel, scrollPos, subst, res;
306
300
307 if (typeof(document["selection"]) != "undefined") {
301 if (typeof(document["selection"]) != "undefined") {
308 sel = document.selection.createRange().text;
302 sel = document.selection.createRange().text;
309 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
303 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
310 start = this.textarea.selectionStart;
304 start = this.textarea.selectionStart;
311 end = this.textarea.selectionEnd;
305 end = this.textarea.selectionEnd;
312 scrollPos = this.textarea.scrollTop;
306 scrollPos = this.textarea.scrollTop;
313 sel = this.textarea.value.substring(start, end);
307 sel = this.textarea.value.substring(start, end);
314 }
308 }
315
309
316 if (sel.match(/ $/)) { // exclude ending space char, if any
310 if (sel.match(/ $/)) { // exclude ending space char, if any
317 sel = sel.substring(0, sel.length - 1);
311 sel = sel.substring(0, sel.length - 1);
318 suffix = suffix + " ";
312 suffix = suffix + " ";
319 }
313 }
320
314
321 if (typeof(fn) == 'function') {
315 if (typeof(fn) == 'function') {
322 res = (sel) ? fn.call(this,sel) : fn('');
316 res = (sel) ? fn.call(this,sel) : fn('');
323 } else {
317 } else {
324 res = (sel) ? sel : '';
318 res = (sel) ? sel : '';
325 }
319 }
326
320
327 subst = prefix + res + suffix;
321 subst = prefix + res + suffix;
328
322
329 if (typeof(document["selection"]) != "undefined") {
323 if (typeof(document["selection"]) != "undefined") {
330 document.selection.createRange().text = subst;
324 document.selection.createRange().text = subst;
331 var range = this.textarea.createTextRange();
325 var range = this.textarea.createTextRange();
332 range.collapse(false);
326 range.collapse(false);
333 range.move('character', -suffix.length);
327 range.move('character', -suffix.length);
334 range.select();
328 range.select();
335 // this.textarea.caretPos -= suffix.length;
329 // this.textarea.caretPos -= suffix.length;
336 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
330 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
337 this.textarea.value = this.textarea.value.substring(0, start) + subst +
331 this.textarea.value = this.textarea.value.substring(0, start) + subst +
338 this.textarea.value.substring(end);
332 this.textarea.value.substring(end);
339 if (sel) {
333 if (sel) {
340 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
334 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
341 } else {
335 } else {
342 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
336 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
343 }
337 }
344 this.textarea.scrollTop = scrollPos;
338 this.textarea.scrollTop = scrollPos;
345 }
339 }
346 },
340 },
347
341
348 stripBaseURL: function(url) {
342 stripBaseURL: function(url) {
349 if (this.base_url != '') {
343 if (this.base_url != '') {
350 var pos = url.indexOf(this.base_url);
344 var pos = url.indexOf(this.base_url);
351 if (pos == 0) {
345 if (pos == 0) {
352 url = url.substr(this.base_url.length);
346 url = url.substr(this.base_url.length);
353 }
347 }
354 }
348 }
355
349
356 return url;
350 return url;
357 }
351 }
358 };
352 };
359
353
360 /** Resizer
354 /** Resizer
361 -------------------------------------------------------- */
355 -------------------------------------------------------- */
362 jsToolBar.prototype.resizeSetStartH = function() {
356 jsToolBar.prototype.resizeSetStartH = function() {
363 this.dragStartH = this.textarea.offsetHeight + 0;
357 this.dragStartH = this.textarea.offsetHeight + 0;
364 };
358 };
365 jsToolBar.prototype.resizeDragStart = function(event) {
359 jsToolBar.prototype.resizeDragStart = function(event) {
366 var This = this;
360 var This = this;
367 this.dragStartY = event.clientY;
361 this.dragStartY = event.clientY;
368 this.resizeSetStartH();
362 this.resizeSetStartH();
369 document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false);
363 document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false);
370 document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false);
364 document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false);
371 };
365 };
372
366
373 jsToolBar.prototype.resizeDragMove = function(event) {
367 jsToolBar.prototype.resizeDragMove = function(event) {
374 this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px';
368 this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px';
375 };
369 };
376
370
377 jsToolBar.prototype.resizeDragStop = function(event) {
371 jsToolBar.prototype.resizeDragStop = function(event) {
378 document.removeEventListener('mousemove', this.dragMoveHdlr, false);
372 document.removeEventListener('mousemove', this.dragMoveHdlr, false);
379 document.removeEventListener('mouseup', this.dragStopHdlr, false);
373 document.removeEventListener('mouseup', this.dragStopHdlr, false);
380 };
374 };
@@ -1,200 +1,211
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 // strong
25 // strong
26 jsToolBar.prototype.elements.strong = {
26 jsToolBar.prototype.elements.strong = {
27 type: 'button',
27 type: 'button',
28 title: 'Strong',
28 title: 'Strong',
29 fn: {
29 fn: {
30 wiki: function() { this.singleTag('*') }
30 wiki: function() { this.singleTag('*') }
31 }
31 }
32 }
32 }
33
33
34 // em
34 // em
35 jsToolBar.prototype.elements.em = {
35 jsToolBar.prototype.elements.em = {
36 type: 'button',
36 type: 'button',
37 title: 'Italic',
37 title: 'Italic',
38 fn: {
38 fn: {
39 wiki: function() { this.singleTag("_") }
39 wiki: function() { this.singleTag("_") }
40 }
40 }
41 }
41 }
42
42
43 // ins
43 // ins
44 jsToolBar.prototype.elements.ins = {
44 jsToolBar.prototype.elements.ins = {
45 type: 'button',
45 type: 'button',
46 title: 'Underline',
46 title: 'Underline',
47 fn: {
47 fn: {
48 wiki: function() { this.singleTag('+') }
48 wiki: function() { this.singleTag('+') }
49 }
49 }
50 }
50 }
51
51
52 // del
52 // del
53 jsToolBar.prototype.elements.del = {
53 jsToolBar.prototype.elements.del = {
54 type: 'button',
54 type: 'button',
55 title: 'Deleted',
55 title: 'Deleted',
56 fn: {
56 fn: {
57 wiki: function() { this.singleTag('-') }
57 wiki: function() { this.singleTag('-') }
58 }
58 }
59 }
59 }
60
60
61 // code
61 // code
62 jsToolBar.prototype.elements.code = {
62 jsToolBar.prototype.elements.code = {
63 type: 'button',
63 type: 'button',
64 title: 'Code',
64 title: 'Code',
65 fn: {
65 fn: {
66 wiki: function() { this.singleTag('@') }
66 wiki: function() { this.singleTag('@') }
67 }
67 }
68 }
68 }
69
69
70 // spacer
70 // spacer
71 jsToolBar.prototype.elements.space1 = {type: 'space'}
71 jsToolBar.prototype.elements.space1 = {type: 'space'}
72
72
73 // headings
73 // headings
74 jsToolBar.prototype.elements.h1 = {
74 jsToolBar.prototype.elements.h1 = {
75 type: 'button',
75 type: 'button',
76 title: 'Heading 1',
76 title: 'Heading 1',
77 fn: {
77 fn: {
78 wiki: function() {
78 wiki: function() {
79 this.encloseLineSelection('h1. ', '',function(str) {
79 this.encloseLineSelection('h1. ', '',function(str) {
80 str = str.replace(/^h\d+\.\s+/, '')
80 str = str.replace(/^h\d+\.\s+/, '')
81 return str;
81 return str;
82 });
82 });
83 }
83 }
84 }
84 }
85 }
85 }
86 jsToolBar.prototype.elements.h2 = {
86 jsToolBar.prototype.elements.h2 = {
87 type: 'button',
87 type: 'button',
88 title: 'Heading 2',
88 title: 'Heading 2',
89 fn: {
89 fn: {
90 wiki: function() {
90 wiki: function() {
91 this.encloseLineSelection('h2. ', '',function(str) {
91 this.encloseLineSelection('h2. ', '',function(str) {
92 str = str.replace(/^h\d+\.\s+/, '')
92 str = str.replace(/^h\d+\.\s+/, '')
93 return str;
93 return str;
94 });
94 });
95 }
95 }
96 }
96 }
97 }
97 }
98 jsToolBar.prototype.elements.h3 = {
98 jsToolBar.prototype.elements.h3 = {
99 type: 'button',
99 type: 'button',
100 title: 'Heading 3',
100 title: 'Heading 3',
101 fn: {
101 fn: {
102 wiki: function() {
102 wiki: function() {
103 this.encloseLineSelection('h3. ', '',function(str) {
103 this.encloseLineSelection('h3. ', '',function(str) {
104 str = str.replace(/^h\d+\.\s+/, '')
104 str = str.replace(/^h\d+\.\s+/, '')
105 return str;
105 return str;
106 });
106 });
107 }
107 }
108 }
108 }
109 }
109 }
110
110
111 // spacer
111 // spacer
112 jsToolBar.prototype.elements.space2 = {type: 'space'}
112 jsToolBar.prototype.elements.space2 = {type: 'space'}
113
113
114 // ul
114 // ul
115 jsToolBar.prototype.elements.ul = {
115 jsToolBar.prototype.elements.ul = {
116 type: 'button',
116 type: 'button',
117 title: 'Unordered list',
117 title: 'Unordered list',
118 fn: {
118 fn: {
119 wiki: function() {
119 wiki: function() {
120 this.encloseLineSelection('','',function(str) {
120 this.encloseLineSelection('','',function(str) {
121 str = str.replace(/\r/g,'');
121 str = str.replace(/\r/g,'');
122 return str.replace(/(\n|^)[#-]?\s*/g,"$1* ");
122 return str.replace(/(\n|^)[#-]?\s*/g,"$1* ");
123 });
123 });
124 }
124 }
125 }
125 }
126 }
126 }
127
127
128 // ol
128 // ol
129 jsToolBar.prototype.elements.ol = {
129 jsToolBar.prototype.elements.ol = {
130 type: 'button',
130 type: 'button',
131 title: 'Ordered list',
131 title: 'Ordered list',
132 fn: {
132 fn: {
133 wiki: function() {
133 wiki: function() {
134 this.encloseLineSelection('','',function(str) {
134 this.encloseLineSelection('','',function(str) {
135 str = str.replace(/\r/g,'');
135 str = str.replace(/\r/g,'');
136 return str.replace(/(\n|^)[*-]?\s*/g,"$1# ");
136 return str.replace(/(\n|^)[*-]?\s*/g,"$1# ");
137 });
137 });
138 }
138 }
139 }
139 }
140 }
140 }
141
141
142 // spacer
142 // spacer
143 jsToolBar.prototype.elements.space3 = {type: 'space'}
143 jsToolBar.prototype.elements.space3 = {type: 'space'}
144
144
145 // bq
145 // bq
146 jsToolBar.prototype.elements.bq = {
146 jsToolBar.prototype.elements.bq = {
147 type: 'button',
147 type: 'button',
148 title: 'Quote',
148 title: 'Quote',
149 fn: {
149 fn: {
150 wiki: function() {
150 wiki: function() {
151 this.encloseLineSelection('','',function(str) {
151 this.encloseLineSelection('','',function(str) {
152 str = str.replace(/\r/g,'');
152 str = str.replace(/\r/g,'');
153 return str.replace(/(\n|^) *([^\n]*)/g,"$1> $2");
153 return str.replace(/(\n|^) *([^\n]*)/g,"$1> $2");
154 });
154 });
155 }
155 }
156 }
156 }
157 }
157 }
158
158
159 // unbq
159 // unbq
160 jsToolBar.prototype.elements.unbq = {
160 jsToolBar.prototype.elements.unbq = {
161 type: 'button',
161 type: 'button',
162 title: 'Unquote',
162 title: 'Unquote',
163 fn: {
163 fn: {
164 wiki: function() {
164 wiki: function() {
165 this.encloseLineSelection('','',function(str) {
165 this.encloseLineSelection('','',function(str) {
166 str = str.replace(/\r/g,'');
166 str = str.replace(/\r/g,'');
167 return str.replace(/(\n|^) *[>]? *([^\n]*)/g,"$1$2");
167 return str.replace(/(\n|^) *[>]? *([^\n]*)/g,"$1$2");
168 });
168 });
169 }
169 }
170 }
170 }
171 }
171 }
172
172
173 // pre
173 // pre
174 jsToolBar.prototype.elements.pre = {
174 jsToolBar.prototype.elements.pre = {
175 type: 'button',
175 type: 'button',
176 title: 'Preformatted text',
176 title: 'Preformatted text',
177 fn: {
177 fn: {
178 wiki: function() { this.encloseLineSelection('<pre>\n', '\n</pre>') }
178 wiki: function() { this.encloseLineSelection('<pre>\n', '\n</pre>') }
179 }
179 }
180 }
180 }
181
181
182 // spacer
182 // spacer
183 jsToolBar.prototype.elements.space4 = {type: 'space'}
183 jsToolBar.prototype.elements.space4 = {type: 'space'}
184
184
185 // wiki page
185 // wiki page
186 jsToolBar.prototype.elements.link = {
186 jsToolBar.prototype.elements.link = {
187 type: 'button',
187 type: 'button',
188 title: 'Wiki link',
188 title: 'Wiki link',
189 fn: {
189 fn: {
190 wiki: function() { this.encloseSelection("[[", "]]") }
190 wiki: function() { this.encloseSelection("[[", "]]") }
191 }
191 }
192 }
192 }
193 // image
193 // image
194 jsToolBar.prototype.elements.img = {
194 jsToolBar.prototype.elements.img = {
195 type: 'button',
195 type: 'button',
196 title: 'Image',
196 title: 'Image',
197 fn: {
197 fn: {
198 wiki: function() { this.encloseSelection("!", "!") }
198 wiki: function() { this.encloseSelection("!", "!") }
199 }
199 }
200 }
200 }
201
202 // spacer
203 jsToolBar.prototype.elements.space5 = {type: 'space'}
204 // help
205 jsToolBar.prototype.elements.help = {
206 type: 'button',
207 title: 'Help',
208 fn: {
209 wiki: function() { window.open(this.help_link, '', 'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes') }
210 }
211 }
@@ -1,97 +1,100
1 .jstEditor {
1 .jstEditor {
2 padding-left: 0px;
2 padding-left: 0px;
3 }
3 }
4 .jstEditor textarea, .jstEditor iframe {
4 .jstEditor textarea, .jstEditor iframe {
5 margin: 0;
5 margin: 0;
6 }
6 }
7
7
8 .jstHandle {
8 .jstHandle {
9 height: 10px;
9 height: 10px;
10 font-size: 0.1em;
10 font-size: 0.1em;
11 cursor: s-resize;
11 cursor: s-resize;
12 /*background: transparent url(img/resizer.png) no-repeat 45% 50%;*/
12 /*background: transparent url(img/resizer.png) no-repeat 45% 50%;*/
13 }
13 }
14
14
15 .jstElements {
15 .jstElements {
16 padding: 3px 3px 3px 0;
16 padding: 3px 3px 3px 0;
17 }
17 }
18
18
19 .jstElements button {
19 .jstElements button {
20 margin-right: 4px;
20 margin-right: 4px;
21 width : 24px;
21 width : 24px;
22 height: 24px;
22 height: 24px;
23 padding: 4px;
23 padding: 4px;
24 border-style: solid;
24 border-style: solid;
25 border-width: 1px;
25 border-width: 1px;
26 border-color: #ddd;
26 border-color: #ddd;
27 background-color : #f7f7f7;
27 background-color : #f7f7f7;
28 background-position : 50% 50%;
28 background-position : 50% 50%;
29 background-repeat: no-repeat;
29 background-repeat: no-repeat;
30 }
30 }
31 .jstElements button:hover {
31 .jstElements button:hover {
32 border-color: #bbb;
32 border-color: #bbb;
33 background-color: #e5e5e5;
33 background-color: #e5e5e5;
34 }
34 }
35 .jstElements button span {
35 .jstElements button span {
36 display : none;
36 display : none;
37 }
37 }
38 .jstElements span {
38 .jstElements span {
39 display : inline;
39 display : inline;
40 }
40 }
41
41
42 .jstSpacer {
42 .jstSpacer {
43 width : 0px;
43 width : 0px;
44 font-size: 1px;
44 font-size: 1px;
45 margin-right: 6px;
45 margin-right: 6px;
46 }
46 }
47
47
48 .jstElements .help { float: right; margin-right: 0.5em; padding-top: 8px; font-size: 0.9em; }
48 .jstElements .help { float: right; margin-right: 0.5em; padding-top: 8px; font-size: 0.9em; }
49 .jstElements .help a {padding: 2px 0 2px 20px; background: url(../images/help.png) no-repeat 0 50%;}
49 .jstElements .help a {padding: 2px 0 2px 20px; background: url(../images/help.png) no-repeat 0 50%;}
50
50
51 /* Buttons
51 /* Buttons
52 -------------------------------------------------------- */
52 -------------------------------------------------------- */
53 .jstb_strong {
53 .jstb_strong {
54 background-image: url(../images/jstoolbar/bt_strong.png);
54 background-image: url(../images/jstoolbar/bt_strong.png);
55 }
55 }
56 .jstb_em {
56 .jstb_em {
57 background-image: url(../images/jstoolbar/bt_em.png);
57 background-image: url(../images/jstoolbar/bt_em.png);
58 }
58 }
59 .jstb_ins {
59 .jstb_ins {
60 background-image: url(../images/jstoolbar/bt_ins.png);
60 background-image: url(../images/jstoolbar/bt_ins.png);
61 }
61 }
62 .jstb_del {
62 .jstb_del {
63 background-image: url(../images/jstoolbar/bt_del.png);
63 background-image: url(../images/jstoolbar/bt_del.png);
64 }
64 }
65 .jstb_code {
65 .jstb_code {
66 background-image: url(../images/jstoolbar/bt_code.png);
66 background-image: url(../images/jstoolbar/bt_code.png);
67 }
67 }
68 .jstb_h1 {
68 .jstb_h1 {
69 background-image: url(../images/jstoolbar/bt_h1.png);
69 background-image: url(../images/jstoolbar/bt_h1.png);
70 }
70 }
71 .jstb_h2 {
71 .jstb_h2 {
72 background-image: url(../images/jstoolbar/bt_h2.png);
72 background-image: url(../images/jstoolbar/bt_h2.png);
73 }
73 }
74 .jstb_h3 {
74 .jstb_h3 {
75 background-image: url(../images/jstoolbar/bt_h3.png);
75 background-image: url(../images/jstoolbar/bt_h3.png);
76 }
76 }
77 .jstb_ul {
77 .jstb_ul {
78 background-image: url(../images/jstoolbar/bt_ul.png);
78 background-image: url(../images/jstoolbar/bt_ul.png);
79 }
79 }
80 .jstb_ol {
80 .jstb_ol {
81 background-image: url(../images/jstoolbar/bt_ol.png);
81 background-image: url(../images/jstoolbar/bt_ol.png);
82 }
82 }
83 .jstb_bq {
83 .jstb_bq {
84 background-image: url(../images/jstoolbar/bt_bq.png);
84 background-image: url(../images/jstoolbar/bt_bq.png);
85 }
85 }
86 .jstb_unbq {
86 .jstb_unbq {
87 background-image: url(../images/jstoolbar/bt_bq_remove.png);
87 background-image: url(../images/jstoolbar/bt_bq_remove.png);
88 }
88 }
89 .jstb_pre {
89 .jstb_pre {
90 background-image: url(../images/jstoolbar/bt_pre.png);
90 background-image: url(../images/jstoolbar/bt_pre.png);
91 }
91 }
92 .jstb_link {
92 .jstb_link {
93 background-image: url(../images/jstoolbar/bt_link.png);
93 background-image: url(../images/jstoolbar/bt_link.png);
94 }
94 }
95 .jstb_img {
95 .jstb_img {
96 background-image: url(../images/jstoolbar/bt_img.png);
96 background-image: url(../images/jstoolbar/bt_img.png);
97 }
97 }
98 .jstb_help {
99 background-image: url(../images/help.png);
100 }
General Comments 0
You need to be logged in to leave comments. Login now