mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2026-01-20 10:52:43 +01:00
Implemented support of multiple commands trough hash
This commit is contained in:
@@ -197,15 +197,13 @@
|
||||
app.bootstrap(document.getElementById('rootView'));
|
||||
|
||||
var cmd = app.get('cmd');
|
||||
var hashArgs = app.get('hashArgs');
|
||||
|
||||
cmd.execute('help');
|
||||
|
||||
if(window.location.hash.length > 1) {
|
||||
|
||||
cmd.execute(app.get('hash').decodeHash(window.location.hash));
|
||||
if(hashArgs.commands.length > 0) {
|
||||
hashArgs.commands.forEach(cmd.execute.bind(cmd));
|
||||
}
|
||||
else {
|
||||
|
||||
cmd.execute('help');
|
||||
cmd.execute('1|2');
|
||||
cmd.execute('1<<0x2a');
|
||||
cmd.execute('2 4 8 16 32');
|
||||
|
||||
@@ -13,8 +13,48 @@
|
||||
},
|
||||
decodeHash: function(hashValue) {
|
||||
return decodeURI(hashValue).replace(/^\#/, '').replace(/,/g,' ');
|
||||
},
|
||||
getArgs: function (hashValue) {
|
||||
|
||||
core.should.beString(hashValue, 'hashValue');
|
||||
|
||||
var decodedHash = this.decodeHash(hashValue),
|
||||
args = {
|
||||
commands: []
|
||||
};
|
||||
|
||||
splitHashList(decodedHash).forEach(function(value) {
|
||||
if(/^\-[a-zA-Z]+$/.test(value)) {
|
||||
args[value.substr(1)] = true;
|
||||
return;
|
||||
}
|
||||
|
||||
args.commands.push(value);
|
||||
});
|
||||
|
||||
return Object.freeze(args);
|
||||
}
|
||||
};
|
||||
|
||||
function splitHashList(str) {
|
||||
var values = [];
|
||||
|
||||
if(str.indexOf('||')) {
|
||||
str.split('||').forEach(function (v) {
|
||||
if (v.length > 0) {
|
||||
values.push(v);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
values.push(str);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
});
|
||||
|
||||
app.set('hashArgs', function() {
|
||||
return app.get('hash').getArgs(window.location.hash);
|
||||
})
|
||||
|
||||
})(window.app, window.core);
|
||||
Reference in New Issue
Block a user