FIX: Support RTL languages in header menu

This commit is contained in:
Jeff Wong 2018-12-11 10:33:56 -08:00
parent d2569f8e77
commit 5358f25fc6

View File

@ -52,6 +52,22 @@ const SiteHeaderComponent = MountWidget.extend(Docking, PanEvents, {
}); });
}, },
_isRTL() {
return $("html").css("direction") === "rtl";
},
_leftMenuClass() {
return this._isRTL() ? ".user-menu" : ".hamburger-panel";
},
_leftMenuAction() {
return this._isRTL() ? "toggleUserMenu" : "toggleHamburger";
},
_rightMenuAction() {
return this._isRTL() ? "toggleHamburger" : "toggleUserMenu";
},
_handlePanDone(offset, event) { _handlePanDone(offset, event) {
const $window = $(window); const $window = $(window);
const windowWidth = parseInt($window.width()); const windowWidth = parseInt($window.width());
@ -120,7 +136,7 @@ const SiteHeaderComponent = MountWidget.extend(Docking, PanEvents, {
this._panMenuOffset = -SCREEN_OFFSET; this._panMenuOffset = -SCREEN_OFFSET;
this._isPanning = true; this._isPanning = true;
$("header.d-header").removeClass("scroll-down scroll-up"); $("header.d-header").removeClass("scroll-down scroll-up");
this.eventDispatched("toggleHamburger", "header"); this.eventDispatched(this._leftMenuAction(), "header");
} else if ( } else if (
windowWidth - center.x < SCREEN_EDGE_MARGIN && windowWidth - center.x < SCREEN_EDGE_MARGIN &&
!this.$(".menu-panel").length && !this.$(".menu-panel").length &&
@ -131,7 +147,7 @@ const SiteHeaderComponent = MountWidget.extend(Docking, PanEvents, {
this._panMenuOffset = -SCREEN_OFFSET; this._panMenuOffset = -SCREEN_OFFSET;
this._isPanning = true; this._isPanning = true;
$("header.d-header").removeClass("scroll-down scroll-up"); $("header.d-header").removeClass("scroll-down scroll-up");
this.eventDispatched("toggleUserMenu", "header"); this.eventDispatched(this._rightMenuAction(), "header");
} else { } else {
this._isPanning = false; this._isPanning = false;
} }
@ -298,7 +314,7 @@ const SiteHeaderComponent = MountWidget.extend(Docking, PanEvents, {
$headerCloak.css("opacity", 0); $headerCloak.css("opacity", 0);
if ( if (
this.site.mobileView && this.site.mobileView &&
$panel.parent(".hamburger-panel").length > 0 $panel.parent(this._leftMenuClass()).length > 0
) { ) {
this._panMenuOrigin = "left"; this._panMenuOrigin = "left";
$panel.css("left", -windowWidth); $panel.css("left", -windowWidth);