summaryrefslogtreecommitdiff
path: root/addons/website/static/src/snippets/s_popup/000.js
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/website/static/src/snippets/s_popup/000.js
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/website/static/src/snippets/s_popup/000.js')
-rw-r--r--addons/website/static/src/snippets/s_popup/000.js119
1 files changed, 119 insertions, 0 deletions
diff --git a/addons/website/static/src/snippets/s_popup/000.js b/addons/website/static/src/snippets/s_popup/000.js
new file mode 100644
index 00000000..2b11466e
--- /dev/null
+++ b/addons/website/static/src/snippets/s_popup/000.js
@@ -0,0 +1,119 @@
+odoo.define('website.s_popup', function (require) {
+'use strict';
+
+const config = require('web.config');
+const publicWidget = require('web.public.widget');
+const utils = require('web.utils');
+
+const PopupWidget = publicWidget.Widget.extend({
+ selector: '.s_popup',
+ events: {
+ 'click .js_close_popup': '_onCloseClick',
+ 'hide.bs.modal': '_onHideModal',
+ },
+
+ /**
+ * @override
+ */
+ start: function () {
+ this._popupAlreadyShown = !!utils.get_cookie(this.$el.attr('id'));
+ if (!this._popupAlreadyShown) {
+ this._bindPopup();
+ }
+ return this._super(...arguments);
+ },
+ /**
+ * @override
+ */
+ destroy: function () {
+ this._super.apply(this, arguments);
+ $(document).off('mouseleave.open_popup');
+ this.$target.find('.modal').modal('hide');
+ clearTimeout(this.timeout);
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ */
+ _bindPopup: function () {
+ const $main = this.$target.find('.modal');
+
+ let display = $main.data('display');
+ let delay = $main.data('showAfter');
+
+ if (config.device.isMobile) {
+ if (display === 'mouseExit') {
+ display = 'afterDelay';
+ delay = 5000;
+ }
+ this.$('.modal').removeClass('s_popup_middle').addClass('s_popup_bottom');
+ }
+
+ if (display === 'afterDelay') {
+ this.timeout = setTimeout(() => this._showPopup(), delay);
+ } else {
+ $(document).on('mouseleave.open_popup', () => this._showPopup());
+ }
+ },
+ /**
+ * @private
+ */
+ _hidePopup: function () {
+ this.$target.find('.modal').modal('hide');
+ },
+ /**
+ * @private
+ */
+ _showPopup: function () {
+ if (this._popupAlreadyShown) {
+ return;
+ }
+ this.$target.find('.modal').modal('show');
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ */
+ _onCloseClick: function () {
+ this._hidePopup();
+ },
+ /**
+ * @private
+ */
+ _onHideModal: function () {
+ const nbDays = this.$el.find('.modal').data('consentsDuration');
+ utils.set_cookie(this.$el.attr('id'), true, nbDays * 24 * 60 * 60);
+ this._popupAlreadyShown = true;
+ },
+});
+
+publicWidget.registry.popup = PopupWidget;
+
+// Prevent bootstrap to prevent scrolling and to add the strange body
+// padding-right they add if the popup does not use a backdrop (especially
+// important for default cookie bar).
+const _baseSetScrollbar = $.fn.modal.Constructor.prototype._setScrollbar;
+$.fn.modal.Constructor.prototype._setScrollbar = function () {
+ if (this._element.classList.contains('s_popup_no_backdrop')) {
+ return;
+ }
+ return _baseSetScrollbar.apply(this, ...arguments);
+};
+const _baseGetScrollbarWidth = $.fn.modal.Constructor.prototype._getScrollbarWidth;
+$.fn.modal.Constructor.prototype._getScrollbarWidth = function () {
+ if (this._element.classList.contains('s_popup_no_backdrop')) {
+ return 0;
+ }
+ return _baseGetScrollbarWidth.apply(this, ...arguments);
+};
+
+return PopupWidget;
+});