Skip to content

Instantly share code, notes, and snippets.

@dimapaloskin
Created February 22, 2014 10:24
Show Gist options
  • Save dimapaloskin/9151719 to your computer and use it in GitHub Desktop.
Save dimapaloskin/9151719 to your computer and use it in GitHub Desktop.
Ace-editor + CtrlS handler + opacity + text inserting
var js = document.createElement("script");
js.type = "text/javascript";
js.src = 'http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js';
document.body.appendChild(js);
var js = document.createElement("script");
js.type = "text/javascript";
js.src = 'http://code.jquery.com/jquery-1.11.0.min.js';
document.body.appendChild(js);
var style = document.createElement("style");
style.innerHTML = '#editor {position: absolute; opacity: 0.95; top: 0; left: 400px; width: ' +
(document.body.clientHeight - 350) + 'px; height: ' +
(document.body.clientHeight - 40) + 'px;}';
document.body.appendChild(style);
var div = document.createElement("div");
div.setAttribute('id', 'editor');
document.body.appendChild(div);
setTimeout(function () {
window.e = ace.edit("editor");
e.setTheme("ace/theme/monokai");
e.getSession().setMode("ace/mode/html");
ctrlSHook();
}, 1000);
function EditSite_SaveEditingText()
{
EditSite_SetTextFile(window.e.getSession().getValue());
}
var ctrlSHook = function () {
window.$(document).keydown(function(event) {
if (!( String.fromCharCode(event.which).toLowerCase() == 's' && event.ctrlKey) && !(event.which == 19)) return true;
EditSite_SaveEditingText();
event.preventDefault();
return false;
});
}
function EditSite_SetEditingText(Txt)
{
var TextAreaObj=GetObj('IEditSiteTextEdit_TextArea');
//TextAreaObj.innerHTML=Txt;
TextAreaObj.value=Txt;
window.e.getSession().setValue(Txt);
var FileIndex=FilesArray_IdToIndexH[FileId];
var FileRow=Files_Array[FileIndex];
var FileType=FileRow[Files_FILETYPE];
if ( FileType!=60 )
EditSite_EnableEditing(true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment