DO NOT DOWNLOAD, STABLE RELEASE AVAILABLE ON THE RELEASES TAB

Fixes more IE issues with code editor, streamline JS for editor.

[TFS Changeset #59401]
This commit is contained in:
Shandem
2009-09-23 15:37:06 +00:00
parent dd4be329cf
commit 40ee7aeae4
10 changed files with 76 additions and 99 deletions

View File

@@ -0,0 +1,83 @@
//
// jQuery plugin: fieldSelection - v0.1.0 - last change: 2006-12-16
// (c) 2006 Alex Brem <alex@0xab.cd> - http://blog.0xab.cd
//
(function() {
var fieldSelection = {
getSelection: function() {
var e = this.jquery ? this[0] : this;
return (
// mozilla or dom 3.0
('selectionStart' in e && function() {
var l = e.selectionEnd - e.selectionStart;
return { start: e.selectionStart, end: e.selectionEnd, length: l, text: e.value.substr(e.selectionStart, l) };
}) ||
// exploder
(document.selection && function() {
e.focus();
var r = document.selection.createRange();
if (r == null) {
return { start: 0, end: e.value.length, length: 0 }
}
var re = e.createTextRange();
var rc = re.duplicate();
re.moveToBookmark(r.getBookmark());
rc.setEndPoint('EndToStart', re);
return { start: rc.text.length, end: rc.text.length + r.text.length, length: r.text.length, text: r.text };
}) ||
// browser not supported
function() {
return { start: 0, end: e.value.length, length: 0 };
}
)();
},
replaceSelection: function() {
var e = this.jquery ? this[0] : this;
var text = arguments[0] || '';
return (
// mozilla or dom 3.0
('selectionStart' in e && function() {
e.value = e.value.substr(0, e.selectionStart) + text + e.value.substr(e.selectionEnd, e.value.length);
return this;
}) ||
// exploder
(document.selection && function() {
e.focus();
document.selection.createRange().text = text;
return this;
}) ||
// browser not supported
function() {
e.value += text;
return this;
}
)();
}
};
jQuery.each(fieldSelection, function(i) { jQuery.fn[i] = this; });
})();

View File

@@ -4,6 +4,8 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
(function($) {
Umbraco.Controls.CodeEditor.UmbracoEditor = function(isSimpleEditor, controlId) {
//initialize
var _isSimpleEditor = isSimpleEditor;
var _controlId = controlId;
@@ -11,7 +13,8 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
throw "CodeMirror editor not found!";
}
return {
//create the inner object
var obj = {
_editor: (typeof(codeEditor) == "undefined" ? null : codeEditor), //the codemirror object
_control: $("#" + _controlId), //the original textbox as a jquery object
@@ -26,13 +29,24 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
//this is a wrapper for CodeMirror
return this._editor.getCode();
}
},
Insert: function(open, end, txtEl, arg3) {
//arg3 gets appended to open, not actually sure why it's needed but we'll keep it for legacy, it's optional
},
Insert: function(open, end, txtEl, arg3) {
//arg3 gets appended to open, not actually sure why it's needed but we'll keep it for legacy, it's optional
if (_isSimpleEditor) {
this._insertSimple(open, end, txtEl, arg3);
if (navigator.userAgent.match('MSIE')) {
this._IEInsertSelection(open, end, txtEl, arg3);
}
else {
//if not ie, use jquery field select, it's easier
var selection = jQuery("#" + txtEl).getSelection().text;
var replace = (arg3) ? open + arg3 : open; //concat open and arg3, if arg3 specified
if (end != "") {
replace = replace + selection + end;
}
jQuery("#" + txtEl).replaceSelection(replace);
jQuery("#" + txtEl).focus();
this._insertSimple(open, end, txtEl, arg3);
}
}
else {
var selection = this._editor.selection();
@@ -44,77 +58,44 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
this._editor.focus();
}
},
_insertSimple: function(open, end, txtEl) {
_IEInsertSelection: function(open, end, txtEl) {
var tArea = document.getElementById(txtEl);
var sct = tArea.scrollTop;
tArea.focus();
var open = (open) ? open : "";
var end = (end) ? end : "";
var sl;
var isIE = navigator.userAgent.match('MSIE');
if (isIE != null)
isIE = true;
else
isIE = false;
if (isIE) {
//insertAtCaret(tArea, open);
tArea.focus();
var curSelect = tArea.currRange;
if (arguments[3]) {
if (end == "") {
curSelect.text = open + arguments[3];
} else {
curSelect.text = open + arguments[3] + curSelect.text + end;
}
} else {
if (end == "") {
curSelect.text = open;
} else {
curSelect.text = open + curSelect.text + end;
}
}
curSelect.select();
} else if (!isIE && typeof tArea.selectionStart != "undefined") {
var selStart = tArea.value.substr(0, tArea.selectionStart);
var selEnd = tArea.value.substr(tArea.selectionEnd, tArea.value.length);
var curSelection = tArea.value.replace(selStart, "").replace(selEnd, "");
if (arguments[3]) {
if (end == "") {
sl = selStart + open + arguments[3];
tArea.value = sl + selEnd;
} else {
sl = selStart + open + arguments[3] + curSelection + end;
tArea.value = sl + selEnd;
}
} else {
var curSelect = tArea.currRange;
if (arguments[3]) {
if (end == "") {
sl = selStart + open;
tArea.value = sl + selEnd;
} else {
sl = selStart + open + curSelection + end;
tArea.value = sl + selEnd;
curSelect.text = open + arguments[3];
} else {
curSelect.text = open + arguments[3] + curSelect.text + end;
}
} else {
if (end == "") {
curSelect.text = open;
} else {
curSelect.text = open + curSelect.text + end;
}
}
curSelect.select();
},
_IESelectionHelper: function() {
if (navigator.userAgent.match('MSIE')) {
function storeCaret(editEl) {
if (editEl.createTextRange) {
editEl.currRange = document.selection.createRange().duplicate();
}
}
tArea.setSelectionRange(sl.length, sl.length);
tArea.focus();
tArea.scrollTop = sct;
} else {
tArea.value += (arguments[3]) ? open + arguments[3] + end : open + end;
//wire up events for ie editor
this._control.select( function() {storeCaret(this)} );
this._control.click( function() {storeCaret(this)} );
this._control.keyup( function() {storeCaret(this)} );
}
}
};
obj._IESelectionHelper();
return obj;
}
})(jQuery);
})(jQuery);

View File

@@ -1,3 +1,14 @@
function resizeTextArea(textEditor, offsetX, offsetY) {
var clientHeight = getViewportHeight();
var clientWidth = getViewportWidth();
if (textEditor != null) {
textEditor.style.width = (clientWidth - offsetX) + "px";
textEditor.style.height = (clientHeight - getY(textEditor) - offsetY) + "px";
}
}
// Ctrl + S support
var ctrlDown = false;
var shiftDown = false;

View File

@@ -1,9 +0,0 @@
function resizeTextArea(textEditor, offsetX, offsetY) {
var clientHeight = getViewportHeight();
var clientWidth = getViewportWidth();
if (textEditor != null) {
textEditor.style.width = (clientWidth - offsetX) + "px";
textEditor.style.height = (clientHeight - getY(textEditor) - offsetY) + "px";
}
}