Add WebCms
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
/// <reference path="/umbraco_client/Application/NamespaceManager.js" />
|
||||
|
||||
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!";
|
||||
}
|
||||
|
||||
//create the inner object
|
||||
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();
|
||||
}
|
||||
},
|
||||
SetCode: function(code) {
|
||||
if (this.IsSimpleEditor) {
|
||||
this._control.val(code);
|
||||
}
|
||||
else {
|
||||
//this is a wrapper for CodeMirror
|
||||
this._editor.focus();
|
||||
|
||||
var codeChanged = this._editor.getValue() != code;
|
||||
var cursor = this._editor.doc.getCursor();
|
||||
|
||||
this._editor.setValue(code);
|
||||
|
||||
// Restore cursor position if the server saved code matches.
|
||||
if (!codeChanged)
|
||||
this._editor.setCursor(cursor);
|
||||
|
||||
this._editor.focus();
|
||||
}
|
||||
},
|
||||
GetSelection: function(code) {
|
||||
if (this.IsSimpleEditor) {
|
||||
this._control.getSelection().text
|
||||
}
|
||||
else {
|
||||
//this is a wrapper for CodeMirror
|
||||
this._editor.getSelection();
|
||||
}
|
||||
},
|
||||
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')) {
|
||||
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 {
|
||||
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
|
||||
if (end != "") {
|
||||
replace = replace + selection + end;
|
||||
}
|
||||
this._editor.replaceSelection(replace);
|
||||
this._editor.focus();
|
||||
}
|
||||
},
|
||||
_IEInsertSelection: function(open, end, txtEl) {
|
||||
var tArea = document.getElementById(txtEl);
|
||||
tArea.focus();
|
||||
open = (open) ? open : "";
|
||||
end = (end) ? end : "";
|
||||
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();
|
||||
},
|
||||
_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) {
|
||||
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) });
|
||||
}
|
||||
else {
|
||||
|
||||
/*
|
||||
//Removed as its not needed in codemirror2 apparently
|
||||
this._editor.options.cursorActivity = function() {
|
||||
_this._cmSave = {
|
||||
start: _this._editor.cursorPosition(true), //save start position
|
||||
end: _this._editor.cursorPosition(false) //save end position
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// obj._IESelectionHelper();
|
||||
|
||||
// alert(obj);
|
||||
|
||||
return obj;
|
||||
};
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,191 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
function UmbracoCodeSnippet() {
|
||||
this.BeginTag = "";
|
||||
this.EndTag = "";
|
||||
this.TargetId = "";
|
||||
this.CursorPos = 0;
|
||||
}
|
||||
|
||||
|
||||
// Ctrl + S support
|
||||
var ctrlDown = false;
|
||||
var shiftDown = false;
|
||||
var keycode = 0;
|
||||
|
||||
function shortcutCheckKeysDown(e) {
|
||||
|
||||
ctrlDown = e.ctrlKey;
|
||||
shiftDown = e.shiftKey;
|
||||
keycode = e.keyCode;
|
||||
|
||||
//save
|
||||
// uncommented by NH 07-05-11 as it's been replaced by a native bindShortcutkey() method in the ClientManager
|
||||
/*
|
||||
if (ctrlDown && keycode == 83) {
|
||||
doSubmit();
|
||||
if (window.addEventListener) {
|
||||
e.preventDefault();
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
//snippet
|
||||
if (ctrlDown && keycode == 77) {
|
||||
if (window.umbracoInsertSnippet) {
|
||||
var snippetCode = umbracoInsertSnippet();
|
||||
if (window.UmbEditor) {
|
||||
UmbEditor.Insert(snippetCode.BeginTag, snippetCode.EndTag, snippetCode.TargetId);
|
||||
if (window.addEventListener) {
|
||||
e.preventDefault();
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//load the insert value dialog: ctrl + g
|
||||
if (ctrlDown && keycode == 71) {
|
||||
umbracoInsertField('', 'xsltInsertValueOf', '', 'felt', 750, 230, '');
|
||||
if (window.addEventListener) {
|
||||
e.preventDefault();
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function shortcutCheckKeysUp(e) {
|
||||
ctrlDown = e.ctrlKey;
|
||||
shiftDown = e.shiftKey;
|
||||
}
|
||||
|
||||
function shortcutCheckKeysPressFirefox(e) {
|
||||
if (ctrlDown && keycode == 83)
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
if (window.addEventListener) {
|
||||
document.addEventListener('keyup', shortcutCheckKeysUp, false);
|
||||
document.addEventListener('keydown', shortcutCheckKeysDown, false);
|
||||
document.addEventListener('keypress', shortcutCheckKeysPressFirefox, false);
|
||||
} else {
|
||||
document.attachEvent("onkeyup", shortcutCheckKeysUp);
|
||||
document.attachEvent("onkeydown", shortcutCheckKeysDown);
|
||||
}
|
||||
|
||||
|
||||
var tab = {
|
||||
key: 9,
|
||||
string: "\t",
|
||||
nl2br: true,
|
||||
tosp: true,
|
||||
watching: {},
|
||||
results: {},
|
||||
$: function (id) {
|
||||
return document.getElementById(id);
|
||||
},
|
||||
|
||||
watch: function (obj) {
|
||||
if (obj && this.$(obj)) {
|
||||
this.watching["_" + obj] = this.$(obj);
|
||||
this.addEvent(this.$(obj), "keydown", function (evt) {
|
||||
var sct = tab.$(obj).scrollTop;
|
||||
var l = tab.$(obj).value.length;
|
||||
var evt = (evt) ? evt : ((window.event) ? event : null);
|
||||
|
||||
if (evt) {
|
||||
var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
|
||||
|
||||
if (elem) {
|
||||
var char_code = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
|
||||
|
||||
if (char_code == tab.key) {
|
||||
if (tab.$(obj).attachEvent) {
|
||||
var range = document.selection.createRange();
|
||||
|
||||
range.text = tab.string;
|
||||
range.moveStart("character", -1);
|
||||
//range.select();
|
||||
} else if (typeof tab.$(obj).selectionStart != "undefined") {
|
||||
var start = tab.$(obj).value.substr(0, tab.$(obj).selectionStart);
|
||||
var end = tab.$(obj).value.substr(tab.$(obj).selectionStart, l);
|
||||
var selection = tab.$(obj).value.replace(start, "").replace(end, "")
|
||||
tab.$(obj).value = start + tab.string + selection + end;
|
||||
tab.$(obj).setSelectionRange(start.length + 1, start.length + 1);
|
||||
tab.$(obj).scrollTop = sct;
|
||||
} else {
|
||||
tab.$(obj).value += tab.string;
|
||||
}
|
||||
|
||||
if (evt.preventDefault) {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
} else {
|
||||
evt.returnValue = false;
|
||||
evt.cancelBubble = true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
click: function (obj, fn) {
|
||||
if (obj && this.$(obj)) {
|
||||
this.addEvent(this.$(obj), "click", function () {
|
||||
tab.results["_" + this.id.split("_")[1]] = tab.parse(tab.watching["_" + this.id.split("_")[1]].value);
|
||||
|
||||
if (fn && fn.constructor == Function) {
|
||||
fn();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
get: function (obj) {
|
||||
if (obj && this.$(obj)) {
|
||||
return this.results["_" + obj];
|
||||
}
|
||||
},
|
||||
|
||||
parse: function (str) {
|
||||
var str = (str) ? str : "";
|
||||
|
||||
if (str.length) {
|
||||
if (this.tosp) {
|
||||
str = str.replace(/\t/g, " ");
|
||||
}
|
||||
|
||||
if (this.nl2br) {
|
||||
str = str.replace(/\r?\n/g, "<br />");
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
},
|
||||
|
||||
addEvent: function (obj, type, fn) {
|
||||
if (obj.attachEvent) {
|
||||
obj["e" + type + fn] = fn;
|
||||
obj[type + fn] = function () {
|
||||
obj["e" + type + fn](window.event);
|
||||
}
|
||||
|
||||
obj.attachEvent("on" + type, obj[type + fn]);
|
||||
} else {
|
||||
obj.addEventListener(type, fn, false);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
.CodeMirror {
|
||||
border: none !Important;
|
||||
font-size: 15px !Important;
|
||||
}
|
||||
.CodeMirror-gutter{background: none !Important; border: none; padding-right: 5px;}
|
||||
|
||||
span.cm-at{background: yellow !Important;}
|
||||
textarea.codepress{display: block; width: 100% !Important; font-size: 14px;}
|
||||
Reference in New Issue
Block a user