]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/social_share_button.js
Merge remote-tracking branch 'upstream/pull/5957'
[rails.git] / app / assets / javascripts / social_share_button.js
1 $(function () {
2   function openShareUrl(url, initialWidth = 640, initialHeight = 480) {
3     const width = Math.max(100, Math.min(screen.width, initialWidth));
4     const height = Math.max(100, Math.min(screen.height, initialHeight));
5
6     const left = screenLeft + ((outerWidth - width) / 2);
7     const top = screenTop + ((outerHeight - height) / 2);
8     const opts = `width=${width},height=${height},left=${left},top=${top},menubar=no,status=no,location=no`;
9
10     window.open(url, "popup", opts);
11   }
12
13   $(".social-share-buttons [data-share-type='site']").on("click", function (e) {
14     e.preventDefault();
15     openShareUrl(this.href);
16   });
17
18   if (navigator.share) {
19     $(".social-share-buttons [data-share-type='native']").prop("hidden", false).on("click", function () {
20       navigator.share({
21         text: this.dataset.shareText,
22         url: this.dataset.shareUrl
23       });
24     });
25   }
26 });