diff --git a/public/scripts/app-angular.js b/public/scripts/app-angular.js index 8d1133e..a13061d 100644 --- a/public/scripts/app-angular.js +++ b/public/scripts/app-angular.js @@ -29,6 +29,7 @@ app.config(function($stateProvider, $urlRouterProvider, $httpProvider) { templateUrl: '/views/note.html', params: { searchWord: null, + key:null, }, controller: 'noteCtr' }) diff --git a/public/scripts/controllers/edit-controller.js b/public/scripts/controllers/edit-controller.js index ae9ed67..38a0973 100644 --- a/public/scripts/controllers/edit-controller.js +++ b/public/scripts/controllers/edit-controller.js @@ -209,10 +209,10 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', '$document', 'bookmar // 在输入文字的时候也会触发,所以不要用Ctrl,Shift之类的按键 $document.bind("keydown", function(event) { $scope.$apply(function() { - // console.log(event.keyCode); var menusScope = $('div[ng-controller="menuCtr"]').scope(); - // Insert按键,显示 - if (event.keyCode == 45 && menusScope.login) { + var key = event.key.toUpperCase(); + // console.log(key); + if (key == 'INSERT' && menusScope.login) { if ($('.ui.modal.js-add-bookmark').modal('is active')) { $scope.ok(); } else { @@ -228,7 +228,7 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', '$document', 'bookmar } // Esc按键,退出 - if (event.keyCode == 27 && menusScope.login) { + if (key == 'ESCAPE' && menusScope.login) { $scope.cancel(); } }) diff --git a/public/scripts/controllers/menus-controller.js b/public/scripts/controllers/menus-controller.js index 09c658d..f7bc6f8 100644 --- a/public/scripts/controllers/menus-controller.js +++ b/public/scripts/controllers/menus-controller.js @@ -195,6 +195,18 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time $scope.$apply(function() { if (dataService.keyShortcuts()) { var key = event.key.toUpperCase(); + // 全局处理添加备忘录 + if (key == 'A') { + if ($scope.selectLoginIndex !== dataService.LoginIndexNote) { + updateMenuActive($scope.selectLoginIndex = dataService.LoginIndexNote); + $state.go('note', { + key: key, + }, { + reload: true, + }) + } + } + var url = $scope.quickUrl[key]; if (url) { $window.open(url, '_blank'); diff --git a/public/scripts/controllers/note-controller.js b/public/scripts/controllers/note-controller.js index 9a47ad0..b586b2e 100644 --- a/public/scripts/controllers/note-controller.js +++ b/public/scripts/controllers/note-controller.js @@ -14,6 +14,7 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind $scope.currentPage = 1; $scope.inputPage = ''; $scope.searchWord = $stateParams.searchWord + $scope.key = $stateParams.key $scope.totalItems = 0; var timeagoInstance = timeago(); @@ -48,7 +49,8 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind $document.bind("keydown", function(event) { $scope.$apply(function() { // a按键,显示 - if (event.keyCode == 65 && dataService.keyShortcuts() && (!$scope.add)) { + var key = event.key.toUpperCase(); + if (key == 'A' && dataService.keyShortcuts() && (!$scope.add)) { $scope.showAddNote(); } }) @@ -215,6 +217,11 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind $timeout(function() { timeagoInstance.cancel(); timeagoInstance.render(document.querySelectorAll('.need_to_be_rendered'), 'zh_CN'); + // 如果需要增加书签 + if ($scope.key == 'A') { + $scope.key = null; + $scope.showAddNote(); + } }, 100) $scope.loadBusy = false; transition();