diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-06-06 11:54:35 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-06-06 11:54:35 +0200 |
| commit | 71a50a2214748fec413c5a0f042d0e7172ae6ea9 (patch) | |
| tree | 2e9ee11551350e23923390d9c53baf630b6ed834 /addons/website/static | |
| parent | a7621137cb0d75ec545152d5e1d413c9d3548e45 (diff) | |
| parent | 409679866b2ee8352a8cb27460e7332563526924 (diff) | |
[MERGE] forward port branch saas-12.3 up to 409679866b2
Diffstat (limited to 'addons/website/static')
| -rw-r--r-- | addons/website/static/src/js/content/snippets.animation.js | 4 | ||||
| -rw-r--r-- | addons/website/static/src/js/content/website_root.js | 31 | ||||
| -rw-r--r-- | addons/website/static/src/js/menu/seo.js | 62 | ||||
| -rw-r--r-- | addons/website/static/tests/tours/rte.js | 1 |
4 files changed, 70 insertions, 28 deletions
diff --git a/addons/website/static/src/js/content/snippets.animation.js b/addons/website/static/src/js/content/snippets.animation.js index 7f57eb81f2c..33e1e01ebcc 100644 --- a/addons/website/static/src/js/content/snippets.animation.js +++ b/addons/website/static/src/js/content/snippets.animation.js @@ -860,6 +860,10 @@ registry.gallerySlider = publicWidget.Widget.extend({ destroy: function () { this._super.apply(this, arguments); + if (!this.$indicator) { + return; + } + this.$prev.prependTo(this.$indicator); this.$next.appendTo(this.$indicator); this.$carousel.off('.gallery_slider'); diff --git a/addons/website/static/src/js/content/website_root.js b/addons/website/static/src/js/content/website_root.js index 22c71890643..612265124cd 100644 --- a/addons/website/static/src/js/content/website_root.js +++ b/addons/website/static/src/js/content/website_root.js @@ -19,6 +19,7 @@ var WebsiteRoot = publicRootData.PublicRoot.extend({ }), custom_events: _.extend({}, publicRootData.PublicRoot.prototype.custom_events || {}, { 'ready_to_clean_for_save': '_onWidgetsStopRequest', + seo_object_request: '_onSeoObjectRequest', }), /** @@ -111,6 +112,36 @@ var WebsiteRoot = publicRootData.PublicRoot.extend({ window.location.href = _.str.sprintf("/website/lang/%(lang)s?r=%(url)s%(hash)s", redirect); }, /** + /** + * Checks information about the page SEO object. + * + * @private + * @param {OdooEvent} ev + */ + _onSeoObjectRequest: function (ev) { + var res = this._unslugHtmlDataObject('seo-object'); + ev.data.callback(res); + }, + /** + * Returns a model/id object constructed from html data attribute. + * + * @private + * @param {string} dataAttr + * @returns {Object} an object with 2 keys: model and id, or null + * if not found + */ + _unslugHtmlDataObject: function (dataAttr) { + var repr = $('html').data(dataAttr); + var match = repr && repr.match(/(.+)\((\d+),(.*)\)/); + if (!match) { + return null; + } + return { + model: match[1], + id: match[2] | 0, + }; + }, + /** * @todo review * @private */ diff --git a/addons/website/static/src/js/menu/seo.js b/addons/website/static/src/js/menu/seo.js index 332fde71a4f..b65137ecc8f 100644 --- a/addons/website/static/src/js/menu/seo.js +++ b/addons/website/static/src/js/menu/seo.js @@ -129,17 +129,17 @@ var Keyword = Widget.extend({ _updateTitle: function () { var $title = this.$('.js_seo_keyword_title'); if (this.htmlPage.isInTitle(this.keyword)) { - $title.css('visibility','visible'); + $title.css('visibility', 'visible'); } else { - $title.css('visibility','hidden'); + $title.css('visibility', 'hidden'); } }, _updateDescription: function () { var $description = this.$('.js_seo_keyword_description'); if (this.htmlPage.isInDescription(this.keyword)) { - $description.css('visibility','visible'); + $description.css('visibility', 'visible'); } else { - $description.css('visibility','hidden'); + $description.css('visibility', 'hidden'); } }, }); @@ -210,7 +210,7 @@ var Preview = Widget.extend({ this.url = options.url; this.description = options.description || _t("The description will be generated by search engines based on page content unless you specify one."); if (this.description.length > 160) { - this.description = this.description.substring(0,159) + '…'; + this.description = this.description.substring(0, 159) + '…'; } this._super(parent); }, @@ -289,19 +289,19 @@ var HtmlPage = Class.extend(mixins.PropertiesMixin, { return $('body').children().not('.oe_seo_configuration').find('h2').text(); }, isInBody: function (text) { - return new RegExp(WORD_SEPARATORS_REGEX+text+WORD_SEPARATORS_REGEX, 'gi').test(this.bodyText()); + return new RegExp(WORD_SEPARATORS_REGEX + text + WORD_SEPARATORS_REGEX, 'gi').test(this.bodyText()); }, isInTitle: function (text) { - return new RegExp(WORD_SEPARATORS_REGEX+text+WORD_SEPARATORS_REGEX, 'gi').test(this.title()); + return new RegExp(WORD_SEPARATORS_REGEX + text + WORD_SEPARATORS_REGEX, 'gi').test(this.title()); }, isInDescription: function (text) { - return new RegExp(WORD_SEPARATORS_REGEX+text+WORD_SEPARATORS_REGEX, 'gi').test(this.description()); + return new RegExp(WORD_SEPARATORS_REGEX + text + WORD_SEPARATORS_REGEX, 'gi').test(this.description()); }, isInHeading1: function (text) { - return new RegExp(WORD_SEPARATORS_REGEX+text+WORD_SEPARATORS_REGEX, 'gi').test(this.heading1()); + return new RegExp(WORD_SEPARATORS_REGEX + text + WORD_SEPARATORS_REGEX, 'gi').test(this.heading1()); }, isInHeading2: function (text) { - return new RegExp(WORD_SEPARATORS_REGEX+text+WORD_SEPARATORS_REGEX, 'gi').test(this.heading2()); + return new RegExp(WORD_SEPARATORS_REGEX + text + WORD_SEPARATORS_REGEX, 'gi').test(this.heading2()); }, }); @@ -415,7 +415,7 @@ var MetaTitleDescription = Widget.extend({ _renderPreview: function () { var indexed = this.isIndexed; var preview = ""; - if (indexed){ + if (indexed) { preview = new Preview(this, { title: this.getTitle(), description: this.getDescription(), @@ -447,7 +447,7 @@ var MetaKeywords = Widget.extend({ start: function () { var self = this; this.$input = this.$('input[name=website_meta_keywords]'); - this.keywordList = new KeywordList(this, { htmlPage: this.htmlPage }); + this.keywordList = new KeywordList(this, {htmlPage: this.htmlPage}); this.keywordList.on('list-full', this, function () { self.$input.attr({ readonly: 'readonly', @@ -494,7 +494,7 @@ var MetaKeywords = Widget.extend({ model: 'website', method: 'get_languages', args: [[context.website_id]], - }).then( function (data) { + }).then(function (data) { self.$('#language-box').html(core.qweb.render('Configurator.language_promote', { 'language': data, 'def_lang': context.lang @@ -508,7 +508,7 @@ var MetaKeywords = Widget.extend({ * @param {boolean} removed: a keyword is about to be removed, * we need to exclude it from the count */ - _updateTable : function (removed) { + _updateTable: function (removed) { var min = removed ? 1 : 0; if (this.keywordList.keywords().length > min) { this.$('table').show(); @@ -562,7 +562,7 @@ var MetaImageSelector = Widget.extend({ _setDescription: function (description) { this.metaDescription = description || _t("The description will be generated by social media based on page content unless you specify one."); if (this.metaDescription.length > 160) { - this.metaDescription = this.metaDescription.substring(0,159) + '…'; + this.metaDescription = this.metaDescription.substring(0, 159) + '…'; } }, @@ -731,19 +731,25 @@ var SeoConfigurator = Dialog.extend({ }); }, getMainObject: function () { - var repr = $('html').data('main-object'); - var m = repr.match(/(.+)\((\d+),(.*)\)/); - if (!m) { - return null; - } else { - return { - model: m[1], - id: m[2]|0 - }; - } + var mainObject; + this.trigger_up('main_object_request', { + callback: function (value) { + mainObject = value; + }, + }); + return mainObject; + }, + getSeoObject: function () { + var seoObject; + this.trigger_up('seo_object_request', { + callback: function (value) { + seoObject = value; + }, + }); + return seoObject; }, loadMetaData: function () { - var obj = this.getMainObject(); + var obj = this.getSeoObject() || this.getMainObject(); return new Promise(function (resolve, reject) { if (!obj) { // return Promise.reject(new Error("No main_object was found.")); @@ -751,7 +757,7 @@ var SeoConfigurator = Dialog.extend({ } else { var fields = ['website_meta_title', 'website_meta_description', 'website_meta_keywords' ,'website_meta_og_img']; - if (obj.model === 'website.page'){ + if (obj.model === 'website.page') { fields.push('website_indexed'); fields.push('website_id'); } @@ -772,7 +778,7 @@ var SeoConfigurator = Dialog.extend({ }); }, saveMetaData: function (data) { - var obj = this.getMainObject(); + var obj = this.getSeoObject() || this.getMainObject(); if (!obj) { return Promise.reject(); } else { diff --git a/addons/website/static/tests/tours/rte.js b/addons/website/static/tests/tours/rte.js index e29f40e45ed..716562389e7 100644 --- a/addons/website/static/tests/tours/rte.js +++ b/addons/website/static/tests/tours/rte.js @@ -13,6 +13,7 @@ var ready = Promise.all([domReady, session.is_bound, ajax.loadXML()]); tour.register('rte_translator', { test: true, + url: '/', wait_for: ready, url: '/', }, [{ |
