1jQuery(function ($) { 2 3 var $overlay = $('#sp-invite-overlay'); 4 var currentUrl = ''; 5 var currentTitle = ''; 6 7 function setDetail(selector, value) { 8 var $row = $(selector); 9 if (value) { 10 $row.find('span').text(value); 11 $row.addClass('sp-invite-detail-show'); 12 } else { 13 $row.removeClass('sp-invite-detail-show'); 14 } 15 } 16 17 function openModal($trigger) { 18 19 var title = $trigger.attr('data-title') || ''; 20 var subtitle = $trigger.attr('data-subtitle') || ''; 21 var url = $trigger.attr('data-url') || window.location.href; 22 var thumb = $trigger.attr('data-thumb') || ''; 23 var website = $trigger.attr('data-website') || ''; 24 var phone = $trigger.attr('data-phone') || ''; 25 var email = $trigger.attr('data-email') || ''; 26 var address = $trigger.attr('data-address') || ''; 27 28 currentUrl = url; 29 currentTitle = title; 30 31 $('#sp-invite-card-title').text(title); 32 $('#sp-invite-card-subtitle').text(subtitle); 33 34 setDetail('#sp-invite-detail-website', website); 35 setDetail('#sp-invite-detail-phone', phone); 36 setDetail('#sp-invite-detail-email', email); 37 setDetail('#sp-invite-detail-address', address); 38 39 if (thumb) { 40 if ($('#sp-invite-icon-logo').length) { 41 $('#sp-invite-icon-logo').attr('src', thumb); 42 } else { 43 $('.sp-invite-card-icon').html('<img src="' + thumb + '" alt="" id="sp-invite-icon-logo"/>'); 44 } 45 } 46 47 var siteName = (window.submitproInviteShare && submitproInviteShare.siteName) ? submitproInviteShare.siteName : window.location.hostname; 48 var shareText = title + ' - ' + siteName; 49 50 $('#sp-invite-whatsapp').attr('href', 'https://wa.me/?text=' + encodeURIComponent(shareText + ' ' + url)); 51 $('#sp-invite-telegram').attr('href', 'https://t.me/share/url?url=' + encodeURIComponent(url) + '&text=' + encodeURIComponent(shareText)); 52 $('#sp-invite-facebook').attr('href', 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(url)); 53 $('#sp-invite-x').attr('href', 'https://twitter.com/intent/tweet?text=' + encodeURIComponent(shareText) + '&url=' + encodeURIComponent(url)); 54 55 $overlay.addClass('sp-invite-show').attr('aria-hidden', 'false'); 56 } 57 58 function closeModal() { 59 $overlay.removeClass('sp-invite-show').attr('aria-hidden', 'true'); 60 } 61 62 $(document).on('click', '.sp-invite-share-btn', function (e) { 63 e.preventDefault(); 64 openModal($(this)); 65 }); 66 67 $('#sp-invite-close').on('click', closeModal); 68 $overlay.on('click', function (e) { 69 if (e.target === this) { 70 closeModal(); 71 } 72 }); 73 $(document).on('keyup', function (e) { 74 if (e.key === 'Escape') { 75 closeModal(); 76 } 77 }); 78 79 /* Instagram has no share-URL endpoint: copy the listing URL so the 80 user can paste it, then let the link open instagram.com */ 81 $('#sp-invite-instagram').on('click', function () { 82 if (navigator.clipboard && currentUrl) { 83 navigator.clipboard.writeText(currentUrl); 84 } 85 }); 86 87 $('#sp-invite-copy-url').on('click', function () { 88 var $btn = $(this); 89 navigator.clipboard.writeText(currentUrl).then(function () { 90 var original = $btn.html(); 91 $btn.html('<i class="fa fa-check"></i> ' + 'Copied!'); 92 setTimeout(function () { $btn.html(original); }, 1500); 93 }); 94 }); 95 96 /* html2canvas is heavy (46KB) and only needed for this one action, so it 97 is fetched the first time the button is clicked rather than on page load */ 98 function withHtml2Canvas(cb) { 99 if (window.html2canvas) { 100 cb(); 101 return; 102 } 103 var s = document.createElement('script'); 104 s.src = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/html2canvas.min.js'; 105 s.onload = cb; 106 document.head.appendChild(s); 107 } 108 109 $('#sp-invite-copy-card').on('click', function () { 110 var $btn = $(this); 111 withHtml2Canvas(function () { 112 var card = document.getElementById('sp-invite-card'); 113 html2canvas(card, { backgroundColor: '#fdf4f4', scale: 2 }).then(function (canvas) { 114 canvas.toBlob(function (blob) { 115 var original = $btn.html(); 116 if (navigator.clipboard && window.ClipboardItem) { 117 navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]).then(function () { 118 $btn.html('<i class="fa fa-check"></i> Copied!'); 119 setTimeout(function () { $btn.html(original); }, 1500); 120 }).catch(function () { 121 downloadCardImage(blob, $btn, original); 122 }); 123 } else { 124 downloadCardImage(blob, $btn, original); 125 } 126 }); 127 }); 128 }); 129 }); 130 131 function downloadCardImage(blob, $btn, original) { 132 var link = document.createElement('a'); 133 link.href = URL.createObjectURL(blob); 134 link.download = (currentTitle || 'invitation-card').replace(/[^a-z0-9]+/gi, '-').toLowerCase() + '.png'; 135 document.body.appendChild(link); 136 link.click(); 137 document.body.removeChild(link); 138 $btn.html('<i class="fa fa-check"></i> Downloaded!'); 139 setTimeout(function () { $btn.html(original); }, 1500); 140 } 141});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.