GUI: Javascript cleanup and additional utility functions.
Change-Id: Ia16dd7eecedfd116e9d0a65d60d724657e87b8d3
diff --git a/web/gui/src/main/webapp/app/fw/util/ee.js b/web/gui/src/main/webapp/app/fw/util/ee.js
index 43455c2..78f6a9e 100644
--- a/web/gui/src/main/webapp/app/fw/util/ee.js
+++ b/web/gui/src/main/webapp/app/fw/util/ee.js
@@ -21,11 +21,26 @@
'use strict';
// injected services
- var fs;
+ var $log, fs, flash;
// function references
var fcc = String.fromCharCode;
+ // magic beans
+ var beans = [
+ //'umpxwnwcw'
+ //'eufdvexoc',
+ //'egpdytgv',
+ //'xcjvte',
+ //'bgvest',
+ //'sevlr',
+ 'ias'
+ ];
+
+ function pickBean() {
+ return beans[Math.floor(Math.random() * beans.length)] + '.foo';
+ }
+
function computeTransform(x) {
var m = x.split(':'),
h = Number(m[0]),
@@ -45,18 +60,39 @@
data.forEach(function (x) {
var r = computeTransform(x);
- map['shift' + r.e] = r.o.toLowerCase() + '.bin';
+ map[r.e] = r.o.toLowerCase() + '.foo';
});
return map;
}
- angular.module('onosUtil')
- .factory('EeService',
- ['FnService', function (_fs_) {
- fs = _fs_;
+ function cluck(foo) {
+ var f = fs.isF(foo),
+ s = fs.isS(foo);
- return {
- genMap: genMap
+ $log.debug('>>> CLUCK! <<<', foo);
+
+ if (s === 'fgfb.foo') {
+ s = pickBean();
+ $log.debug('bean picked:', s);
}
- }]);
+
+ if (s && fs.endsWith(s, '.foo')) {
+ flash.tempDiv().append('img').attr('src', 'raw/'+s);
+ }
+
+ f && f();
+ }
+
+ angular.module('onosUtil')
+ .factory('EeService', ['$log', 'FnService', 'FlashService',
+ function (_$log_, _fs_, _flash_) {
+ $log = _$log_;
+ fs = _fs_;
+ flash = _flash_;
+
+ return {
+ genMap: genMap,
+ cluck: cluck
+ }
+ }]);
}());
diff --git a/web/gui/src/main/webapp/app/fw/util/keys.js b/web/gui/src/main/webapp/app/fw/util/keys.js
index 393f660..9c60e83 100644
--- a/web/gui/src/main/webapp/app/fw/util/keys.js
+++ b/web/gui/src/main/webapp/app/fw/util/keys.js
@@ -21,11 +21,7 @@
'use strict';
// references to injected services
- var $log, $timeout, fs, ts, ns, qhs;
-
- // constants
- var eeggMin = 'shiftO',
- eeggMax = 'shiftONOS';
+ var $log, $timeout, fs, ts, ns, ee, qhs;
// internal state
var enabled = true,
@@ -37,23 +33,30 @@
viewFn: null,
viewGestures: []
},
- eegg = '';
+ seq = {},
+ matching = false,
+ matched = '',
+ lookup;
- function layEgg(key) {
- eegg += key;
- if (eeggMax.indexOf(eegg) === 0) {
- if (eegg === eeggMax) {
- d3.select('body').append('div').attr('id', 'eegg')
- .append('img').attr('src', 'raw/ewo.foo');
- $timeout(function () { d3.select('#eegg').remove(); }, 3000);
- eegg = '';
- }
+ function matchSeq(key) {
+ if (!matching && key === 'shift') {
+ matching = true;
return true;
}
- if (eegg !== eeggMin) {
- eegg = '';
+ if (matching) {
+ matched += key;
+ lookup = fs.trieLookup(seq, matched);
+ if (lookup === -1) {
+ return true;
+ }
+ matching = false;
+ matched = '';
+ if (!lookup) {
+ return;
+ }
+ ee.cluck(lookup);
+ return true;
}
- return false;
}
function whatKey(code) {
@@ -109,7 +112,7 @@
d3.event.stopPropagation();
if (enabled) {
- if (layEgg(key)) return;
+ if (matchSeq(key)) return;
// global callback?
if (gcb && gcb(token, key, keyCode, event)) {
@@ -230,13 +233,15 @@
angular.module('onosUtil')
.factory('KeyService',
['$log', '$timeout', 'FnService', 'ThemeService', 'NavService',
+ 'EeService',
- function (_$log_, _$timeout_, _fs_, _ts_, _ns_) {
+ function (_$log_, _$timeout_, _fs_, _ts_, _ns_, _ee_) {
$log = _$log_;
$timeout = _$timeout_;
fs = _fs_;
ts = _ts_;
ns = _ns_;
+ ee = _ee_;
return {
bindQhs: function (_qhs_) {
@@ -254,6 +259,12 @@
}
},
unbindKeys: unbindKeys,
+ addSeq: function (word, data) {
+ fs.addToTrie(seq, word, data);
+ },
+ remSeq: function (word) {
+ fs.removeFromTrie(seq, word);
+ },
gestureNotes: function (g) {
if (g === undefined) {
return keyHandler.viewGestures;