[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
This commit is contained in:
Sébastien Theys
2018-09-25 16:09:19 +02:00
parent 01e92a0fa8
commit f6dfa6ee47
+4 -8
View File
@@ -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();
}
},