Merge branch 'finnlabs-305_jstoolbar_fix_for_ie8'
This commit is contained in:
commit
8d6133f6db
|
@ -243,106 +243,105 @@ jsToolBar.prototype = {
|
||||||
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 || '';
|
||||||
|
suffix = suffix || '';
|
||||||
|
var start, end, sel, scrollPos, subst, res;
|
||||||
|
if (typeof(document["selection"]) != "undefined") {
|
||||||
|
// just makes it work in IE8 somehow
|
||||||
|
var range = document.selection.createRange();
|
||||||
|
var bookmark = range.getBookmark();
|
||||||
|
var origParent = range.parentElement();
|
||||||
|
// we move the starting point of the selection to the last newline
|
||||||
|
try {
|
||||||
|
while (range.text[0] != "\n" && range.text[0] != "\r") {
|
||||||
|
bookmark = range.getBookmark();
|
||||||
|
range.moveStart("character", -1);
|
||||||
|
if (origParent != range.parentElement()) {
|
||||||
|
throw "Outside of Textarea";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
range.moveStart("character", 1);
|
||||||
|
} catch(err) {
|
||||||
|
if (err == "Outside of Textarea")
|
||||||
|
range.moveToBookmark(bookmark);
|
||||||
|
else
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
if (range.text.match(/ $/))
|
||||||
|
range.moveEnd("character", -1);
|
||||||
|
sel = range.text;
|
||||||
|
} else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
|
||||||
|
start = this.textarea.selectionStart;
|
||||||
|
end = this.textarea.selectionEnd;
|
||||||
|
scrollPos = this.textarea.scrollTop;
|
||||||
|
// go to the start of the line
|
||||||
|
start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length;
|
||||||
|
// 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;
|
||||||
|
sel = this.textarea.value.substring(start, end);
|
||||||
|
}
|
||||||
|
if (sel.match(/ $/)) {
|
||||||
|
sel = sel.substring(0, sel.length - 1);
|
||||||
|
suffix = suffix + " ";
|
||||||
|
}
|
||||||
|
if (typeof(fn) == 'function') {
|
||||||
|
res = (sel) ? fn.call(this, sel) : fn('');
|
||||||
|
} else {
|
||||||
|
res = (sel) ? sel : '';
|
||||||
|
}
|
||||||
|
subst = prefix + res + suffix;
|
||||||
|
if (typeof(document["selection"]) != "undefined") {
|
||||||
|
range.text = subst;
|
||||||
|
this.textarea.caretPos -= suffix.length;
|
||||||
|
} else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
|
||||||
|
this.textarea.value = this.textarea.value.substring(0, start) + subst + this.textarea.value.substring(end);
|
||||||
|
if (sel) {
|
||||||
|
this.textarea.setSelectionRange(start + subst.length, start + subst.length);
|
||||||
|
} else {
|
||||||
|
this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
|
||||||
|
}
|
||||||
|
this.textarea.scrollTop = scrollPos;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
prefix = prefix || '';
|
encloseSelection: function (prefix, suffix, fn) {
|
||||||
suffix = suffix || '';
|
this.textarea.focus();
|
||||||
|
prefix = prefix || '';
|
||||||
var start, end, sel, scrollPos, subst, res;
|
suffix = suffix || '';
|
||||||
|
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
|
sel = this.textarea.value.substring(start, end);
|
||||||
start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length;
|
}
|
||||||
// go to the end of the line
|
if (sel.match(/ $/)) {
|
||||||
end = this.textarea.value.length - this.textarea.value.substring(end, this.textarea.value.length).replace(/^[^\r\n]*/, '').length;
|
sel = sel.substring(0, sel.length - 1);
|
||||||
sel = this.textarea.value.substring(start, end);
|
suffix = suffix + " ";
|
||||||
}
|
}
|
||||||
|
if (typeof(fn) == 'function') {
|
||||||
if (sel.match(/ $/)) { // exclude ending space char, if any
|
res = (sel) ? fn.call(this, sel) : fn('');
|
||||||
sel = sel.substring(0, sel.length - 1);
|
} else {
|
||||||
suffix = suffix + " ";
|
res = (sel) ? sel : '';
|
||||||
}
|
}
|
||||||
|
subst = prefix + res + suffix;
|
||||||
if (typeof(fn) == 'function') {
|
if (typeof(document["selection"]) != "undefined") {
|
||||||
res = (sel) ? fn.call(this,sel) : fn('');
|
var range = document.selection.createRange().text = subst;
|
||||||
} else {
|
this.textarea.caretPos -= suffix.length;
|
||||||
res = (sel) ? sel : '';
|
} else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
|
||||||
}
|
this.textarea.value = this.textarea.value.substring(0, start) + subst + this.textarea.value.substring(end);
|
||||||
|
if (sel) {
|
||||||
subst = prefix + res + suffix;
|
this.textarea.setSelectionRange(start + subst.length, start + subst.length);
|
||||||
|
} else {
|
||||||
if (typeof(document["selection"]) != "undefined") {
|
this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
|
||||||
document.selection.createRange().text = subst;
|
}
|
||||||
var range = this.textarea.createTextRange();
|
this.textarea.scrollTop = scrollPos;
|
||||||
range.collapse(false);
|
}
|
||||||
range.move('character', -suffix.length);
|
},
|
||||||
range.select();
|
|
||||||
} else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
|
|
||||||
this.textarea.value = this.textarea.value.substring(0, start) + subst +
|
|
||||||
this.textarea.value.substring(end);
|
|
||||||
if (sel) {
|
|
||||||
this.textarea.setSelectionRange(start + subst.length, start + subst.length);
|
|
||||||
} else {
|
|
||||||
this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
|
|
||||||
}
|
|
||||||
this.textarea.scrollTop = scrollPos;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
encloseSelection: function(prefix, suffix, fn) {
|
|
||||||
this.textarea.focus();
|
|
||||||
|
|
||||||
prefix = prefix || '';
|
|
||||||
suffix = suffix || '';
|
|
||||||
|
|
||||||
var start, end, sel, scrollPos, subst, res;
|
|
||||||
|
|
||||||
if (typeof(document["selection"]) != "undefined") {
|
|
||||||
sel = document.selection.createRange().text;
|
|
||||||
} else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
|
|
||||||
start = this.textarea.selectionStart;
|
|
||||||
end = this.textarea.selectionEnd;
|
|
||||||
scrollPos = this.textarea.scrollTop;
|
|
||||||
sel = this.textarea.value.substring(start, end);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sel.match(/ $/)) { // exclude ending space char, if any
|
|
||||||
sel = sel.substring(0, sel.length - 1);
|
|
||||||
suffix = suffix + " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof(fn) == 'function') {
|
|
||||||
res = (sel) ? fn.call(this,sel) : fn('');
|
|
||||||
} else {
|
|
||||||
res = (sel) ? sel : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
subst = prefix + res + suffix;
|
|
||||||
|
|
||||||
if (typeof(document["selection"]) != "undefined") {
|
|
||||||
document.selection.createRange().text = subst;
|
|
||||||
var range = this.textarea.createTextRange();
|
|
||||||
range.collapse(false);
|
|
||||||
range.move('character', -suffix.length);
|
|
||||||
range.select();
|
|
||||||
// this.textarea.caretPos -= suffix.length;
|
|
||||||
} else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
|
|
||||||
this.textarea.value = this.textarea.value.substring(0, start) + subst +
|
|
||||||
this.textarea.value.substring(end);
|
|
||||||
if (sel) {
|
|
||||||
this.textarea.setSelectionRange(start + subst.length, start + subst.length);
|
|
||||||
} else {
|
|
||||||
this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
|
|
||||||
}
|
|
||||||
this.textarea.scrollTop = scrollPos;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
stripBaseURL: function(url) {
|
stripBaseURL: function(url) {
|
||||||
if (this.base_url != '') {
|
if (this.base_url != '') {
|
||||||
|
|
Loading…
Reference in New Issue