summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorKohei Yoshino <kohei.yoshino@gmail.com>2017-12-13 22:06:06 +0100
committerDylan William Hardison <dylan@hardison.net>2017-12-13 22:06:06 +0100
commit2e5d910d9401c4fa8f105d8f9502d9e4ea27bb99 (patch)
treeaba81e2eedc8af3136af73af3beba04c092ff80c /js
parent48fe3a1e0a4a833aa14e7f95136d0e4542959eb8 (diff)
downloadbugzilla-2e5d910d9401c4fa8f105d8f9502d9e4ea27bb99.tar.gz
bugzilla-2e5d910d9401c4fa8f105d8f9502d9e4ea27bb99.tar.xz
Bug 1376826 - New HTML Header for BMO
Diffstat (limited to 'js')
-rw-r--r--js/comments.js22
-rw-r--r--js/dropdown.js100
-rw-r--r--js/global.js15
3 files changed, 127 insertions, 10 deletions
diff --git a/js/comments.js b/js/comments.js
index 12bc00d46..88ba49364 100644
--- a/js/comments.js
+++ b/js/comments.js
@@ -144,7 +144,7 @@ function goto_add_comments( anchor ){
anchor = (anchor || "add_comment");
// we need this line to expand the comment box
document.getElementById('comment').focus();
- setTimeout(function(){
+ setTimeout(function(){
document.location.hash = anchor;
// firefox doesn't seem to keep focus through the anchor change
document.getElementById('comment').focus();
@@ -178,3 +178,23 @@ function getText(element) {
}
return text;
}
+
+/**
+ * If the URL contains a comment ID like #c10, scroll down the page to show the
+ * entire comment below the fixed global header.
+ */
+function scroll_comment_into_view() {
+ if (location.hash.match(/^#c\d+$/)) {
+ var $header = document.querySelector('#header');
+ var $comment = document.querySelector(location.hash);
+
+ if ($comment) {
+ window.setTimeout(function() {
+ window.scrollTo(0, $comment.offsetTop - $header.offsetHeight - 20);
+ }, 100);
+ }
+ }
+}
+
+window.addEventListener('load', scroll_comment_into_view, { once: true });
+window.addEventListener('hashchange', scroll_comment_into_view);
diff --git a/js/dropdown.js b/js/dropdown.js
new file mode 100644
index 000000000..32ce4696f
--- /dev/null
+++ b/js/dropdown.js
@@ -0,0 +1,100 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This Source Code Form is "Incompatible With Secondary Licenses", as
+ * defined by the Mozilla Public License, v. 2.0. */
+
+$(function() {
+ 'use strict';
+
+ $(window).click(function(e) {
+ // clicking dropdown button opens or closes the dropdown content
+ if (!$(e.target).hasClass('dropdown-button')) {
+ $('.dropdown-button').each(function() {
+ toggleDropDown(e, $(this), $('#' + $(this).attr('aria-controls')), 1);
+ });
+ }
+ }).keydown(function(e) {
+ // Escape key hides the dropdown if visible
+ if (e.keyCode == 27) {
+ $('.dropdown-button').each(function() {
+ var $button = $(this);
+ if ($button.siblings('.dropdown-content').is(':visible')) {
+ toggleDropDown(e, $button, $('#' + $button.attr('aria-controls')), 1);
+ $button.focus();
+ }
+ });
+ }
+ // allow arrow up and down keys to choose one of the dropdown items if menu visible
+ if (e.keyCode == 38 || e.keyCode == 40) {
+ $('.dropdown-content').each(function() {
+ var $content = $(this);
+ if ($content.is(':visible')) {
+ e.preventDefault();
+ e.stopPropagation();
+ var $items = $content.find('[role="menuitem"]');
+ // if none focused select the first or last
+ var $any_focused = $items.filter(':focus');
+ if ($any_focused.length == 0) {
+ var index = e.keyCode == 40 ? 0 : $items.length - 1;
+ var $link = $items.eq(index);
+ $link.addClass('active').focus();
+ return;
+ }
+ // otherwise move up or down the list based on arrow key pressed
+ var inc = e.keyCode == 40 ? 1 : -1;
+ var move = $items.index($any_focused) + inc;
+ var $link = $items.eq(move % $items.length);
+ $content.find('a').removeClass('active');
+ $link.addClass('active').focus();
+ }
+ });
+ }
+
+ // enter clicks on a link
+ if (e.keyCode == 13) {
+ $('.dropdown-content:visible a.active').trigger('click');
+ }
+ });
+
+ $('.dropdown-content a').hover(
+ function(){ $(this).addClass('active') },
+ function(){ $(this).removeClass('active') }
+ );
+
+ $('.dropdown').each(function() {
+ var $div = $(this);
+ var $button = $div.find('.dropdown-button');
+ var $content = $div.find('.dropdown-content');
+ $button.click(function(e) {
+ toggleDropDown(e, $button, $content);
+ }).keydown(function(e) {
+ // allow enter to toggle menu
+ if (e.keyCode == 13) {
+ toggleDropDown(e, $button, $content);
+ }
+ });
+ });
+
+ function toggleDropDown(e, $button, $content, hide_only) {
+ // hide other expanded dropdown menu if any
+ var $expanded = $('.dropdown-button[aria-expanded="true"]');
+ if ($expanded.length && !$expanded.is($button)) {
+ $('#' + $expanded.attr('aria-controls')).hide();
+ $expanded.attr('aria-expanded', false);
+ }
+
+ // clear all active links
+ $content.find('a').removeClass('active');
+ if ($content.is(':visible')) {
+ $content.hide();
+ $button.attr('aria-expanded', false);
+ }
+ // if not using Escape or clicking outside the dropdown div, then we are hiding
+ else if (!hide_only) {
+ $content.show();
+ $button.attr('aria-expanded', true);
+ }
+ }
+});
diff --git a/js/global.js b/js/global.js
index 102ab05af..b7b517631 100644
--- a/js/global.js
+++ b/js/global.js
@@ -10,10 +10,10 @@
*
* The Original Code is the Bugzilla Bug Tracking System.
*
-* Contributor(s):
+* Contributor(s):
* Guy Pyrzak <guy.pyrzak@gmail.com>
* Max Kanat-Alexander <mkanat@bugzilla.org>
-*
+*
*/
var BUGZILLA = $("#bugzilla-global").data("bugzilla");
@@ -85,30 +85,27 @@ function manage_old_lists() {
function show_mini_login_form( suffix ) {
- $('#login_link' + suffix).addClass('bz_default_hidden');
- $('#mini_login' + suffix).removeClass('bz_default_hidden');
- $('.mini_login' + suffix).removeClass('bz_default_hidden');
+ hide_forgot_form(suffix);
+ $('#mini_login' + suffix).removeClass('bz_default_hidden').find('input[required]:first').focus();
$('#new_account_container' + suffix).addClass('bz_default_hidden');
return false;
}
function hide_mini_login_form( suffix ) {
- $('#login_link' + suffix).removeClass('bz_default_hidden');
$('#mini_login' + suffix).addClass('bz_default_hidden');
$('#new_account_container' + suffix).removeClass('bz_default_hidden');
return false;
}
function show_forgot_form( suffix ) {
- $('#forgot_link' + suffix).addClass('bz_default_hidden');
- $('#forgot_form' + suffix).removeClass('bz_default_hidden');
+ hide_mini_login_form(suffix);
+ $('#forgot_form' + suffix).removeClass('bz_default_hidden').find('input[required]:first').focus();
$('#login_container' + suffix).addClass('bz_default_hidden');
return false;
}
function hide_forgot_form( suffix ) {
- $('#forgot_link' + suffix).removeClass('bz_default_hidden');
$('#forgot_form' + suffix).addClass('bz_default_hidden');
$('#login_container' + suffix).removeClass('bz_default_hidden');
return false;