From 62823442d369705290807fa2a5191a1a67d6ee09 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 26 Nov 2016 08:16:15 +0000 Subject: Replaces project jump select with custom dropdown (#23310). git-svn-id: http://svn.redmine.org/redmine/trunk@15994 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- public/javascripts/application.js | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'public/javascripts') diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 3d1ad43cd..ad7109e2b 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -572,6 +572,69 @@ function observeSearchfield(fieldId, targetId, url) { }); } +$(document).ready(function(){ + $(".drdn .autocomplete").val(''); + + $(".drdn-trigger").click(function(e){ + var drdn = $(this).closest(".drdn"); + if (drdn.hasClass("expanded")) { + drdn.removeClass("expanded"); + } else { + $(".drdn").removeClass("expanded"); + drdn.addClass("expanded"); + if (!isMobile()) { + drdn.find(".autocomplete").focus(); + } + e.stopPropagation(); + } + }); + $(document).click(function(e){ + if ($(e.target).closest(".drdn").length < 1) { + $(".drdn.expanded").removeClass("expanded"); + } + }); + + observeSearchfield('projects-quick-search', null, $('#projects-quick-search').data('automcomplete-url')); + + $(".drdn-content").keydown(function(event){ + var items = $(this).find(".drdn-items"); + var focused = items.find("a:focus"); + switch (event.which) { + case 40: //down + if (focused.length > 0) { + focused.nextAll("a").first().focus();; + } else { + items.find("a").first().focus();; + } + event.preventDefault(); + break; + case 38: //up + if (focused.length > 0) { + var prev = focused.prevAll("a"); + if (prev.length > 0) { + prev.first().focus(); + } else { + $(this).find(".autocomplete").focus(); + } + event.preventDefault(); + } + break; + case 35: //end + if (focused.length > 0) { + focused.nextAll("a").last().focus(); + event.preventDefault(); + } + break; + case 36: //home + if (focused.length > 0) { + focused.prevAll("a").last().focus(); + event.preventDefault(); + } + break; + } + }); +}); + function beforeShowDatePicker(input, inst) { var default_date = null; switch ($(input).attr("id")) { -- cgit v1.2.3