diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-08-04 22:51:44 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-08-04 22:52:12 -0400 |
commit | e13872fc2e46976a668454d7528b0e7daef85d52 (patch) | |
tree | 5485d244f0dd4865720dc39e78cd4d1ff559f6e5 /assets/js/src/Search.js | |
parent | f04ec0700cb111baabc49febf22425612a5b7c58 (diff) |
Javascript refactoring
Diffstat (limited to 'assets/js/src/Search.js')
-rw-r--r-- | assets/js/src/Search.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/assets/js/src/Search.js b/assets/js/src/Search.js new file mode 100644 index 00000000..d38ffd2b --- /dev/null +++ b/assets/js/src/Search.js @@ -0,0 +1,61 @@ +function Search() { + this.keyboardShortcuts(); +} + +Search.prototype.focus = function() { + // Place cursor at the end when focusing on the search box + $(document).on("focus", "#form-search", function() { + if ($("#form-search")[0].setSelectionRange) { + $('#form-search')[0].setSelectionRange($('#form-search').val().length, $('#form-search').val().length); + } + }); +}; + +Search.prototype.listen = function() { + // Filter helper for search + $(document).on("click", ".filter-helper", function (e) { + e.preventDefault(); + $("#form-search").val($(this).data("filter")); + $("form.search").submit(); + }); +}; + +Search.prototype.keyboardShortcuts = function() { + // Switch view mode for projects: go to the board + Mousetrap.bind("v b", function(e) { + var link = $(".view-board"); + + if (link.length) { + window.location = link.attr('href'); + } + }); + + // Switch view mode for projects: go to the calendar + Mousetrap.bind("v c", function(e) { + var link = $(".view-calendar"); + + if (link.length) { + window.location = link.attr('href'); + } + }); + + // Switch view mode for projects: go to the listing + Mousetrap.bind("v l", function(e) { + var link = $(".view-listing"); + + if (link.length) { + window.location = link.attr('href'); + } + }); + + // Focus to the search field + Mousetrap.bind("f", function(e) { + e.preventDefault(); + var input = document.getElementById("form-search"); + + if (input) { + input.focus(); + } + }); +}; + |