Committed by
Gerrit Code Review
GUI: Javascript cleanup and additional utility functions.
Change-Id: Ia16dd7eecedfd116e9d0a65d60d724657e87b8d3
Showing
7 changed files
with
371 additions
and
290 deletions
... | @@ -143,6 +143,13 @@ | ... | @@ -143,6 +143,13 @@ |
143 | enabled = !!b; | 143 | enabled = !!b; |
144 | } | 144 | } |
145 | 145 | ||
146 | + function tempDiv(ms) { | ||
147 | + var div = d3.select('body').append('div').classed('centered', true), | ||
148 | + delay = (ms === undefined || ms < 100) ? 3000 : ms; | ||
149 | + $timeout(function () { div.remove(); }, delay); | ||
150 | + return div; | ||
151 | + } | ||
152 | + | ||
146 | angular.module('onosLayer') | 153 | angular.module('onosLayer') |
147 | .factory('FlashService', ['$log', '$timeout', | 154 | .factory('FlashService', ['$log', '$timeout', |
148 | function (_$log_, _$timeout_) { | 155 | function (_$log_, _$timeout_) { |
... | @@ -158,7 +165,8 @@ | ... | @@ -158,7 +165,8 @@ |
158 | return { | 165 | return { |
159 | initFlash: initFlash, | 166 | initFlash: initFlash, |
160 | flash: flash, | 167 | flash: flash, |
161 | - enable: enable | 168 | + enable: enable, |
169 | + tempDiv: tempDiv | ||
162 | }; | 170 | }; |
163 | }]); | 171 | }]); |
164 | 172 | ... | ... |
... | @@ -28,266 +28,274 @@ | ... | @@ -28,266 +28,274 @@ |
28 | // injected references | 28 | // injected references |
29 | var $log, fs; | 29 | var $log, fs; |
30 | 30 | ||
31 | - angular.module('onosSvg') | 31 | + // TODO: change 'force' ref to be 'force.alpha' ref. |
32 | - .factory('SvgUtilService', ['$log', 'FnService', | 32 | + function createDragBehavior(force, selectCb, atDragEnd, |
33 | - function (_$log_, _fs_) { | 33 | + dragEnabled, clickEnabled) { |
34 | - $log = _$log_; | 34 | + var draggedThreshold = d3.scale.linear() |
35 | - fs = _fs_; | 35 | + .domain([0, 0.1]) |
36 | - | 36 | + .range([5, 20]) |
37 | - // TODO: change 'force' ref to be 'force.alpha' ref. | 37 | + .clamp(true), |
38 | - function createDragBehavior(force, selectCb, atDragEnd, | 38 | + drag, |
39 | - dragEnabled, clickEnabled) { | 39 | + fSel = fs.isF(selectCb), |
40 | - var draggedThreshold = d3.scale.linear() | 40 | + fEnd = fs.isF(atDragEnd), |
41 | - .domain([0, 0.1]) | 41 | + fDEn = fs.isF(dragEnabled), |
42 | - .range([5, 20]) | 42 | + fCEn = fs.isF(clickEnabled), |
43 | - .clamp(true), | 43 | + bad = []; |
44 | - drag, | 44 | + |
45 | - fSel = fs.isF(selectCb), | 45 | + function naf(what) { |
46 | - fEnd = fs.isF(atDragEnd), | 46 | + return 'SvgUtilService: createDragBehavior(): ' + what + |
47 | - fDEn = fs.isF(dragEnabled), | 47 | + ' is not a function'; |
48 | - fCEn = fs.isF(clickEnabled), | 48 | + } |
49 | - bad = []; | 49 | + |
50 | - | 50 | + if (!force) { |
51 | - function naf(what) { | 51 | + bad.push('SvgUtilService: createDragBehavior(): ' + |
52 | - return 'SvgUtilService: createDragBehavior(): ' + what + | 52 | + 'Bad force reference'); |
53 | - ' is not a function'; | 53 | + } |
54 | - } | 54 | + if (!fSel) { |
55 | - | 55 | + bad.push(naf('selectCb')); |
56 | - if (!force) { | 56 | + } |
57 | - bad.push('SvgUtilService: createDragBehavior(): ' + | 57 | + if (!fEnd) { |
58 | - 'Bad force reference'); | 58 | + bad.push(naf('atDragEnd')); |
59 | - } | 59 | + } |
60 | - if (!fSel) { | 60 | + if (!fDEn) { |
61 | - bad.push(naf('selectCb')); | 61 | + bad.push(naf('dragEnabled')); |
62 | - } | 62 | + } |
63 | - if (!fEnd) { | 63 | + if (!fCEn) { |
64 | - bad.push(naf('atDragEnd')); | 64 | + bad.push(naf('clickEnabled')); |
65 | - } | 65 | + } |
66 | - if (!fDEn) { | 66 | + |
67 | - bad.push(naf('dragEnabled')); | 67 | + if (bad.length) { |
68 | - } | 68 | + $log.error(bad.join('\n')); |
69 | - if (!fCEn) { | 69 | + return null; |
70 | - bad.push(naf('clickEnabled')); | 70 | + } |
71 | - } | 71 | + |
72 | - | 72 | + function dragged(d) { |
73 | - if (bad.length) { | 73 | + var threshold = draggedThreshold(force.alpha()), |
74 | - $log.error(bad.join('\n')); | 74 | + dx = d.oldX - d.px, |
75 | - return null; | 75 | + dy = d.oldY - d.py; |
76 | + if (Math.abs(dx) >= threshold || Math.abs(dy) >= threshold) { | ||
77 | + d.dragged = true; | ||
78 | + } | ||
79 | + return d.dragged; | ||
80 | + } | ||
81 | + | ||
82 | + drag = d3.behavior.drag() | ||
83 | + .origin(function(d) { return d; }) | ||
84 | + .on('dragstart', function(d) { | ||
85 | + if (clickEnabled() || dragEnabled()) { | ||
86 | + d3.event.sourceEvent.stopPropagation(); | ||
87 | + | ||
88 | + d.oldX = d.x; | ||
89 | + d.oldY = d.y; | ||
90 | + d.dragged = false; | ||
91 | + d.fixed |= 2; | ||
92 | + d.dragStarted = true; | ||
76 | } | 93 | } |
77 | - | 94 | + }) |
78 | - function dragged(d) { | 95 | + .on('drag', function(d) { |
79 | - var threshold = draggedThreshold(force.alpha()), | 96 | + if (dragEnabled()) { |
80 | - dx = d.oldX - d.px, | 97 | + d.px = d3.event.x; |
81 | - dy = d.oldY - d.py; | 98 | + d.py = d3.event.y; |
82 | - if (Math.abs(dx) >= threshold || Math.abs(dy) >= threshold) { | 99 | + if (dragged(d)) { |
83 | - d.dragged = true; | 100 | + if (!force.alpha()) { |
101 | + force.alpha(.025); | ||
102 | + } | ||
84 | } | 103 | } |
85 | - return d.dragged; | ||
86 | } | 104 | } |
87 | - | 105 | + }) |
88 | - drag = d3.behavior.drag() | 106 | + .on('dragend', function(d) { |
89 | - .origin(function(d) { return d; }) | 107 | + if (d.dragStarted) { |
90 | - .on('dragstart', function(d) { | 108 | + d.dragStarted = false; |
91 | - if (clickEnabled() || dragEnabled()) { | 109 | + if (!dragged(d)) { |
92 | - d3.event.sourceEvent.stopPropagation(); | 110 | + // consider this the same as a 'click' |
93 | - | 111 | + // (selection of a node) |
94 | - d.oldX = d.x; | 112 | + if (clickEnabled()) { |
95 | - d.oldY = d.y; | 113 | + selectCb.call(this, d); |
96 | - d.dragged = false; | ||
97 | - d.fixed |= 2; | ||
98 | - d.dragStarted = true; | ||
99 | - } | ||
100 | - }) | ||
101 | - .on('drag', function(d) { | ||
102 | - if (dragEnabled()) { | ||
103 | - d.px = d3.event.x; | ||
104 | - d.py = d3.event.y; | ||
105 | - if (dragged(d)) { | ||
106 | - if (!force.alpha()) { | ||
107 | - force.alpha(.025); | ||
108 | - } | ||
109 | - } | ||
110 | - } | ||
111 | - }) | ||
112 | - .on('dragend', function(d) { | ||
113 | - if (d.dragStarted) { | ||
114 | - d.dragStarted = false; | ||
115 | - if (!dragged(d)) { | ||
116 | - // consider this the same as a 'click' | ||
117 | - // (selection of a node) | ||
118 | - if (clickEnabled()) { | ||
119 | - selectCb.call(this, d); | ||
120 | - } | ||
121 | - } | ||
122 | - d.fixed &= ~6; | ||
123 | - | ||
124 | - // hook at the end of a drag gesture | ||
125 | - if (dragEnabled()) { | ||
126 | - atDragEnd.call(this, d); | ||
127 | - } | ||
128 | } | 114 | } |
129 | - }); | ||
130 | - | ||
131 | - return drag; | ||
132 | - } | ||
133 | - | ||
134 | - | ||
135 | - function loadGlow(defs, r, g, b, id) { | ||
136 | - var glow = defs.append('filter') | ||
137 | - .attr('x', '-50%') | ||
138 | - .attr('y', '-50%') | ||
139 | - .attr('width', '200%') | ||
140 | - .attr('height', '200%') | ||
141 | - .attr('id', id); | ||
142 | - | ||
143 | - glow.append('feColorMatrix') | ||
144 | - .attr('type', 'matrix') | ||
145 | - .attr('values', | ||
146 | - '0 0 0 0 ' + r + ' ' + | ||
147 | - '0 0 0 0 ' + g + ' ' + | ||
148 | - '0 0 0 0 ' + b + ' ' + | ||
149 | - '0 0 0 1 0 '); | ||
150 | - | ||
151 | - glow.append('feGaussianBlur') | ||
152 | - .attr('stdDeviation', 3) | ||
153 | - .attr('result', 'coloredBlur'); | ||
154 | - | ||
155 | - glow.append('feMerge').selectAll('feMergeNode') | ||
156 | - .data(['coloredBlur', 'SourceGraphic']) | ||
157 | - .enter().append('feMergeNode') | ||
158 | - .attr('in', String); | ||
159 | - } | ||
160 | - | ||
161 | - function loadGlowDefs(defs) { | ||
162 | - loadGlow(defs, 0.0, 0.0, 0.7, 'blue-glow'); | ||
163 | - loadGlow(defs, 1.0, 1.0, 0.3, 'yellow-glow'); | ||
164 | - } | ||
165 | - | ||
166 | - // --- Ordinal scales for 7 values. | ||
167 | - | ||
168 | - // blue brown brick red sea green purple dark teal lime | ||
169 | - var lightNorm = ['#3E5780', '#78533B', '#CB4D28', '#018D61', '#8A2979', '#006D73', '#56AF00'], | ||
170 | - lightMute = ['#A8B8CC', '#CCB3A8', '#FFC2BD', '#96D6BF', '#D19FCE', '#8FCCCA', '#CAEAA4'], | ||
171 | - | ||
172 | - darkNorm = ['#304860', '#664631', '#A8391B', '#00754B', '#77206D', '#005959', '#428700'], | ||
173 | - darkMute = ['#304860', '#664631', '#A8391B', '#00754B', '#77206D', '#005959', '#428700']; | ||
174 | - | ||
175 | - var colors= { | ||
176 | - light: { | ||
177 | - norm: d3.scale.ordinal().range(lightNorm), | ||
178 | - mute: d3.scale.ordinal().range(lightMute) | ||
179 | - }, | ||
180 | - dark: { | ||
181 | - norm: d3.scale.ordinal().range(darkNorm), | ||
182 | - mute: d3.scale.ordinal().range(darkMute) | ||
183 | - } | ||
184 | - }; | ||
185 | - | ||
186 | - function cat7() { | ||
187 | - var tcid = 'd3utilTestCard'; | ||
188 | - | ||
189 | - function getColor(id, muted, theme) { | ||
190 | - // NOTE: since we are lazily assigning domain ids, we need to | ||
191 | - // get the color from all 4 scales, to keep the domains | ||
192 | - // in sync. | ||
193 | - var ln = colors.light.norm(id), | ||
194 | - lm = colors.light.mute(id), | ||
195 | - dn = colors.dark.norm(id), | ||
196 | - dm = colors.dark.mute(id); | ||
197 | - if (theme === 'dark') { | ||
198 | - return muted ? dm : dn; | ||
199 | - } else { | ||
200 | - return muted ? lm : ln; | ||
201 | } | 115 | } |
202 | - } | 116 | + d.fixed &= ~6; |
203 | 117 | ||
204 | - function testCard(svg) { | 118 | + // hook at the end of a drag gesture |
205 | - var g = svg.select('g#' + tcid), | 119 | + if (dragEnabled()) { |
206 | - dom = d3.range(7), | 120 | + atDragEnd.call(this, d); |
207 | - k, muted, theme, what; | ||
208 | - | ||
209 | - if (!g.empty()) { | ||
210 | - g.remove(); | ||
211 | - | ||
212 | - } else { | ||
213 | - g = svg.append('g') | ||
214 | - .attr('id', tcid) | ||
215 | - .attr('transform', 'scale(4)translate(20,20)'); | ||
216 | - | ||
217 | - for (k=0; k<4; k++) { | ||
218 | - muted = k%2; | ||
219 | - what = muted ? ' muted' : ' normal'; | ||
220 | - theme = k < 2 ? 'light' : 'dark'; | ||
221 | - dom.forEach(function (id, i) { | ||
222 | - var x = i * 20, | ||
223 | - y = k * 20, | ||
224 | - f = get(id, muted, theme); | ||
225 | - g.append('circle').attr({ | ||
226 | - cx: x, | ||
227 | - cy: y, | ||
228 | - r: 5, | ||
229 | - fill: f | ||
230 | - }); | ||
231 | - }); | ||
232 | - g.append('rect').attr({ | ||
233 | - x: 140, | ||
234 | - y: k * 20 - 5, | ||
235 | - width: 32, | ||
236 | - height: 10, | ||
237 | - rx: 2, | ||
238 | - fill: '#888' | ||
239 | - }); | ||
240 | - g.append('text').text(theme + what) | ||
241 | - .attr({ | ||
242 | - x: 142, | ||
243 | - y: k * 20 + 2, | ||
244 | - fill: 'white' | ||
245 | - }) | ||
246 | - .style('font-size', '4pt'); | ||
247 | - } | ||
248 | } | 121 | } |
249 | } | 122 | } |
250 | - | 123 | + }); |
251 | - return { | 124 | + |
252 | - testCard: testCard, | 125 | + return drag; |
253 | - getColor: getColor | 126 | + } |
254 | - }; | 127 | + |
128 | + | ||
129 | + function loadGlow(defs, r, g, b, id) { | ||
130 | + var glow = defs.append('filter') | ||
131 | + .attr('x', '-50%') | ||
132 | + .attr('y', '-50%') | ||
133 | + .attr('width', '200%') | ||
134 | + .attr('height', '200%') | ||
135 | + .attr('id', id); | ||
136 | + | ||
137 | + glow.append('feColorMatrix') | ||
138 | + .attr('type', 'matrix') | ||
139 | + .attr('values', | ||
140 | + '0 0 0 0 ' + r + ' ' + | ||
141 | + '0 0 0 0 ' + g + ' ' + | ||
142 | + '0 0 0 0 ' + b + ' ' + | ||
143 | + '0 0 0 1 0 '); | ||
144 | + | ||
145 | + glow.append('feGaussianBlur') | ||
146 | + .attr('stdDeviation', 3) | ||
147 | + .attr('result', 'coloredBlur'); | ||
148 | + | ||
149 | + glow.append('feMerge').selectAll('feMergeNode') | ||
150 | + .data(['coloredBlur', 'SourceGraphic']) | ||
151 | + .enter().append('feMergeNode') | ||
152 | + .attr('in', String); | ||
153 | + } | ||
154 | + | ||
155 | + function loadGlowDefs(defs) { | ||
156 | + loadGlow(defs, 0.0, 0.0, 0.7, 'blue-glow'); | ||
157 | + loadGlow(defs, 1.0, 1.0, 0.3, 'yellow-glow'); | ||
158 | + } | ||
159 | + | ||
160 | + // --- Ordinal scales for 7 values. | ||
161 | + | ||
162 | + // blue brown brick red sea green purple dark teal lime | ||
163 | + var lightNorm = ['#3E5780', '#78533B', '#CB4D28', '#018D61', '#8A2979', '#006D73', '#56AF00'], | ||
164 | + lightMute = ['#A8B8CC', '#CCB3A8', '#FFC2BD', '#96D6BF', '#D19FCE', '#8FCCCA', '#CAEAA4'], | ||
165 | + | ||
166 | + darkNorm = ['#304860', '#664631', '#A8391B', '#00754B', '#77206D', '#005959', '#428700'], | ||
167 | + darkMute = ['#304860', '#664631', '#A8391B', '#00754B', '#77206D', '#005959', '#428700']; | ||
168 | + | ||
169 | + var colors= { | ||
170 | + light: { | ||
171 | + norm: d3.scale.ordinal().range(lightNorm), | ||
172 | + mute: d3.scale.ordinal().range(lightMute) | ||
173 | + }, | ||
174 | + dark: { | ||
175 | + norm: d3.scale.ordinal().range(darkNorm), | ||
176 | + mute: d3.scale.ordinal().range(darkMute) | ||
177 | + } | ||
178 | + }; | ||
179 | + | ||
180 | + function cat7() { | ||
181 | + var tcid = 'd3utilTestCard'; | ||
182 | + | ||
183 | + function getColor(id, muted, theme) { | ||
184 | + // NOTE: since we are lazily assigning domain ids, we need to | ||
185 | + // get the color from all 4 scales, to keep the domains | ||
186 | + // in sync. | ||
187 | + var ln = colors.light.norm(id), | ||
188 | + lm = colors.light.mute(id), | ||
189 | + dn = colors.dark.norm(id), | ||
190 | + dm = colors.dark.mute(id); | ||
191 | + if (theme === 'dark') { | ||
192 | + return muted ? dm : dn; | ||
193 | + } else { | ||
194 | + return muted ? lm : ln; | ||
255 | } | 195 | } |
256 | - | 196 | + } |
257 | - function translate(x, y) { | 197 | + |
258 | - if (fs.isA(x) && x.length === 2 && !y) { | 198 | + function testCard(svg) { |
259 | - return 'translate(' + x[0] + ',' + x[1] + ')'; | 199 | + var g = svg.select('g#' + tcid), |
200 | + dom = d3.range(7), | ||
201 | + k, muted, theme, what; | ||
202 | + | ||
203 | + if (!g.empty()) { | ||
204 | + g.remove(); | ||
205 | + | ||
206 | + } else { | ||
207 | + g = svg.append('g') | ||
208 | + .attr('id', tcid) | ||
209 | + .attr('transform', 'scale(4)translate(20,20)'); | ||
210 | + | ||
211 | + for (k=0; k<4; k++) { | ||
212 | + muted = k%2; | ||
213 | + what = muted ? ' muted' : ' normal'; | ||
214 | + theme = k < 2 ? 'light' : 'dark'; | ||
215 | + dom.forEach(function (id, i) { | ||
216 | + var x = i * 20, | ||
217 | + y = k * 20, | ||
218 | + f = get(id, muted, theme); | ||
219 | + g.append('circle').attr({ | ||
220 | + cx: x, | ||
221 | + cy: y, | ||
222 | + r: 5, | ||
223 | + fill: f | ||
224 | + }); | ||
225 | + }); | ||
226 | + g.append('rect').attr({ | ||
227 | + x: 140, | ||
228 | + y: k * 20 - 5, | ||
229 | + width: 32, | ||
230 | + height: 10, | ||
231 | + rx: 2, | ||
232 | + fill: '#888' | ||
233 | + }); | ||
234 | + g.append('text').text(theme + what) | ||
235 | + .attr({ | ||
236 | + x: 142, | ||
237 | + y: k * 20 + 2, | ||
238 | + fill: 'white' | ||
239 | + }) | ||
240 | + .style('font-size', '4pt'); | ||
260 | } | 241 | } |
261 | - return 'translate(' + x + ',' + y + ')'; | ||
262 | - } | ||
263 | - | ||
264 | - function scale(x, y) { | ||
265 | - return 'scale(' + x + ',' + y + ')'; | ||
266 | - } | ||
267 | - | ||
268 | - function skewX(x) { | ||
269 | - return 'skewX(' + x + ')'; | ||
270 | - } | ||
271 | - | ||
272 | - function rotate(deg) { | ||
273 | - return 'rotate(' + deg + ')'; | ||
274 | - } | ||
275 | - | ||
276 | - function stripPx(s) { | ||
277 | - return s.replace(/px$/,''); | ||
278 | - } | ||
279 | - | ||
280 | - function safeId(s) { | ||
281 | - return s.replace(/[^a-z0-9]/gi, '-'); | ||
282 | } | 242 | } |
243 | + } | ||
244 | + | ||
245 | + return { | ||
246 | + testCard: testCard, | ||
247 | + getColor: getColor | ||
248 | + }; | ||
249 | + } | ||
250 | + | ||
251 | + function translate(x, y) { | ||
252 | + if (fs.isA(x) && x.length === 2 && !y) { | ||
253 | + return 'translate(' + x[0] + ',' + x[1] + ')'; | ||
254 | + } | ||
255 | + return 'translate(' + x + ',' + y + ')'; | ||
256 | + } | ||
257 | + | ||
258 | + function scale(x, y) { | ||
259 | + return 'scale(' + x + ',' + y + ')'; | ||
260 | + } | ||
261 | + | ||
262 | + function skewX(x) { | ||
263 | + return 'skewX(' + x + ')'; | ||
264 | + } | ||
265 | + | ||
266 | + function rotate(deg) { | ||
267 | + return 'rotate(' + deg + ')'; | ||
268 | + } | ||
269 | + | ||
270 | + function stripPx(s) { | ||
271 | + return s.replace(/px$/,''); | ||
272 | + } | ||
273 | + | ||
274 | + function safeId(s) { | ||
275 | + return s.replace(/[^a-z0-9]/gi, '-'); | ||
276 | + } | ||
277 | + | ||
278 | + function makeVisible(el, b) { | ||
279 | + el.style('visibility', (b ? 'visible' : 'hidden')); | ||
280 | + } | ||
281 | + | ||
282 | + function isVisible(el) { | ||
283 | + return el.style('visibility') === 'visible'; | ||
284 | + } | ||
285 | + | ||
286 | + function visible(el, x) { | ||
287 | + if (x === undefined) { | ||
288 | + return isVisible(el); | ||
289 | + } else { | ||
290 | + makeVisible(el, x); | ||
291 | + } | ||
292 | + } | ||
283 | 293 | ||
284 | - function makeVisible(el, b) { | 294 | + angular.module('onosSvg') |
285 | - el.style('visibility', (b ? 'visible' : 'hidden')); | 295 | + .factory('SvgUtilService', ['$log', 'FnService', |
286 | - } | 296 | + function (_$log_, _fs_) { |
287 | - | 297 | + $log = _$log_; |
288 | - function isVisible(el) { | 298 | + fs = _fs_; |
289 | - return el.style('visibility') === 'visible'; | ||
290 | - } | ||
291 | 299 | ||
292 | return { | 300 | return { |
293 | createDragBehavior: createDragBehavior, | 301 | createDragBehavior: createDragBehavior, |
... | @@ -299,13 +307,7 @@ | ... | @@ -299,13 +307,7 @@ |
299 | rotate: rotate, | 307 | rotate: rotate, |
300 | stripPx: stripPx, | 308 | stripPx: stripPx, |
301 | safeId: safeId, | 309 | safeId: safeId, |
302 | - visible: function (el, x) { | 310 | + visible: visible |
303 | - if (x === undefined) { | ||
304 | - return isVisible(el); | ||
305 | - } else { | ||
306 | - makeVisible(el, x); | ||
307 | - } | ||
308 | - } | ||
309 | }; | 311 | }; |
310 | }]); | 312 | }]); |
311 | }()); | 313 | }()); | ... | ... |
... | @@ -21,11 +21,26 @@ | ... | @@ -21,11 +21,26 @@ |
21 | 'use strict'; | 21 | 'use strict'; |
22 | 22 | ||
23 | // injected services | 23 | // injected services |
24 | - var fs; | 24 | + var $log, fs, flash; |
25 | 25 | ||
26 | // function references | 26 | // function references |
27 | var fcc = String.fromCharCode; | 27 | var fcc = String.fromCharCode; |
28 | 28 | ||
29 | + // magic beans | ||
30 | + var beans = [ | ||
31 | + //'umpxwnwcw' | ||
32 | + //'eufdvexoc', | ||
33 | + //'egpdytgv', | ||
34 | + //'xcjvte', | ||
35 | + //'bgvest', | ||
36 | + //'sevlr', | ||
37 | + 'ias' | ||
38 | + ]; | ||
39 | + | ||
40 | + function pickBean() { | ||
41 | + return beans[Math.floor(Math.random() * beans.length)] + '.foo'; | ||
42 | + } | ||
43 | + | ||
29 | function computeTransform(x) { | 44 | function computeTransform(x) { |
30 | var m = x.split(':'), | 45 | var m = x.split(':'), |
31 | h = Number(m[0]), | 46 | h = Number(m[0]), |
... | @@ -45,18 +60,39 @@ | ... | @@ -45,18 +60,39 @@ |
45 | 60 | ||
46 | data.forEach(function (x) { | 61 | data.forEach(function (x) { |
47 | var r = computeTransform(x); | 62 | var r = computeTransform(x); |
48 | - map['shift' + r.e] = r.o.toLowerCase() + '.bin'; | 63 | + map[r.e] = r.o.toLowerCase() + '.foo'; |
49 | }); | 64 | }); |
50 | return map; | 65 | return map; |
51 | } | 66 | } |
52 | 67 | ||
53 | - angular.module('onosUtil') | 68 | + function cluck(foo) { |
54 | - .factory('EeService', | 69 | + var f = fs.isF(foo), |
55 | - ['FnService', function (_fs_) { | 70 | + s = fs.isS(foo); |
56 | - fs = _fs_; | 71 | + |
72 | + $log.debug('>>> CLUCK! <<<', foo); | ||
73 | + | ||
74 | + if (s === 'fgfb.foo') { | ||
75 | + s = pickBean(); | ||
76 | + $log.debug('bean picked:', s); | ||
77 | + } | ||
57 | 78 | ||
58 | - return { | 79 | + if (s && fs.endsWith(s, '.foo')) { |
59 | - genMap: genMap | 80 | + flash.tempDiv().append('img').attr('src', 'raw/'+s); |
60 | } | 81 | } |
61 | - }]); | 82 | + |
83 | + f && f(); | ||
84 | + } | ||
85 | + | ||
86 | + angular.module('onosUtil') | ||
87 | + .factory('EeService', ['$log', 'FnService', 'FlashService', | ||
88 | + function (_$log_, _fs_, _flash_) { | ||
89 | + $log = _$log_; | ||
90 | + fs = _fs_; | ||
91 | + flash = _flash_; | ||
92 | + | ||
93 | + return { | ||
94 | + genMap: genMap, | ||
95 | + cluck: cluck | ||
96 | + } | ||
97 | + }]); | ||
62 | }()); | 98 | }()); | ... | ... |
... | @@ -21,11 +21,7 @@ | ... | @@ -21,11 +21,7 @@ |
21 | 'use strict'; | 21 | 'use strict'; |
22 | 22 | ||
23 | // references to injected services | 23 | // references to injected services |
24 | - var $log, $timeout, fs, ts, ns, qhs; | 24 | + var $log, $timeout, fs, ts, ns, ee, qhs; |
25 | - | ||
26 | - // constants | ||
27 | - var eeggMin = 'shiftO', | ||
28 | - eeggMax = 'shiftONOS'; | ||
29 | 25 | ||
30 | // internal state | 26 | // internal state |
31 | var enabled = true, | 27 | var enabled = true, |
... | @@ -37,23 +33,30 @@ | ... | @@ -37,23 +33,30 @@ |
37 | viewFn: null, | 33 | viewFn: null, |
38 | viewGestures: [] | 34 | viewGestures: [] |
39 | }, | 35 | }, |
40 | - eegg = ''; | 36 | + seq = {}, |
37 | + matching = false, | ||
38 | + matched = '', | ||
39 | + lookup; | ||
41 | 40 | ||
42 | - function layEgg(key) { | 41 | + function matchSeq(key) { |
43 | - eegg += key; | 42 | + if (!matching && key === 'shift') { |
44 | - if (eeggMax.indexOf(eegg) === 0) { | 43 | + matching = true; |
45 | - if (eegg === eeggMax) { | ||
46 | - d3.select('body').append('div').attr('id', 'eegg') | ||
47 | - .append('img').attr('src', 'raw/ewo.foo'); | ||
48 | - $timeout(function () { d3.select('#eegg').remove(); }, 3000); | ||
49 | - eegg = ''; | ||
50 | - } | ||
51 | return true; | 44 | return true; |
52 | } | 45 | } |
53 | - if (eegg !== eeggMin) { | 46 | + if (matching) { |
54 | - eegg = ''; | 47 | + matched += key; |
48 | + lookup = fs.trieLookup(seq, matched); | ||
49 | + if (lookup === -1) { | ||
50 | + return true; | ||
51 | + } | ||
52 | + matching = false; | ||
53 | + matched = ''; | ||
54 | + if (!lookup) { | ||
55 | + return; | ||
56 | + } | ||
57 | + ee.cluck(lookup); | ||
58 | + return true; | ||
55 | } | 59 | } |
56 | - return false; | ||
57 | } | 60 | } |
58 | 61 | ||
59 | function whatKey(code) { | 62 | function whatKey(code) { |
... | @@ -109,7 +112,7 @@ | ... | @@ -109,7 +112,7 @@ |
109 | d3.event.stopPropagation(); | 112 | d3.event.stopPropagation(); |
110 | 113 | ||
111 | if (enabled) { | 114 | if (enabled) { |
112 | - if (layEgg(key)) return; | 115 | + if (matchSeq(key)) return; |
113 | 116 | ||
114 | // global callback? | 117 | // global callback? |
115 | if (gcb && gcb(token, key, keyCode, event)) { | 118 | if (gcb && gcb(token, key, keyCode, event)) { |
... | @@ -230,13 +233,15 @@ | ... | @@ -230,13 +233,15 @@ |
230 | angular.module('onosUtil') | 233 | angular.module('onosUtil') |
231 | .factory('KeyService', | 234 | .factory('KeyService', |
232 | ['$log', '$timeout', 'FnService', 'ThemeService', 'NavService', | 235 | ['$log', '$timeout', 'FnService', 'ThemeService', 'NavService', |
236 | + 'EeService', | ||
233 | 237 | ||
234 | - function (_$log_, _$timeout_, _fs_, _ts_, _ns_) { | 238 | + function (_$log_, _$timeout_, _fs_, _ts_, _ns_, _ee_) { |
235 | $log = _$log_; | 239 | $log = _$log_; |
236 | $timeout = _$timeout_; | 240 | $timeout = _$timeout_; |
237 | fs = _fs_; | 241 | fs = _fs_; |
238 | ts = _ts_; | 242 | ts = _ts_; |
239 | ns = _ns_; | 243 | ns = _ns_; |
244 | + ee = _ee_; | ||
240 | 245 | ||
241 | return { | 246 | return { |
242 | bindQhs: function (_qhs_) { | 247 | bindQhs: function (_qhs_) { |
... | @@ -254,6 +259,12 @@ | ... | @@ -254,6 +259,12 @@ |
254 | } | 259 | } |
255 | }, | 260 | }, |
256 | unbindKeys: unbindKeys, | 261 | unbindKeys: unbindKeys, |
262 | + addSeq: function (word, data) { | ||
263 | + fs.addToTrie(seq, word, data); | ||
264 | + }, | ||
265 | + remSeq: function (word) { | ||
266 | + fs.removeFromTrie(seq, word); | ||
267 | + }, | ||
257 | gestureNotes: function (g) { | 268 | gestureNotes: function (g) { |
258 | if (g === undefined) { | 269 | if (g === undefined) { |
259 | return keyHandler.viewGestures; | 270 | return keyHandler.viewGestures; | ... | ... |
... | @@ -21,6 +21,9 @@ | ... | @@ -21,6 +21,9 @@ |
21 | (function () { | 21 | (function () { |
22 | 'use strict'; | 22 | 'use strict'; |
23 | 23 | ||
24 | + // injected refs | ||
25 | + var $log; | ||
26 | + | ||
24 | // define core module dependencies here... | 27 | // define core module dependencies here... |
25 | var coreDependencies = [ | 28 | var coreDependencies = [ |
26 | 'ngRoute', | 29 | 'ngRoute', |
... | @@ -41,6 +44,18 @@ | ... | @@ -41,6 +44,18 @@ |
41 | '' | 44 | '' |
42 | ]; | 45 | ]; |
43 | 46 | ||
47 | + // secret sauce | ||
48 | + var sauce = [ | ||
49 | + '20:70717066', | ||
50 | + '24:886774868469', | ||
51 | + '6:698570688669887967', | ||
52 | + '7:6971806889847186', | ||
53 | + '22:8369867682', | ||
54 | + '13:736583', | ||
55 | + '7:667186698384', | ||
56 | + '1:857780888778876787' | ||
57 | + ]; | ||
58 | + | ||
44 | var defaultView = 'topo', | 59 | var defaultView = 'topo', |
45 | viewDependencies = []; | 60 | viewDependencies = []; |
46 | 61 | ||
... | @@ -52,6 +67,13 @@ | ... | @@ -52,6 +67,13 @@ |
52 | 67 | ||
53 | var moduleDependencies = coreDependencies.concat(viewDependencies); | 68 | var moduleDependencies = coreDependencies.concat(viewDependencies); |
54 | 69 | ||
70 | + function saucy(ee, ks) { | ||
71 | + var map = ee.genMap(sauce); | ||
72 | + Object.keys(map).forEach(function (k) { | ||
73 | + ks.addSeq(k, map[k]); | ||
74 | + }); | ||
75 | + } | ||
76 | + | ||
55 | function cap(s) { | 77 | function cap(s) { |
56 | return s ? s[0].toUpperCase() + s.slice(1) : s; | 78 | return s ? s[0].toUpperCase() + s.slice(1) : s; |
57 | } | 79 | } |
... | @@ -61,17 +83,18 @@ | ... | @@ -61,17 +83,18 @@ |
61 | .controller('OnosCtrl', [ | 83 | .controller('OnosCtrl', [ |
62 | '$log', '$scope', '$route', '$routeParams', '$location', | 84 | '$log', '$scope', '$route', '$routeParams', '$location', |
63 | 'KeyService', 'ThemeService', 'GlyphService', 'VeilService', | 85 | 'KeyService', 'ThemeService', 'GlyphService', 'VeilService', |
64 | - 'PanelService', 'FlashService', 'QuickHelpService', | 86 | + 'PanelService', 'FlashService', 'QuickHelpService', 'EeService', |
65 | 'WebSocketService', | 87 | 'WebSocketService', |
66 | 88 | ||
67 | - function ($log, $scope, $route, $routeParams, $location, | 89 | + function (_$log_, $scope, $route, $routeParams, $location, |
68 | - ks, ts, gs, vs, ps, flash, qhs, wss) { | 90 | + ks, ts, gs, vs, ps, flash, qhs, ee, wss) { |
69 | var self = this; | 91 | var self = this; |
92 | + $log = _$log_; | ||
70 | 93 | ||
71 | self.$route = $route; | 94 | self.$route = $route; |
72 | self.$routeParams = $routeParams; | 95 | self.$routeParams = $routeParams; |
73 | self.$location = $location; | 96 | self.$location = $location; |
74 | - self.version = '1.3.0'; | 97 | + self.version = '1.5.0'; |
75 | 98 | ||
76 | // shared object inherited by all views: | 99 | // shared object inherited by all views: |
77 | $scope.onos = {}; | 100 | $scope.onos = {}; |
... | @@ -83,6 +106,7 @@ | ... | @@ -83,6 +106,7 @@ |
83 | gs.init(); | 106 | gs.init(); |
84 | vs.init(); | 107 | vs.init(); |
85 | ps.init(); | 108 | ps.init(); |
109 | + saucy(ee, ks); | ||
86 | flash.initFlash(); | 110 | flash.initFlash(); |
87 | qhs.initQuickHelp(); | 111 | qhs.initQuickHelp(); |
88 | 112 | ... | ... |
No preview for this file type
-
Please register or login to post a comment