diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website/static/src/js/menu/mobile_view.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website/static/src/js/menu/mobile_view.js')
| -rw-r--r-- | addons/website/static/src/js/menu/mobile_view.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/addons/website/static/src/js/menu/mobile_view.js b/addons/website/static/src/js/menu/mobile_view.js new file mode 100644 index 00000000..668962c8 --- /dev/null +++ b/addons/website/static/src/js/menu/mobile_view.js @@ -0,0 +1,68 @@ +odoo.define('website.mobile', function (require) { +'use strict'; + +var core = require('web.core'); +var Dialog = require('web.Dialog'); +var websiteNavbarData = require('website.navbar'); + +var _t = core._t; + +var MobilePreviewDialog = Dialog.extend({ + /** + * Tweaks the modal so that it appears as a phone and modifies the iframe + * rendering to show more accurate mobile view. + * + * @override + */ + start: function () { + var self = this; + this.$modal.addClass('oe_mobile_preview'); + this.$modal.on('click', '.modal-header', function () { + self.$el.toggleClass('o_invert_orientation'); + }); + this.$iframe = $('<iframe/>', { + id: 'mobile-viewport', + src: $.param.querystring(window.location.href, 'mobilepreview'), + }); + this.$iframe.on('load', function (e) { + self.$iframe.contents().find('body').removeClass('o_connected_user'); + self.$iframe.contents().find('#oe_main_menu_navbar').remove(); + }); + this.$iframe.appendTo(this.$el); + + return this._super.apply(this, arguments); + }, +}); + +var MobileMenu = websiteNavbarData.WebsiteNavbarActionWidget.extend({ + actions: _.extend({}, websiteNavbarData.WebsiteNavbarActionWidget.prototype.actions || {}, { + 'show-mobile-preview': '_onMobilePreviewClick', + }), + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Called when the mobile action is triggered -> instantiate the mobile + * preview dialog. + * + * @private + */ + _onMobilePreviewClick: function () { + if (this.mobilePreview && !this.mobilePreview.isDestroyed()) { + return this.mobilePreview.close(); + } + this.mobilePreview = new MobilePreviewDialog(this, { + title: _t('Mobile preview') + ' <span class="fa fa-refresh"/>', + }).open(); + }, +}); + +websiteNavbarData.websiteNavbarRegistry.add(MobileMenu, '#mobile-menu'); + +return { + MobileMenu: MobileMenu, + MobilePreviewDialog: MobilePreviewDialog, +}; +}); |
