From f6dfa6ee47d5a4526306669e583b71c1c6d3528d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Wed, 19 Sep 2018 17:22:39 +0200 Subject: [PATCH] [FIX] website: make ?enable_seo more robust Sometimes we try to append a query string to an url, but if there is a remaining anchor, the query string will not be added at the right place. The title and description tags might not exist (translated page) so it would be displaying false instead of empty string. PR: #27110 task-1885419 --- addons/website/static/src/js/menu/seo.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/addons/website/static/src/js/menu/seo.js b/addons/website/static/src/js/menu/seo.js index 4267cad2bbf..dd1c3a7baf0 100644 --- a/addons/website/static/src/js/menu/seo.js +++ b/addons/website/static/src/js/menu/seo.js @@ -217,13 +217,10 @@ var HtmlPage = Class.extend(mixins.PropertiesMixin, { this.initDescription = this.description(); }, url: function () { - var url = window.location.href; - var hashIndex = url.indexOf('?'); - return hashIndex >= 0 ? url.substring(0, hashIndex) : url; + return window.location.origin + window.location.pathname; }, title: function () { - var $title = $('title'); - return ($title.length > 0) && $title.text() && $title.text().trim(); + return $('title').text().trim(); }, changeTitle: function (title) { // TODO create tag if missing @@ -231,8 +228,7 @@ var HtmlPage = Class.extend(mixins.PropertiesMixin, { this.trigger('title-changed', title); }, description: function () { - var $description = $('meta[name=description]'); - return ($description.length > 0) && ($description.attr('content') && $description.attr('content').trim()); + return ($('meta[name=description]').attr('content') || '').trim(); }, changeDescription: function (description) { // TODO create tag if missing @@ -801,7 +797,7 @@ var SeoMenu = websiteNavbarData.WebsiteNavbarActionWidget.extend({ init: function (parent, options) { this._super(parent, options); - if (window.location.href.includes('enable_seo')) { + if ($.deparam.querystring().enable_seo !== undefined) { this._promoteCurrentPage(); } },