Replace tabs with two spaces in jstoolbar scripts (#20241).

Patch by Mischa The Evil.

git-svn-id: http://svn.redmine.org/redmine/trunk@14414 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2015-07-05 13:55:14 +00:00
parent cb3edf00a5
commit ae6c99321d
3 changed files with 533 additions and 533 deletions

View File

@@ -23,352 +23,352 @@
/* Modified by JP LANG for textile formatting */ /* Modified by JP LANG for textile formatting */
function jsToolBar(textarea) { function jsToolBar(textarea) {
if (!document.createElement) { return; } if (!document.createElement) { return; }
if (!textarea) { return; } if (!textarea) { return; }
if ((typeof(document["selection"]) == "undefined") if ((typeof(document["selection"]) == "undefined")
&& (typeof(textarea["setSelectionRange"]) == "undefined")) { && (typeof(textarea["setSelectionRange"]) == "undefined")) {
return; return;
} }
this.textarea = textarea; this.textarea = textarea;
this.editor = document.createElement('div'); this.editor = document.createElement('div');
this.editor.className = 'jstEditor'; this.editor.className = 'jstEditor';
this.textarea.parentNode.insertBefore(this.editor,this.textarea); this.textarea.parentNode.insertBefore(this.editor,this.textarea);
this.editor.appendChild(this.textarea); this.editor.appendChild(this.textarea);
this.toolbar = document.createElement("div"); this.toolbar = document.createElement("div");
this.toolbar.className = 'jstElements'; this.toolbar.className = 'jstElements';
this.editor.parentNode.insertBefore(this.toolbar,this.editor); this.editor.parentNode.insertBefore(this.toolbar,this.editor);
// Dragable resizing // Dragable resizing
if (this.editor.addEventListener && navigator.appVersion.match(/\bMSIE\b/)) if (this.editor.addEventListener && navigator.appVersion.match(/\bMSIE\b/))
{ {
this.handle = document.createElement('div'); this.handle = document.createElement('div');
this.handle.className = 'jstHandle'; this.handle.className = 'jstHandle';
var dragStart = this.resizeDragStart; var dragStart = this.resizeDragStart;
var This = this; var This = this;
this.handle.addEventListener('mousedown',function(event) { dragStart.call(This,event); },false); this.handle.addEventListener('mousedown',function(event) { dragStart.call(This,event); },false);
// fix memory leak in Firefox (bug #241518) // fix memory leak in Firefox (bug #241518)
window.addEventListener('unload',function() { window.addEventListener('unload',function() {
var del = This.handle.parentNode.removeChild(This.handle); var del = This.handle.parentNode.removeChild(This.handle);
delete(This.handle); delete(This.handle);
},false); },false);
this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling); this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling);
} }
this.context = null; this.context = null;
this.toolNodes = {}; // lorsque la toolbar est dessinée , cet objet est garni this.toolNodes = {}; // lorsque la toolbar est dessinée , cet objet est garni
// de raccourcis vers les éléments DOM correspondants aux outils. // de raccourcis vers les éléments DOM correspondants aux outils.
} }
function jsButton(title, fn, scope, className) { function jsButton(title, fn, scope, className) {
if(typeof jsToolBar.strings == 'undefined') { if(typeof jsToolBar.strings == 'undefined') {
this.title = title || null; this.title = title || null;
} else { } else {
this.title = jsToolBar.strings[title] || title || null; this.title = jsToolBar.strings[title] || title || null;
} }
this.fn = fn || function(){}; this.fn = fn || function(){};
this.scope = scope || null; this.scope = scope || null;
this.className = className || null; this.className = className || null;
} }
jsButton.prototype.draw = function() { jsButton.prototype.draw = function() {
if (!this.scope) return null; if (!this.scope) return null;
var button = document.createElement('button'); var button = document.createElement('button');
button.setAttribute('type','button'); button.setAttribute('type','button');
button.tabIndex = 200; button.tabIndex = 200;
if (this.className) button.className = this.className; if (this.className) button.className = this.className;
button.title = this.title; button.title = this.title;
var span = document.createElement('span'); var span = document.createElement('span');
span.appendChild(document.createTextNode(this.title)); span.appendChild(document.createTextNode(this.title));
button.appendChild(span); button.appendChild(span);
if (this.icon != undefined) { if (this.icon != undefined) {
button.style.backgroundImage = 'url('+this.icon+')'; button.style.backgroundImage = 'url('+this.icon+')';
} }
if (typeof(this.fn) == 'function') { if (typeof(this.fn) == 'function') {
var This = this; var This = this;
button.onclick = function() { try { This.fn.apply(This.scope, arguments) } catch (e) {} return false; }; button.onclick = function() { try { This.fn.apply(This.scope, arguments) } catch (e) {} return false; };
} }
return button; return button;
} }
function jsSpace(id) { function jsSpace(id) {
this.id = id || null; this.id = id || null;
this.width = null; this.width = null;
} }
jsSpace.prototype.draw = function() { jsSpace.prototype.draw = function() {
var span = document.createElement('span'); var span = document.createElement('span');
if (this.id) span.id = this.id; if (this.id) span.id = this.id;
span.appendChild(document.createTextNode(String.fromCharCode(160))); span.appendChild(document.createTextNode(String.fromCharCode(160)));
span.className = 'jstSpacer'; span.className = 'jstSpacer';
if (this.width) span.style.marginRight = this.width+'px'; if (this.width) span.style.marginRight = this.width+'px';
return span; return span;
} }
function jsCombo(title, options, scope, fn, className) { function jsCombo(title, options, scope, fn, className) {
this.title = title || null; this.title = title || null;
this.options = options || null; this.options = options || null;
this.scope = scope || null; this.scope = scope || null;
this.fn = fn || function(){}; this.fn = fn || function(){};
this.className = className || null; this.className = className || null;
} }
jsCombo.prototype.draw = function() { jsCombo.prototype.draw = function() {
if (!this.scope || !this.options) return null; if (!this.scope || !this.options) return null;
var select = document.createElement('select'); var select = document.createElement('select');
if (this.className) select.className = className; if (this.className) select.className = className;
select.title = this.title; select.title = this.title;
for (var o in this.options) { for (var o in this.options) {
//var opt = this.options[o]; //var opt = this.options[o];
var option = document.createElement('option'); var option = document.createElement('option');
option.value = o; option.value = o;
option.appendChild(document.createTextNode(this.options[o])); option.appendChild(document.createTextNode(this.options[o]));
select.appendChild(option); select.appendChild(option);
} }
var This = this; var This = this;
select.onchange = function() { select.onchange = function() {
try { try {
This.fn.call(This.scope, this.value); This.fn.call(This.scope, this.value);
} catch (e) { alert(e); } } catch (e) { alert(e); }
return false; return false;
} }
return select; return select;
} }
jsToolBar.prototype = { jsToolBar.prototype = {
base_url: '', base_url: '',
mode: 'wiki', mode: 'wiki',
elements: {}, elements: {},
help_link: '', help_link: '',
getMode: function() { getMode: function() {
return this.mode; return this.mode;
}, },
setMode: function(mode) { setMode: function(mode) {
this.mode = mode || 'wiki'; this.mode = mode || 'wiki';
}, },
switchMode: function(mode) { switchMode: function(mode) {
mode = mode || 'wiki'; mode = mode || 'wiki';
this.draw(mode); this.draw(mode);
}, },
setHelpLink: function(link) { setHelpLink: function(link) {
this.help_link = link; this.help_link = link;
}, },
button: function(toolName) { button: function(toolName) {
var tool = this.elements[toolName]; var tool = this.elements[toolName];
if (typeof tool.fn[this.mode] != 'function') return null; if (typeof tool.fn[this.mode] != 'function') return null;
var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_'+toolName); var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_'+toolName);
if (tool.icon != undefined) b.icon = tool.icon; if (tool.icon != undefined) b.icon = tool.icon;
return b; return b;
}, },
space: function(toolName) { space: function(toolName) {
var tool = new jsSpace(toolName) var tool = new jsSpace(toolName)
if (this.elements[toolName].width !== undefined) if (this.elements[toolName].width !== undefined)
tool.width = this.elements[toolName].width; tool.width = this.elements[toolName].width;
return tool; return tool;
}, },
combo: function(toolName) { combo: function(toolName) {
var tool = this.elements[toolName]; var tool = this.elements[toolName];
var length = tool[this.mode].list.length; var length = tool[this.mode].list.length;
if (typeof tool[this.mode].fn != 'function' || length == 0) { if (typeof tool[this.mode].fn != 'function' || length == 0) {
return null; return null;
} else { } else {
var options = {}; var options = {};
for (var i=0; i < length; i++) { for (var i=0; i < length; i++) {
var opt = tool[this.mode].list[i]; var opt = tool[this.mode].list[i];
options[opt] = tool.options[opt]; options[opt] = tool.options[opt];
} }
return new jsCombo(tool.title, options, this, tool[this.mode].fn); return new jsCombo(tool.title, options, this, tool[this.mode].fn);
} }
}, },
draw: function(mode) { draw: function(mode) {
this.setMode(mode); this.setMode(mode);
// Empty toolbar // Empty toolbar
while (this.toolbar.hasChildNodes()) { while (this.toolbar.hasChildNodes()) {
this.toolbar.removeChild(this.toolbar.firstChild) this.toolbar.removeChild(this.toolbar.firstChild)
} }
this.toolNodes = {}; // vide les raccourcis DOM/**/ this.toolNodes = {}; // vide les raccourcis DOM/**/
// Draw toolbar elements // Draw toolbar elements
var b, tool, newTool; var b, tool, newTool;
for (var i in this.elements) { for (var i in this.elements) {
b = this.elements[i]; b = this.elements[i];
var disabled = var disabled =
b.type == undefined || b.type == '' b.type == undefined || b.type == ''
|| (b.disabled != undefined && b.disabled) || (b.disabled != undefined && b.disabled)
|| (b.context != undefined && b.context != null && b.context != this.context); || (b.context != undefined && b.context != null && b.context != this.context);
if (!disabled && typeof this[b.type] == 'function') { if (!disabled && typeof this[b.type] == 'function') {
tool = this[b.type](i); tool = this[b.type](i);
if (tool) newTool = tool.draw(); if (tool) newTool = tool.draw();
if (newTool) { if (newTool) {
this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur
this.toolbar.appendChild(newTool); this.toolbar.appendChild(newTool);
} }
} }
} }
}, },
singleTag: function(stag,etag) { singleTag: function(stag,etag) {
stag = stag || null; stag = stag || null;
etag = etag || stag; etag = etag || stag;
if (!stag || !etag) { return; } if (!stag || !etag) { return; }
this.encloseSelection(stag,etag); this.encloseSelection(stag,etag);
}, },
encloseLineSelection: function(prefix, suffix, fn) { encloseLineSelection: function(prefix, suffix, fn) {
this.textarea.focus(); this.textarea.focus();
prefix = prefix || ''; prefix = prefix || '';
suffix = suffix || ''; suffix = suffix || '';
var start, end, sel, scrollPos, subst, res; var start, end, sel, scrollPos, subst, res;
if (typeof(document["selection"]) != "undefined") { if (typeof(document["selection"]) != "undefined") {
sel = document.selection.createRange().text; sel = document.selection.createRange().text;
} else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
start = this.textarea.selectionStart; start = this.textarea.selectionStart;
end = this.textarea.selectionEnd; end = this.textarea.selectionEnd;
scrollPos = this.textarea.scrollTop; scrollPos = this.textarea.scrollTop;
// go to the start of the line // go to the start of the line
start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length; start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length;
// go to the end of the line // go to the end of the line
end = this.textarea.value.length - this.textarea.value.substring(end, this.textarea.value.length).replace(/^[^\r\n]*/, '').length; end = this.textarea.value.length - this.textarea.value.substring(end, this.textarea.value.length).replace(/^[^\r\n]*/, '').length;
sel = this.textarea.value.substring(start, end); sel = this.textarea.value.substring(start, end);
} }
if (sel.match(/ $/)) { // exclude ending space char, if any if (sel.match(/ $/)) { // exclude ending space char, if any
sel = sel.substring(0, sel.length - 1); sel = sel.substring(0, sel.length - 1);
suffix = suffix + " "; suffix = suffix + " ";
} }
if (typeof(fn) == 'function') { if (typeof(fn) == 'function') {
res = (sel) ? fn.call(this,sel) : fn(''); res = (sel) ? fn.call(this,sel) : fn('');
} else { } else {
res = (sel) ? sel : ''; res = (sel) ? sel : '';
} }
subst = prefix + res + suffix; subst = prefix + res + suffix;
if (typeof(document["selection"]) != "undefined") { if (typeof(document["selection"]) != "undefined") {
document.selection.createRange().text = subst; document.selection.createRange().text = subst;
var range = this.textarea.createTextRange(); var range = this.textarea.createTextRange();
range.collapse(false); range.collapse(false);
range.move('character', -suffix.length); range.move('character', -suffix.length);
range.select(); range.select();
} else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
this.textarea.value = this.textarea.value.substring(0, start) + subst + this.textarea.value = this.textarea.value.substring(0, start) + subst +
this.textarea.value.substring(end); this.textarea.value.substring(end);
if (sel) { if (sel) {
this.textarea.setSelectionRange(start + subst.length, start + subst.length); this.textarea.setSelectionRange(start + subst.length, start + subst.length);
} else { } else {
this.textarea.setSelectionRange(start + prefix.length, start + prefix.length); this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
} }
this.textarea.scrollTop = scrollPos; this.textarea.scrollTop = scrollPos;
} }
}, },
encloseSelection: function(prefix, suffix, fn) { encloseSelection: function(prefix, suffix, fn) {
this.textarea.focus(); this.textarea.focus();
prefix = prefix || ''; prefix = prefix || '';
suffix = suffix || ''; suffix = suffix || '';
var start, end, sel, scrollPos, subst, res; var start, end, sel, scrollPos, subst, res;
if (typeof(document["selection"]) != "undefined") { if (typeof(document["selection"]) != "undefined") {
sel = document.selection.createRange().text; sel = document.selection.createRange().text;
} else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
start = this.textarea.selectionStart; start = this.textarea.selectionStart;
end = this.textarea.selectionEnd; end = this.textarea.selectionEnd;
scrollPos = this.textarea.scrollTop; scrollPos = this.textarea.scrollTop;
sel = this.textarea.value.substring(start, end); sel = this.textarea.value.substring(start, end);
} }
if (sel.match(/ $/)) { // exclude ending space char, if any if (sel.match(/ $/)) { // exclude ending space char, if any
sel = sel.substring(0, sel.length - 1); sel = sel.substring(0, sel.length - 1);
suffix = suffix + " "; suffix = suffix + " ";
} }
if (typeof(fn) == 'function') { if (typeof(fn) == 'function') {
res = (sel) ? fn.call(this,sel) : fn(''); res = (sel) ? fn.call(this,sel) : fn('');
} else { } else {
res = (sel) ? sel : ''; res = (sel) ? sel : '';
} }
subst = prefix + res + suffix; subst = prefix + res + suffix;
if (typeof(document["selection"]) != "undefined") { if (typeof(document["selection"]) != "undefined") {
document.selection.createRange().text = subst; document.selection.createRange().text = subst;
var range = this.textarea.createTextRange(); var range = this.textarea.createTextRange();
range.collapse(false); range.collapse(false);
range.move('character', -suffix.length); range.move('character', -suffix.length);
range.select(); range.select();
// this.textarea.caretPos -= suffix.length; // this.textarea.caretPos -= suffix.length;
} else if (typeof(this.textarea["setSelectionRange"]) != "undefined") { } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
this.textarea.value = this.textarea.value.substring(0, start) + subst + this.textarea.value = this.textarea.value.substring(0, start) + subst +
this.textarea.value.substring(end); this.textarea.value.substring(end);
if (sel) { if (sel) {
this.textarea.setSelectionRange(start + subst.length, start + subst.length); this.textarea.setSelectionRange(start + subst.length, start + subst.length);
} else { } else {
this.textarea.setSelectionRange(start + prefix.length, start + prefix.length); this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
} }
this.textarea.scrollTop = scrollPos; this.textarea.scrollTop = scrollPos;
} }
}, },
stripBaseURL: function(url) { stripBaseURL: function(url) {
if (this.base_url != '') { if (this.base_url != '') {
var pos = url.indexOf(this.base_url); var pos = url.indexOf(this.base_url);
if (pos == 0) { if (pos == 0) {
url = url.substr(this.base_url.length); url = url.substr(this.base_url.length);
} }
} }
return url; return url;
} }
}; };
/** Resizer /** Resizer
-------------------------------------------------------- */ -------------------------------------------------------- */
jsToolBar.prototype.resizeSetStartH = function() { jsToolBar.prototype.resizeSetStartH = function() {
this.dragStartH = this.textarea.offsetHeight + 0; this.dragStartH = this.textarea.offsetHeight + 0;
}; };
jsToolBar.prototype.resizeDragStart = function(event) { jsToolBar.prototype.resizeDragStart = function(event) {
var This = this; var This = this;
this.dragStartY = event.clientY; this.dragStartY = event.clientY;
this.resizeSetStartH(); this.resizeSetStartH();
document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false); document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false);
document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false); document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false);
}; };
jsToolBar.prototype.resizeDragMove = function(event) { jsToolBar.prototype.resizeDragMove = function(event) {
this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px'; this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px';
}; };
jsToolBar.prototype.resizeDragStop = function(event) { jsToolBar.prototype.resizeDragStop = function(event) {
document.removeEventListener('mousemove', this.dragMoveHdlr, false); document.removeEventListener('mousemove', this.dragMoveHdlr, false);
document.removeEventListener('mouseup', this.dragStopHdlr, false); document.removeEventListener('mouseup', this.dragStopHdlr, false);
}; };

View File

@@ -24,38 +24,38 @@
// strong // strong
jsToolBar.prototype.elements.strong = { jsToolBar.prototype.elements.strong = {
type: 'button', type: 'button',
title: 'Strong', title: 'Strong',
fn: { fn: {
wiki: function() { this.singleTag('**') } wiki: function() { this.singleTag('**') }
} }
} }
// em // em
jsToolBar.prototype.elements.em = { jsToolBar.prototype.elements.em = {
type: 'button', type: 'button',
title: 'Italic', title: 'Italic',
fn: { fn: {
wiki: function() { this.singleTag("*") } wiki: function() { this.singleTag("*") }
} }
} }
// del // del
jsToolBar.prototype.elements.del = { jsToolBar.prototype.elements.del = {
type: 'button', type: 'button',
title: 'Deleted', title: 'Deleted',
fn: { fn: {
wiki: function() { this.singleTag('~~') } wiki: function() { this.singleTag('~~') }
} }
} }
// code // code
jsToolBar.prototype.elements.code = { jsToolBar.prototype.elements.code = {
type: 'button', type: 'button',
title: 'Code', title: 'Code',
fn: { fn: {
wiki: function() { this.singleTag('`') } wiki: function() { this.singleTag('`') }
} }
} }
// spacer // spacer
@@ -63,40 +63,40 @@ jsToolBar.prototype.elements.space1 = {type: 'space'}
// headings // headings
jsToolBar.prototype.elements.h1 = { jsToolBar.prototype.elements.h1 = {
type: 'button', type: 'button',
title: 'Heading 1', title: 'Heading 1',
fn: { fn: {
wiki: function() { wiki: function() {
this.encloseLineSelection('# ', '',function(str) { this.encloseLineSelection('# ', '',function(str) {
str = str.replace(/^#+\s+/, '') str = str.replace(/^#+\s+/, '')
return str; return str;
}); });
} }
} }
} }
jsToolBar.prototype.elements.h2 = { jsToolBar.prototype.elements.h2 = {
type: 'button', type: 'button',
title: 'Heading 2', title: 'Heading 2',
fn: { fn: {
wiki: function() { wiki: function() {
this.encloseLineSelection('## ', '',function(str) { this.encloseLineSelection('## ', '',function(str) {
str = str.replace(/^#+\s+/, '') str = str.replace(/^#+\s+/, '')
return str; return str;
}); });
} }
} }
} }
jsToolBar.prototype.elements.h3 = { jsToolBar.prototype.elements.h3 = {
type: 'button', type: 'button',
title: 'Heading 3', title: 'Heading 3',
fn: { fn: {
wiki: function() { wiki: function() {
this.encloseLineSelection('### ', '',function(str) { this.encloseLineSelection('### ', '',function(str) {
str = str.replace(/^#+\s+/, '') str = str.replace(/^#+\s+/, '')
return str; return str;
}); });
} }
} }
} }
// spacer // spacer
@@ -104,30 +104,30 @@ jsToolBar.prototype.elements.space2 = {type: 'space'}
// ul // ul
jsToolBar.prototype.elements.ul = { jsToolBar.prototype.elements.ul = {
type: 'button', type: 'button',
title: 'Unordered list', title: 'Unordered list',
fn: { fn: {
wiki: function() { wiki: function() {
this.encloseLineSelection('','',function(str) { this.encloseLineSelection('','',function(str) {
str = str.replace(/\r/g,''); str = str.replace(/\r/g,'');
return str.replace(/(\n|^)[#-]?\s*/g,"$1* "); return str.replace(/(\n|^)[#-]?\s*/g,"$1* ");
}); });
} }
} }
} }
// ol // ol
jsToolBar.prototype.elements.ol = { jsToolBar.prototype.elements.ol = {
type: 'button', type: 'button',
title: 'Ordered list', title: 'Ordered list',
fn: { fn: {
wiki: function() { wiki: function() {
this.encloseLineSelection('','',function(str) { this.encloseLineSelection('','',function(str) {
str = str.replace(/\r/g,''); str = str.replace(/\r/g,'');
return str.replace(/(\n|^)[*-]?\s*/g,"$11. "); return str.replace(/(\n|^)[*-]?\s*/g,"$11. ");
}); });
} }
} }
} }
// spacer // spacer
@@ -135,39 +135,39 @@ jsToolBar.prototype.elements.space3 = {type: 'space'}
// bq // bq
jsToolBar.prototype.elements.bq = { jsToolBar.prototype.elements.bq = {
type: 'button', type: 'button',
title: 'Quote', title: 'Quote',
fn: { fn: {
wiki: function() { wiki: function() {
this.encloseLineSelection('','',function(str) { this.encloseLineSelection('','',function(str) {
str = str.replace(/\r/g,''); str = str.replace(/\r/g,'');
return str.replace(/(\n|^) *([^\n]*)/g,"$1> $2"); return str.replace(/(\n|^) *([^\n]*)/g,"$1> $2");
}); });
} }
} }
} }
// unbq // unbq
jsToolBar.prototype.elements.unbq = { jsToolBar.prototype.elements.unbq = {
type: 'button', type: 'button',
title: 'Unquote', title: 'Unquote',
fn: { fn: {
wiki: function() { wiki: function() {
this.encloseLineSelection('','',function(str) { this.encloseLineSelection('','',function(str) {
str = str.replace(/\r/g,''); str = str.replace(/\r/g,'');
return str.replace(/(\n|^) *[>]? *([^\n]*)/g,"$1$2"); return str.replace(/(\n|^) *[>]? *([^\n]*)/g,"$1$2");
}); });
} }
} }
} }
// pre // pre
jsToolBar.prototype.elements.pre = { jsToolBar.prototype.elements.pre = {
type: 'button', type: 'button',
title: 'Preformatted text', title: 'Preformatted text',
fn: { fn: {
wiki: function() { this.encloseLineSelection('~~~\n', '\n~~~') } wiki: function() { this.encloseLineSelection('~~~\n', '\n~~~') }
} }
} }
// spacer // spacer
@@ -175,28 +175,28 @@ jsToolBar.prototype.elements.space4 = {type: 'space'}
// wiki page // wiki page
jsToolBar.prototype.elements.link = { jsToolBar.prototype.elements.link = {
type: 'button', type: 'button',
title: 'Wiki link', title: 'Wiki link',
fn: { fn: {
wiki: function() { this.encloseSelection("[[", "]]") } wiki: function() { this.encloseSelection("[[", "]]") }
} }
} }
// image // image
jsToolBar.prototype.elements.img = { jsToolBar.prototype.elements.img = {
type: 'button', type: 'button',
title: 'Image', title: 'Image',
fn: { fn: {
wiki: function() { this.encloseSelection("![](", ")") } wiki: function() { this.encloseSelection("![](", ")") }
} }
} }
// spacer // spacer
jsToolBar.prototype.elements.space5 = {type: 'space'} jsToolBar.prototype.elements.space5 = {type: 'space'}
// help // help
jsToolBar.prototype.elements.help = { jsToolBar.prototype.elements.help = {
type: 'button', type: 'button',
title: 'Help', title: 'Help',
fn: { fn: {
wiki: function() { window.open(this.help_link, '', 'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes') } wiki: function() { window.open(this.help_link, '', 'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes') }
} }
} }

View File

@@ -24,47 +24,47 @@
// strong // strong
jsToolBar.prototype.elements.strong = { jsToolBar.prototype.elements.strong = {
type: 'button', type: 'button',
title: 'Strong', title: 'Strong',
fn: { fn: {
wiki: function() { this.singleTag('*') } wiki: function() { this.singleTag('*') }
} }
} }
// em // em
jsToolBar.prototype.elements.em = { jsToolBar.prototype.elements.em = {
type: 'button', type: 'button',
title: 'Italic', title: 'Italic',
fn: { fn: {
wiki: function() { this.singleTag("_") } wiki: function() { this.singleTag("_") }
} }
} }
// ins // ins
jsToolBar.prototype.elements.ins = { jsToolBar.prototype.elements.ins = {
type: 'button', type: 'button',
title: 'Underline', title: 'Underline',
fn: { fn: {
wiki: function() { this.singleTag('+') } wiki: function() { this.singleTag('+') }
} }
} }
// del // del
jsToolBar.prototype.elements.del = { jsToolBar.prototype.elements.del = {
type: 'button', type: 'button',
title: 'Deleted', title: 'Deleted',
fn: { fn: {
wiki: function() { this.singleTag('-') } wiki: function() { this.singleTag('-') }
} }
} }
// code // code
jsToolBar.prototype.elements.code = { jsToolBar.prototype.elements.code = {
type: 'button', type: 'button',
title: 'Code', title: 'Code',
fn: { fn: {
wiki: function() { this.singleTag('@') } wiki: function() { this.singleTag('@') }
} }
} }
// spacer // spacer
@@ -72,40 +72,40 @@ jsToolBar.prototype.elements.space1 = {type: 'space'}
// headings // headings
jsToolBar.prototype.elements.h1 = { jsToolBar.prototype.elements.h1 = {
type: 'button', type: 'button',
title: 'Heading 1', title: 'Heading 1',
fn: { fn: {
wiki: function() { wiki: function() {
this.encloseLineSelection('h1. ', '',function(str) { this.encloseLineSelection('h1. ', '',function(str) {
str = str.replace(/^h\d+\.\s+/, '') str = str.replace(/^h\d+\.\s+/, '')
return str; return str;
}); });
} }
} }
} }
jsToolBar.prototype.elements.h2 = { jsToolBar.prototype.elements.h2 = {
type: 'button', type: 'button',
title: 'Heading 2', title: 'Heading 2',
fn: { fn: {
wiki: function() { wiki: function() {
this.encloseLineSelection('h2. ', '',function(str) { this.encloseLineSelection('h2. ', '',function(str) {
str = str.replace(/^h\d+\.\s+/, '') str = str.replace(/^h\d+\.\s+/, '')
return str; return str;
}); });
} }
} }
} }
jsToolBar.prototype.elements.h3 = { jsToolBar.prototype.elements.h3 = {
type: 'button', type: 'button',
title: 'Heading 3', title: 'Heading 3',
fn: { fn: {
wiki: function() { wiki: function() {
this.encloseLineSelection('h3. ', '',function(str) { this.encloseLineSelection('h3. ', '',function(str) {
str = str.replace(/^h\d+\.\s+/, '') str = str.replace(/^h\d+\.\s+/, '')
return str; return str;
}); });
} }
} }
} }
// spacer // spacer
@@ -113,30 +113,30 @@ jsToolBar.prototype.elements.space2 = {type: 'space'}
// ul // ul
jsToolBar.prototype.elements.ul = { jsToolBar.prototype.elements.ul = {
type: 'button', type: 'button',
title: 'Unordered list', title: 'Unordered list',
fn: { fn: {
wiki: function() { wiki: function() {
this.encloseLineSelection('','',function(str) { this.encloseLineSelection('','',function(str) {
str = str.replace(/\r/g,''); str = str.replace(/\r/g,'');
return str.replace(/(\n|^)[#-]?\s*/g,"$1* "); return str.replace(/(\n|^)[#-]?\s*/g,"$1* ");
}); });
} }
} }
} }
// ol // ol
jsToolBar.prototype.elements.ol = { jsToolBar.prototype.elements.ol = {
type: 'button', type: 'button',
title: 'Ordered list', title: 'Ordered list',
fn: { fn: {
wiki: function() { wiki: function() {
this.encloseLineSelection('','',function(str) { this.encloseLineSelection('','',function(str) {
str = str.replace(/\r/g,''); str = str.replace(/\r/g,'');
return str.replace(/(\n|^)[*-]?\s*/g,"$1# "); return str.replace(/(\n|^)[*-]?\s*/g,"$1# ");
}); });
} }
} }
} }
// spacer // spacer
@@ -144,39 +144,39 @@ jsToolBar.prototype.elements.space3 = {type: 'space'}
// bq // bq
jsToolBar.prototype.elements.bq = { jsToolBar.prototype.elements.bq = {
type: 'button', type: 'button',
title: 'Quote', title: 'Quote',
fn: { fn: {
wiki: function() { wiki: function() {
this.encloseLineSelection('','',function(str) { this.encloseLineSelection('','',function(str) {
str = str.replace(/\r/g,''); str = str.replace(/\r/g,'');
return str.replace(/(\n|^) *([^\n]*)/g,"$1> $2"); return str.replace(/(\n|^) *([^\n]*)/g,"$1> $2");
}); });
} }
} }
} }
// unbq // unbq
jsToolBar.prototype.elements.unbq = { jsToolBar.prototype.elements.unbq = {
type: 'button', type: 'button',
title: 'Unquote', title: 'Unquote',
fn: { fn: {
wiki: function() { wiki: function() {
this.encloseLineSelection('','',function(str) { this.encloseLineSelection('','',function(str) {
str = str.replace(/\r/g,''); str = str.replace(/\r/g,'');
return str.replace(/(\n|^) *[>]? *([^\n]*)/g,"$1$2"); return str.replace(/(\n|^) *[>]? *([^\n]*)/g,"$1$2");
}); });
} }
} }
} }
// pre // pre
jsToolBar.prototype.elements.pre = { jsToolBar.prototype.elements.pre = {
type: 'button', type: 'button',
title: 'Preformatted text', title: 'Preformatted text',
fn: { fn: {
wiki: function() { this.encloseLineSelection('<pre>\n', '\n</pre>') } wiki: function() { this.encloseLineSelection('<pre>\n', '\n</pre>') }
} }
} }
// spacer // spacer
@@ -184,28 +184,28 @@ jsToolBar.prototype.elements.space4 = {type: 'space'}
// wiki page // wiki page
jsToolBar.prototype.elements.link = { jsToolBar.prototype.elements.link = {
type: 'button', type: 'button',
title: 'Wiki link', title: 'Wiki link',
fn: { fn: {
wiki: function() { this.encloseSelection("[[", "]]") } wiki: function() { this.encloseSelection("[[", "]]") }
} }
} }
// image // image
jsToolBar.prototype.elements.img = { jsToolBar.prototype.elements.img = {
type: 'button', type: 'button',
title: 'Image', title: 'Image',
fn: { fn: {
wiki: function() { this.encloseSelection("!", "!") } wiki: function() { this.encloseSelection("!", "!") }
} }
} }
// spacer // spacer
jsToolBar.prototype.elements.space5 = {type: 'space'} jsToolBar.prototype.elements.space5 = {type: 'space'}
// help // help
jsToolBar.prototype.elements.help = { jsToolBar.prototype.elements.help = {
type: 'button', type: 'button',
title: 'Help', title: 'Help',
fn: { fn: {
wiki: function() { window.open(this.help_link, '', 'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes') } wiki: function() { window.open(this.help_link, '', 'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes') }
} }
} }