From 6e284dfd7e196d9504ee4209b3d3193d2c648e76 Mon Sep 17 00:00:00 2001 From: Mario Volke Date: Mon, 10 Nov 2014 14:14:34 +0100 Subject: [PATCH] refactored focusMe directive into common directives as woFocusMe --- src/js/controller/write.js | 23 ----------------------- src/js/directive/common.js | 20 ++++++++++++++++++++ src/tpl/action-bar.html | 2 +- src/tpl/create-account.html | 2 +- src/tpl/login-existing.html | 2 +- src/tpl/login-privatekey-download.html | 4 ++-- src/tpl/login-set-credentials.html | 2 +- src/tpl/mail-list.html | 2 +- src/tpl/privatekey-upload.html | 4 ++-- src/tpl/set-passphrase.html | 2 +- src/tpl/validate-phone.html | 2 +- src/tpl/write.html | 2 +- 12 files changed, 32 insertions(+), 35 deletions(-) diff --git a/src/js/controller/write.js b/src/js/controller/write.js index 3be3deb..5713ec6 100644 --- a/src/js/controller/write.js +++ b/src/js/controller/write.js @@ -448,29 +448,6 @@ var WriteCtrl = function($scope, $filter, $q) { var ngModule = angular.module('write', []); -ngModule.directive('focusMe', function($timeout, $parse) { - return { - //scope: true, // optionally create a child scope - link: function(scope, element, attrs) { - var model = $parse(attrs.focusMe); - scope.$watch(model, function(value) { - if (value === true) { - $timeout(function() { - var el = element[0]; - el.focus(); - // set cursor to start of textarea - if (el.type === 'textarea') { - el.selectionStart = 0; - el.selectionEnd = 0; - el.scrollTop = 0; - } - }, 100); - } - }); - } - }; -}); - ngModule.directive('focusInput', function($timeout, $parse) { return { //scope: true, // optionally create a child scope diff --git a/src/js/directive/common.js b/src/js/directive/common.js index e34cb8d..52dc403 100644 --- a/src/js/directive/common.js +++ b/src/js/directive/common.js @@ -143,4 +143,24 @@ ngModule.directive('woDropdown', function($document, $timeout) { }; }); +ngModule.directive('woFocusMe', function($timeout, $parse) { + return function(scope, element, attrs) { + var model = $parse(attrs.woFocusMe); + scope.$watch(model, function(value) { + if (value === true) { + $timeout(function() { + var el = element[0]; + el.focus(); + // set cursor to start of textarea + if (el.type === 'textarea') { + el.selectionStart = 0; + el.selectionEnd = 0; + el.scrollTop = 0; + } + }, 100); + } + }); + }; +}); + module.exports = ngModule; \ No newline at end of file diff --git a/src/tpl/action-bar.html b/src/tpl/action-bar.html index 44f9b5a..4598bb4 100644 --- a/src/tpl/action-bar.html +++ b/src/tpl/action-bar.html @@ -20,7 +20,7 @@ Search + placeholder="Search" wo-focus-me="state.mailList.searching"> diff --git a/src/tpl/create-account.html b/src/tpl/create-account.html index aca0e1f..f946074 100644 --- a/src/tpl/create-account.html +++ b/src/tpl/create-account.html @@ -10,7 +10,7 @@

{{errMsg}}

- @wmail.io diff --git a/src/tpl/login-existing.html b/src/tpl/login-existing.html index 5f543db..cb8e642 100644 --- a/src/tpl/login-existing.html +++ b/src/tpl/login-existing.html @@ -12,7 +12,7 @@
+ placeholder="Passphrase" tabindex="1" wo-focus-me="true" required>
diff --git a/src/tpl/login-privatekey-download.html b/src/tpl/login-privatekey-download.html index c55ed18..578bbc8 100644 --- a/src/tpl/login-privatekey-download.html +++ b/src/tpl/login-privatekey-download.html @@ -13,7 +13,7 @@
+ size="6" maxlength="6" ng-model="recoveryToken" placeholder="Token" wo-focus-me="step === 1" pattern="([a-zA-Z0-9]*)" required>
@@ -44,7 +44,7 @@
- - + - - - - diff --git a/src/tpl/login-set-credentials.html b/src/tpl/login-set-credentials.html index 8995013..8a978e3 100644 --- a/src/tpl/login-set-credentials.html +++ b/src/tpl/login-set-credentials.html @@ -32,7 +32,7 @@
+ placeholder="Full name (optional)" wo-focus-me="true" tabindex="2">
Search + placeholder="Search" wo-focus-me="state.mailList.searching">
diff --git a/src/tpl/privatekey-upload.html b/src/tpl/privatekey-upload.html index 6dd73dc..764565a 100644 --- a/src/tpl/privatekey-upload.html +++ b/src/tpl/privatekey-upload.html @@ -26,7 +26,7 @@

Please confirm the keychain code you have written down.

- - + - - - - @@ -39,7 +39,7 @@

Please enter a memorable name for this device e.g. “MacBook Work”.

- +
diff --git a/src/tpl/set-passphrase.html b/src/tpl/set-passphrase.html index 42195de..da781cf 100644 --- a/src/tpl/set-passphrase.html +++ b/src/tpl/set-passphrase.html @@ -13,7 +13,7 @@
- +

{{passphraseMsg}}

diff --git a/src/tpl/validate-phone.html b/src/tpl/validate-phone.html index b9f1533..c2e91f1 100644 --- a/src/tpl/validate-phone.html +++ b/src/tpl/validate-phone.html @@ -10,7 +10,7 @@

{{errMsg}}

+ size="6" maxlength="6" ng-model="token" placeholder="Code" required pattern="([a-zA-Z0-9]*)" wo-focus-me="true" tabindex="1">
diff --git a/src/tpl/write.html b/src/tpl/write.html index 0f36a74..db6c120 100644 --- a/src/tpl/write.html +++ b/src/tpl/write.html @@ -64,7 +64,7 @@ - +