[FIX] website, *: avoid top menu flickering

* portal, web
This commit is contained in:
qsm-odoo
2018-08-31 18:57:12 +02:00
parent 7253b55f41
commit 4bc79da943
5 changed files with 43 additions and 18 deletions
+20 -9
View File
@@ -3,10 +3,12 @@
/// rules.
///
$-navbar-height: $nav-link-height !default;
// Resize and vertically align navbar’s items relative to navbar
@mixin o-w-fill-navbar($ratio: 1) {
height: round($nav-link-height * $ratio * 100) / 100;
margin-top: round($nav-link-height * (1 - $ratio) / 2 * 100) / 100;
height: round($-navbar-height * $ratio * 100) / 100;
margin-top: round($-navbar-height * (1 - $ratio) / 2 * 100) / 100;
}
// Frontend general
@@ -26,14 +28,23 @@
}
header {
.navbar-brand.logo {
padding-top: 0;
padding-bottom: 0;
.navbar-brand {
flex: 0 0 auto;
img {
@include o-w-fill-navbar;
width: auto;
max-width: none;
&.logo {
// Width and height are fixed to prevent navbar flickering due to
// image loading
width: 4 * $-navbar-height;
height: $-navbar-height;
padding-top: 0;
padding-bottom: 0;
img {
@include o-w-fill-navbar;
width: auto;
max-width: none;
}
}
}
.nav-link {
+2 -2
View File
@@ -409,7 +409,7 @@ return {
}, 0);
if (maxWidth - menuItemsWidth >= -0.001) {
return
return;
}
var $dropdownMenu = $('<ul/>', {class: 'dropdown-menu'});
@@ -422,7 +422,7 @@ return {
menuItemsWidth += computeFloatOuterWidthWithMargins($extraItemsToggle[0]);
do {
menuItemsWidth -= computeFloatOuterWidthWithMargins($items.eq(--nbItems)[0]);
} while (menuItemsWidth > maxWidth);
} while (!(maxWidth - menuItemsWidth >= -0.001));
var $extraItems = $items.slice(nbItems).detach();
$extraItems.removeClass('nav-item');
+9 -7
View File
@@ -1,7 +1,6 @@
odoo.define('website.content.menu', function (require) {
'use strict';
var config = require('web.config');
var dom = require('web.dom');
var sAnimation = require('website.content.snippets.animation');
@@ -76,18 +75,19 @@ sAnimation.registry.affixMenu = sAnimation.Class.extend({
*
* Note: this works well with the affixMenu... by chance (autohideMenu is called
* after alphabetically).
*
* @todo We may want to avoid some code duplication by sharing what is done in
* the backend in enterprise...
*/
sAnimation.registry.autohideMenu = sAnimation.Class.extend({
selector: 'header:not(.o_no_autohide_menu) #top_menu',
selector: 'header #top_menu',
/**
* @override
*/
start: function () {
dom.initAutoMoreMenu(this.$el, {unfoldable: '.divider, .divider ~ li'});
this.noAutohide = this.$el.closest('.o_no_autohide_menu').length;
if (!this.noAutohide) {
dom.initAutoMoreMenu(this.$el, {unfoldable: '.divider, .divider ~ li'});
}
this.$el.removeClass('o_menu_loading');
return this._super.apply(this, arguments);
},
/**
@@ -95,7 +95,9 @@ sAnimation.registry.autohideMenu = sAnimation.Class.extend({
*/
destroy: function () {
this._super.apply(this, arguments);
dom.destroyAutoMoreMenu(this.$el);
if (!this.noAutohide) {
dom.destroyAutoMoreMenu(this.$el);
}
},
});
@@ -28,6 +28,15 @@ $-theme-font: nth($o-theme-font-urls, $o-theme-font-number);
.navbar {
@include o-bg-color(color('menu'));
.nav-item {
transition: opacity 1000ms ease 0s;
}
.o_menu_loading .nav-item {
height: 0 !important;
overflow: hidden !important;
opacity: 0 !important;
}
}
.o_footer {
@include o-bg-color(color('footer'));
@@ -213,6 +213,9 @@
<xpath expr="//header//a[hasclass('navbar-brand')]" position="replace">
<a class="navbar-brand" href="/" t-if="website" t-field="website.name">My Website</a>
</xpath>
<xpath expr="//header//ul[@id='top_menu']" position="attributes">
<attribute name="class" separator=" " add="o_menu_loading"/>
</xpath>
<xpath expr="//header//ul[@id='top_menu']/li[hasclass('divider')]" position="attributes">
<attribute name="t-if">website.user_id != user_id</attribute>
</xpath>