diff options
Diffstat (limited to 'addons/web/static/src/js')
| -rw-r--r-- | addons/web/static/src/js/public/public_root.js | 92 | ||||
| -rw-r--r-- | addons/web/static/src/js/public/public_widget.js | 24 |
2 files changed, 57 insertions, 59 deletions
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,20 +203,20 @@ 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); }, //-------------------------------------------------------------------------- @@ -224,28 +224,6 @@ var PublicRoot = publicWidget.RootWidget.extend(ServiceProviderMixin, { //-------------------------------------------------------------------------- /** - * 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. * * @private @@ -273,6 +251,28 @@ var PublicRoot = publicWidget.RootWidget.extend(ServiceProviderMixin, { }); }, /** + * 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 <a/> tags. - * Unfortunatly one snippet uses a <div/> tag instead. The fix forces an empty + * Unfortunatly some layouts use a <div/> 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"]', |
