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

@@ -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
* Moved all old TinyMCE plugins to legacy project
* Moved jquery-fieldselection.js to umbraco_client/Application/jQuery

View File

@@ -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;

View File

@@ -1456,7 +1456,6 @@
<Content Include="umbraco\images\umbraco\bin_closed.png" />
<Content Include="umbraco\images\umbraco\bin_empty.png" />
<Content Include="umbraco_client\CodeArea\UmbracoEditor.js" />
<Content Include="umbraco_client\CodeArea\resizeTextEditor.js" />
<Content Include="umbraco_client\CodeMirror\css\csscolors.css" />
<Content Include="umbraco_client\CodeMirror\css\docs.css" />
<Content Include="umbraco_client\CodeMirror\css\jscolors.css" />
@@ -1588,7 +1587,7 @@
<Content Include="umbraco\images\false.png" />
<Content Include="umbraco\images\new.png" />
<Content Include="umbraco\images\umbraco\sprites_ie6.gif" />
<Content Include="umbraco\js\jquery-fieldselection.js" />
<Content Include="umbraco_client\Application\JQuery\jquery-fieldselection.js" />
<Content Include="umbraco_client\Tree\css.js" />
<Content Include="umbraco_client\Application\JQuery\jquery.metadata.min.js" />
<Content Include="umbraco_client\Application\UmbracoUtils.js" />

View File

@@ -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 @@
</script>
<umb:JsInclude ID="JsInclude1" runat="server" FilePath="js/jquery-fieldselection.js" PathNameAlias="UmbracoRoot" />
<umb:JsInclude ID="JsInclude1" runat="server" FilePath="Application/jQuery/jquery-fieldselection.js" PathNameAlias="UmbracoClient" />
</asp:Content>
<asp:Content ContentPlaceHolderID="body" runat="server" ID="cp1">

View File

@@ -67,7 +67,7 @@
UmbEditor.Insert('\n<' + cp, '\n</asp:Content' + '>\n', '<%= editorSource.ClientID %>');
}
function insertPlaceHolderElement(id){
function insertPlaceHolderElement(id){
var cp = 'asp:ContentPlaceHolder Id="' + id + '"';
cp += ' runat="server"';

View File

@@ -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
}
}

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";
}
}