1/** 2 * Share buttons. 3 */ 4 5( function( $ ) { 6 7 $( document ).ready( function() { 8 9 // Blockquote 10 let blockquoteLength = $( '.pk-share-buttons-blockquote' ).length; 11 12 if ( blockquoteLength ) { 13 $( '.entry-content' ).find( 'blockquote' ).each( function( index, item ) { 14 15 if ( $( item ).closest( '.wp-block-embed' ).length ) { 16 return; 17 } 18 19 if ( $( item ).closest( '.twitter-tweet' ).length ) { 20 return; 21 } 22 23 var text = $( this ).find( 'p' ).text(); 24 25 if ( ! text ) { 26 text = $( this ).text(); 27 } 28 29 let container = $( '.pk-share-buttons-blockquote' ).not( '.pk-share-buttons-blockquote-clone' ).clone().appendTo( item ); 30 31 container.addClass( 'pk-share-buttons-blockquote-clone' ); 32 33 container.find( '.pk-share-buttons-link' ).each( function( index, item ) { 34 35 let url = $( this ).attr( 'href' ).replace( '--SHARETEXT--', encodeURIComponent( text ) ); 36 37 $( this ).attr( 'href', url ); 38 } ); 39 } ); 40 } 41 42 // Highlight and Share 43 let highlightLength = $( '.pk-share-buttons-highlight-text' ).length; 44 45 if ( highlightLength ) { 46 47 /* 48 * Events 49 */ 50 51 $( 'body' ).on( 'mouseup', function( e ) { 52 if ( ! $( e.target ).closest( '.entry-content' ).length && 53 ! $( e.target ).closest( '.pk-share-buttons-wrap' ).length ) { 54 highlightRemove(); 55 } 56 } ); 57 58 $( 'body' ).on( 'mouseup', '.entry-content', function( e ) { 59 e.preventDefault(); 60 61 highlightRemove(); 62 63 let selection = window.getSelection(); 64 let text = selection.toString(); 65 66 // Current title. 67 this.title = ''; 68 69 // Check exists text. 70 if ( '' != text ) { 71 highlightDisplay( text, e );; 72 } 73 } ); 74 75 /* 76 * Remove highlight container 77 */ 78 var highlightRemove = function() { 79 $( '.pk-share-buttons-highlight-clone' ).remove(); 80 }; 81 82 /* 83 * Show highlight container 84 */ 85 var highlightDisplay = function( text, e ) { 86 highlightRemove(); 87 88 let container = $( '.pk-share-buttons-highlight-text' ).not( '.pk-share-buttons-highlight-clone' ).clone().appendTo( 'body' ); 89 90 let wrapper_x = e.pageX + 10; 91 let wrapper_y = e.pageY + 10; 92 93 container.addClass( 'pk-share-buttons-highlight-clone' ); 94 95 container.css( { left: wrapper_x, top: wrapper_y } ); 96 97 container.find( '.pk-share-buttons-link' ).each( function( index, item ) { 98 99 let url = $( this ).attr( 'href' ).replace( '--SHARETEXT--', encodeURIComponent( text ) ); 100 101 $( this ).attr( 'href', url ); 102 } ); 103 } 104 } 105 106 // Mobile Share 107 let mobileShare = $( '.pk-share-buttons-layout-right-side, .pk-share-buttons-layout-left-side, .pk-share-buttons-layout-popup' ); 108 109 $( mobileShare ).each( function(index, elem) { 110 $( elem ).find( '.pk-share-buttons-total, .pk-share-buttons-link' ).on( 'click', function(e){ 111 $( 'body' ).toggleClass( 'pk-mobile-share-active' ); 112 }); 113 } ); 114 115 // Close outside. 116 $( document ).on( 'click', function(e) { 117 if ( ! $( e.target ) .closest( '.pk-share-buttons-total' ).length ) { 118 $( 'body' ).removeClass( 'pk-mobile-share-active' ); 119 } 120 }); 121 122 } ); 123 124} )( jQuery );
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.