diff options
| author | 2014-08-24 11:34:58 -0400 | |
|---|---|---|
| committer | 2014-08-24 11:37:07 -0400 | |
| commit | 7b17c60bb18b122f3d14795780f4642717cfd81b (patch) | |
| tree | 09613f885adc2cdad4095f1676c5a154ae096711 /p/scripts | |
| parent | d1f79fee69a3667913f419cd9726ffb11f410bd0 (diff) | |
Add shortcuts
Add a shortcut to open the wiki. Shortcut is F1 and is not modifiable.
Add a shortcut to access user filters the same way to access share actions.
Diffstat (limited to 'p/scripts')
| -rw-r--r-- | p/scripts/main.js | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/p/scripts/main.js b/p/scripts/main.js index c37f9f6f2..ad6cc8bef 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -378,6 +378,36 @@ function collapse_entry() { } } +function user_filter(key) { + console.log('user filter'); + console.warn(key); + var filter = $('#dropdown-query'); + var filters = filter.siblings('.dropdown-menu').find('.item.query a'); + if (typeof key === "undefined") { + if (!filter.length) { + return; + } + // Display the filter div + window.location.hash = filter.attr('id'); + // Force scrolling to the filter div + var scroll = needsScroll($('.header')); + if (scroll !== 0) { + $('html,body').scrollTop(scroll); + } + // Force the key value if there is only one action, so we can trigger it automatically + if (filters.length === 1) { + key = 1; + } else { + return; + } + } + // Trigger selected share action + key = parseInt(key); + if (key <= filters.length) { + filters[key - 1].click(); + } +} + function auto_share(key) { var share = $(".flux.current.active").find('.dropdown-target[id^="dropdown-share"]'); var shares = share.siblings('.dropdown-menu').find('.item a'); @@ -531,9 +561,19 @@ function init_shortcuts() { }, { 'disable_in_input': true }); + + shortcut.add(shortcuts.user_filter, function () { + user_filter(); + }, { + 'disable_in_input': true + }); for(var i = 1; i < 10; i++){ shortcut.add(i.toString(), function (e) { - auto_share(String.fromCharCode(e.keyCode)); + if ($('#dropdown-query').siblings('.dropdown-menu').is(':visible')) { + user_filter(String.fromCharCode(e.keyCode)); + } else { + auto_share(String.fromCharCode(e.keyCode)); + } }, { 'disable_in_input': true }); @@ -618,6 +658,13 @@ function init_shortcuts() { }, { 'disable_in_input': true }); + + shortcut.add(shortcuts.help, function () { + redirect(help_url, true); + }, { + 'disable_in_input': true + }); + } function init_stream(divStream) { |
