diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index 7667291ca0b..509fa04089f 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -294,6 +294,27 @@ var SnippetOption = Widget.extend({ this.$target.addClass(value); } }, + /** + * Default option method which allows to select one and only one value in + * the option values set and set it on the associated snippet as a data + * attribute. The name of the data attribute is given by the closest + * ancestor's data value for 'attributeName'. + * + * @param {boolean} previewMode - @see this.selectClass + * @param {Object} value - the data attribute value to set + * @param {jQuery} $opt - the related DOMElement option + */ + selectDataAttribute: function (previewMode, value, $opt) { + const $ancestor = $opt && $opt.closest('[data-attribute-name]'); + if (!$ancestor || !$ancestor.length) { + return; + } + const dataName = $ancestor[0].dataset.attributeName; + if (!dataName) { + return; + } + this.$target[0].dataset[dataName] = value || ''; + }, /** * Default option method which allows to select one or multiple classes in * the option classes set and set it on the associated snippet. The common @@ -528,6 +549,23 @@ var SnippetOption = Widget.extend({ .addClass('active'); } + // --- SELECT DATA ATTRIBUTE --- + + this.$el.find('[data-select-data-attribute]') + .removeClass('active') + .filter((i, el) => { + const ancestorEl = el.closest('[data-attribute-name]'); + if (!ancestorEl) { + return false; + } + const dataName = ancestorEl.dataset.attributeName; + const defaultValue = ancestorEl.dataset.attributeDefaultValue; + const dataValue = el.dataset.selectDataAttribute; + const targetValue = this.$target[0].dataset[dataName] || defaultValue; + return (!targetValue && !dataValue) || targetValue === dataValue; + }) + .addClass('active'); + // --- SET DATA ATTRIBUTE --- (note: important to be done last because of active removal) this.el.querySelectorAll('[data-set-data-attribute]').forEach(el => { diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index d159c10ee16..2d5747e57e3 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -9,8 +9,28 @@ var options = require('web_editor.snippets.options'); var _t = core._t; var qweb = core.qweb; +// TODO should we refresh public widgets for all option changes by default ? options.Class.include({ + //-------------------------------------------------------------------------- + // Options + //-------------------------------------------------------------------------- + + /** + * @override + */ + setDataAttribute: function (previewMode, dataName, $opt) { + this._super(...arguments); + this._refreshPublicWidgets(); + }, + /** + * @override + */ + selectDataAttribute: function (previewMode, value, $opt) { + this._super(...arguments); + this._refreshPublicWidgets(); + }, + //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- @@ -690,33 +710,6 @@ options.registry.parallax = options.Class.extend({ onMove: function () { this._refreshPublicWidgets(); }, - - //-------------------------------------------------------------------------- - // Options - //-------------------------------------------------------------------------- - - /** - * Changes the scrolling speed of the parallax effect. - * - * @see this.selectClass for parameters - */ - scroll: function (previewMode, value) { - this.$target.attr('data-scroll-background-ratio', value); - this._refreshPublicWidgets(); - }, - - //-------------------------------------------------------------------------- - // Private - //-------------------------------------------------------------------------- - - /** - * @override - */ - _setActive: function () { - this._super.apply(this, arguments); - this.$el.find('[data-scroll]').removeClass('active') - .filter('[data-scroll="' + (this.$target.attr('data-scroll-background-ratio') || 0) + '"]').addClass('active'); - }, }); var FacebookPageDialog = weWidgets.Dialog.extend({ diff --git a/addons/website/views/snippets.xml b/addons/website/views/snippets.xml index 79fbc30e51b..c8c89c0bebe 100644 --- a/addons/website/views/snippets.xml +++ b/addons/website/views/snippets.xml @@ -1244,15 +1244,15 @@
- - No-scroll + + No-scroll - Fixed + Fixed - Very Slow - Slow - Fast - Very Fast + Very Slow + Slow + Fast + Very Fast
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 0c6ae3fc948..6000b2d27a7 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 @@ -1,46 +1,9 @@ odoo.define('website_blog.s_latest_posts_editor', function (require) { 'use strict'; -var core = require('web.core'); var sOptions = require('web_editor.snippets.options'); var wUtils = require('website.utils'); -var _t = core._t; - -sOptions.registry.js_get_posts_limit = sOptions.Class.extend({ - - //-------------------------------------------------------------------------- - // Options - //-------------------------------------------------------------------------- - - /** - * @see this.selectClass for parameters - */ - postsLimit: function (previewMode, value, $opt) { - value = parseInt(value); - this.$target.attr('data-posts-limit', value).data('postsLimit', value); - this.trigger_up('widgets_start_request', { - editableMode: true, - $target: this.$target, - }); - }, - - //-------------------------------------------------------------------------- - // Private - //-------------------------------------------------------------------------- - - /** - * @override - */ - _setActive: function () { - this._super.apply(this, arguments); - var activeLimit = this.$target.data('postsLimit') || 3; - - this.$el.find('[data-posts-limit]').removeClass('active'); - this.$el.find('[data-posts-limit=' + activeLimit + ']').addClass('active'); - }, -}); - sOptions.registry.js_get_posts_selectBlog = sOptions.Class.extend({ /** * @override diff --git a/addons/website_blog/views/snippets.xml b/addons/website_blog/views/snippets.xml index 3e9c8e0bfbe..388bf6e0fbb 100644 --- a/addons/website_blog/views/snippets.xml +++ b/addons/website_blog/views/snippets.xml @@ -17,18 +17,18 @@ -
- - 1 post max - 2 posts max - 3 posts max - 4 posts max - 5 posts max - 6 posts max - 7 posts max - 8 posts max - 9 posts max - 10 posts max +
+ + 1 post max + 2 posts max + 3 posts max + 4 posts max + 5 posts max + 6 posts max + 7 posts max + 8 posts max + 9 posts max + 10 posts max