added jqconsole lib

This commit is contained in:
coderaiser 2012-08-02 10:31:56 -04:00
parent 47b7f36824
commit f60b799a01
3 changed files with 53 additions and 63 deletions

View file

@ -19,6 +19,7 @@ var CloudClient={
keyBinding :function(){},/* функция нажатий обработки клавишь */
Editor :function(){},/* function loads and shows editor */
Viewer :function(){},/* function loads and shows viewer */
Terminal :function(){},/* function loads and shows terminal */
keyBinded :false,/* оброботка нажатий клавишь установлена*/
_loadDir :function(){},
/*
@ -172,6 +173,17 @@ CloudClient.Viewer = (function(){
})
});
});
/* function loads and shows terminal */
CloudClient.Terminal = (function(){
CloudCommander.jsload(CloudClient.LIBDIRCLIENT +
'terminal.js',{
onload: (function(){
CloudCommander.Terminal.Keys();
})
});
});
/*
* Функция привязываеться ко всем ссылкам и
* загружает содержимое каталогов

View file

@ -56,14 +56,20 @@ CloudCommander.keyBinding=(function(){
/* if f2 pressed */
else if(event.keyCode===113){
}
else if(event.keyCode===114){
if (typeof CloudCommander.Viewer === 'function')
CloudCommander.Viewer();
}
}
/* if f3 pressed */
else if(event.keyCode===114){
if (typeof CloudCommander.Viewer === 'function')
CloudCommander.Viewer();
}
/* if alt+f3 pressed */
else if(event.keyCode===114 &&
event.altKey){
if (typeof CloudCommander.Terminal === 'function')
CloudCommander.Terminal();
}
/* if f4 pressed */
else if(event.keyCode === 115) {
else if(event.keyCode === 115) {
if (typeof CloudCommander.Editor === 'function')
CloudCommander.Editor();
}

View file

@ -17,60 +17,32 @@ CloudCommander.Terminal.jqconsole = {
},
init: function(){
$(function() {
// Creating the console.
var header = 'Welcome to JQConsole!\n' +
'Use jqconsole.Write() to write and ' +
'jqconsole.Input() to read.\n';
window.jqconsole = $('#console').jqconsole(header, 'JS> ');
// Abort prompt on Ctrl+Z.
jqconsole.RegisterShortcut('Z', function() {
jqconsole.AbortPrompt();
handler();
});
// Move to line start Ctrl+A.
jqconsole.RegisterShortcut('A', function() {
jqconsole.MoveToStart();
handler();
});
// Move to line end Ctrl+E.
jqconsole.RegisterShortcut('E', function() {
jqconsole.MoveToEnd();
handler();
});
jqconsole.RegisterMatching('{', '}', 'brace');
jqconsole.RegisterMatching('(', ')', 'paran');
jqconsole.RegisterMatching('[', ']', 'bracket');
// Handle a command.
var handler = function(command) {
if (command) {
try {
jqconsole.Write('==> ' + window.eval(command) + '\n');
} catch (e) {
jqconsole.Write('ERROR: ' + e.message + '\n');
}
}
jqconsole.Prompt(true, handler, function(command) {
// Continue line if can't compile the command.
try {
Function(command);
} catch (e) {
if (/[\[\{\(]$/.test(command)) {
return 1;
} else {
return 0;
}
}
return false;
});
};
// Initiate the first prompt.
handler();
});
}
};
CloudCommander.Terminal.Keys = (function(){
"use strict";
/* loading js and css of CodeMirror */
CloudCommander.Editor.Terminal.load(this.jqconsole);
var key_event=function(event){
/* если клавиши можно обрабатывать */
if(CloudCommander.keyBinded){
/* if f4 pressed */
if(event.keyCode===114 &&
event.altKey){
CloudCommander.Terminal.jqconsole.show();
}
}
};
};
/* добавляем обработчик клавишь */
if (document.addEventListener)
document.addEventListener('keydown', key_event,false);
else
document.onkeypress=key_event;
});