@@ -1,1 +1,1 | |||||
1 | function jsToolBar(e){if(document.createElement&&e&&("undefined"!=typeof document.selection||"undefined"!=typeof e.setSelectionRange)){if(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),this.editor.addEventListener&&navigator.appVersion.match(/\bMSIE\b/)){this.handle=document.createElement("div"),this.handle.className="jstHandle";var t=this.resizeDragStart,n=this;this.handle.addEventListener("mousedown",function(e){t.call(n,e)},!1),window.addEventListener("unload",function(){n.handle.parentNode.removeChild(n.handle);delete n.handle},!1),this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling)}this.context=null,this.toolNodes={}}}function jsButton(e,t,n,o){"undefined"==typeof jsToolBar.strings?this.title=e||null:this.title=jsToolBar.strings[e]||e||null,this.fn=t||function(){},this.scope=n||null,this.className=o||null}function jsSpace(e){this.id=e||null,this.width=null}function jsCombo(e,t,n,o,i){this.title=e||null,this.options=t||null,this.scope=n||null,this.fn=o||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,this.className&&(e.className=this.className),e.title=this.title;var t=document.createElement("span");if(t.appendChild(document.createTextNode(this.title)),e.appendChild(t),void 0!=this.icon&&(e.style.backgroundImage="url("+this.icon+")"),"function"==typeof this.fn){var n=this;e.onclick=function(){try{n.fn.apply(n.scope,arguments)}catch(e){}return!1}}return e},jsSpace.prototype.draw=function(){var e=document.createElement("span");return this.id&&(e.id=this.id),e.appendChild(document.createTextNode(String.fromCharCode(160))),e.className="jstSpacer",this.width&&(e.style.marginRight=this.width+"px"),e},jsCombo.prototype.draw=function(){if(!this.scope||!this.options)return null;var e=document.createElement("select");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 o=this;return e.onchange=function(){try{o.fn.call(o.scope,this.value)}catch(e){alert(e)}return!1},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("function"!=typeof t.fn[this.mode])return null;var n=new jsButton(t.title,t.fn[this.mode],this,"jstb_"+e);return void 0!=t.icon&&(n.icon=t.icon),n},space:function(e){var t=new jsSpace(e);return void 0!==this.elements[e].width&&(t.width=this.elements[e].width),t},combo:function(e){var t=this.elements[e],n=t[this.mode].list.length;if("function"!=typeof t[this.mode].fn||0==n)return null;for(var o={},i=0;n>i;i++){var s=t[this.mode].list[i];o[s]=t.options[s]}return new jsCombo(t.title,o,this,t[this.mode].fn)},draw:function(e){for(this.setMode(e);this.toolbar.hasChildNodes();)this.toolbar.removeChild(this.toolbar.firstChild);this.toolNodes={};var t,n,o;for(var i in this.elements){t=this.elements[i];var s=void 0==t.type||""==t.type||void 0!=t.disabled&&t.disabled||void 0!=t.context&&null!=t.context&&t.context!=this.context;s||"function"!=typeof this[t.type]||(n=this[t.type](i),n&&(o=n.draw()),o&&(this.toolNodes[i]=o,this.toolbar.appendChild(o)))}},singleTag:function(e,t){e=e||null,t=t||e,e&&t&&this.encloseSelection(e,t)},encloseLineSelection:function(e,t,n){this.textarea.focus(),e=e||"",t=t||"";var o,i,s,l,a,r;if("undefined"!=typeof document.selection?s=document.selection.createRange().text:"undefined"!=typeof this.textarea.setSelectionRange&&(o=this.textarea.selectionStart,i=this.textarea.selectionEnd,l=this.textarea.scrollTop,o=this.textarea.value.substring(0,o).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(o,i)),s.match(/ $/)&&(s=s.substring(0,s.length-1),t+=" "),r="function"==typeof n?s?n.call(this,s):n(""):s?s:"",a=e+r+t,"undefined"!=typeof document.selection){document.selection.createRange().text=a;var c=this.textarea.createTextRange();c.collapse(!1),c.move("character",-t.length),c.select()}else"undefined"!=typeof this.textarea.setSelectionRange&&(this.textarea.value=this.textarea.value.substring(0,o)+a+this.textarea.value.substring(i),s?this.textarea.setSelectionRange(o+a.length,o+a.length):this.textarea.setSelectionRange(o+e.length,o+e.length),this.textarea.scrollTop=l)},encloseSelection:function(e,t,n){this.textarea.focus(),e=e||"",t=t||"";var o,i,s,l,a,r;if("undefined"!=typeof document.selection?s=document.selection.createRange().text:"undefined"!=typeof this.textarea.setSelectionRange&&(o=this.textarea.selectionStart,i=this.textarea.selectionEnd,l=this.textarea.scrollTop,s=this.textarea.value.substring(o,i)),s.match(/ $/)&&(s=s.substring(0,s.length-1),t+=" "),r="function"==typeof n?s?n.call(this,s):n(""):s?s:"",a=e+r+t,"undefined"!=typeof document.selection){document.selection.createRange().text=a;var c=this.textarea.createTextRange();c.collapse(!1),c.move("character",-t.length),c.select()}else"undefined"!=typeof this.textarea.setSelectionRange&&(this.textarea.value=this.textarea.value.substring(0,o)+a+this.textarea.value.substring(i),s?this.textarea.setSelectionRange(o+a.length,o+a.length):this.textarea.setSelectionRange(o+e.length,o+e.length),this.textarea.scrollTop=l)},stripBaseURL:function(e){if(""!=this.base_url){var t=e.indexOf(this.base_url);0==t&&(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)},!1),document.addEventListener("mouseup",this.dragStopHdlr=function(e){t.resizeDragStop(e)},!1)},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,!1),document.removeEventListener("mouseup",this.dragStopHdlr,!1)},jsToolBar.prototype.precodeMenu=function(e){for(var t=["c","clojure","cpp","css","delphi","diff","erb","go","groovy","haml","html","java","javascript","json","lua","php","python","ruby","sass","sql","text","xml","yaml"],n=$("<ul style='position:absolute;'></ul>"),o=0;o<t.length;o++)$("<li></li>").text(t[o]).appendTo(n).mousedown(function(){e($(this).text())});return $("body").append(n),n.menu().width(150).position({my:"left top",at:"left bottom",of:this.toolNodes.precode}),$(document).on("mousedown",function(){n.remove()}),!1},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){return e=e.replace(/^h\d+\.\s+/,"")})}}},jsToolBar.prototype.elements.h2={type:"button",title:"Heading 2",fn:{wiki:function(){this.encloseLineSelection("h2. ","",function(e){return e=e.replace(/^h\d+\.\s+/,"")})}}},jsToolBar.prototype.elements.h3={type:"button",title:"Heading 3",fn:{wiki:function(){this.encloseLineSelection("h3. ","",function(e){return e=e.replace(/^h\d+\.\s+/,"")})}}},jsToolBar.prototype.elements.space2={type:"space"},jsToolBar.prototype.elements.ul={type:"button",title:"Unordered list",fn:{wiki:function(){this.encloseLineSelection("","",function(e){return e=e.replace(/\r/g,""),e.replace(/(\n|^)[#-]?\s*/g,"$1* ")})}}},jsToolBar.prototype.elements.ol={type:"button",title:"Ordered list",fn:{wiki:function(){this.encloseLineSelection("","",function(e){return e=e.replace(/\r/g,""),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){return e=e.replace(/\r/g,""),e.replace(/(\n|^) *([^\n]*)/g,"$1> $2")})}}},jsToolBar.prototype.elements.unbq={type:"button",title:"Unquote",fn:{wiki:function(){this.encloseLineSelection("","",function(e){return e=e.replace(/\r/g,""),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.precode={type:"button",title:"Highlighted code",fn:{wiki:function(){var e=this;this.precodeMenu(function(t){e.encloseLineSelection('<pre><code class="'+t+'">\n',"\n</code></pre>\n")})}}},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 | function jsToolBar(e){if(document.createElement&&e&&("undefined"!=typeof document.selection||"undefined"!=typeof e.setSelectionRange)){if(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),this.editor.addEventListener&&navigator.appVersion.match(/\bMSIE\b/)){this.handle=document.createElement("div"),this.handle.className="jstHandle";var t=this.resizeDragStart,n=this;this.handle.addEventListener("mousedown",function(e){t.call(n,e)},!1),window.addEventListener("unload",function(){n.handle.parentNode.removeChild(n.handle);delete n.handle},!1),this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling)}this.context=null,this.toolNodes={}}}function jsButton(e,t,n,o){"undefined"==typeof jsToolBar.strings?this.title=e||null:this.title=jsToolBar.strings[e]||e||null,this.fn=t||function(){},this.scope=n||null,this.className=o||null}function jsSpace(e){this.id=e||null,this.width=null}function jsCombo(e,t,n,o,i){this.title=e||null,this.options=t||null,this.scope=n||null,this.fn=o||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,this.className&&(e.className=this.className),e.title=this.title;var t=document.createElement("span");if(t.appendChild(document.createTextNode(this.title)),e.appendChild(t),void 0!=this.icon&&(e.style.backgroundImage="url("+this.icon+")"),"function"==typeof this.fn){var n=this;e.onclick=function(){try{n.fn.apply(n.scope,arguments)}catch(e){}return!1}}return e},jsSpace.prototype.draw=function(){var e=document.createElement("span");return this.id&&(e.id=this.id),e.appendChild(document.createTextNode(String.fromCharCode(160))),e.className="jstSpacer",this.width&&(e.style.marginRight=this.width+"px"),e},jsCombo.prototype.draw=function(){if(!this.scope||!this.options)return null;var e=document.createElement("select");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 o=this;return e.onchange=function(){try{o.fn.call(o.scope,this.value)}catch(e){alert(e)}return!1},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("function"!=typeof t.fn[this.mode])return null;var n=new jsButton(t.title,t.fn[this.mode],this,"jstb_"+e);return void 0!=t.icon&&(n.icon=t.icon),n},space:function(e){var t=new jsSpace(e);return void 0!==this.elements[e].width&&(t.width=this.elements[e].width),t},combo:function(e){var t=this.elements[e],n=t[this.mode].list.length;if("function"!=typeof t[this.mode].fn||0==n)return null;for(var o={},i=0;n>i;i++){var s=t[this.mode].list[i];o[s]=t.options[s]}return new jsCombo(t.title,o,this,t[this.mode].fn)},draw:function(e){for(this.setMode(e);this.toolbar.hasChildNodes();)this.toolbar.removeChild(this.toolbar.firstChild);this.toolNodes={};var t,n,o;for(var i in this.elements){t=this.elements[i];var s=void 0==t.type||""==t.type||void 0!=t.disabled&&t.disabled||void 0!=t.context&&null!=t.context&&t.context!=this.context;s||"function"!=typeof this[t.type]||(n=this[t.type](i),n&&(o=n.draw()),o&&(this.toolNodes[i]=o,this.toolbar.appendChild(o)))}},singleTag:function(e,t){e=e||null,t=t||e,e&&t&&this.encloseSelection(e,t)},encloseLineSelection:function(e,t,n){this.textarea.focus(),e=e||"",t=t||"";var o,i,s,l,a,r;if("undefined"!=typeof document.selection?s=document.selection.createRange().text:"undefined"!=typeof this.textarea.setSelectionRange&&(o=this.textarea.selectionStart,i=this.textarea.selectionEnd,l=this.textarea.scrollTop,o=this.textarea.value.substring(0,o).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(o,i)),s.match(/ $/)&&(s=s.substring(0,s.length-1),t+=" "),r="function"==typeof n?s?n.call(this,s):n(""):s?s:"",a=e+r+t,"undefined"!=typeof document.selection){document.selection.createRange().text=a;var c=this.textarea.createTextRange();c.collapse(!1),c.move("character",-t.length),c.select()}else"undefined"!=typeof this.textarea.setSelectionRange&&(this.textarea.value=this.textarea.value.substring(0,o)+a+this.textarea.value.substring(i),s?this.textarea.setSelectionRange(o+a.length,o+a.length):this.textarea.setSelectionRange(o+e.length,o+e.length),this.textarea.scrollTop=l)},encloseSelection:function(e,t,n){this.textarea.focus(),e=e||"",t=t||"";var o,i,s,l,a,r;if("undefined"!=typeof document.selection?s=document.selection.createRange().text:"undefined"!=typeof this.textarea.setSelectionRange&&(o=this.textarea.selectionStart,i=this.textarea.selectionEnd,l=this.textarea.scrollTop,s=this.textarea.value.substring(o,i)),s.match(/ $/)&&(s=s.substring(0,s.length-1),t+=" "),r="function"==typeof n?s?n.call(this,s):n(""):s?s:"",a=e+r+t,"undefined"!=typeof document.selection){document.selection.createRange().text=a;var c=this.textarea.createTextRange();c.collapse(!1),c.move("character",-t.length),c.select()}else"undefined"!=typeof this.textarea.setSelectionRange&&(this.textarea.value=this.textarea.value.substring(0,o)+a+this.textarea.value.substring(i),s?this.textarea.setSelectionRange(o+a.length,o+a.length):this.textarea.setSelectionRange(o+e.length,o+e.length),this.textarea.scrollTop=l)},stripBaseURL:function(e){if(""!=this.base_url){var t=e.indexOf(this.base_url);0==t&&(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)},!1),document.addEventListener("mouseup",this.dragStopHdlr=function(e){t.resizeDragStop(e)},!1)},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,!1),document.removeEventListener("mouseup",this.dragStopHdlr,!1)},jsToolBar.prototype.precodeMenu=function(e){for(var t=["c","clojure","cpp","css","delphi","diff","erb","go","groovy","haml","html","java","javascript","json","lua","php","python","ruby","sass","sql","taskpaper","text","xml","yaml"],n=$("<ul style='position:absolute;'></ul>"),o=0;o<t.length;o++)$("<li></li>").text(t[o]).appendTo(n).mousedown(function(){e($(this).text())});return $("body").append(n),n.menu().width(150).position({my:"left top",at:"left bottom",of:this.toolNodes.precode}),$(document).on("mousedown",function(){n.remove()}),!1},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){return e=e.replace(/^h\d+\.\s+/,"")})}}},jsToolBar.prototype.elements.h2={type:"button",title:"Heading 2",fn:{wiki:function(){this.encloseLineSelection("h2. ","",function(e){return e=e.replace(/^h\d+\.\s+/,"")})}}},jsToolBar.prototype.elements.h3={type:"button",title:"Heading 3",fn:{wiki:function(){this.encloseLineSelection("h3. ","",function(e){return e=e.replace(/^h\d+\.\s+/,"")})}}},jsToolBar.prototype.elements.space2={type:"space"},jsToolBar.prototype.elements.ul={type:"button",title:"Unordered list",fn:{wiki:function(){this.encloseLineSelection("","",function(e){return e=e.replace(/\r/g,""),e.replace(/(\n|^)[#-]?\s*/g,"$1* ")})}}},jsToolBar.prototype.elements.ol={type:"button",title:"Ordered list",fn:{wiki:function(){this.encloseLineSelection("","",function(e){return e=e.replace(/\r/g,""),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){return e=e.replace(/\r/g,""),e.replace(/(\n|^) *([^\n]*)/g,"$1> $2")})}}},jsToolBar.prototype.elements.unbq={type:"button",title:"Unquote",fn:{wiki:function(){this.encloseLineSelection("","",function(e){return e=e.replace(/\r/g,""),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.precode={type:"button",title:"Highlighted code",fn:{wiki:function(){var e=this;this.precodeMenu(function(t){e.encloseLineSelection('<pre><code class="'+t+'">\n',"\n</code></pre>\n")})}}},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,395 +1,395 | |||||
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 | // Draw toolbar elements |
|
210 | // Draw toolbar elements | |
211 | var b, tool, newTool; |
|
211 | var b, tool, newTool; | |
212 |
|
212 | |||
213 | for (var i in this.elements) { |
|
213 | for (var i in this.elements) { | |
214 | b = this.elements[i]; |
|
214 | b = this.elements[i]; | |
215 |
|
215 | |||
216 | var disabled = |
|
216 | var disabled = | |
217 | b.type == undefined || b.type == '' |
|
217 | b.type == undefined || b.type == '' | |
218 | || (b.disabled != undefined && b.disabled) |
|
218 | || (b.disabled != undefined && b.disabled) | |
219 | || (b.context != undefined && b.context != null && b.context != this.context); |
|
219 | || (b.context != undefined && b.context != null && b.context != this.context); | |
220 |
|
220 | |||
221 | if (!disabled && typeof this[b.type] == 'function') { |
|
221 | if (!disabled && typeof this[b.type] == 'function') { | |
222 | tool = this[b.type](i); |
|
222 | tool = this[b.type](i); | |
223 | if (tool) newTool = tool.draw(); |
|
223 | if (tool) newTool = tool.draw(); | |
224 | if (newTool) { |
|
224 | if (newTool) { | |
225 | 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 | |
226 | this.toolbar.appendChild(newTool); |
|
226 | this.toolbar.appendChild(newTool); | |
227 | } |
|
227 | } | |
228 | } |
|
228 | } | |
229 | } |
|
229 | } | |
230 | }, |
|
230 | }, | |
231 |
|
231 | |||
232 | singleTag: function(stag,etag) { |
|
232 | singleTag: function(stag,etag) { | |
233 | stag = stag || null; |
|
233 | stag = stag || null; | |
234 | etag = etag || stag; |
|
234 | etag = etag || stag; | |
235 |
|
235 | |||
236 | if (!stag || !etag) { return; } |
|
236 | if (!stag || !etag) { return; } | |
237 |
|
237 | |||
238 | this.encloseSelection(stag,etag); |
|
238 | this.encloseSelection(stag,etag); | |
239 | }, |
|
239 | }, | |
240 |
|
240 | |||
241 | encloseLineSelection: function(prefix, suffix, fn) { |
|
241 | encloseLineSelection: function(prefix, suffix, fn) { | |
242 | this.textarea.focus(); |
|
242 | this.textarea.focus(); | |
243 |
|
243 | |||
244 | prefix = prefix || ''; |
|
244 | prefix = prefix || ''; | |
245 | suffix = suffix || ''; |
|
245 | suffix = suffix || ''; | |
246 |
|
246 | |||
247 | var start, end, sel, scrollPos, subst, res; |
|
247 | var start, end, sel, scrollPos, subst, res; | |
248 |
|
248 | |||
249 | if (typeof(document["selection"]) != "undefined") { |
|
249 | if (typeof(document["selection"]) != "undefined") { | |
250 | sel = document.selection.createRange().text; |
|
250 | sel = document.selection.createRange().text; | |
251 | } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { |
|
251 | } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { | |
252 | start = this.textarea.selectionStart; |
|
252 | start = this.textarea.selectionStart; | |
253 | end = this.textarea.selectionEnd; |
|
253 | end = this.textarea.selectionEnd; | |
254 | scrollPos = this.textarea.scrollTop; |
|
254 | scrollPos = this.textarea.scrollTop; | |
255 | // go to the start of the line |
|
255 | // go to the start of the line | |
256 | 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; | |
257 | // go to the end of the line |
|
257 | // go to the end of the line | |
258 | 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; | |
259 | sel = this.textarea.value.substring(start, end); |
|
259 | sel = this.textarea.value.substring(start, end); | |
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | if (sel.match(/ $/)) { // exclude ending space char, if any |
|
262 | if (sel.match(/ $/)) { // exclude ending space char, if any | |
263 | sel = sel.substring(0, sel.length - 1); |
|
263 | sel = sel.substring(0, sel.length - 1); | |
264 | suffix = suffix + " "; |
|
264 | suffix = suffix + " "; | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | if (typeof(fn) == 'function') { |
|
267 | if (typeof(fn) == 'function') { | |
268 | res = (sel) ? fn.call(this,sel) : fn(''); |
|
268 | res = (sel) ? fn.call(this,sel) : fn(''); | |
269 | } else { |
|
269 | } else { | |
270 | res = (sel) ? sel : ''; |
|
270 | res = (sel) ? sel : ''; | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | subst = prefix + res + suffix; |
|
273 | subst = prefix + res + suffix; | |
274 |
|
274 | |||
275 | if (typeof(document["selection"]) != "undefined") { |
|
275 | if (typeof(document["selection"]) != "undefined") { | |
276 | document.selection.createRange().text = subst; |
|
276 | document.selection.createRange().text = subst; | |
277 | var range = this.textarea.createTextRange(); |
|
277 | var range = this.textarea.createTextRange(); | |
278 | range.collapse(false); |
|
278 | range.collapse(false); | |
279 | range.move('character', -suffix.length); |
|
279 | range.move('character', -suffix.length); | |
280 | range.select(); |
|
280 | range.select(); | |
281 | } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { |
|
281 | } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { | |
282 | this.textarea.value = this.textarea.value.substring(0, start) + subst + |
|
282 | this.textarea.value = this.textarea.value.substring(0, start) + subst + | |
283 | this.textarea.value.substring(end); |
|
283 | this.textarea.value.substring(end); | |
284 | if (sel) { |
|
284 | if (sel) { | |
285 | this.textarea.setSelectionRange(start + subst.length, start + subst.length); |
|
285 | this.textarea.setSelectionRange(start + subst.length, start + subst.length); | |
286 | } else { |
|
286 | } else { | |
287 | this.textarea.setSelectionRange(start + prefix.length, start + prefix.length); |
|
287 | this.textarea.setSelectionRange(start + prefix.length, start + prefix.length); | |
288 | } |
|
288 | } | |
289 | this.textarea.scrollTop = scrollPos; |
|
289 | this.textarea.scrollTop = scrollPos; | |
290 | } |
|
290 | } | |
291 | }, |
|
291 | }, | |
292 |
|
292 | |||
293 | encloseSelection: function(prefix, suffix, fn) { |
|
293 | encloseSelection: function(prefix, suffix, fn) { | |
294 | this.textarea.focus(); |
|
294 | this.textarea.focus(); | |
295 |
|
295 | |||
296 | prefix = prefix || ''; |
|
296 | prefix = prefix || ''; | |
297 | suffix = suffix || ''; |
|
297 | suffix = suffix || ''; | |
298 |
|
298 | |||
299 | var start, end, sel, scrollPos, subst, res; |
|
299 | var start, end, sel, scrollPos, subst, res; | |
300 |
|
300 | |||
301 | if (typeof(document["selection"]) != "undefined") { |
|
301 | if (typeof(document["selection"]) != "undefined") { | |
302 | sel = document.selection.createRange().text; |
|
302 | sel = document.selection.createRange().text; | |
303 | } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { |
|
303 | } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { | |
304 | start = this.textarea.selectionStart; |
|
304 | start = this.textarea.selectionStart; | |
305 | end = this.textarea.selectionEnd; |
|
305 | end = this.textarea.selectionEnd; | |
306 | scrollPos = this.textarea.scrollTop; |
|
306 | scrollPos = this.textarea.scrollTop; | |
307 | sel = this.textarea.value.substring(start, end); |
|
307 | sel = this.textarea.value.substring(start, end); | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | if (sel.match(/ $/)) { // exclude ending space char, if any |
|
310 | if (sel.match(/ $/)) { // exclude ending space char, if any | |
311 | sel = sel.substring(0, sel.length - 1); |
|
311 | sel = sel.substring(0, sel.length - 1); | |
312 | suffix = suffix + " "; |
|
312 | suffix = suffix + " "; | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | if (typeof(fn) == 'function') { |
|
315 | if (typeof(fn) == 'function') { | |
316 | res = (sel) ? fn.call(this,sel) : fn(''); |
|
316 | res = (sel) ? fn.call(this,sel) : fn(''); | |
317 | } else { |
|
317 | } else { | |
318 | res = (sel) ? sel : ''; |
|
318 | res = (sel) ? sel : ''; | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 | subst = prefix + res + suffix; |
|
321 | subst = prefix + res + suffix; | |
322 |
|
322 | |||
323 | if (typeof(document["selection"]) != "undefined") { |
|
323 | if (typeof(document["selection"]) != "undefined") { | |
324 | document.selection.createRange().text = subst; |
|
324 | document.selection.createRange().text = subst; | |
325 | var range = this.textarea.createTextRange(); |
|
325 | var range = this.textarea.createTextRange(); | |
326 | range.collapse(false); |
|
326 | range.collapse(false); | |
327 | range.move('character', -suffix.length); |
|
327 | range.move('character', -suffix.length); | |
328 | range.select(); |
|
328 | range.select(); | |
329 | // this.textarea.caretPos -= suffix.length; |
|
329 | // this.textarea.caretPos -= suffix.length; | |
330 | } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { |
|
330 | } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { | |
331 | this.textarea.value = this.textarea.value.substring(0, start) + subst + |
|
331 | this.textarea.value = this.textarea.value.substring(0, start) + subst + | |
332 | this.textarea.value.substring(end); |
|
332 | this.textarea.value.substring(end); | |
333 | if (sel) { |
|
333 | if (sel) { | |
334 | this.textarea.setSelectionRange(start + subst.length, start + subst.length); |
|
334 | this.textarea.setSelectionRange(start + subst.length, start + subst.length); | |
335 | } else { |
|
335 | } else { | |
336 | this.textarea.setSelectionRange(start + prefix.length, start + prefix.length); |
|
336 | this.textarea.setSelectionRange(start + prefix.length, start + prefix.length); | |
337 | } |
|
337 | } | |
338 | this.textarea.scrollTop = scrollPos; |
|
338 | this.textarea.scrollTop = scrollPos; | |
339 | } |
|
339 | } | |
340 | }, |
|
340 | }, | |
341 |
|
341 | |||
342 | stripBaseURL: function(url) { |
|
342 | stripBaseURL: function(url) { | |
343 | if (this.base_url != '') { |
|
343 | if (this.base_url != '') { | |
344 | var pos = url.indexOf(this.base_url); |
|
344 | var pos = url.indexOf(this.base_url); | |
345 | if (pos == 0) { |
|
345 | if (pos == 0) { | |
346 | url = url.substr(this.base_url.length); |
|
346 | url = url.substr(this.base_url.length); | |
347 | } |
|
347 | } | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | return url; |
|
350 | return url; | |
351 | } |
|
351 | } | |
352 | }; |
|
352 | }; | |
353 |
|
353 | |||
354 | /** Resizer |
|
354 | /** Resizer | |
355 | -------------------------------------------------------- */ |
|
355 | -------------------------------------------------------- */ | |
356 | jsToolBar.prototype.resizeSetStartH = function() { |
|
356 | jsToolBar.prototype.resizeSetStartH = function() { | |
357 | this.dragStartH = this.textarea.offsetHeight + 0; |
|
357 | this.dragStartH = this.textarea.offsetHeight + 0; | |
358 | }; |
|
358 | }; | |
359 | jsToolBar.prototype.resizeDragStart = function(event) { |
|
359 | jsToolBar.prototype.resizeDragStart = function(event) { | |
360 | var This = this; |
|
360 | var This = this; | |
361 | this.dragStartY = event.clientY; |
|
361 | this.dragStartY = event.clientY; | |
362 | this.resizeSetStartH(); |
|
362 | this.resizeSetStartH(); | |
363 | document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false); |
|
363 | document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false); | |
364 | document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false); |
|
364 | document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false); | |
365 | }; |
|
365 | }; | |
366 |
|
366 | |||
367 | jsToolBar.prototype.resizeDragMove = function(event) { |
|
367 | jsToolBar.prototype.resizeDragMove = function(event) { | |
368 | this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px'; |
|
368 | this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px'; | |
369 | }; |
|
369 | }; | |
370 |
|
370 | |||
371 | jsToolBar.prototype.resizeDragStop = function(event) { |
|
371 | jsToolBar.prototype.resizeDragStop = function(event) { | |
372 | document.removeEventListener('mousemove', this.dragMoveHdlr, false); |
|
372 | document.removeEventListener('mousemove', this.dragMoveHdlr, false); | |
373 | document.removeEventListener('mouseup', this.dragStopHdlr, false); |
|
373 | document.removeEventListener('mouseup', this.dragStopHdlr, false); | |
374 | }; |
|
374 | }; | |
375 |
|
375 | |||
376 | /* Code highlighting menu */ |
|
376 | /* Code highlighting menu */ | |
377 | jsToolBar.prototype.precodeMenu = function(fn){ |
|
377 | jsToolBar.prototype.precodeMenu = function(fn){ | |
378 | var codeRayLanguages = ["c", "clojure", "cpp", "css", "delphi", "diff", "erb", "go", "groovy", "haml", "html", "java", "javascript", "json", "lua", "php", "python", "ruby", "sass", "sql", "text", "xml", "yaml"]; |
|
378 | var codeRayLanguages = ["c", "clojure", "cpp", "css", "delphi", "diff", "erb", "go", "groovy", "haml", "html", "java", "javascript", "json", "lua", "php", "python", "ruby", "sass", "sql", "taskpaper", "text", "xml", "yaml"]; | |
379 | var menu = $("<ul style='position:absolute;'></ul>"); |
|
379 | var menu = $("<ul style='position:absolute;'></ul>"); | |
380 | for (var i = 0; i < codeRayLanguages.length; i++) { |
|
380 | for (var i = 0; i < codeRayLanguages.length; i++) { | |
381 | $("<li></li>").text(codeRayLanguages[i]).appendTo(menu).mousedown(function(){ |
|
381 | $("<li></li>").text(codeRayLanguages[i]).appendTo(menu).mousedown(function(){ | |
382 | fn($(this).text()); |
|
382 | fn($(this).text()); | |
383 | }); |
|
383 | }); | |
384 | } |
|
384 | } | |
385 | $("body").append(menu); |
|
385 | $("body").append(menu); | |
386 | menu.menu().width(150).position({ |
|
386 | menu.menu().width(150).position({ | |
387 | my: "left top", |
|
387 | my: "left top", | |
388 | at: "left bottom", |
|
388 | at: "left bottom", | |
389 | of: this.toolNodes['precode'] |
|
389 | of: this.toolNodes['precode'] | |
390 | }); |
|
390 | }); | |
391 | $(document).on("mousedown", function() { |
|
391 | $(document).on("mousedown", function() { | |
392 | menu.remove(); |
|
392 | menu.remove(); | |
393 | }); |
|
393 | }); | |
394 | return false; |
|
394 | return false; | |
395 | }; |
|
395 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now