annotate .svn/pristine/3e/3ecbdf2b380b8b58c6f31309dfb99930076f3961.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 /* ***** BEGIN LICENSE BLOCK *****
Chris@1295 2 * This file is part of DotClear.
Chris@1295 3 * Copyright (c) 2005 Nicolas Martin & Olivier Meunier and contributors. All
Chris@1295 4 * rights reserved.
Chris@1295 5 *
Chris@1295 6 * DotClear is free software; you can redistribute it and/or modify
Chris@1295 7 * it under the terms of the GNU General Public License as published by
Chris@1295 8 * the Free Software Foundation; either version 2 of the License, or
Chris@1295 9 * (at your option) any later version.
Chris@1295 10 *
Chris@1295 11 * DotClear is distributed in the hope that it will be useful,
Chris@1295 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 14 * GNU General Public License for more details.
Chris@1295 15 *
Chris@1295 16 * You should have received a copy of the GNU General Public License
Chris@1295 17 * along with DotClear; if not, write to the Free Software
Chris@1295 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Chris@1295 19 *
Chris@1295 20 * ***** END LICENSE BLOCK *****
Chris@1295 21 */
Chris@1295 22
Chris@1295 23 /* Modified by JP LANG for textile formatting */
Chris@1295 24
Chris@1295 25 function jsToolBar(textarea) {
Chris@1295 26 if (!document.createElement) { return; }
Chris@1295 27
Chris@1295 28 if (!textarea) { return; }
Chris@1295 29
Chris@1295 30 if ((typeof(document["selection"]) == "undefined")
Chris@1295 31 && (typeof(textarea["setSelectionRange"]) == "undefined")) {
Chris@1295 32 return;
Chris@1295 33 }
Chris@1295 34
Chris@1295 35 this.textarea = textarea;
Chris@1295 36
Chris@1295 37 this.editor = document.createElement('div');
Chris@1295 38 this.editor.className = 'jstEditor';
Chris@1295 39
Chris@1295 40 this.textarea.parentNode.insertBefore(this.editor,this.textarea);
Chris@1295 41 this.editor.appendChild(this.textarea);
Chris@1295 42
Chris@1295 43 this.toolbar = document.createElement("div");
Chris@1295 44 this.toolbar.className = 'jstElements';
Chris@1295 45 this.editor.parentNode.insertBefore(this.toolbar,this.editor);
Chris@1295 46
Chris@1295 47 // Dragable resizing
Chris@1295 48 if (this.editor.addEventListener && navigator.appVersion.match(/\bMSIE\b/))
Chris@1295 49 {
Chris@1295 50 this.handle = document.createElement('div');
Chris@1295 51 this.handle.className = 'jstHandle';
Chris@1295 52 var dragStart = this.resizeDragStart;
Chris@1295 53 var This = this;
Chris@1295 54 this.handle.addEventListener('mousedown',function(event) { dragStart.call(This,event); },false);
Chris@1295 55 // fix memory leak in Firefox (bug #241518)
Chris@1295 56 window.addEventListener('unload',function() {
Chris@1295 57 var del = This.handle.parentNode.removeChild(This.handle);
Chris@1295 58 delete(This.handle);
Chris@1295 59 },false);
Chris@1295 60
Chris@1295 61 this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling);
Chris@1295 62 }
Chris@1295 63
Chris@1295 64 this.context = null;
Chris@1295 65 this.toolNodes = {}; // lorsque la toolbar est dessinée , cet objet est garni
Chris@1295 66 // de raccourcis vers les éléments DOM correspondants aux outils.
Chris@1295 67 }
Chris@1295 68
Chris@1295 69 function jsButton(title, fn, scope, className) {
Chris@1295 70 if(typeof jsToolBar.strings == 'undefined') {
Chris@1295 71 this.title = title || null;
Chris@1295 72 } else {
Chris@1295 73 this.title = jsToolBar.strings[title] || title || null;
Chris@1295 74 }
Chris@1295 75 this.fn = fn || function(){};
Chris@1295 76 this.scope = scope || null;
Chris@1295 77 this.className = className || null;
Chris@1295 78 }
Chris@1295 79 jsButton.prototype.draw = function() {
Chris@1295 80 if (!this.scope) return null;
Chris@1295 81
Chris@1295 82 var button = document.createElement('button');
Chris@1295 83 button.setAttribute('type','button');
Chris@1295 84 button.tabIndex = 200;
Chris@1295 85 if (this.className) button.className = this.className;
Chris@1295 86 button.title = this.title;
Chris@1295 87 var span = document.createElement('span');
Chris@1295 88 span.appendChild(document.createTextNode(this.title));
Chris@1295 89 button.appendChild(span);
Chris@1295 90
Chris@1295 91 if (this.icon != undefined) {
Chris@1295 92 button.style.backgroundImage = 'url('+this.icon+')';
Chris@1295 93 }
Chris@1295 94 if (typeof(this.fn) == 'function') {
Chris@1295 95 var This = this;
Chris@1295 96 button.onclick = function() { try { This.fn.apply(This.scope, arguments) } catch (e) {} return false; };
Chris@1295 97 }
Chris@1295 98 return button;
Chris@1295 99 }
Chris@1295 100
Chris@1295 101 function jsSpace(id) {
Chris@1295 102 this.id = id || null;
Chris@1295 103 this.width = null;
Chris@1295 104 }
Chris@1295 105 jsSpace.prototype.draw = function() {
Chris@1295 106 var span = document.createElement('span');
Chris@1295 107 if (this.id) span.id = this.id;
Chris@1295 108 span.appendChild(document.createTextNode(String.fromCharCode(160)));
Chris@1295 109 span.className = 'jstSpacer';
Chris@1295 110 if (this.width) span.style.marginRight = this.width+'px';
Chris@1295 111
Chris@1295 112 return span;
Chris@1295 113 }
Chris@1295 114
Chris@1295 115 function jsCombo(title, options, scope, fn, className) {
Chris@1295 116 this.title = title || null;
Chris@1295 117 this.options = options || null;
Chris@1295 118 this.scope = scope || null;
Chris@1295 119 this.fn = fn || function(){};
Chris@1295 120 this.className = className || null;
Chris@1295 121 }
Chris@1295 122 jsCombo.prototype.draw = function() {
Chris@1295 123 if (!this.scope || !this.options) return null;
Chris@1295 124
Chris@1295 125 var select = document.createElement('select');
Chris@1295 126 if (this.className) select.className = className;
Chris@1295 127 select.title = this.title;
Chris@1295 128
Chris@1295 129 for (var o in this.options) {
Chris@1295 130 //var opt = this.options[o];
Chris@1295 131 var option = document.createElement('option');
Chris@1295 132 option.value = o;
Chris@1295 133 option.appendChild(document.createTextNode(this.options[o]));
Chris@1295 134 select.appendChild(option);
Chris@1295 135 }
Chris@1295 136
Chris@1295 137 var This = this;
Chris@1295 138 select.onchange = function() {
Chris@1295 139 try {
Chris@1295 140 This.fn.call(This.scope, this.value);
Chris@1295 141 } catch (e) { alert(e); }
Chris@1295 142
Chris@1295 143 return false;
Chris@1295 144 }
Chris@1295 145
Chris@1295 146 return select;
Chris@1295 147 }
Chris@1295 148
Chris@1295 149
Chris@1295 150 jsToolBar.prototype = {
Chris@1295 151 base_url: '',
Chris@1295 152 mode: 'wiki',
Chris@1295 153 elements: {},
Chris@1295 154 help_link: '',
Chris@1295 155
Chris@1295 156 getMode: function() {
Chris@1295 157 return this.mode;
Chris@1295 158 },
Chris@1295 159
Chris@1295 160 setMode: function(mode) {
Chris@1295 161 this.mode = mode || 'wiki';
Chris@1295 162 },
Chris@1295 163
Chris@1295 164 switchMode: function(mode) {
Chris@1295 165 mode = mode || 'wiki';
Chris@1295 166 this.draw(mode);
Chris@1295 167 },
Chris@1295 168
Chris@1295 169 setHelpLink: function(link) {
Chris@1295 170 this.help_link = link;
Chris@1295 171 },
Chris@1295 172
Chris@1295 173 button: function(toolName) {
Chris@1295 174 var tool = this.elements[toolName];
Chris@1295 175 if (typeof tool.fn[this.mode] != 'function') return null;
Chris@1295 176 var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_'+toolName);
Chris@1295 177 if (tool.icon != undefined) b.icon = tool.icon;
Chris@1295 178 return b;
Chris@1295 179 },
Chris@1295 180 space: function(toolName) {
Chris@1295 181 var tool = new jsSpace(toolName)
Chris@1295 182 if (this.elements[toolName].width !== undefined)
Chris@1295 183 tool.width = this.elements[toolName].width;
Chris@1295 184 return tool;
Chris@1295 185 },
Chris@1295 186 combo: function(toolName) {
Chris@1295 187 var tool = this.elements[toolName];
Chris@1295 188 var length = tool[this.mode].list.length;
Chris@1295 189
Chris@1295 190 if (typeof tool[this.mode].fn != 'function' || length == 0) {
Chris@1295 191 return null;
Chris@1295 192 } else {
Chris@1295 193 var options = {};
Chris@1295 194 for (var i=0; i < length; i++) {
Chris@1295 195 var opt = tool[this.mode].list[i];
Chris@1295 196 options[opt] = tool.options[opt];
Chris@1295 197 }
Chris@1295 198 return new jsCombo(tool.title, options, this, tool[this.mode].fn);
Chris@1295 199 }
Chris@1295 200 },
Chris@1295 201 draw: function(mode) {
Chris@1295 202 this.setMode(mode);
Chris@1295 203
Chris@1295 204 // Empty toolbar
Chris@1295 205 while (this.toolbar.hasChildNodes()) {
Chris@1295 206 this.toolbar.removeChild(this.toolbar.firstChild)
Chris@1295 207 }
Chris@1295 208 this.toolNodes = {}; // vide les raccourcis DOM/**/
Chris@1295 209
Chris@1295 210 // Draw toolbar elements
Chris@1295 211 var b, tool, newTool;
Chris@1295 212
Chris@1295 213 for (var i in this.elements) {
Chris@1295 214 b = this.elements[i];
Chris@1295 215
Chris@1295 216 var disabled =
Chris@1295 217 b.type == undefined || b.type == ''
Chris@1295 218 || (b.disabled != undefined && b.disabled)
Chris@1295 219 || (b.context != undefined && b.context != null && b.context != this.context);
Chris@1295 220
Chris@1295 221 if (!disabled && typeof this[b.type] == 'function') {
Chris@1295 222 tool = this[b.type](i);
Chris@1295 223 if (tool) newTool = tool.draw();
Chris@1295 224 if (newTool) {
Chris@1295 225 this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur
Chris@1295 226 this.toolbar.appendChild(newTool);
Chris@1295 227 }
Chris@1295 228 }
Chris@1295 229 }
Chris@1295 230 },
Chris@1295 231
Chris@1295 232 singleTag: function(stag,etag) {
Chris@1295 233 stag = stag || null;
Chris@1295 234 etag = etag || stag;
Chris@1295 235
Chris@1295 236 if (!stag || !etag) { return; }
Chris@1295 237
Chris@1295 238 this.encloseSelection(stag,etag);
Chris@1295 239 },
Chris@1295 240
Chris@1295 241 encloseLineSelection: function(prefix, suffix, fn) {
Chris@1295 242 this.textarea.focus();
Chris@1295 243
Chris@1295 244 prefix = prefix || '';
Chris@1295 245 suffix = suffix || '';
Chris@1295 246
Chris@1295 247 var start, end, sel, scrollPos, subst, res;
Chris@1295 248
Chris@1295 249 if (typeof(document["selection"]) != "undefined") {
Chris@1295 250 sel = document.selection.createRange().text;
Chris@1295 251 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
Chris@1295 252 start = this.textarea.selectionStart;
Chris@1295 253 end = this.textarea.selectionEnd;
Chris@1295 254 scrollPos = this.textarea.scrollTop;
Chris@1295 255 // go to the start of the line
Chris@1295 256 start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length;
Chris@1295 257 // go to the end of the line
Chris@1295 258 end = this.textarea.value.length - this.textarea.value.substring(end, this.textarea.value.length).replace(/^[^\r\n]*/, '').length;
Chris@1295 259 sel = this.textarea.value.substring(start, end);
Chris@1295 260 }
Chris@1295 261
Chris@1295 262 if (sel.match(/ $/)) { // exclude ending space char, if any
Chris@1295 263 sel = sel.substring(0, sel.length - 1);
Chris@1295 264 suffix = suffix + " ";
Chris@1295 265 }
Chris@1295 266
Chris@1295 267 if (typeof(fn) == 'function') {
Chris@1295 268 res = (sel) ? fn.call(this,sel) : fn('');
Chris@1295 269 } else {
Chris@1295 270 res = (sel) ? sel : '';
Chris@1295 271 }
Chris@1295 272
Chris@1295 273 subst = prefix + res + suffix;
Chris@1295 274
Chris@1295 275 if (typeof(document["selection"]) != "undefined") {
Chris@1295 276 document.selection.createRange().text = subst;
Chris@1295 277 var range = this.textarea.createTextRange();
Chris@1295 278 range.collapse(false);
Chris@1295 279 range.move('character', -suffix.length);
Chris@1295 280 range.select();
Chris@1295 281 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
Chris@1295 282 this.textarea.value = this.textarea.value.substring(0, start) + subst +
Chris@1295 283 this.textarea.value.substring(end);
Chris@1295 284 if (sel) {
Chris@1295 285 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
Chris@1295 286 } else {
Chris@1295 287 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
Chris@1295 288 }
Chris@1295 289 this.textarea.scrollTop = scrollPos;
Chris@1295 290 }
Chris@1295 291 },
Chris@1295 292
Chris@1295 293 encloseSelection: function(prefix, suffix, fn) {
Chris@1295 294 this.textarea.focus();
Chris@1295 295
Chris@1295 296 prefix = prefix || '';
Chris@1295 297 suffix = suffix || '';
Chris@1295 298
Chris@1295 299 var start, end, sel, scrollPos, subst, res;
Chris@1295 300
Chris@1295 301 if (typeof(document["selection"]) != "undefined") {
Chris@1295 302 sel = document.selection.createRange().text;
Chris@1295 303 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
Chris@1295 304 start = this.textarea.selectionStart;
Chris@1295 305 end = this.textarea.selectionEnd;
Chris@1295 306 scrollPos = this.textarea.scrollTop;
Chris@1295 307 sel = this.textarea.value.substring(start, end);
Chris@1295 308 }
Chris@1295 309
Chris@1295 310 if (sel.match(/ $/)) { // exclude ending space char, if any
Chris@1295 311 sel = sel.substring(0, sel.length - 1);
Chris@1295 312 suffix = suffix + " ";
Chris@1295 313 }
Chris@1295 314
Chris@1295 315 if (typeof(fn) == 'function') {
Chris@1295 316 res = (sel) ? fn.call(this,sel) : fn('');
Chris@1295 317 } else {
Chris@1295 318 res = (sel) ? sel : '';
Chris@1295 319 }
Chris@1295 320
Chris@1295 321 subst = prefix + res + suffix;
Chris@1295 322
Chris@1295 323 if (typeof(document["selection"]) != "undefined") {
Chris@1295 324 document.selection.createRange().text = subst;
Chris@1295 325 var range = this.textarea.createTextRange();
Chris@1295 326 range.collapse(false);
Chris@1295 327 range.move('character', -suffix.length);
Chris@1295 328 range.select();
Chris@1295 329 // this.textarea.caretPos -= suffix.length;
Chris@1295 330 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
Chris@1295 331 this.textarea.value = this.textarea.value.substring(0, start) + subst +
Chris@1295 332 this.textarea.value.substring(end);
Chris@1295 333 if (sel) {
Chris@1295 334 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
Chris@1295 335 } else {
Chris@1295 336 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
Chris@1295 337 }
Chris@1295 338 this.textarea.scrollTop = scrollPos;
Chris@1295 339 }
Chris@1295 340 },
Chris@1295 341
Chris@1295 342 stripBaseURL: function(url) {
Chris@1295 343 if (this.base_url != '') {
Chris@1295 344 var pos = url.indexOf(this.base_url);
Chris@1295 345 if (pos == 0) {
Chris@1295 346 url = url.substr(this.base_url.length);
Chris@1295 347 }
Chris@1295 348 }
Chris@1295 349
Chris@1295 350 return url;
Chris@1295 351 }
Chris@1295 352 };
Chris@1295 353
Chris@1295 354 /** Resizer
Chris@1295 355 -------------------------------------------------------- */
Chris@1295 356 jsToolBar.prototype.resizeSetStartH = function() {
Chris@1295 357 this.dragStartH = this.textarea.offsetHeight + 0;
Chris@1295 358 };
Chris@1295 359 jsToolBar.prototype.resizeDragStart = function(event) {
Chris@1295 360 var This = this;
Chris@1295 361 this.dragStartY = event.clientY;
Chris@1295 362 this.resizeSetStartH();
Chris@1295 363 document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false);
Chris@1295 364 document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false);
Chris@1295 365 };
Chris@1295 366
Chris@1295 367 jsToolBar.prototype.resizeDragMove = function(event) {
Chris@1295 368 this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px';
Chris@1295 369 };
Chris@1295 370
Chris@1295 371 jsToolBar.prototype.resizeDragStop = function(event) {
Chris@1295 372 document.removeEventListener('mousemove', this.dragMoveHdlr, false);
Chris@1295 373 document.removeEventListener('mouseup', this.dragStopHdlr, false);
Chris@1295 374 };