diff options
Diffstat (limited to 'addons/website/static/src')
4 files changed, 66 insertions, 10 deletions
diff --git a/addons/website/static/src/js/content/menu.js b/addons/website/static/src/js/content/menu.js index 7e06140f657..b8ea9f61564 100644 --- a/addons/website/static/src/js/content/menu.js +++ b/addons/website/static/src/js/content/menu.js @@ -13,9 +13,6 @@ sAnimation.registry.affixMenu = sAnimation.Class.extend({ */ start: function () { var def = this._super.apply(this, arguments); - if (this.editableMode) { - return def; - } var self = this; this.$headerClone = this.$target.clone().addClass('o_header_affix affix').removeClass('o_affix_enabled'); diff --git a/addons/website/static/src/js/content/snippets.animation.js b/addons/website/static/src/js/content/snippets.animation.js index d2ef26a1bf6..ae4df825c50 100644 --- a/addons/website/static/src/js/content/snippets.animation.js +++ b/addons/website/static/src/js/content/snippets.animation.js @@ -34,6 +34,54 @@ if (!window.performance || !window.performance.now) { } /** + * Add the notion of edit mode to public widgets. + */ +publicWidget.Widget.include({ + /** + * Indicates if the widget should not be instantiated in edit. The default + * is true, indeed most (all?) defined widgets only want to initialize + * events and states which should not be active in edit mode (this is + * especially true for non-website widgets). + * + * @type {boolean} + */ + 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 + * 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 + * makes sense if @see disabledInEditableMode is false, you should simply + * use @see Widget.events otherwise. + */ + read_events: null, + + /** + * Initializes the events that will need to be binded according to the + * given mode. + * + * @constructor + * @param {Object} parent + * @param {Object} [options] + * @param {boolean} [options.editableMode=false] + * true if the page is in edition mode + */ + init: function (parent, options) { + this._super.apply(this, arguments); + + this.editableMode = this.options.editableMode || false; + var extraEvents = this.editableMode ? this.edit_events : this.read_events; + if (extraEvents) { + this.events = _.extend(this.events || {}, extraEvents); + } + }, +}); + +/** * In charge of handling one animation loop using the requestAnimationFrame * feature. This is used by the `Animation` class below and should not be called * directly by an end developer. @@ -379,6 +427,7 @@ var registry = publicWidget.registry; registry.slider = publicWidget.Widget.extend({ selector: '.carousel', + disabledInEditableMode: false, edit_events: { 'slid.bs.carousel': '_onEditionSlide', }, @@ -669,7 +718,7 @@ registry.ul = publicWidget.Widget.extend({ registry.gallery = publicWidget.Widget.extend({ selector: '.o_gallery:not(.o_slideshow)', xmlDependencies: ['/website/static/src/xml/website.gallery.xml'], - read_events: { + events: { 'click img': '_onClickImg', }, @@ -741,6 +790,7 @@ registry.gallery = publicWidget.Widget.extend({ registry.gallerySlider = publicWidget.Widget.extend({ selector: '.o_slideshow', xmlDependencies: ['/website/static/src/xml/website.gallery.xml'], + disabledInEditableMode: false, /** * @override @@ -820,7 +870,7 @@ registry.gallerySlider = publicWidget.Widget.extend({ registry.socialShare = publicWidget.Widget.extend({ selector: '.oe_social_share', xmlDependencies: ['/website/static/src/xml/website.share.xml'], - read_events: { + events: { 'mouseenter': '_onMouseEnter', }, @@ -947,7 +997,7 @@ registry.facebookPage = publicWidget.Widget.extend({ registry.anchorSlide = publicWidget.Widget.extend({ selector: 'a[href^="/"][href*="#"], a[href^="#"]', - read_events: { + events: { 'click': '_onAnimateClick', }, diff --git a/addons/website/static/src/js/content/website_root.js b/addons/website/static/src/js/content/website_root.js index ce4ebfec435..fee9488583e 100644 --- a/addons/website/static/src/js/content/website_root.js +++ b/addons/website/static/src/js/content/website_root.js @@ -70,6 +70,18 @@ var WebsiteRoot = publicRootData.PublicRoot.extend({ 'edit_translations': !!html.dataset.edit_translations, }, this._super.apply(this, arguments)); }, + /** + * @override + */ + _getPublicWidgetsRegistry: function (options) { + var registry = this._super.apply(this, arguments); + if (options.editableMode) { + return _.pick(registry, function (PublicWidget) { + return !PublicWidget.prototype.disabledInEditableMode; + }); + } + return registry; + }, //-------------------------------------------------------------------------- // Handlers diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index f51dda964db..c6423fa359d 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -246,10 +246,7 @@ options.registry.carousel = options.Class.extend({ } }); _.defer(function () { - self.trigger_up('animation_start_demand', { - editableMode: true, - $target: self.$target, - }); + self._refreshAnimations(); self.$target.carousel(index > 0 ? --index : cycle); }); } |
