From bd02f0f66a2c2347166c7fdaa09ba36afab338f6 Mon Sep 17 00:00:00 2001 From: Leonardo Merlin Date: Wed, 18 Nov 2015 13:50:44 -0200 Subject: [PATCH] Fixes #1 --- src/app/components/a11y-bar/a11y-bar.html | 2 +- src/app/index.run.js | 260 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------- 2 files changed, 161 insertions(+), 101 deletions(-) diff --git a/src/app/components/a11y-bar/a11y-bar.html b/src/app/components/a11y-bar/a11y-bar.html index 93395ed..63fed64 100644 --- a/src/app/components/a11y-bar/a11y-bar.html +++ b/src/app/components/a11y-bar/a11y-bar.html @@ -16,7 +16,7 @@
  • - + Ir para a busca 3 diff --git a/src/app/index.run.js b/src/app/index.run.js index 5986da8..7299514 100644 --- a/src/app/index.run.js +++ b/src/app/index.run.js @@ -7,7 +7,7 @@ .run(runAccessibility) .run(runAuth) .run(runCaptcha) - .run(runColorUtils) + // .run(runColorUtils) .run(runHistory) .run(runPath) .run(runSocialAuth) @@ -16,6 +16,118 @@ .run(runBlock); /** @ngInject */ + function runAccessibility($rootScope, $timeout, $interval, $cookies, $state, $log) { + + var contrast = $cookies.get('dialoga_contraste') === 'true'; + adjustContrast(contrast); + + function adjustContrast(state) { + var bodyEl = angular.element(document).find('body'); + angular.element(bodyEl).toggleClass('contraste', !!state); + } + + $rootScope.actionContrast = function() { + // toggle contrast + contrast = !contrast; + $cookies.put('dialoga_contraste', contrast); + adjustContrast(contrast); + }; + + $rootScope.focusOn = function(elId, $event) { + var el = angular.element(elId); + $rootScope.scrollTo(el, $event); + el.attr('tabIndex', -1).focus(); + }; + + $rootScope.focusMainContent = function($event) { + + var mainContentArea = document.querySelector('[role="main"]'); + + if (mainContentArea) { + $timeout(function() { + $rootScope.scrollTo(angular.element(mainContentArea), $event); + }, 90); // force queue + } else { + $log.info('role="main" not found.'); + } + }; + + $rootScope.focusOnSearch = function($event) { + + // prevent skip link from redirecting + if ($event) { $event.preventDefault(); } + + // find a input search + var $searchEl = angular.element('input[type="search"]:visible'); + + if($searchEl && $searchEl.length > 0){ + // scroll + angular.element('html,body').animate({scrollTop: $searchEl.offset().top}, 'fast'); + // focus + $searchEl.focus(); + } else { + // input search not found + + // 1. redirect to home + var promise = $state.go('inicio', { reload: true}); + + // 2. focus on input search at home. + promise.then(function(){ + + findElAsync('input[type="search"]:visible', function ($el) { + // scroll + angular.element('html,body').animate({scrollTop: $el.offset().top}, 'fast'); + // focus + $el.focus(); + }); + }); + } + + // use jQuery and $interval to find element async. + function findElAsync(query, cb, delay, max_exec) { + delay = delay || 200; + max_exec = max_exec || 20; + var count_exec = 0; + + var stop = null; + stop = $interval(function() { + var $el = angular.element(query); + + if ($el && $el.length > 0) { + cb($el); + }else { + $log.debug('[findElAsync] element not found.'); + } + + count_exec++; + + if (count_exec >= max_exec){ + $interval.cancel(stop); + stop = undefined; + } + + }, delay); + } + + $log.debug('TODO: focusOnSearch'); + }; + + $rootScope.scrollTo = function(target, $event) { + + // prevent skip link from redirecting + if ($event) { $event.preventDefault(); } + + if (angular.isString(target)) { + target = angular.element(target); + } + + angular.element('html,body').animate({scrollTop: target.offset().top}, 'fast'); + }; + + $log.debug('[RUN] Accessibility end.'); + } + + /** @ngInject */ function runAuth($rootScope, $localStorage, USER_ROLES, AUTH_EVENTS, AuthService, $log) { // Listner url/state changes, and check permission @@ -82,89 +194,32 @@ $log.debug('runCaptcha'); } - /** @ngInject */ - function runSocialAuth($window, $rootScope, $interval) { + // /** @ngInject */ + // function runColorUtils($window) { - $window.oauthClientAction = function(url) { - var child = $window.open(url, '_blank'); - var interval = $interval(function() { - try { - if (!child.closed) { - child.postMessage({ - message: 'requestOauthClientPluginResult' - }, '*'); - } - } catch (e) { - // we're here when the child window has been navigated away or closed - if (child.closed) { - $interval.cancel(interval); - interval = undefined; - } - } - }, 300); - }; + // $window.ColorLuminance = function(hex, lum) { - $window.addEventListener('message', function(eventMessage) { - // $log.debug('eventMessage', eventMessage); + // // validate hex string + // hex = String(hex).replace(/[^0-9a-f]/gi, ''); + // if (hex.length < 6) { + // hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; + // } + // lum = lum || 0; - if (eventMessage.data.message === 'oauthClientPluginResult') { - $rootScope.$broadcast('oauthClientPluginResult', eventMessage); - // eventMessage.source.close(); - } - }); - } + // // convert to decimal and change luminosity + // var rgb = '#'; + // var c; + // var i; - /** @ngInject */ - function runAccessibility($rootScope, $timeout, $cookies, $log) { - - var contrast = $cookies.get('dialoga_contraste') === 'true'; - adjustContrast(contrast); + // for (i = 0; i < 3; i++) { + // c = parseInt(hex.substr(i * 2, 2), 16); + // c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16); + // rgb += ('00' + c).substr(c.length); + // } - function adjustContrast(state) { - var bodyEl = angular.element(document).find('body'); - angular.element(bodyEl).toggleClass('contraste', !!state); - } - - $rootScope.actionContrast = function() { - // toggle contrast - contrast = !contrast; - $cookies.put('dialoga_contraste', contrast); - adjustContrast(contrast); - }; - - $rootScope.focusOn = function(elId, $event) { - var el = angular.element(elId); - $rootScope.scrollTo(el, $event); - el.attr('tabIndex', -1).focus(); - }; - - $rootScope.focusMainContent = function($event) { - - var mainContentArea = document.querySelector('[role="main"]'); - - if (mainContentArea) { - $timeout(function() { - $rootScope.scrollTo(angular.element(mainContentArea), $event); - }, 90); // force queue - } else { - $log.info('role="main" not found.'); - } - }; - - $rootScope.scrollTo = function(target, $event) { - - // prevent skip link from redirecting - if ($event) { $event.preventDefault(); } - - if (angular.isString(target)) { - target = angular.element(target); - } - - angular.element('body').animate({scrollTop: target.offset().top}, 'fast'); - }; - - $log.debug('[RUN] Accessibility end.'); - } + // return rgb; + // }; + // } /** @ngInject */ function runHistory($rootScope) { @@ -188,30 +243,35 @@ } /** @ngInject */ - function runColorUtils($window) { - - $window.ColorLuminance = function(hex, lum) { + function runSocialAuth($window, $rootScope, $interval) { - // validate hex string - hex = String(hex).replace(/[^0-9a-f]/gi, ''); - if (hex.length < 6) { - hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; - } - lum = lum || 0; + $window.oauthClientAction = function(url) { + var child = $window.open(url, '_blank'); + var interval = $interval(function() { + try { + if (!child.closed) { + child.postMessage({ + message: 'requestOauthClientPluginResult' + }, '*'); + } + } catch (e) { + // we're here when the child window has been navigated away or closed + if (child.closed) { + $interval.cancel(interval); + interval = undefined; + } + } + }, 300); + }; - // convert to decimal and change luminosity - var rgb = '#'; - var c; - var i; + $window.addEventListener('message', function(eventMessage) { + // $log.debug('eventMessage', eventMessage); - for (i = 0; i < 3; i++) { - c = parseInt(hex.substr(i * 2, 2), 16); - c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16); - rgb += ('00' + c).substr(c.length); + if (eventMessage.data.message === 'oauthClientPluginResult') { + $rootScope.$broadcast('oauthClientPluginResult', eventMessage); + // eventMessage.source.close(); } - - return rgb; - }; + }); } /** @ngInject */ @@ -221,7 +281,7 @@ if($resultEl && $resultEl.length > 0){ $rootScope.scrollTo($resultEl); - // angular.element('body').animate({scrollTop: $resultEl.offset().top}, 'fast'); + // angular.element('html,body').animate({scrollTop: $resultEl.offset().top}, 'fast'); } }); } -- libgit2 0.21.2