diff --git a/src/js/app.js b/src/js/app.js index c249b6e..096f3d1 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -7,8 +7,7 @@ app.set('cmdConfig', core.ObservableObject.create({ emphasizeBytes: true, - theme: 'dark', - mode: 'dec' + theme: 'dark' })); app.debugMode = false; diff --git a/src/js/app/bitwise/expression.js b/src/js/app/bitwise/expression.js index 79be83c..3e1fb0a 100644 --- a/src/js/app/bitwise/expression.js +++ b/src/js/app/bitwise/expression.js @@ -5,23 +5,21 @@ app.set('expression', function() { var listRegex = /^((\d+|0x[\d,a-f]+)\s?)+$/ return { - canParse: function(string, mode) { + canParse: function(string) { return exprRegex.test(string) || listRegex.test(string); }, - parse: function(string, mode) { - mode = (mode || 'dec'); - + parse: function(string) { var trimmed = string.replace(/^\s+|\s+$/, ''); - var base = getBase(mode); + var matches = exprRegex.exec(trimmed); if(matches != null) { - return createCalculableExpression(matches, base); + return createCalculableExpression(matches); } matches = listRegex.exec(string); if(matches != null) { - return createListOfNumbersExpression(string, base) + return createListOfNumbersExpression(string) } }, parseOperand: function(input) { @@ -38,7 +36,7 @@ app.set('expression', function() { }; - function createCalculableExpression(matches, base) { + function createCalculableExpression(matches) { var m = new app.models.BitwiseOperation(); m.operand1 = new Operand(matches[1]); @@ -50,7 +48,7 @@ app.set('expression', function() { return m; } - function createListOfNumbersExpression(input, base) { + function createListOfNumbersExpression(input) { var operands = []; input.split(' ').forEach(function(n){ if(n.trim().length > 0) { @@ -62,8 +60,8 @@ app.set('expression', function() { return new app.models.BitwiseNumbers(operands); } - function getBase(mode) { - switch (mode){ + function getBase(kind) { + switch (kind){ case 'bin': return 2; case 'hex': return 16; case 'dec': return 10; diff --git a/src/js/app/bitwise/formatter.js b/src/js/app/bitwise/formatter.js index 1f2658f..2456a53 100644 --- a/src/js/app/bitwise/formatter.js +++ b/src/js/app/bitwise/formatter.js @@ -5,10 +5,10 @@ app.set("formatter", function() { var is = app.get('is'); return { - formatString: function(num, mode) { - mode = mode || "bin"; + formatString: function(num, kind) { + kind = kind || "bin"; - var convertedString = num.toString(getBase(mode)); + var convertedString = num.toString(getBase(kind)); return convertedString; }, @@ -27,8 +27,8 @@ app.set("formatter", function() { } }; - function getBase(mode) { - switch (mode){ + function getBase(kind) { + switch (kind){ case 'bin': return 2; case 'hex': return 16; case 'dec': return 10; diff --git a/src/js/app/cmd/commands.js b/src/js/app/cmd/commands.js index 7eb424f..d7ab137 100644 --- a/src/js/app/cmd/commands.js +++ b/src/js/app/cmd/commands.js @@ -26,12 +26,6 @@ app.run(function() { light: function () { cmdConfig.theme = 'light'; }, - dec: function () { - cmdConfig.mode = 'dec'; - }, - hex: function() { - cmdConfig.mode = 'hex'; - }, about: function() { var aboutResult = document.querySelector('.result .aboutTpl'); if(aboutResult != null) { @@ -47,9 +41,9 @@ app.run(function() { // TODO: Make as function cmd.command({ - canHandle: function(input) { return app.get('expression').canParse(input, cmdConfig.mode); }, + canHandle: function(input) { return app.get('expression').canParse(input); }, handle: function(input) { - return app.get('expression').parse(input, cmdConfig.mode); + return app.get('expression').parse(input); } }); diff --git a/src/js/app/modelViews.js b/src/js/app/modelViews.js index 799d795..e0db390 100644 --- a/src/js/app/modelViews.js +++ b/src/js/app/modelViews.js @@ -31,8 +31,7 @@ app.compose(function () { app.modelView(app.models.BitwiseNumbers, { renderView: function(model) { var maxLen = getBinaryLength(model.numbers); - var table = html.element('