From 62ce7bea603a1963b1dada41f46fe4d1fdf79b70 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Sun, 13 Oct 2013 12:46:24 +0200 Subject: [PATCH] add keyboard shortcuts --- src/index.html | 2 +- src/js/app.js | 2 +- src/js/controller/mail-list.js | 2 +- src/js/controller/navigation.js | 25 ++++++++++++++++++++++++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/index.html b/src/index.html index 4bf1faf..3b5aea0 100755 --- a/src/index.html +++ b/src/index.html @@ -16,7 +16,7 @@ - +
diff --git a/src/js/app.js b/src/js/app.js index 7c7a6fd..1b2d983 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -13,7 +13,7 @@ require([ ], function(angular, LoginCtrl, MailListCtrl, ReadCtrl, WriteCtrl, NavigationCtrl) { 'use strict'; - var app = angular.module('mail', ['ngRoute', 'ngTouch', 'write', 'read']); + var app = angular.module('mail', ['ngRoute', 'ngTouch', 'navigation', 'write', 'read']); // set router paths app.config(function($routeProvider) { diff --git a/src/js/controller/mail-list.js b/src/js/controller/mail-list.js index 1acd66d..74b2028 100644 --- a/src/js/controller/mail-list.js +++ b/src/js/controller/mail-list.js @@ -73,7 +73,6 @@ define(function(require) { // function initList() { - firstSelect = true; updateStatus('Read cache ...'); // list messaged from local db @@ -116,6 +115,7 @@ define(function(require) { } function listLocalMessages(options, callback) { + firstSelect = true; emailDao.listMessages(options, function(err, emails) { if (err) { console.log(err); diff --git a/src/js/controller/navigation.js b/src/js/controller/navigation.js index 7c2ea15..b825bf3 100644 --- a/src/js/controller/navigation.js +++ b/src/js/controller/navigation.js @@ -1,7 +1,8 @@ define(function(require) { 'use strict'; - var appController = require('js/app-controller'), + var angular = require('angular'), + appController = require('js/app-controller'), emailDao; var NavigationCtrl = function($scope) { @@ -86,5 +87,27 @@ define(function(require) { } }; + // + // Directives + // + + var ngModule = angular.module('navigation', []); + ngModule.directive('keyShortcuts', function() { + return function(scope, elm) { + elm.bind('keydown', function(e) { + if (e.keyCode === 78 && scope.$$childTail && scope.$$childTail.write) { + // n + e.preventDefault(); + return scope.$$childTail.write(); + + } else if (e.keyCode === 82 && scope.$$childTail && scope.$$childTail.write && scope.$$childTail.selected) { + // r + e.preventDefault(); + return scope.$$childTail.write(scope.$$childTail.selected); + } + }); + }; + }); + return NavigationCtrl; }); \ No newline at end of file