occweb/js/index.js

51 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

(function (OC, window, $, undefined) {
'use strict';
$(function() {
function scrollToBottom(){
var html = $('html');
html.scrollTop(html.prop('scrollHeight'));
}
2019-01-19 14:54:24 +00:00
var baseUrl = OC.generateUrl('/apps/occweb');
$.get(baseUrl + '/cmd', function(response){
$('#app-content').terminal(function(command, term) {
switch (command) {
case "c":
this.clear();
break;
case "exit":
this.reset();
break;
default:
var occCommand = {
command: command
};
term.pause();
$.ajax({
url: baseUrl + '/cmd',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(occCommand)
}).done(function (response) {
term.echo('\n' + response).resume();
}).fail(function (response, code) {
term.echo('\n' + response).resume();
});
}
}, {
greetings: function (callback) {
callback('[[;green;]' + new Date().toString().slice(0, 24) + "]\n\nPress [[;#ff5e99;]Enter] for more information on [[;#009ae3;]occ] commands.\n")
},
name: 'occ',
prompt: 'occ $ ',
completion: response,
onResize: function(){
scrollToBottom()
}
});
});
2019-01-19 17:09:39 +00:00
$('html').keypress(function(){
scrollToBottom()
})
});
})(OC, window, jQuery);