summaryrefslogtreecommitdiff
path: root/addons/website/static/src/js/content/menu.js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2017-11-10 14:13:45 +0100
committerqsm-odoo <qsm@odoo.com>2017-12-21 09:52:36 +0100
commit76abdd4ace726c7a46ea13e5d3ad5ff09092b682 (patch)
tree738a4d287eb822983cff66f3ef1c9ba373b3091f /addons/website/static/src/js/content/menu.js
parent5d8de48c65d253cf5800bd32b3040f3c4e1b57a4 (diff)
[REF] website: menu-related JS is supposed to grow, so rename "affix" file
Diffstat (limited to 'addons/website/static/src/js/content/menu.js')
-rw-r--r--addons/website/static/src/js/content/menu.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/addons/website/static/src/js/content/menu.js b/addons/website/static/src/js/content/menu.js
new file mode 100644
index 00000000000..d5c3b06ba64
--- /dev/null
+++ b/addons/website/static/src/js/content/menu.js
@@ -0,0 +1,72 @@
+odoo.define('website.content.menu', function (require) {
+'use strict';
+
+var sAnimation = require('website.content.snippets.animation');
+
+sAnimation.registry.affixMenu = sAnimation.Class.extend({
+ selector: 'header.o_affix_enabled',
+
+ /**
+ * @override
+ */
+ start: function () {
+ var def = this._super.apply(this, arguments);
+ if (this.editableMode) {
+ return def;
+ }
+
+ var self = this;
+ this.$headerClone = this.$target.clone().attr('class', 'o_header_affix affix');
+ this.$headerClone.insertAfter(this.$target);
+ this.$headers = this.$target.add(this.$headerClone);
+ this.$dropdowns = this.$headers.find('.dropdown');
+ this.$navbarCollapses = this.$headers.find('.navbar-collapse');
+
+ // Handle events for the collapse menus
+ _.each(this.$headerClone.find('[data-toggle="collapse"]'), function (el) {
+ var $source = $(el);
+ var targetClass = $source.attr('data-target');
+ var $target = self.$headerClone.find(targetClass);
+ var className = targetClass.substring(1);
+ $source.attr('data-target', targetClass + '_clone');
+ $target.removeClass(className).addClass(className + '_clone');
+ });
+
+ // Window Handlers
+ $(window).on('resize.affixMenu scroll.affixMenu', _.throttle(this._onWindowUpdate.bind(this), 200));
+ setTimeout(this._onWindowUpdate.bind(this), 0); // setTimeout to allow override with advanced stuff... see themes
+
+ return def;
+ },
+ /**
+ * @override
+ */
+ destroy: function () {
+ if (this.$headerClone) {
+ this.$headerClone.remove();
+ $(window).off('.affixMenu');
+ }
+ this._super.apply(this, arguments);
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * Called when the window is resized or scrolled -> updates affix status and
+ * automatically closes submenus.
+ *
+ * @private
+ */
+ _onWindowUpdate: function () {
+ var wOffset = $(window).scrollTop();
+ var hOffset = this.$target.scrollTop();
+ this.$headerClone.toggleClass('affixed', wOffset > (hOffset + 300));
+
+ // Reset opened menus
+ this.$dropdowns.removeClass('open');
+ this.$navbarCollapses.removeClass('in').attr('aria-expanded', false);
+ },
+});
+});