Files
BitwiseCmd/app/cmd/commands.js
2015-04-06 00:36:53 +03:00

60 lines
1.6 KiB
JavaScript

app.run(function() {
"use strict";
var cmd = app.get('cmd');
var cmdConfig = app.get('cmdConfig');
var rootView = app.get('rootView');
var shell = app.get('shell');
cmd.commands({
'help': function() {
var helpResult = document.querySelector('.result .helpResultTpl');
if(helpResult != null) {
moveResultUp(helpResult);
return;
}
return new app.models.ViewResult('helpResultTpl');
},
'clear': function() {
cmd.clear();
},
'em': function() {
cmdConfig.emphasizeBytes = !cmdConfig.emphasizeBytes;
},
'dark': function() {
shell.setDarkTheme();
},
light: function () {
shell.setLightTheme();
},
about: function() {
var aboutResult = document.querySelector('.result .aboutTpl');
if(aboutResult != null) {
moveResultUp(aboutResult);
return;
}
return new app.models.ViewResult('aboutTpl');
}
});
// TODO: Make as function
cmd.command({
canHandle: function(input) { return app.get('expression').canParse(input); },
handle: function(input) {
return app.get('expression').parse(input);
}
});
function moveResultUp(helpResult) {
var container = helpResult.parentNode.parentNode;
if(container.parentNode.firstChild != container) {
var out = container.parentNode;
out.removeChild(container);
out.insertBefore(container, out.firstChild);
}
}
});