1function r9_tinysocial_dispatch_share_event(el, detail) { 2 el.dispatchEvent(new CustomEvent('r9.tinysocial.share', detail)); 3} 4 5function r9_tinysocial_get_event_details(el) { 6 return { 7 network: el.getAttribute('data-network'), 8 url: el.getAttribute('data-url'), 9 title: el.getAttribute('data-title') 10 } 11} 12 13function r9_tinysocial_open_popup( url, width, height ) { 14 const left = ( screen.width / 2 ) - ( width / 2 ); 15 const top = ( screen.height / 2 ) - ( height / 2 ); 16 window.open( url, '', 'left='+left+',top='+top+',width='+width+',height='+height+',menubar=no,status=no,scrollbars=no,toolbar=no' ); 17} 18 19function r9_tinysocial_handle_popup_share(e) { 20 e.preventDefault(); 21 const height = this.getAttribute('data-height') || 350; 22 const width = this.getAttribute('data-width') || 655; 23 24 r9_tinysocial_open_popup(this.getAttribute( 'href' ), width, height); 25 26 const eventDetails = r9_tinysocial_get_event_details(this); 27 r9_tinysocial_dispatch_share_event(this, eventDetails); 28} 29 30async function r9_tinysocial_handle_web_share_api(e) { 31 e.preventDefault(); 32 const shareData = { 33 title: this.getAttribute('data-title'), 34 url: this.getAttribute('data-url'), 35 } 36 37 try { 38 await navigator.share(shareData) 39 40 const eventDetails = r9_tinysocial_get_event_details(this); 41 r9_tinysocial_dispatch_share_event(this, eventDetails); 42 } catch(err) { 43 console.log( 'Error: ' + err ); 44 } 45} 46 47function r9_tinysocial_prepare_buttons(el) { 48 const network = el.getAttribute('data-network'); 49 if (network === 'Webshare') { 50 if (navigator.canShare) { 51 el.addEventListener( 'click', r9_tinysocial_handle_web_share_api); 52 } else { 53 el.classList.add('disabled'); 54 } 55 } else { 56 if (!navigator.canShare) { 57 el.addEventListener('click', r9_tinysocial_handle_popup_share); 58 } else { 59 el.classList.add('disabled'); 60 } 61 } 62} 63 64const r9_tinysocial_buttons = document.querySelectorAll( ".tinysocial:not([data-external])" ); 65[].forEach.call( r9_tinysocial_buttons, (button) => { 66 r9_tinysocial_prepare_buttons(button); 67});
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.