From 40ee7aeae439a9c593c728a9b1f765718244e74d Mon Sep 17 00:00:00 2001 From: Shandem Date: Wed, 23 Sep 2009 15:37:06 +0000 Subject: [PATCH] DO NOT DOWNLOAD, STABLE RELEASE AVAILABLE ON THE RELEASES TAB Fixes more IE issues with code editor, streamline JS for editor. [TFS Changeset #59401] --- UpgradeReadme.txt | 4 +- components/umbraco.controls/CodeArea.cs | 16 +-- .../presentation/umbraco.presentation.csproj | 3 +- .../umbraco/developer/Xslt/editXslt.aspx | 4 +- .../umbraco/settings/editTemplate.aspx | 2 +- .../umbraco/settings/editTemplate.aspx.cs | 3 +- .../JQuery}/jquery-fieldselection.js | 0 .../umbraco_client/CodeArea/UmbracoEditor.js | 123 ++++++++---------- .../umbraco_client/CodeArea/javascript.js | 11 ++ .../CodeArea/resizeTextEditor.js | 9 -- 10 files changed, 76 insertions(+), 99 deletions(-) rename umbraco/presentation/{umbraco/js => umbraco_client/Application/JQuery}/jquery-fieldselection.js (100%) delete mode 100644 umbraco/presentation/umbraco_client/CodeArea/resizeTextEditor.js diff --git a/UpgradeReadme.txt b/UpgradeReadme.txt index 388ad8e5b7..be1c22aecc 100644 --- a/UpgradeReadme.txt +++ b/UpgradeReadme.txt @@ -33,4 +33,6 @@ to use the UmbracoClientPath setting * Moved all old TinyMCE supporting files to legacy project * Moved all old TinyMCE code files (that are not used to legacy project) -* Moved all old TinyMCE plugins to legacy project \ No newline at end of file +* Moved all old TinyMCE plugins to legacy project + +* Moved jquery-fieldselection.js to umbraco_client/Application/jQuery diff --git a/components/umbraco.controls/CodeArea.cs b/components/umbraco.controls/CodeArea.cs index fd1849e63b..361be62f57 100644 --- a/components/umbraco.controls/CodeArea.cs +++ b/components/umbraco.controls/CodeArea.cs @@ -14,8 +14,9 @@ using ClientDependency.Core.Controls; namespace umbraco.uicontrols { - [ClientDependency(ClientDependencyType.Javascript, "CodeArea/resizeTextEditor.js", "UmbracoClient")] + [ClientDependency(ClientDependencyType.Javascript, "CodeArea/javascript.js", "UmbracoClient")] [ClientDependency(ClientDependencyType.Javascript, "CodeArea/UmbracoEditor.js", "UmbracoClient")] + [ClientDependency(ClientDependencyType.Javascript, "Application/jQuery/jquery-fieldselection.js", "UmbracoClient")] public class CodeArea : WebControl { @@ -58,15 +59,12 @@ namespace umbraco.uicontrols { { base.OnInit(e); EnsureChildControls(); - + if (!UmbracoSettings.ScriptDisableEditor) { ClientDependencyLoader.Instance.RegisterDependency("CodeMirror/js/codemirror.js", "UmbracoClient", ClientDependencyType.Javascript); ClientDependencyLoader.Instance.RegisterDependency("CodeArea/styles.css", "UmbracoClient", ClientDependencyType.Css); - } - - ClientDependencyLoader.Instance.RegisterDependency("CodeArea/javascript.js", "UmbracoClient", ClientDependencyType.Javascript); - + } } protected override void CreateChildControls() @@ -80,9 +78,6 @@ namespace umbraco.uicontrols { if (UmbracoSettings.ScriptDisableEditor) { CodeTextBox.Attributes.Add("class", "codepress"); - CodeTextBox.Attributes.Add("onclick", "storeCaret(this)"); - CodeTextBox.Attributes.Add("onselect", "storeCaret(this)"); - CodeTextBox.Attributes.Add("onkeyup", "storeCaret(this)"); CodeTextBox.Attributes.Add("wrap", "off"); } else @@ -182,13 +177,12 @@ namespace umbraco.uicontrols { protected string RenderBasicEditor() { string jsEventCode = @" - var m_textEditor = document.getElementById('" + this.ClientID + @"'); if (navigator.userAgent.match('MSIE')) { //addEvent(m_textEditor, ""select"", function() { storeCaret(this); }); //addEvent(m_textEditor, ""click"", function() { storeCaret(this); }); //addEvent(m_textEditor, ""keyup"", function() { storeCaret(this); }); } - + var m_textEditor = document.getElementById('" + this.ClientID + @"'); tab.watch('" + this.ClientID + @"'); "; return jsEventCode; diff --git a/umbraco/presentation/umbraco.presentation.csproj b/umbraco/presentation/umbraco.presentation.csproj index af4323572d..d4acf2638e 100644 --- a/umbraco/presentation/umbraco.presentation.csproj +++ b/umbraco/presentation/umbraco.presentation.csproj @@ -1456,7 +1456,6 @@ - @@ -1588,7 +1587,7 @@ - + diff --git a/umbraco/presentation/umbraco/developer/Xslt/editXslt.aspx b/umbraco/presentation/umbraco/developer/Xslt/editXslt.aspx index 6b95306087..a6a8692ad0 100644 --- a/umbraco/presentation/umbraco/developer/Xslt/editXslt.aspx +++ b/umbraco/presentation/umbraco/developer/Xslt/editXslt.aspx @@ -58,7 +58,7 @@ xsltSnippet = UmbEditor.IsSimpleEditor - ? jQuery("#ctl00_body_editorSource").getSelection().text + ? jQuery("#<%= editorSource.ClientID %>").getSelection().text : UmbEditor._editor.selection(); if (xsltSnippet == '') { @@ -71,7 +71,7 @@ - + diff --git a/umbraco/presentation/umbraco/settings/editTemplate.aspx b/umbraco/presentation/umbraco/settings/editTemplate.aspx index 2486f6d794..9956627c7b 100644 --- a/umbraco/presentation/umbraco/settings/editTemplate.aspx +++ b/umbraco/presentation/umbraco/settings/editTemplate.aspx @@ -67,7 +67,7 @@ UmbEditor.Insert('\n<' + cp, '\n\n', '<%= editorSource.ClientID %>'); } - function insertPlaceHolderElement(id){ + function insertPlaceHolderElement(id){ var cp = 'asp:ContentPlaceHolder Id="' + id + '"'; cp += ' runat="server"'; diff --git a/umbraco/presentation/umbraco/settings/editTemplate.aspx.cs b/umbraco/presentation/umbraco/settings/editTemplate.aspx.cs index 1566a39e50..0a145dc855 100644 --- a/umbraco/presentation/umbraco/settings/editTemplate.aspx.cs +++ b/umbraco/presentation/umbraco/settings/editTemplate.aspx.cs @@ -70,7 +70,6 @@ namespace umbraco.cms.presentation.settings - #region Web Form Designer generated code override protected void OnInit(EventArgs e) { _template = new cms.businesslogic.template.Template(int.Parse(Request.QueryString["templateID"])); @@ -145,7 +144,7 @@ namespace umbraco.cms.presentation.settings { } - #endregion + } } diff --git a/umbraco/presentation/umbraco/js/jquery-fieldselection.js b/umbraco/presentation/umbraco_client/Application/JQuery/jquery-fieldselection.js similarity index 100% rename from umbraco/presentation/umbraco/js/jquery-fieldselection.js rename to umbraco/presentation/umbraco_client/Application/JQuery/jquery-fieldselection.js diff --git a/umbraco/presentation/umbraco_client/CodeArea/UmbracoEditor.js b/umbraco/presentation/umbraco_client/CodeArea/UmbracoEditor.js index cd234da761..af770924c7 100644 --- a/umbraco/presentation/umbraco_client/CodeArea/UmbracoEditor.js +++ b/umbraco/presentation/umbraco_client/CodeArea/UmbracoEditor.js @@ -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); \ No newline at end of file +})(jQuery); + diff --git a/umbraco/presentation/umbraco_client/CodeArea/javascript.js b/umbraco/presentation/umbraco_client/CodeArea/javascript.js index 67ed27d1cd..be8ace80e6 100644 --- a/umbraco/presentation/umbraco_client/CodeArea/javascript.js +++ b/umbraco/presentation/umbraco_client/CodeArea/javascript.js @@ -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; diff --git a/umbraco/presentation/umbraco_client/CodeArea/resizeTextEditor.js b/umbraco/presentation/umbraco_client/CodeArea/resizeTextEditor.js deleted file mode 100644 index 45825d2dda..0000000000 --- a/umbraco/presentation/umbraco_client/CodeArea/resizeTextEditor.js +++ /dev/null @@ -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"; - } -} \ No newline at end of file