添加分类定制的快捷键

This commit is contained in:
luchenqun 2017-11-30 17:20:44 +08:00
parent 715b67fdfe
commit ec1da85efd
4 changed files with 41 additions and 28 deletions

View File

@ -46,6 +46,7 @@ app.config(function($stateProvider, $urlRouterProvider, $httpProvider) {
templateUrl: '/views/tags.html', templateUrl: '/views/tags.html',
params: { params: {
tagId: null, tagId: null,
orderIndex: null,
}, },
controller: 'tagsCtr' controller: 'tagsCtr'
}) })

View File

@ -1,4 +1,4 @@
app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$timeout', '$document', 'pubSubService', 'bookmarkService', 'dataService', function($scope, $stateParams, $state, $window, $timeout, $document, pubSubService, bookmarkService, dataService) { app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$timeout', '$document', 'pubSubService', 'bookmarkService', 'dataService', function ($scope, $stateParams, $state, $window, $timeout, $document, pubSubService, bookmarkService, dataService) {
console.log("Hello menuCtr") console.log("Hello menuCtr")
$scope.login = false; /**< 是否登陆 */ $scope.login = false; /**< 是否登陆 */
$scope.selectLoginIndex = 0; /**< 默认登陆之后的选择的菜单索引,下表从 0 开始 */ $scope.selectLoginIndex = 0; /**< 默认登陆之后的选择的菜单索引,下表从 0 开始 */
@ -11,14 +11,14 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
$scope.longPress = false; $scope.longPress = false;
// 防止在登陆的情况下在浏览器里面直接输入url这时候要更新菜单选项 // 防止在登陆的情况下在浏览器里面直接输入url这时候要更新菜单选项
pubSubService.subscribe('Common.menuActive', $scope, function(event, params) { pubSubService.subscribe('Common.menuActive', $scope, function (event, params) {
console.log("subscribe Common.menuActive, login = " + params.login + ", index = " + params.index); console.log("subscribe Common.menuActive, login = " + params.login + ", index = " + params.index);
$scope.login = (params && params.login) || false; $scope.login = (params && params.login) || false;
var index = $scope.login ? ($scope.selectLoginIndex = (params && params.index) || 0) : ($scope.selectNotLoginIndex = (params && params.index) || 0); var index = $scope.login ? ($scope.selectLoginIndex = (params && params.index) || 0) : ($scope.selectNotLoginIndex = (params && params.index) || 0);
updateMenuActive(index); updateMenuActive(index);
}); });
pubSubService.subscribe('Settings.quickUrl', $scope, function(event, params) { pubSubService.subscribe('Settings.quickUrl', $scope, function (event, params) {
$scope.quickUrl = params.quickUrl; $scope.quickUrl = params.quickUrl;
}); });
@ -29,7 +29,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
* @func * @func
* @desc 点击搜索按钮搜索书签 * @desc 点击搜索按钮搜索书签
*/ */
$scope.search = function(searchWord) { $scope.search = function (searchWord) {
console.log('search......', searchWord); console.log('search......', searchWord);
$scope.login = true; $scope.login = true;
@ -84,7 +84,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
} }
} }
$scope.searchByHistory = function(type, data) { $scope.searchByHistory = function (type, data) {
$scope.searchWord = data; $scope.searchWord = data;
$('.search-item').val($scope.searchWord); $('.search-item').val($scope.searchWord);
@ -98,7 +98,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
$scope.search(data); $scope.search(data);
} }
$scope.delHistory = function(type, data) { $scope.delHistory = function (type, data) {
var delIndex = -1; var delIndex = -1;
$scope.searchHistory.forEach((item, index) => { $scope.searchHistory.forEach((item, index) => {
if (index >= 1 && item.t == type && item.d == data) { if (index >= 1 && item.t == type && item.d == data) {
@ -109,12 +109,12 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
$scope.searchHistory.splice(delIndex, 1); $scope.searchHistory.splice(delIndex, 1);
} }
saveHistory(); saveHistory();
$timeout(function() { $timeout(function () {
$('.js-history-popup').removeClass('hidden').addClass('visible'); $('.js-history-popup').removeClass('hidden').addClass('visible');
}, 500) }, 500)
} }
$scope.updateShowStyle = function(showStyle) { $scope.updateShowStyle = function (showStyle) {
console.log('updateShowStyle', showStyle); console.log('updateShowStyle', showStyle);
$scope.showStyle = showStyle; $scope.showStyle = showStyle;
$('.js-radio-' + showStyle).checkbox('set checked'); $('.js-radio-' + showStyle).checkbox('set checked');
@ -125,12 +125,12 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
}) })
} }
$scope.showAddBookmarkMoadl = function() { $scope.showAddBookmarkMoadl = function () {
pubSubService.publish('MenuCtr.showAddBookmarkMoadl', { pubSubService.publish('MenuCtr.showAddBookmarkMoadl', {
'action': 'add' 'action': 'add'
}); });
} }
$scope.logout = function() { $scope.logout = function () {
bookmarkService.logout({}) bookmarkService.logout({})
.then((data) => { .then((data) => {
console.log('logout..........', data) console.log('logout..........', data)
@ -186,7 +186,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
$scope.searchHistory = JSON.parse(user.search_history || '[]'); $scope.searchHistory = JSON.parse(user.search_history || '[]');
$scope.quickUrl = JSON.parse(user.quick_url || '{}'); $scope.quickUrl = JSON.parse(user.quick_url || '{}');
$timeout(function() { $timeout(function () {
var showStyle = (user && user.show_style) || 'navigate'; var showStyle = (user && user.show_style) || 'navigate';
if (showStyle) { if (showStyle) {
$('.js-bookmark-dropdown' + ' .radio.checkbox').checkbox('set unchecked'); $('.js-bookmark-dropdown' + ' .radio.checkbox').checkbox('set unchecked');
@ -201,7 +201,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
// toastr.error('获取信息失败。错误信息:' + JSON.stringify(err), "错误"); // toastr.error('获取信息失败。错误信息:' + JSON.stringify(err), "错误");
}); });
$timeout(function() { $timeout(function () {
$('.suggest') $('.suggest')
.popup({ .popup({
title: '操作提示', title: '操作提示',
@ -212,8 +212,8 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
}, 1000) }, 1000)
// 在输入文字的时候也会触发所以不要用Ctrl,Shift之类的按键 // 在输入文字的时候也会触发所以不要用Ctrl,Shift之类的按键
$document.bind("keydown", function(event) { $document.bind("keydown", function (event) {
$scope.$apply(function() { $scope.$apply(function () {
var key = event.key.toUpperCase(); var key = event.key.toUpperCase();
if (key == 'CONTROL' || key == 'SHIFT' || key == 'ALT') { if (key == 'CONTROL' || key == 'SHIFT' || key == 'ALT') {
$scope.longPress = true; $scope.longPress = true;
@ -225,14 +225,22 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
if (key == 'A') { if (key == 'A') {
if ($scope.selectLoginIndex !== dataService.LoginIndexNote) { if ($scope.selectLoginIndex !== dataService.LoginIndexNote) {
updateMenuActive($scope.selectLoginIndex = dataService.LoginIndexNote); updateMenuActive($scope.selectLoginIndex = dataService.LoginIndexNote);
$state.go('note', { $state.go('note', { key: key }, { reload: true })
key: key,
}, {
reload: true,
})
} }
} }
if (key == ',' || key == '.' || key == '/') {
pubSubService.publish('Common.menuActive', {
login: $scope.login,
index: dataService.LoginIndexTags
});
var stateParams = {
tagId: -1,
orderIndex: (key == ',' ? 0 : (key == '.' ? 1 : 2)),
}
$state.go(dataService.loginMenus[dataService.LoginIndexTags].uiSref, stateParams, { reload: true, })
}
// 数字键用来切换菜单 // 数字键用来切换菜单
if (!isNaN(key)) { if (!isNaN(key)) {
var num = parseInt(key); var num = parseInt(key);
@ -254,8 +262,8 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
}); });
// 在输入文字的时候也会触发所以不要用Ctrl,Shift之类的按键 // 在输入文字的时候也会触发所以不要用Ctrl,Shift之类的按键
$document.bind("keyup", function(event) { $document.bind("keyup", function (event) {
$scope.$apply(function() { $scope.$apply(function () {
var key = event.key.toUpperCase(); var key = event.key.toUpperCase();
// console.log('keyup key = ', key); // console.log('keyup key = ', key);
if (key == 'CONTROL' || key == 'SHIFT' || key == 'ALT') { if (key == 'CONTROL' || key == 'SHIFT' || key == 'ALT') {

View File

@ -78,6 +78,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim
} }
$scope.getBookmarks = function(tagId, currentPage) { $scope.getBookmarks = function(tagId, currentPage) {
console.log(tagId, currentPage)
$scope.bookmarkClicked = true; $scope.bookmarkClicked = true;
$scope.currentTagId = tagId; $scope.currentTagId = tagId;
$scope.currentPage = currentPage; $scope.currentPage = currentPage;
@ -473,7 +474,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim
find = true; // 如果是删了分类返回来,那么要重新默认选中第一个分类 find = true; // 如果是删了分类返回来,那么要重新默认选中第一个分类
} }
}) })
if (!find) $scope.currentTagId = null; if (!find && $scope.currentTagId !== -1) $scope.currentTagId = null;
if (!$scope.currentTagId && $scope.tags.length > 0) { if (!$scope.currentTagId && $scope.tags.length > 0) {
$scope.currentTagId = $scope.tags[0].id; $scope.currentTagId = $scope.tags[0].id;
$scope.tags[0].bookmarkClicked = true; $scope.tags[0].bookmarkClicked = true;

View File

@ -91,6 +91,9 @@ app.factory('dataService', [function() {
'R': '在热门收藏界面,已用作随机查看热门收藏', 'R': '在热门收藏界面,已用作随机查看热门收藏',
'INSERT': '全局页面,已用做添加书签', 'INSERT': '全局页面,已用做添加书签',
'ESC': '全局页面,已用做退出弹窗', 'ESC': '全局页面,已用做退出弹窗',
',': '跳转到分类定制点击次数',
'.': '跳转到分类定制添加日期',
'/': '跳转到分类定制最后点击',
}, },
keyShortcuts: function() { // 判断快捷方式是否生效 keyShortcuts: function() { // 判断快捷方式是否生效
var ret = true; var ret = true;