diff --git a/addons/web/static/src/js/public/public_root.js b/addons/web/static/src/js/public/public_root.js index ebf9bb0937d..7c508bd9192 100644 --- a/addons/web/static/src/js/public/public_root.js +++ b/addons/web/static/src/js/public/public_root.js @@ -30,10 +30,10 @@ var PublicRoot = publicWidget.RootWidget.extend(ServiceProviderMixin, { 'click .js_disable_on_click': '_onDisableOnClick', }), custom_events: _.extend({}, publicWidget.RootWidget.prototype.custom_events || {}, { - 'animation_start_demand': '_onAnimationStartDemand', - 'animation_stop_demand': '_onAnimationStopDemand', 'context_get': '_onContextGet', 'main_object_request': '_onMainObjectRequest', + 'widgets_start_request': '_onWidgetsStartRequest', + 'widgets_stop_request': '_onWidgetsStopRequest', }), /** @@ -42,7 +42,7 @@ var PublicRoot = publicWidget.RootWidget.extend(ServiceProviderMixin, { init: function () { this._super.apply(this, arguments); ServiceProviderMixin.init.call(this); - this.animations = []; + this.publicWidgets = []; }, /** * @override @@ -59,10 +59,10 @@ var PublicRoot = publicWidget.RootWidget.extend(ServiceProviderMixin, { * @override */ start: function () { - var defs = [this._super.apply(this, arguments)]; - - // Animations - defs.push(this._startAnimations()); + var defs = [ + this._super.apply(this, arguments), + this._startWidgets() + ]; // Display image thumbnail this.$(".o_image[data-mimetype^='image']").each(function () { @@ -161,12 +161,12 @@ var PublicRoot = publicWidget.RootWidget.extend(ServiceProviderMixin, { * * @private * @param {jQuery} [$from] - * only initialize the animations whose `selector` matches the + * only initialize the public widgets whose `selector` matches the * element or one of its descendant (default to the wrapwrap element) * @param {Object} [options] * @returns {Deferred} */ - _startAnimations: function ($from, options) { + _startWidgets: function ($from, options) { var self = this; if ($from === undefined) { @@ -182,16 +182,16 @@ var PublicRoot = publicWidget.RootWidget.extend(ServiceProviderMixin, { options = {}; } - this._stopAnimations($from); + this._stopWidgets($from); - var defs = _.map(this._getPublicWidgetsRegistry(options), function (WebsiteWidget) { - var selector = WebsiteWidget.prototype.selector || ''; + var defs = _.map(this._getPublicWidgetsRegistry(options), function (PublicWidget) { + var selector = PublicWidget.prototype.selector || ''; var $target = $from.find(selector).addBack(selector); var defs = _.map($target, function (el) { - var animation = new WebsiteWidget(self, options); - self.animations.push(animation); - return animation.attachTo($(el)); + var widget = new PublicWidget(self, options); + self.publicWidgets.push(widget); + return widget.attachTo($(el)); }); return $.when.apply($, defs); }); @@ -203,48 +203,26 @@ var PublicRoot = publicWidget.RootWidget.extend(ServiceProviderMixin, { * * @private * @param {jQuery} [$from] - * only stop the animations linked to the given element(s) or one of - * its descendants + * only stop the public widgets linked to the given element(s) or one + * of its descendants */ - _stopAnimations: function ($from) { - var removedAnimations = _.map(this.animations, function (animation) { + _stopWidgets: function ($from) { + var removedWidgets = _.map(this.publicWidgets, function (widget) { if (!$from - || $from.filter(animation.el).length - || $from.find(animation.el).length) { - animation.destroy(); - return animation; + || $from.filter(widget.el).length + || $from.find(widget.el).length) { + widget.destroy(); + return widget; } return null; }); - this.animations = _.difference(this.animations, removedAnimations); + this.publicWidgets = _.difference(this.publicWidgets, removedWidgets); }, //-------------------------------------------------------------------------- // Handlers //-------------------------------------------------------------------------- - /** - * Called when the root is notified that the animations have to be - * (re)started. - * - * @private - * @param {OdooEvent} ev - */ - _onAnimationStartDemand: function (ev) { - this._startAnimations(ev.data.$target, ev.data.options) - .done(ev.data.onSuccess) - .fail(ev.data.onFailure); - }, - /** - * Called when the root is notified that the animations have to be - * stopped. - * - * @private - * @param {OdooEvent} ev - */ - _onAnimationStopDemand: function (ev) { - this._stopAnimations(ev.data.$target); - }, /** * Called when someone asked for the global public context. * @@ -272,6 +250,28 @@ var PublicRoot = publicWidget.RootWidget.extend(ServiceProviderMixin, { id: m[2] | 0, }); }, + /** + * Called when the root is notified that the public widgets have to be + * (re)started. + * + * @private + * @param {OdooEvent} ev + */ + _onWidgetsStartRequest: function (ev) { + this._startWidgets(ev.data.$target, ev.data.options) + .done(ev.data.onSuccess) + .fail(ev.data.onFailure); + }, + /** + * Called when the root is notified that the public widgets have to be + * stopped. + * + * @private + * @param {OdooEvent} ev + */ + _onWidgetsStopRequest: function (ev) { + this._stopWidgets(ev.data.$target); + }, /** * @todo review * @private diff --git a/addons/web/static/src/js/public/public_widget.js b/addons/web/static/src/js/public/public_widget.js index ed99c5da457..ec9c50ad9a8 100644 --- a/addons/web/static/src/js/public/public_widget.js +++ b/addons/web/static/src/js/public/public_widget.js @@ -2,7 +2,7 @@ odoo.define('web.public.widget', function (require) { 'use strict'; /** - * Provides a way to start JS code for snippets' initialization and animations. + * Provides a way to start JS code for public contents. */ var Class = require('web.Class'); @@ -175,10 +175,10 @@ var RootWidgetRegistry = Class.extend(mixins.EventDispatcherMixin, { var PublicWidget = Widget.extend({ /** * The selector attribute, if defined, allows to automatically create an - * instance of this animation on page load for each DOM element which - * matches this selector. The `Animation.$target` element will then be that - * particular DOM element. This should be the main way of instantiating - * `Animation` elements. + * instance of this widget on page load for each DOM element which + * matches this selector. The `PublicWidget.$target` element will then be + * that particular DOM element. This should be the main way of instantiating + * `PublicWidget` elements. * * @todo do not make this part of the Widget but rather an info to give when * registering the widget. @@ -218,11 +218,10 @@ var PublicWidget = Widget.extend({ this.options = options || {}; }, /** - * Destroys the animation and basically restores the target to the state it + * Destroys the widget and basically restores the target to the state it * was before the start method was called (unlike standard widget, the - * associated $el DOM is not removed). - * - * Also stops animation effects and destroys them if any. + * associated $el DOM is not removed, if this was instantiated thanks to the + * selector property). */ destroy: function () { if (this.selector) { @@ -330,17 +329,16 @@ var PublicWidget = Widget.extend({ //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** - * The registry object contains the list of available animations. + * The registry object contains the list of widgets that should be instantiated + * thanks to their selector property if any. */ var registry = {}; /** * This is a fix for apple device (<= IPhone 4, IPad 2) * Standard bootstrap requires data-toggle='collapse' element to be tags. - * Unfortunatly one snippet uses a
tag instead. The fix forces an empty + * Unfortunatly some layouts use a tag instead. The fix forces an empty * click handler on these div, which allows standard bootstrap to work. - * - * This should be removed in a future odoo snippets refactoring. */ registry._fixAppleCollapse = PublicWidget.extend({ selector: 'div[data-toggle="collapse"]', diff --git a/addons/website/static/src/js/content/snippets.animation.js b/addons/website/static/src/js/content/snippets.animation.js index ae4df825c50..d2885c0750f 100644 --- a/addons/website/static/src/js/content/snippets.animation.js +++ b/addons/website/static/src/js/content/snippets.animation.js @@ -48,13 +48,13 @@ publicWidget.Widget.include({ disabledInEditableMode: true, /** * Acts as @see Widget.events except that the events are only binded if the - * Animation instance is instanciated in edit mode. The property is not + * Widget instance is instanciated in edit mode. The property is not * considered if @see disabledInEditableMode is false. */ edit_events: null, /** * Acts as @see Widget.events except that the events are only binded if the - * Animation instance is instanciated in readonly mode. The property only + * Widget instance is instanciated in readonly mode. The property only * makes sense if @see disabledInEditableMode is false, you should simply * use @see Widget.events otherwise. */ @@ -779,7 +779,7 @@ registry.gallery = publicWidget.Widget.extend({ $modal.appendTo(document.body); $modal.one('shown.bs.modal', function () { - self.trigger_up('animation_start_demand', { + self.trigger_up('widgets_start_request', { editableMode: false, $target: $modal.find('.modal-body.o_slideshow'), }); diff --git a/addons/website/static/src/js/content/website_root.js b/addons/website/static/src/js/content/website_root.js index fee9488583e..e1a7be21487 100644 --- a/addons/website/static/src/js/content/website_root.js +++ b/addons/website/static/src/js/content/website_root.js @@ -19,7 +19,7 @@ var WebsiteRoot = publicRootData.PublicRoot.extend({ 'shown.bs.modal': '_onModalShown', }), custom_events: _.extend({}, publicRootData.PublicRoot.prototype.custom_events || {}, { - 'ready_to_clean_for_save': '_onAnimationStopDemand', + 'ready_to_clean_for_save': '_onWidgetsStopRequest', }), /** @@ -90,7 +90,7 @@ var WebsiteRoot = publicRootData.PublicRoot.extend({ /** * @override */ - _onAnimationStartDemand: function (ev) { + _onWidgetsStartRequest: function (ev) { ev.data.options = _.clone(ev.data.options || {}); ev.data.options.editableMode = ev.data.editableMode; this._super.apply(this, arguments); diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index c6423fa359d..b90f1f91075 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -16,13 +16,13 @@ options.Class.include({ //-------------------------------------------------------------------------- /** - * Refreshes all animations related to the given element. + * Refreshes all public widgets related to the given element. * * @private * @param {jQuery} [$el=this.$target] */ - _refreshAnimations: function ($el) { - this.trigger_up('animation_start_demand', { + _refreshPublicWidgets: function ($el) { + this.trigger_up('widgets_start_request', { editableMode: true, $target: $el || this.$target, }); @@ -246,7 +246,7 @@ options.registry.carousel = options.Class.extend({ } }); _.defer(function () { - self._refreshAnimations(); + self._refreshPublicWidgets(); self.$target.carousel(index > 0 ? --index : cycle); }); } @@ -544,7 +544,7 @@ options.registry.parallax = options.Class.extend({ start: function () { var self = this; this.$target.on('snippet-option-change snippet-option-preview', function () { - self._refreshAnimations(); + self._refreshPublicWidgets(); }); return this._super.apply(this, arguments); }, @@ -561,13 +561,13 @@ options.registry.parallax = options.Class.extend({ // there may have been changes in the page that influenced the parallax // rendering (new snippets, ...). // TODO make this automatic. - this._refreshAnimations(); + this._refreshPublicWidgets(); }, /** * @override */ onMove: function () { - this._refreshAnimations(); + this._refreshPublicWidgets(); }, //-------------------------------------------------------------------------- @@ -581,7 +581,7 @@ options.registry.parallax = options.Class.extend({ */ scroll: function (previewMode, value) { this.$target.attr('data-scroll-background-ratio', value); - this._refreshAnimations(); + this._refreshPublicWidgets(); }, //-------------------------------------------------------------------------- @@ -674,7 +674,7 @@ var FacebookPageDialog = weWidgets.Dialog.extend({ * @param {boolean} toggle */ _toggleWarning: function (toggle) { - this.trigger_up('animation_stop_demand', { + this.trigger_up('widgets_stop_request', { $target: this.$previewPage, }); this.$('.facebook_page_warning').toggleClass('d-none', toggle); @@ -704,8 +704,7 @@ var FacebookPageDialog = weWidgets.Dialog.extend({ }); options.registry.facebookPage = options.Class.extend({ /** - * Initializes the required facebook page data to create the animation - * iframe. + * Initializes the required facebook page data to create the iframe. * * @override */ @@ -789,7 +788,7 @@ options.registry.facebookPage = options.Class.extend({ $el.attr('data-' + key, value); $el.data(key, value); }); - self._refreshAnimations($el); + self._refreshPublicWidgets($el); }, }); @@ -825,7 +824,7 @@ options.registry.ul = options.Class.extend({ toggleClass: function () { this._super.apply(this, arguments); - this.trigger_up('animation_stop_demand', { + this.trigger_up('widgets_stop_request', { $target: this.$target, }); @@ -846,7 +845,7 @@ options.registry.ul = options.Class.extend({ .prepend(''); $li.removeClass('o_open').next().addClass('o_close'); this.$target.find('li').removeClass('o_open'); - this._refreshAnimations(); + this._refreshPublicWidgets(); }, }); @@ -1188,7 +1187,7 @@ options.registry.gallery = options.Class.extend({ // Apply layout animation this.$target.off('slide.bs.carousel').off('slid.bs.carousel'); this.$('li.fa').off('click'); - this._refreshAnimations(); + this._refreshPublicWidgets(); }, /** * Allows to change the style of the individual images. diff --git a/addons/website/static/src/js/menu/edit.js b/addons/website/static/src/js/menu/edit.js index e3883cac4b3..a9712be72bb 100644 --- a/addons/website/static/src/js/menu/edit.js +++ b/addons/website/static/src/js/menu/edit.js @@ -92,7 +92,7 @@ var EditPageMenu = websiteNavbarData.WebsiteNavbarActionWidget.extend({ if (this.editModeEnable) { return; } - this.trigger_up('animation_stop_demand', { + this.trigger_up('widgets_stop_request', { $target: this._targetForEdition(), }); var $welcomeMessageParent = null; @@ -112,7 +112,7 @@ var EditPageMenu = websiteNavbarData.WebsiteNavbarActionWidget.extend({ .not('[data-editor-message]') .attr('data-editor-message', _t('DRAG BUILDING BLOCKS HERE')); var def = $.Deferred(); - self.trigger_up('animation_start_demand', { + self.trigger_up('widgets_start_request', { editableMode: true, onSuccess: def.resolve.bind(def), onFailure: def.reject.bind(def), @@ -154,77 +154,77 @@ var EditPageMenu = websiteNavbarData.WebsiteNavbarActionWidget.extend({ /** * Called when content will be destroyed in the page. Notifies the - * WebsiteRoot that is should stop the animations. + * WebsiteRoot that is should stop the public widgets. * * @private * @param {OdooEvent} ev */ _onContentWillBeDestroyed: function (ev) { - this.trigger_up('animation_stop_demand', { + this.trigger_up('widgets_stop_request', { $target: ev.data.$target, }); }, /** * Called when content was recreated in the page. Notifies the - * WebsiteRoot that is should start the animations. + * WebsiteRoot that is should start the public widgets. * * @private * @param {OdooEvent} ev */ _onContentWasRecreated: function (ev) { - this.trigger_up('animation_start_demand', { + this.trigger_up('widgets_start_request', { editableMode: true, $target: ev.data.$target, }); }, /** * Called when edition will stop. Notifies the - * WebsiteRoot that is should stop the animations. + * WebsiteRoot that is should stop the public widgets. * * @private * @param {OdooEvent} ev */ _onEditionWillStop: function (ev) { this.$editorMessageElements.removeAttr('data-editor-message'); - this.trigger_up('animation_stop_demand', { + this.trigger_up('widgets_stop_request', { $target: this._targetForEdition(), }); }, /** * Called when edition was stopped. Notifies the - * WebsiteRoot that is should start the animations. + * WebsiteRoot that is should start the public widgets. * * @private * @param {OdooEvent} ev */ _onEditionWasStopped: function (ev) { - this.trigger_up('animation_start_demand', { + this.trigger_up('widgets_start_request', { $target: this._targetForEdition(), }); this.editModeEnable = false; }, /** * Called when a snippet is cloned in the page. Notifies the WebsiteRoot - * that is should start the animations for this snippet. + * that is should start the public widgets for this snippet. * * @private * @param {OdooEvent} ev */ _onSnippetCloned: function (ev) { - this.trigger_up('animation_start_demand', { + this.trigger_up('widgets_start_request', { editableMode: true, $target: ev.data.$target, }); }, /** * Called when a snippet is dropped in the page. Notifies the WebsiteRoot - * that is should start the animations for this snippet. + * that is should start the public widgets for this snippet. * * @private * @param {OdooEvent} ev */ _onSnippetDropped: function (ev) { - this.trigger_up('animation_start_demand', { + this.trigger_up('widgets_start_request', { editableMode: true, $target: ev.data.$target, }); diff --git a/addons/website/static/src/js/widgets/theme.js b/addons/website/static/src/js/widgets/theme.js index a5e0731e4b0..f35769a3748 100644 --- a/addons/website/static/src/js/widgets/theme.js +++ b/addons/website/static/src/js/widgets/theme.js @@ -619,9 +619,9 @@ var ThemeCustomizeDialog = Dialog.extend({ $allLinks.remove(); }); }).then(function () { - // Some animations may depend on the variables that were + // Some public widgets may depend on the variables that were // customized, so we have to restart them. - self.trigger_up('animation_start_demand'); + self.trigger_up('widgets_start_request'); }); }, /** diff --git a/addons/website_blog/static/src/js/s_latest_posts_editor.js b/addons/website_blog/static/src/js/s_latest_posts_editor.js index 10052de87b7..0528aa522fc 100644 --- a/addons/website_blog/static/src/js/s_latest_posts_editor.js +++ b/addons/website_blog/static/src/js/s_latest_posts_editor.js @@ -18,7 +18,7 @@ sOptions.registry.js_get_posts_limit = sOptions.Class.extend({ postsLimit: function (previewMode, value, $opt) { value = parseInt(value); this.$target.attr('data-posts-limit', value).data('postsLimit', value); - this.trigger_up('animation_start_demand', { + this.trigger_up('widgets_start_request', { editableMode: true, $target: this.$target, }); @@ -79,7 +79,7 @@ sOptions.registry.js_get_posts_selectBlog = sOptions.Class.extend({ filterByBlogId: function (previewMode, value, $opt) { value = parseInt(value); this.$target.attr('data-filter-by-blog-id', value).data('filterByBlogId', value); - this.trigger_up('animation_start_demand', { + this.trigger_up('widgets_start_request', { editableMode: true, $target: this.$target, }); diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index 1b132b32b85..09b4677fe61 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -400,7 +400,7 @@ publicWidget.registry.WebsiteSale = publicWidget.Widget.extend(ProductConfigurat $carousel.carousel(0); this._startZoom(); // fix issue with carousel height - this.trigger_up('animation_start_demand', {$target: $carousel}); + this.trigger_up('widgets_start_request', {$target: $carousel}); } } else { // compatibility 12.0 diff --git a/addons/website_twitter/static/src/js/website.twitter.editor.js b/addons/website_twitter/static/src/js/website.twitter.editor.js index 53509d88568..bc9a38a4414 100644 --- a/addons/website_twitter/static/src/js/website.twitter.editor.js +++ b/addons/website_twitter/static/src/js/website.twitter.editor.js @@ -46,7 +46,7 @@ sOptions.registry.twitter = sOptions.Class.extend({ this.$target.on('click.website_twitter', '.lnk_configure', function (e) { window.location = e.currentTarget.href; }); - this.trigger_up('animation_stop_demand', { + this.trigger_up('widgets_stop_request', { $target: this.$target, }); return this._super.apply(this, arguments);