annotate .svn/pristine/3e/3ecbdf2b380b8b58c6f31309dfb99930076f3961.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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