Crated InsertMacroSplitButton webforms control instead of the hacky js code used to insert the split button in the template editor.

Have implemented it now in the EditView (will transition over its use in editTemplate soon but is low priority).
Have got the js callbacks working now for inserting a macro for the mvc editor but need to implement the correct syntax. Also need
to migrate and update the editMacro dialog screen to check if we are rendering for MVC or not and if it is MVC then use the correct
syntax.
This commit is contained in:
Shannon Deminick
2012-12-31 18:39:36 +03:00
parent eeabee22bd
commit b292cb3ab3
14 changed files with 436 additions and 133 deletions

View File

@@ -4,28 +4,27 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
(function($) {
Umbraco.Controls.CodeEditor.UmbracoEditor = function(isSimpleEditor, controlId) {
//initialize
var _isSimpleEditor = isSimpleEditor;
var _controlId = controlId;
if (!_isSimpleEditor && typeof(codeEditor) == "undefined") {
throw "CodeMirror editor not found!";
}
throw "CodeMirror editor not found!";
}
//create the inner object
var obj = {
var obj = {
_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,
GetCode: function() {
if (this.IsSimpleEditor) {
return this._control.val();
}
}
else {
//this is a wrapper for CodeMirror
return this._editor.getValue();
@@ -48,8 +47,8 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
//this is a wrapper for CodeMirror
this._editor.getSelection();
}
},
Insert: function(open, end, txtEl, arg3) {
},
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) {
if (navigator.userAgent.match('MSIE')) {
@@ -65,16 +64,16 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
jQuery("#" + txtEl).replaceSelection(replace);
jQuery("#" + txtEl).focus();
this._insertSimple(open, end, txtEl, arg3);
}
}
}
else {
this._editor.focus(); //need to restore the focus to the editor body
//if the saved selection (IE only) is not null, then
if (this._cmSave != null) {
this._editor.selectLines(this._cmSave.start.line, this._cmSave.start.character, this._cmSave.end.line, this._cmSave.end.character);
}
}
var selection = this._editor.getSelection();
var replace = (arg3) ? open + arg3 : open; //concat open and arg3, if arg3 specified
@@ -88,43 +87,48 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
_IEInsertSelection: function(open, end, txtEl) {
var tArea = document.getElementById(txtEl);
tArea.focus();
var open = (open) ? open : "";
var end = (end) ? end : "";
var curSelect = tArea.currRange;
open = (open) ? open : "";
end = (end) ? end : "";
var curSelect = tArea.currRange;
if (arguments[3]) {
if (end == "") {
curSelect.text = open + arguments[3];
} else {
}
else {
curSelect.text = open + arguments[3] + curSelect.text + end;
}
} else {
}
else {
if (end == "") {
curSelect.text = open;
} else {
}
else {
curSelect.text = open + curSelect.text + end;
}
}
curSelect.select();
},
},
_IESelectionHelper: function() {
/// <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 (document.all) {
/// <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 (document.all) {
var _this = this;
if (this._editor == null) {
if (this._editor == null) {
function storeCaret(editEl) {
editEl.currRange = document.selection.createRange().duplicate();
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)} );
this._control.select(function() { storeCaret(this) });
this._control.click(function() { storeCaret(this) });
this._control.keyup(function() { storeCaret(this) });
}
else {
/*
//Removed as its not needed in codemirror2 apparently
this._editor.options.cursorActivity = function() {
@@ -134,16 +138,16 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls.CodeEditor");
}
}*/
}
}
}
}
};
// obj._IESelectionHelper();
// obj._IESelectionHelper();
// alert(obj);
// alert(obj);
return obj;
}
};
})(jQuery);