Skip to content

Commit

Permalink
Merge pull request #1571 from Alex-D/hotfix-dataclick-1570
Browse files Browse the repository at this point in the history
Roue dentée des paramètres
  • Loading branch information
SpaceFox committed Oct 7, 2014
2 parents d467bf4 + 9f31ea8 commit ba605fe
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 33 deletions.
47 changes: 29 additions & 18 deletions assets/js/data-click.js
Expand Up @@ -4,26 +4,37 @@
Author: Alex-D / Alexandre Demode
========================================================================== */

(function($, undefined){
(function($, document, undefined){
"use strict";

var dropdownMouseDown = false;

$("body")
.on("mousedown", "[data-click]", function(){
dropdownMouseDown = true;
})
.on("mouseup", "[data-click]", function(){
dropdownMouseDown = false;
})
.on("click focus", "[data-click]", function(e){
if(e.type === "focus" && dropdownMouseDown)
return false;

if(!($(this).hasClass("dont-click-if-sidebar") && $(".header-container .mobile-menu-btn").is(":visible"))){
e.preventDefault();
e.stopPropagation();
$("#" + $(this).attr("data-click")).trigger("click");
}
function dataClick($elem){
$elem
.attr("tabindex", -1)
.attr("aria-hidden", true)
.on("mousedown", function(){
dropdownMouseDown = true;
})
.on("mouseup", function(){
dropdownMouseDown = false;
})
.on("click focus", function(e){
if(e.type === "focus" && dropdownMouseDown)
return false;

if(!($(this).hasClass("dont-click-if-sidebar") && $(".header-container .mobile-menu-btn").is(":visible"))){
e.preventDefault();
e.stopPropagation();
$("#" + $(this).attr("data-click")).trigger(e.type);
}
});
}

$(document).ready(function(){
dataClick($("[data-click]"));
$("#content").on("DOMNodeInserted", "[data-click]", function(e){
dataClick($(e.target));
});
});
})(jQuery);
})(jQuery, document);
48 changes: 34 additions & 14 deletions assets/js/dropdown-menu.js
Expand Up @@ -7,20 +7,26 @@
(function($, undefined){
"use strict";

var dropdownMouseDown = false;
var mouseDown = false,
shiftHold = false;

$(document).on("keydown keyup", function(e){
shiftHold = e.shiftKey;
});

$(".dropdown").each(function(){
var $elem = $(this).parent().find("> a");
var $dropdown = $(this),
$elem = $(this).parent().find("> a");

if(!$elem.parents(".logbox").length)
$elem.addClass("has-dropdown");

$elem
.on("mousedown", function(){
dropdownMouseDown = true;
mouseDown = true;
})
.on("mouseup", function(){
dropdownMouseDown = false;
mouseDown = false;
})
.on("click", function(e){
if(($(this).parents(".header-menu-list").length > 0 && parseInt($("html").css("width")) < 960))
Expand All @@ -40,18 +46,32 @@
.on("focus", function(e){
e.preventDefault();

if(!dropdownMouseDown && !$(this).hasClass("active")){
activeDropdown($(this));
if(!mouseDown && !$elem.hasClass("active")){
activeDropdown($elem);

$(this)
.one("blur", function(){
$elem = $(this);
$elem
.off("blur")
.on("blur", function(){
$elem
.one("blur", function(){
if(shiftHold)
triggerCloseDropdown($elem);
});

setTimeout(function(){
if($(":tabbable:focus", $elem.parent().find(".dropdown")).length){
$(":tabbable:last", $elem.parent().find(".dropdown")).one("blur", function(){
$elem.removeClass("active");
triggerCloseDropdown($elem);
});
if($(":tabbable:focus", $dropdown).length){
var listenBlurLast = function(){
$(":tabbable:last", $dropdown)
.one("blur", function(){
if(shiftHold){
listenBlurLast();
return;
}
$elem.removeClass("active");
triggerCloseDropdown($elem);
});
};
listenBlurLast();
} else {
$elem.removeClass("active");
triggerCloseDropdown($elem);
Expand Down
1 change: 0 additions & 1 deletion templates/base.html
Expand Up @@ -393,7 +393,6 @@
data-title="Mon compte"

{% if not perms.forum.change_post %}
tabindex="-1"
data-active="open-my-account"
{% endif %}
>
Expand Down

0 comments on commit ba605fe

Please sign in to comment.