Commit bd02f0f66a2c2347166c7fdaa09ba36afab338f6
1 parent
3e7217e8
Exists in
master
and in
6 other branches
Fixes #1
Showing
2 changed files
with
161 additions
and
101 deletions
Show diff stats
src/app/components/a11y-bar/a11y-bar.html
@@ -16,7 +16,7 @@ | @@ -16,7 +16,7 @@ | ||
16 | </a> | 16 | </a> |
17 | </li> | 17 | </li> |
18 | <li> | 18 | <li> |
19 | - <a class="color-theme-common-fg" accesskey="3" id="skip-to-search" ui-sref="inicio({scroll:'lista-de-programas'})" ui-sref-opts="{reload: true}"> | 19 | + <a class="color-theme-common-fg" accesskey="3" id="skip-to-search" href="#search" ng-click="focusOnSearch($event)"> |
20 | Ir para a busca | 20 | Ir para a busca |
21 | <span class="color-theme-common-bg">3</span> | 21 | <span class="color-theme-common-bg">3</span> |
22 | </a> | 22 | </a> |
src/app/index.run.js
@@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
7 | .run(runAccessibility) | 7 | .run(runAccessibility) |
8 | .run(runAuth) | 8 | .run(runAuth) |
9 | .run(runCaptcha) | 9 | .run(runCaptcha) |
10 | - .run(runColorUtils) | 10 | + // .run(runColorUtils) |
11 | .run(runHistory) | 11 | .run(runHistory) |
12 | .run(runPath) | 12 | .run(runPath) |
13 | .run(runSocialAuth) | 13 | .run(runSocialAuth) |
@@ -16,6 +16,118 @@ | @@ -16,6 +16,118 @@ | ||
16 | .run(runBlock); | 16 | .run(runBlock); |
17 | 17 | ||
18 | /** @ngInject */ | 18 | /** @ngInject */ |
19 | + function runAccessibility($rootScope, $timeout, $interval, $cookies, $state, $log) { | ||
20 | + | ||
21 | + var contrast = $cookies.get('dialoga_contraste') === 'true'; | ||
22 | + adjustContrast(contrast); | ||
23 | + | ||
24 | + function adjustContrast(state) { | ||
25 | + var bodyEl = angular.element(document).find('body'); | ||
26 | + angular.element(bodyEl).toggleClass('contraste', !!state); | ||
27 | + } | ||
28 | + | ||
29 | + $rootScope.actionContrast = function() { | ||
30 | + // toggle contrast | ||
31 | + contrast = !contrast; | ||
32 | + $cookies.put('dialoga_contraste', contrast); | ||
33 | + adjustContrast(contrast); | ||
34 | + }; | ||
35 | + | ||
36 | + $rootScope.focusOn = function(elId, $event) { | ||
37 | + var el = angular.element(elId); | ||
38 | + $rootScope.scrollTo(el, $event); | ||
39 | + el.attr('tabIndex', -1).focus(); | ||
40 | + }; | ||
41 | + | ||
42 | + $rootScope.focusMainContent = function($event) { | ||
43 | + | ||
44 | + var mainContentArea = document.querySelector('[role="main"]'); | ||
45 | + | ||
46 | + if (mainContentArea) { | ||
47 | + $timeout(function() { | ||
48 | + $rootScope.scrollTo(angular.element(mainContentArea), $event); | ||
49 | + }, 90); // force queue | ||
50 | + } else { | ||
51 | + $log.info('role="main" not found.'); | ||
52 | + } | ||
53 | + }; | ||
54 | + | ||
55 | + $rootScope.focusOnSearch = function($event) { | ||
56 | + | ||
57 | + // prevent skip link from redirecting | ||
58 | + if ($event) { $event.preventDefault(); } | ||
59 | + | ||
60 | + // find a input search | ||
61 | + var $searchEl = angular.element('input[type="search"]:visible'); | ||
62 | + | ||
63 | + if($searchEl && $searchEl.length > 0){ | ||
64 | + // scroll | ||
65 | + angular.element('html,body').animate({scrollTop: $searchEl.offset().top}, 'fast'); | ||
66 | + // focus | ||
67 | + $searchEl.focus(); | ||
68 | + } else { | ||
69 | + // input search not found | ||
70 | + | ||
71 | + // 1. redirect to home | ||
72 | + var promise = $state.go('inicio', { reload: true}); | ||
73 | + | ||
74 | + // 2. focus on input search at home. | ||
75 | + promise.then(function(){ | ||
76 | + | ||
77 | + findElAsync('input[type="search"]:visible', function ($el) { | ||
78 | + // scroll | ||
79 | + angular.element('html,body').animate({scrollTop: $el.offset().top}, 'fast'); | ||
80 | + // focus | ||
81 | + $el.focus(); | ||
82 | + }); | ||
83 | + }); | ||
84 | + } | ||
85 | + | ||
86 | + // use jQuery and $interval to find element async. | ||
87 | + function findElAsync(query, cb, delay, max_exec) { | ||
88 | + delay = delay || 200; | ||
89 | + max_exec = max_exec || 20; | ||
90 | + var count_exec = 0; | ||
91 | + | ||
92 | + var stop = null; | ||
93 | + stop = $interval(function() { | ||
94 | + var $el = angular.element(query); | ||
95 | + | ||
96 | + if ($el && $el.length > 0) { | ||
97 | + cb($el); | ||
98 | + }else { | ||
99 | + $log.debug('[findElAsync] element not found.'); | ||
100 | + } | ||
101 | + | ||
102 | + count_exec++; | ||
103 | + | ||
104 | + if (count_exec >= max_exec){ | ||
105 | + $interval.cancel(stop); | ||
106 | + stop = undefined; | ||
107 | + } | ||
108 | + | ||
109 | + }, delay); | ||
110 | + } | ||
111 | + | ||
112 | + $log.debug('TODO: focusOnSearch'); | ||
113 | + }; | ||
114 | + | ||
115 | + $rootScope.scrollTo = function(target, $event) { | ||
116 | + | ||
117 | + // prevent skip link from redirecting | ||
118 | + if ($event) { $event.preventDefault(); } | ||
119 | + | ||
120 | + if (angular.isString(target)) { | ||
121 | + target = angular.element(target); | ||
122 | + } | ||
123 | + | ||
124 | + angular.element('html,body').animate({scrollTop: target.offset().top}, 'fast'); | ||
125 | + }; | ||
126 | + | ||
127 | + $log.debug('[RUN] Accessibility end.'); | ||
128 | + } | ||
129 | + | ||
130 | + /** @ngInject */ | ||
19 | function runAuth($rootScope, $localStorage, USER_ROLES, AUTH_EVENTS, AuthService, $log) { | 131 | function runAuth($rootScope, $localStorage, USER_ROLES, AUTH_EVENTS, AuthService, $log) { |
20 | 132 | ||
21 | // Listner url/state changes, and check permission | 133 | // Listner url/state changes, and check permission |
@@ -82,89 +194,32 @@ | @@ -82,89 +194,32 @@ | ||
82 | $log.debug('runCaptcha'); | 194 | $log.debug('runCaptcha'); |
83 | } | 195 | } |
84 | 196 | ||
85 | - /** @ngInject */ | ||
86 | - function runSocialAuth($window, $rootScope, $interval) { | 197 | + // /** @ngInject */ |
198 | + // function runColorUtils($window) { | ||
87 | 199 | ||
88 | - $window.oauthClientAction = function(url) { | ||
89 | - var child = $window.open(url, '_blank'); | ||
90 | - var interval = $interval(function() { | ||
91 | - try { | ||
92 | - if (!child.closed) { | ||
93 | - child.postMessage({ | ||
94 | - message: 'requestOauthClientPluginResult' | ||
95 | - }, '*'); | ||
96 | - } | ||
97 | - } catch (e) { | ||
98 | - // we're here when the child window has been navigated away or closed | ||
99 | - if (child.closed) { | ||
100 | - $interval.cancel(interval); | ||
101 | - interval = undefined; | ||
102 | - } | ||
103 | - } | ||
104 | - }, 300); | ||
105 | - }; | 200 | + // $window.ColorLuminance = function(hex, lum) { |
106 | 201 | ||
107 | - $window.addEventListener('message', function(eventMessage) { | ||
108 | - // $log.debug('eventMessage', eventMessage); | 202 | + // // validate hex string |
203 | + // hex = String(hex).replace(/[^0-9a-f]/gi, ''); | ||
204 | + // if (hex.length < 6) { | ||
205 | + // hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; | ||
206 | + // } | ||
207 | + // lum = lum || 0; | ||
109 | 208 | ||
110 | - if (eventMessage.data.message === 'oauthClientPluginResult') { | ||
111 | - $rootScope.$broadcast('oauthClientPluginResult', eventMessage); | ||
112 | - // eventMessage.source.close(); | ||
113 | - } | ||
114 | - }); | ||
115 | - } | 209 | + // // convert to decimal and change luminosity |
210 | + // var rgb = '#'; | ||
211 | + // var c; | ||
212 | + // var i; | ||
116 | 213 | ||
117 | - /** @ngInject */ | ||
118 | - function runAccessibility($rootScope, $timeout, $cookies, $log) { | ||
119 | - | ||
120 | - var contrast = $cookies.get('dialoga_contraste') === 'true'; | ||
121 | - adjustContrast(contrast); | 214 | + // for (i = 0; i < 3; i++) { |
215 | + // c = parseInt(hex.substr(i * 2, 2), 16); | ||
216 | + // c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16); | ||
217 | + // rgb += ('00' + c).substr(c.length); | ||
218 | + // } | ||
122 | 219 | ||
123 | - function adjustContrast(state) { | ||
124 | - var bodyEl = angular.element(document).find('body'); | ||
125 | - angular.element(bodyEl).toggleClass('contraste', !!state); | ||
126 | - } | ||
127 | - | ||
128 | - $rootScope.actionContrast = function() { | ||
129 | - // toggle contrast | ||
130 | - contrast = !contrast; | ||
131 | - $cookies.put('dialoga_contraste', contrast); | ||
132 | - adjustContrast(contrast); | ||
133 | - }; | ||
134 | - | ||
135 | - $rootScope.focusOn = function(elId, $event) { | ||
136 | - var el = angular.element(elId); | ||
137 | - $rootScope.scrollTo(el, $event); | ||
138 | - el.attr('tabIndex', -1).focus(); | ||
139 | - }; | ||
140 | - | ||
141 | - $rootScope.focusMainContent = function($event) { | ||
142 | - | ||
143 | - var mainContentArea = document.querySelector('[role="main"]'); | ||
144 | - | ||
145 | - if (mainContentArea) { | ||
146 | - $timeout(function() { | ||
147 | - $rootScope.scrollTo(angular.element(mainContentArea), $event); | ||
148 | - }, 90); // force queue | ||
149 | - } else { | ||
150 | - $log.info('role="main" not found.'); | ||
151 | - } | ||
152 | - }; | ||
153 | - | ||
154 | - $rootScope.scrollTo = function(target, $event) { | ||
155 | - | ||
156 | - // prevent skip link from redirecting | ||
157 | - if ($event) { $event.preventDefault(); } | ||
158 | - | ||
159 | - if (angular.isString(target)) { | ||
160 | - target = angular.element(target); | ||
161 | - } | ||
162 | - | ||
163 | - angular.element('body').animate({scrollTop: target.offset().top}, 'fast'); | ||
164 | - }; | ||
165 | - | ||
166 | - $log.debug('[RUN] Accessibility end.'); | ||
167 | - } | 220 | + // return rgb; |
221 | + // }; | ||
222 | + // } | ||
168 | 223 | ||
169 | /** @ngInject */ | 224 | /** @ngInject */ |
170 | function runHistory($rootScope) { | 225 | function runHistory($rootScope) { |
@@ -188,30 +243,35 @@ | @@ -188,30 +243,35 @@ | ||
188 | } | 243 | } |
189 | 244 | ||
190 | /** @ngInject */ | 245 | /** @ngInject */ |
191 | - function runColorUtils($window) { | ||
192 | - | ||
193 | - $window.ColorLuminance = function(hex, lum) { | 246 | + function runSocialAuth($window, $rootScope, $interval) { |
194 | 247 | ||
195 | - // validate hex string | ||
196 | - hex = String(hex).replace(/[^0-9a-f]/gi, ''); | ||
197 | - if (hex.length < 6) { | ||
198 | - hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; | ||
199 | - } | ||
200 | - lum = lum || 0; | 248 | + $window.oauthClientAction = function(url) { |
249 | + var child = $window.open(url, '_blank'); | ||
250 | + var interval = $interval(function() { | ||
251 | + try { | ||
252 | + if (!child.closed) { | ||
253 | + child.postMessage({ | ||
254 | + message: 'requestOauthClientPluginResult' | ||
255 | + }, '*'); | ||
256 | + } | ||
257 | + } catch (e) { | ||
258 | + // we're here when the child window has been navigated away or closed | ||
259 | + if (child.closed) { | ||
260 | + $interval.cancel(interval); | ||
261 | + interval = undefined; | ||
262 | + } | ||
263 | + } | ||
264 | + }, 300); | ||
265 | + }; | ||
201 | 266 | ||
202 | - // convert to decimal and change luminosity | ||
203 | - var rgb = '#'; | ||
204 | - var c; | ||
205 | - var i; | 267 | + $window.addEventListener('message', function(eventMessage) { |
268 | + // $log.debug('eventMessage', eventMessage); | ||
206 | 269 | ||
207 | - for (i = 0; i < 3; i++) { | ||
208 | - c = parseInt(hex.substr(i * 2, 2), 16); | ||
209 | - c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16); | ||
210 | - rgb += ('00' + c).substr(c.length); | 270 | + if (eventMessage.data.message === 'oauthClientPluginResult') { |
271 | + $rootScope.$broadcast('oauthClientPluginResult', eventMessage); | ||
272 | + // eventMessage.source.close(); | ||
211 | } | 273 | } |
212 | - | ||
213 | - return rgb; | ||
214 | - }; | 274 | + }); |
215 | } | 275 | } |
216 | 276 | ||
217 | /** @ngInject */ | 277 | /** @ngInject */ |
@@ -221,7 +281,7 @@ | @@ -221,7 +281,7 @@ | ||
221 | 281 | ||
222 | if($resultEl && $resultEl.length > 0){ | 282 | if($resultEl && $resultEl.length > 0){ |
223 | $rootScope.scrollTo($resultEl); | 283 | $rootScope.scrollTo($resultEl); |
224 | - // angular.element('body').animate({scrollTop: $resultEl.offset().top}, 'fast'); | 284 | + // angular.element('html,body').animate({scrollTop: $resultEl.offset().top}, 'fast'); |
225 | } | 285 | } |
226 | }); | 286 | }); |
227 | } | 287 | } |