annotate .svn/pristine/74/748d85e16c7b39630792941f331af582630a591a.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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