DO NOT DOWNLOAD, STABLE RELEASE AVAILABLE ON THE RELEASES TAB
Another very annoying IE fix complete for code editor [TFS Changeset #59431]
This commit is contained in:
@@ -27,13 +27,6 @@ namespace umbraco.uicontrols {
|
||||
}
|
||||
|
||||
protected TextBox CodeTextBox;
|
||||
protected HiddenField CodeEditorValue;
|
||||
|
||||
/// <summary>
|
||||
/// Used to track the postback event, this updates the hidden field's value so that
|
||||
/// on postback the value is returned.
|
||||
/// </summary>
|
||||
protected CustomValidator UpdateCodeValueValidator;
|
||||
|
||||
public bool AutoResize { get; set ; }
|
||||
public int OffSetX { get; set; }
|
||||
@@ -42,11 +35,11 @@ namespace umbraco.uicontrols {
|
||||
{
|
||||
get
|
||||
{
|
||||
return CodeEditorValue.Value;
|
||||
return CodeTextBox.Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
CodeEditorValue.Value = value;
|
||||
CodeTextBox.Text = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,8 +63,6 @@ namespace umbraco.uicontrols {
|
||||
protected override void CreateChildControls()
|
||||
{
|
||||
base.CreateChildControls();
|
||||
CodeEditorValue = new HiddenField();
|
||||
CodeEditorValue.ID = "CodeEditorValue";
|
||||
CodeTextBox = new TextBox();
|
||||
CodeTextBox.ID = "CodeTextBox";
|
||||
|
||||
@@ -80,30 +71,16 @@ namespace umbraco.uicontrols {
|
||||
CodeTextBox.Attributes.Add("class", "codepress");
|
||||
CodeTextBox.Attributes.Add("wrap", "off");
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateCodeValueValidator = new CustomValidator();
|
||||
UpdateCodeValueValidator.ID = "UpdateCodeValueValidator";
|
||||
UpdateCodeValueValidator.ClientValidationFunction = "updateCodeEditorValue";
|
||||
UpdateCodeValueValidator.Display = ValidatorDisplay.None;
|
||||
this.Controls.Add(UpdateCodeValueValidator);
|
||||
}
|
||||
else
|
||||
|
||||
CodeTextBox.TextMode = TextBoxMode.MultiLine;
|
||||
|
||||
this.CssClass = "codepress";
|
||||
|
||||
this.Controls.Add(CodeEditorValue);
|
||||
this.Controls.Add(CodeTextBox);
|
||||
|
||||
}
|
||||
|
||||
protected override void OnPreRender(EventArgs e)
|
||||
{
|
||||
base.OnPreRender(e);
|
||||
CodeTextBox.Text = CodeEditorValue.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Client ID is different if the code editor is turned on/off
|
||||
/// </summary>
|
||||
@@ -129,10 +106,7 @@ namespace umbraco.uicontrols {
|
||||
jsEventCode = RenderBasicEditor();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateCodeValueValidator.RenderControl(writer);
|
||||
CodeEditorValue.RenderControl(writer);
|
||||
|
||||
{
|
||||
writer.WriteBeginTag("div");
|
||||
writer.WriteAttribute("id", this.ClientID);
|
||||
writer.WriteAttribute("class", this.CssClass);
|
||||
@@ -218,17 +192,11 @@ namespace umbraco.uicontrols {
|
||||
break;
|
||||
}
|
||||
|
||||
var jsEventCode = @"
|
||||
|
||||
var textarea = document.getElementById('" + CodeTextBox.ClientID + @"');
|
||||
var codeVal = document.getElementById('" + CodeEditorValue.ClientID + @"');
|
||||
function updateCodeEditorValue(source, args) {
|
||||
codeVal.value = codeEditor.getCode();
|
||||
//alert(codeVal.value);
|
||||
args.IsValid = true;
|
||||
}
|
||||
var jsEventCode = @"
|
||||
var textarea = document.getElementById('" + CodeTextBox.ClientID + @"');
|
||||
|
||||
|
||||
var codeEditor = new CodeMirror(CodeMirror.replace(textarea), {
|
||||
var codeEditor = CodeMirror.fromTextArea(textarea, {
|
||||
width: ""100%"",
|
||||
height: ""100%"",
|
||||
tabMode: ""shift"",
|
||||
@@ -244,7 +212,7 @@ namespace umbraco.uicontrols {
|
||||
.ToArray()) + @"],
|
||||
path: """ + GlobalSettings.ClientPath + @"/CodeMirror/js/"",
|
||||
content: textarea.value,
|
||||
autoMatchParens: true,"
|
||||
autoMatchParens: false,"
|
||||
+ (string.IsNullOrEmpty(ClientSaveMethod) ? "" : @"saveFunction: " + ClientSaveMethod + ",") + @"
|
||||
onChange: function() { /*codeVal.value = codeEditor.getCode(); */}});
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
|
||||
|
||||
_editor: (typeof(codeEditor) == "undefined" ? null : codeEditor), //the codemirror object
|
||||
_control: $("#" + _controlId), //the original textbox as a jquery object
|
||||
_cmSave: null,//the saved selection of the code mirror editor (used for IE)
|
||||
|
||||
IsSimpleEditor: typeof(CodeMirror) == "undefined" ? true : typeof(codeEditor) == "undefined" ? true : _isSimpleEditor,
|
||||
|
||||
@@ -49,6 +50,20 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._editor.win.document.body.focus(); //need to restore the focus to the editor body
|
||||
|
||||
//if the saved selection (IE only) is not null, then
|
||||
//reselect the selection there is one, otherwise, expand the non-selection by 1
|
||||
//I know, this is wierd but it's an IE issue and this fixes it.
|
||||
if (this._cmSave != null) {
|
||||
if (this._cmSave.text.length > 0) {
|
||||
this._cmSave.select();
|
||||
}
|
||||
else {
|
||||
this._cmSave.expand("character");
|
||||
}
|
||||
}
|
||||
|
||||
var selection = this._editor.selection();
|
||||
var replace = (arg3) ? open + arg3 : open; //concat open and arg3, if arg3 specified
|
||||
if (end != "") {
|
||||
@@ -78,19 +93,32 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
|
||||
}
|
||||
}
|
||||
curSelect.select();
|
||||
},
|
||||
},
|
||||
_IESelectionHelper: function() {
|
||||
if (navigator.userAgent.match('MSIE')) {
|
||||
|
||||
function storeCaret(editEl) {
|
||||
if (editEl.createTextRange) {
|
||||
editEl.currRange = document.selection.createRange().duplicate();
|
||||
/// <summary>
|
||||
/// Because IE is lame, we have to continuously save the selections created by the user
|
||||
/// in the editors so that when the selections are lost (i.e. the user types in a different text box
|
||||
/// we'll need to restore the selection when they return focus
|
||||
/// </summary>
|
||||
if (navigator.userAgent.match('MSIE')) {
|
||||
var _this = this;
|
||||
if (this._editor == null) {
|
||||
function storeCaret(editEl) {
|
||||
editEl.currRange = document.selection.createRange().duplicate();
|
||||
}
|
||||
//need to store the selection details on each event while editing content
|
||||
this._control.select( function() {storeCaret(this)} );
|
||||
this._control.click( function() {storeCaret(this)} );
|
||||
this._control.keyup( function() {storeCaret(this)} );
|
||||
}
|
||||
//wire up events for ie editor
|
||||
this._control.select( function() {storeCaret(this)} );
|
||||
this._control.click( function() {storeCaret(this)} );
|
||||
this._control.keyup( function() {storeCaret(this)} );
|
||||
else {
|
||||
//when the editor loses focus, save the current selection
|
||||
this._editor.win.document.body.onblur = function()
|
||||
{
|
||||
_this._cmSave = _this._editor.win.document.selection.createRange();
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user