From fde251330d2bac8757f283f36d6b51b36d8c3a03 Mon Sep 17 00:00:00 2001 From: Ravi Singh Date: Mon, 15 Nov 2021 12:48:08 +0000 Subject: [PATCH] [FIX] website: fix sharers of share snippet The whatsapp sharer was fixed via [1]. This uses https for all sharers and fix the pinterest one using the logo image with their new API. [1]: https://github.com/odoo/odoo/commit/62575b75ff48a34df23f8742737226949f13c13c closes odoo/odoo#79891 X-original-commit: 45497060d9185e7fddb3fc6fcfcbcb81040c8d8b Signed-off-by: Quentin Smetz (qsm) Co-authored-by: jpr-odoo Co-authored-by: qsm-odoo --- .../static/src/snippets/s_share/000.js | 21 ++++++++++++------- addons/website/views/snippets/s_share.xml | 4 ++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/addons/website/static/src/snippets/s_share/000.js b/addons/website/static/src/snippets/s_share/000.js index b6d630b12f8..a5ef7c6c4a0 100644 --- a/addons/website/static/src/snippets/s_share/000.js +++ b/addons/website/static/src/snippets/s_share/000.js @@ -10,14 +10,17 @@ const ShareWidget = publicWidget.Widget.extend({ * @override */ start: function () { - var urlRegex = /(\?(?:|.*&)(?:u|url|body)=)(.*?)(&|#|$)/; - var titleRegex = /(\?(?:|.*&)(?:title|text|subject)=)(.*?)(&|#|$)/; - var url = encodeURIComponent(window.location.href); - var title = encodeURIComponent($('title').text()); - this.$('a').each(function () { - var $a = $(this); - $a.attr('href', function (i, href) { - return href.replace(urlRegex, function (match, a, b, c) { + const urlRegex = /(\?(?:|.*&)(?:u|url|body)=)(.*?)(&|#|$)/; + const titleRegex = /(\?(?:|.*&)(?:title|text|subject|description)=)(.*?)(&|#|$)/; + const mediaRegex = /(\?(?:|.*&)(?:media)=)(.*?)(&|#|$)/; + const url = encodeURIComponent(window.location.href); + const title = encodeURIComponent($('title').text()); + const media = encodeURIComponent($('meta[property="og:image"]').attr('content')); + + this.$('a').each((index, element) => { + const $a = $(element); + $a.attr('href', (i, href) => { + return href.replace(urlRegex, (match, a, b, c) => { return a + url + c; }).replace(titleRegex, function (match, a, b, c) { if ($a.hasClass('s_share_whatsapp')) { @@ -29,6 +32,8 @@ const ShareWidget = publicWidget.Widget.extend({ return a + title + url + c; } return a + title + c; + }).replace(mediaRegex, (match, a, b, c) => { + return a + media + c; }); }); if ($a.attr('target') && $a.attr('target').match(/_blank/i) && !$a.closest('.o_editable').length) { diff --git a/addons/website/views/snippets/s_share.xml b/addons/website/views/snippets/s_share.xml index 54c2aa47455..aaf48d46cf9 100644 --- a/addons/website/views/snippets/s_share.xml +++ b/addons/website/views/snippets/s_share.xml @@ -10,13 +10,13 @@ - + - +