##// END OF EJS Templates
Removes textarea resizer in favour of built-in browser support....
Jean-Philippe Lang -
r10667:0ef82b3dcf7f
parent child
Show More
@@ -1,1 +1,1
1 function jsToolBar(a){if(!document.createElement){return}if(!a){return}if(typeof document["selection"]=="undefined"&&typeof a["setSelectionRange"]=="undefined"){return}this.textarea=a;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){this.handle=document.createElement("div");this.handle.className="jstHandle";var b=this.resizeDragStart;var c=this;this.handle.addEventListener("mousedown",function(a){b.call(c,a)},false);window.addEventListener("unload",function(){var a=c.handle.parentNode.removeChild(c.handle);delete c.handle},false);this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling)}this.context=null;this.toolNodes={}}function jsButton(a,b,c,d){if(typeof jsToolBar.strings=="undefined"){this.title=a||null}else{this.title=jsToolBar.strings[a]||a||null}this.fn=b||function(){};this.scope=c||null;this.className=d||null}function jsSpace(a){this.id=a||null;this.width=null}function jsCombo(a,b,c,d,e){this.title=a||null;this.options=b||null;this.scope=c||null;this.fn=d||function(){};this.className=e||null}jsButton.prototype.draw=function(){if(!this.scope)return null;var a=document.createElement("button");a.setAttribute("type","button");a.tabIndex=200;if(this.className)a.className=this.className;a.title=this.title;var b=document.createElement("span");b.appendChild(document.createTextNode(this.title));a.appendChild(b);if(this.icon!=undefined){a.style.backgroundImage="url("+this.icon+")"}if(typeof this.fn=="function"){var c=this;a.onclick=function(){try{c.fn.apply(c.scope,arguments)}catch(a){}return false}}return a};jsSpace.prototype.draw=function(){var a=document.createElement("span");if(this.id)a.id=this.id;a.appendChild(document.createTextNode(String.fromCharCode(160)));a.className="jstSpacer";if(this.width)a.style.marginRight=this.width+"px";return a};jsCombo.prototype.draw=function(){if(!this.scope||!this.options)return null;var a=document.createElement("select");if(this.className)a.className=className;a.title=this.title;for(var b in this.options){var c=document.createElement("option");c.value=b;c.appendChild(document.createTextNode(this.options[b]));a.appendChild(c)}var d=this;a.onchange=function(){try{d.fn.call(d.scope,this.value)}catch(a){alert(a)}return false};return a};jsToolBar.prototype={base_url:"",mode:"wiki",elements:{},help_link:"",getMode:function(){return this.mode},setMode:function(a){this.mode=a||"wiki"},switchMode:function(a){a=a||"wiki";this.draw(a)},setHelpLink:function(a){this.help_link=a},button:function(a){var b=this.elements[a];if(typeof b.fn[this.mode]!="function")return null;var c=new jsButton(b.title,b.fn[this.mode],this,"jstb_"+a);if(b.icon!=undefined)c.icon=b.icon;return c},space:function(a){var b=new jsSpace(a);if(this.elements[a].width!==undefined)b.width=this.elements[a].width;return b},combo:function(a){var b=this.elements[a];var c=b[this.mode].list.length;if(typeof b[this.mode].fn!="function"||c==0){return null}else{var d={};for(var e=0;e<c;e++){var f=b[this.mode].list[e];d[f]=b.options[f]}return new jsCombo(b.title,d,this,b[this.mode].fn)}},draw:function(a){this.setMode(a);while(this.toolbar.hasChildNodes()){this.toolbar.removeChild(this.toolbar.firstChild)}this.toolNodes={};var b=document.createElement("div");b.className="help";b.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(b);var c,d,e;for(var f in this.elements){c=this.elements[f];var g=c.type==undefined||c.type==""||c.disabled!=undefined&&c.disabled||c.context!=undefined&&c.context!=null&&c.context!=this.context;if(!g&&typeof this[c.type]=="function"){d=this[c.type](f);if(d)e=d.draw();if(e){this.toolNodes[f]=e;this.toolbar.appendChild(e)}}}},singleTag:function(a,b){a=a||null;b=b||a;if(!a||!b){return}this.encloseSelection(a,b)},encloseLineSelection:function(a,b,c){this.textarea.focus();a=a||"";b=b||"";var d,e,f,g,h,i;if(typeof document["selection"]!="undefined"){f=document.selection.createRange().text}else if(typeof this.textarea["setSelectionRange"]!="undefined"){d=this.textarea.selectionStart;e=this.textarea.selectionEnd;g=this.textarea.scrollTop;d=this.textarea.value.substring(0,d).replace(/[^\r\n]*$/g,"").length;e=this.textarea.value.length-this.textarea.value.substring(e,this.textarea.value.length).replace(/^[^\r\n]*/,"").length;f=this.textarea.value.substring(d,e)}if(f.match(/ $/)){f=f.substring(0,f.length-1);b=b+" "}if(typeof c=="function"){i=f?c.call(this,f):c("")}else{i=f?f:""}h=a+i+b;if(typeof document["selection"]!="undefined"){document.selection.createRange().text=h;var j=this.textarea.createTextRange();j.collapse(false);j.move("character",-b.length);j.select()}else if(typeof this.textarea["setSelectionRange"]!="undefined"){this.textarea.value=this.textarea.value.substring(0,d)+h+this.textarea.value.substring(e);if(f){this.textarea.setSelectionRange(d+h.length,d+h.length)}else{this.textarea.setSelectionRange(d+a.length,d+a.length)}this.textarea.scrollTop=g}},encloseSelection:function(a,b,c){this.textarea.focus();a=a||"";b=b||"";var d,e,f,g,h,i;if(typeof document["selection"]!="undefined"){f=document.selection.createRange().text}else if(typeof this.textarea["setSelectionRange"]!="undefined"){d=this.textarea.selectionStart;e=this.textarea.selectionEnd;g=this.textarea.scrollTop;f=this.textarea.value.substring(d,e)}if(f.match(/ $/)){f=f.substring(0,f.length-1);b=b+" "}if(typeof c=="function"){i=f?c.call(this,f):c("")}else{i=f?f:""}h=a+i+b;if(typeof document["selection"]!="undefined"){document.selection.createRange().text=h;var j=this.textarea.createTextRange();j.collapse(false);j.move("character",-b.length);j.select()}else if(typeof this.textarea["setSelectionRange"]!="undefined"){this.textarea.value=this.textarea.value.substring(0,d)+h+this.textarea.value.substring(e);if(f){this.textarea.setSelectionRange(d+h.length,d+h.length)}else{this.textarea.setSelectionRange(d+a.length,d+a.length)}this.textarea.scrollTop=g}},stripBaseURL:function(a){if(this.base_url!=""){var b=a.indexOf(this.base_url);if(b==0){a=a.substr(this.base_url.length)}}return a}};jsToolBar.prototype.resizeSetStartH=function(){this.dragStartH=this.textarea.offsetHeight+0};jsToolBar.prototype.resizeDragStart=function(a){var b=this;this.dragStartY=a.clientY;this.resizeSetStartH();document.addEventListener("mousemove",this.dragMoveHdlr=function(a){b.resizeDragMove(a)},false);document.addEventListener("mouseup",this.dragStopHdlr=function(a){b.resizeDragStop(a)},false)};jsToolBar.prototype.resizeDragMove=function(a){this.textarea.style.height=this.dragStartH+a.clientY-this.dragStartY+"px"};jsToolBar.prototype.resizeDragStop=function(a){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(a){a=a.replace(/^h\d+\.\s+/,"");return a})}}};jsToolBar.prototype.elements.h2={type:"button",title:"Heading 2",fn:{wiki:function(){this.encloseLineSelection("h2. ","",function(a){a=a.replace(/^h\d+\.\s+/,"");return a})}}};jsToolBar.prototype.elements.h3={type:"button",title:"Heading 3",fn:{wiki:function(){this.encloseLineSelection("h3. ","",function(a){a=a.replace(/^h\d+\.\s+/,"");return a})}}};jsToolBar.prototype.elements.space2={type:"space"};jsToolBar.prototype.elements.ul={type:"button",title:"Unordered list",fn:{wiki:function(){this.encloseLineSelection("","",function(a){a=a.replace(/\r/g,"");return a.replace(/(\n|^)[#-]?\s*/g,"$1* ")})}}};jsToolBar.prototype.elements.ol={type:"button",title:"Ordered list",fn:{wiki:function(){this.encloseLineSelection("","",function(a){a=a.replace(/\r/g,"");return a.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(a){a=a.replace(/\r/g,"");return a.replace(/(\n|^) *([^\n]*)/g,"$1> $2")})}}};jsToolBar.prototype.elements.unbq={type:"button",title:"Unquote",fn:{wiki:function(){this.encloseLineSelection("","",function(a){a=a.replace(/\r/g,"");return a.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("!","!")}}}
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,380 +1,380
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
48 if (this.editor.addEventListener)
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');
210 var h = document.createElement('div');
211 h.className = 'help'
211 h.className = 'help'
212 h.innerHTML = this.help_link;
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>';
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);
214 this.toolbar.appendChild(h);
215
215
216 // Draw toolbar elements
216 // Draw toolbar elements
217 var b, tool, newTool;
217 var b, tool, newTool;
218
218
219 for (var i in this.elements) {
219 for (var i in this.elements) {
220 b = this.elements[i];
220 b = this.elements[i];
221
221
222 var disabled =
222 var disabled =
223 b.type == undefined || b.type == ''
223 b.type == undefined || b.type == ''
224 || (b.disabled != undefined && b.disabled)
224 || (b.disabled != undefined && b.disabled)
225 || (b.context != undefined && b.context != null && b.context != this.context);
225 || (b.context != undefined && b.context != null && b.context != this.context);
226
226
227 if (!disabled && typeof this[b.type] == 'function') {
227 if (!disabled && typeof this[b.type] == 'function') {
228 tool = this[b.type](i);
228 tool = this[b.type](i);
229 if (tool) newTool = tool.draw();
229 if (tool) newTool = tool.draw();
230 if (newTool) {
230 if (newTool) {
231 this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur
231 this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur
232 this.toolbar.appendChild(newTool);
232 this.toolbar.appendChild(newTool);
233 }
233 }
234 }
234 }
235 }
235 }
236 },
236 },
237
237
238 singleTag: function(stag,etag) {
238 singleTag: function(stag,etag) {
239 stag = stag || null;
239 stag = stag || null;
240 etag = etag || stag;
240 etag = etag || stag;
241
241
242 if (!stag || !etag) { return; }
242 if (!stag || !etag) { return; }
243
243
244 this.encloseSelection(stag,etag);
244 this.encloseSelection(stag,etag);
245 },
245 },
246
246
247 encloseLineSelection: function(prefix, suffix, fn) {
247 encloseLineSelection: function(prefix, suffix, fn) {
248 this.textarea.focus();
248 this.textarea.focus();
249
249
250 prefix = prefix || '';
250 prefix = prefix || '';
251 suffix = suffix || '';
251 suffix = suffix || '';
252
252
253 var start, end, sel, scrollPos, subst, res;
253 var start, end, sel, scrollPos, subst, res;
254
254
255 if (typeof(document["selection"]) != "undefined") {
255 if (typeof(document["selection"]) != "undefined") {
256 sel = document.selection.createRange().text;
256 sel = document.selection.createRange().text;
257 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
257 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
258 start = this.textarea.selectionStart;
258 start = this.textarea.selectionStart;
259 end = this.textarea.selectionEnd;
259 end = this.textarea.selectionEnd;
260 scrollPos = this.textarea.scrollTop;
260 scrollPos = this.textarea.scrollTop;
261 // go to the start of the line
261 // go to the start of the line
262 start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length;
262 start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length;
263 // go to the end of the line
263 // 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;
264 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);
265 sel = this.textarea.value.substring(start, end);
266 }
266 }
267
267
268 if (sel.match(/ $/)) { // exclude ending space char, if any
268 if (sel.match(/ $/)) { // exclude ending space char, if any
269 sel = sel.substring(0, sel.length - 1);
269 sel = sel.substring(0, sel.length - 1);
270 suffix = suffix + " ";
270 suffix = suffix + " ";
271 }
271 }
272
272
273 if (typeof(fn) == 'function') {
273 if (typeof(fn) == 'function') {
274 res = (sel) ? fn.call(this,sel) : fn('');
274 res = (sel) ? fn.call(this,sel) : fn('');
275 } else {
275 } else {
276 res = (sel) ? sel : '';
276 res = (sel) ? sel : '';
277 }
277 }
278
278
279 subst = prefix + res + suffix;
279 subst = prefix + res + suffix;
280
280
281 if (typeof(document["selection"]) != "undefined") {
281 if (typeof(document["selection"]) != "undefined") {
282 document.selection.createRange().text = subst;
282 document.selection.createRange().text = subst;
283 var range = this.textarea.createTextRange();
283 var range = this.textarea.createTextRange();
284 range.collapse(false);
284 range.collapse(false);
285 range.move('character', -suffix.length);
285 range.move('character', -suffix.length);
286 range.select();
286 range.select();
287 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
287 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
288 this.textarea.value = this.textarea.value.substring(0, start) + subst +
288 this.textarea.value = this.textarea.value.substring(0, start) + subst +
289 this.textarea.value.substring(end);
289 this.textarea.value.substring(end);
290 if (sel) {
290 if (sel) {
291 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
291 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
292 } else {
292 } else {
293 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
293 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
294 }
294 }
295 this.textarea.scrollTop = scrollPos;
295 this.textarea.scrollTop = scrollPos;
296 }
296 }
297 },
297 },
298
298
299 encloseSelection: function(prefix, suffix, fn) {
299 encloseSelection: function(prefix, suffix, fn) {
300 this.textarea.focus();
300 this.textarea.focus();
301
301
302 prefix = prefix || '';
302 prefix = prefix || '';
303 suffix = suffix || '';
303 suffix = suffix || '';
304
304
305 var start, end, sel, scrollPos, subst, res;
305 var start, end, sel, scrollPos, subst, res;
306
306
307 if (typeof(document["selection"]) != "undefined") {
307 if (typeof(document["selection"]) != "undefined") {
308 sel = document.selection.createRange().text;
308 sel = document.selection.createRange().text;
309 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
309 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
310 start = this.textarea.selectionStart;
310 start = this.textarea.selectionStart;
311 end = this.textarea.selectionEnd;
311 end = this.textarea.selectionEnd;
312 scrollPos = this.textarea.scrollTop;
312 scrollPos = this.textarea.scrollTop;
313 sel = this.textarea.value.substring(start, end);
313 sel = this.textarea.value.substring(start, end);
314 }
314 }
315
315
316 if (sel.match(/ $/)) { // exclude ending space char, if any
316 if (sel.match(/ $/)) { // exclude ending space char, if any
317 sel = sel.substring(0, sel.length - 1);
317 sel = sel.substring(0, sel.length - 1);
318 suffix = suffix + " ";
318 suffix = suffix + " ";
319 }
319 }
320
320
321 if (typeof(fn) == 'function') {
321 if (typeof(fn) == 'function') {
322 res = (sel) ? fn.call(this,sel) : fn('');
322 res = (sel) ? fn.call(this,sel) : fn('');
323 } else {
323 } else {
324 res = (sel) ? sel : '';
324 res = (sel) ? sel : '';
325 }
325 }
326
326
327 subst = prefix + res + suffix;
327 subst = prefix + res + suffix;
328
328
329 if (typeof(document["selection"]) != "undefined") {
329 if (typeof(document["selection"]) != "undefined") {
330 document.selection.createRange().text = subst;
330 document.selection.createRange().text = subst;
331 var range = this.textarea.createTextRange();
331 var range = this.textarea.createTextRange();
332 range.collapse(false);
332 range.collapse(false);
333 range.move('character', -suffix.length);
333 range.move('character', -suffix.length);
334 range.select();
334 range.select();
335 // this.textarea.caretPos -= suffix.length;
335 // this.textarea.caretPos -= suffix.length;
336 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
336 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
337 this.textarea.value = this.textarea.value.substring(0, start) + subst +
337 this.textarea.value = this.textarea.value.substring(0, start) + subst +
338 this.textarea.value.substring(end);
338 this.textarea.value.substring(end);
339 if (sel) {
339 if (sel) {
340 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
340 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
341 } else {
341 } else {
342 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
342 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
343 }
343 }
344 this.textarea.scrollTop = scrollPos;
344 this.textarea.scrollTop = scrollPos;
345 }
345 }
346 },
346 },
347
347
348 stripBaseURL: function(url) {
348 stripBaseURL: function(url) {
349 if (this.base_url != '') {
349 if (this.base_url != '') {
350 var pos = url.indexOf(this.base_url);
350 var pos = url.indexOf(this.base_url);
351 if (pos == 0) {
351 if (pos == 0) {
352 url = url.substr(this.base_url.length);
352 url = url.substr(this.base_url.length);
353 }
353 }
354 }
354 }
355
355
356 return url;
356 return url;
357 }
357 }
358 };
358 };
359
359
360 /** Resizer
360 /** Resizer
361 -------------------------------------------------------- */
361 -------------------------------------------------------- */
362 jsToolBar.prototype.resizeSetStartH = function() {
362 jsToolBar.prototype.resizeSetStartH = function() {
363 this.dragStartH = this.textarea.offsetHeight + 0;
363 this.dragStartH = this.textarea.offsetHeight + 0;
364 };
364 };
365 jsToolBar.prototype.resizeDragStart = function(event) {
365 jsToolBar.prototype.resizeDragStart = function(event) {
366 var This = this;
366 var This = this;
367 this.dragStartY = event.clientY;
367 this.dragStartY = event.clientY;
368 this.resizeSetStartH();
368 this.resizeSetStartH();
369 document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false);
369 document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false);
370 document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false);
370 document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false);
371 };
371 };
372
372
373 jsToolBar.prototype.resizeDragMove = function(event) {
373 jsToolBar.prototype.resizeDragMove = function(event) {
374 this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px';
374 this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px';
375 };
375 };
376
376
377 jsToolBar.prototype.resizeDragStop = function(event) {
377 jsToolBar.prototype.resizeDragStop = function(event) {
378 document.removeEventListener('mousemove', this.dragMoveHdlr, false);
378 document.removeEventListener('mousemove', this.dragMoveHdlr, false);
379 document.removeEventListener('mouseup', this.dragStopHdlr, false);
379 document.removeEventListener('mouseup', this.dragStopHdlr, false);
380 };
380 };
General Comments 0
You need to be logged in to leave comments. Login now