diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website/static/src/snippets/s_share | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website/static/src/snippets/s_share')
| -rw-r--r-- | addons/website/static/src/snippets/s_share/000.js | 49 | ||||
| -rw-r--r-- | addons/website/static/src/snippets/s_share/000.scss | 65 |
2 files changed, 114 insertions, 0 deletions
diff --git a/addons/website/static/src/snippets/s_share/000.js b/addons/website/static/src/snippets/s_share/000.js new file mode 100644 index 00000000..b6d630b1 --- /dev/null +++ b/addons/website/static/src/snippets/s_share/000.js @@ -0,0 +1,49 @@ +odoo.define('website.s_share', function (require) { +'use strict'; + +const publicWidget = require('web.public.widget'); + +const ShareWidget = publicWidget.Widget.extend({ + selector: '.s_share, .oe_share', // oe_share for compatibility + + /** + * @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) { + return a + url + c; + }).replace(titleRegex, function (match, a, b, c) { + if ($a.hasClass('s_share_whatsapp')) { + // WhatsApp does not support the "url" GET parameter. + // Instead we need to include the url within the passed "text" parameter, merging everything together. + // e.g of output: + // https://wa.me/?text=%20OpenWood%20Collection%20Online%20Reveal%20%7C%20My%20Website%20http%3A%2F%2Flocalhost%3A8888%2Fevent%2Fopenwood-collection-online-reveal-2021-06-21-2021-06-23-8%2Fregister + // see https://faq.whatsapp.com/general/chats/how-to-use-click-to-chat/ for more details + return a + title + url + c; + } + return a + title + c; + }); + }); + if ($a.attr('target') && $a.attr('target').match(/_blank/i) && !$a.closest('.o_editable').length) { + $a.on('click', function () { + window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=550,width=600'); + return false; + }); + } + }); + + return this._super.apply(this, arguments); + }, +}); + +publicWidget.registry.share = ShareWidget; + +return ShareWidget; +}); diff --git a/addons/website/static/src/snippets/s_share/000.scss b/addons/website/static/src/snippets/s_share/000.scss new file mode 100644 index 00000000..85ab9edd --- /dev/null +++ b/addons/website/static/src/snippets/s_share/000.scss @@ -0,0 +1,65 @@ + +.s_share { + > * { + display: inline-block; + vertical-align: middle; + } + .s_share_title { + margin: 0 .4rem 0 0; + } + a { + i.fa { + display: flex; + justify-content: center; + align-items: center; + } + margin: .2rem; + } + &:not(.no_icon_color) { + .s_share_facebook { + &, &:hover, &:focus { + @extend .text-facebook; + } + } + .s_share_twitter { + &, &:hover, &:focus { + @extend .text-twitter; + } + } + .s_share_linkedin { + &, &:hover, &:focus { + @extend .text-linkedin; + } + } + .s_share_google { + &, &:hover, &:focus { + @extend .text-google-plus; + } + } + .s_share_whatsapp { + &, &:hover, &:focus { + @extend .text-whatsapp; + } + } + .s_share_pinterest { + &, &:hover, &:focus { + @extend .text-pinterest; + } + } + .s_share_github { + &, &:hover, &:focus { + @extend .text-github; + } + } + .s_share_instagram { + &, &:hover, &:focus { + @extend .text-instagram; + } + } + .s_share_youtube { + &, &:hover, &:focus { + @extend .text-youtube; + } + } + } +} |
