1var remoji_id; 2var remoji_type; 3 4document.addEventListener( 'DOMContentLoaded', function() { jQuery( document ).ready( function( $ ) { 5 6 /** 7 * Count the view 8 */ 9 function remoji_postview() { 10 $.ajax( { 11 url: remoji.postview_url, 12 type: 'POST', 13 data: { post_id: remoji.postview_id }, 14 dataType: 'json', 15 success: function( res ) { 16 var counter_ele = '[data-remoji_counter=' + remoji.postview_id + ']'; 17 if ( res._res !== 'ok' ) { 18 if ( res._msg ) { 19 $( counter_ele ).append( res._msg ); 20 } 21 } else { 22 $( counter_ele ).html( res.num ); 23 } 24 } 25 } ); 26 } 27 28 /** 29 * Postview counter 30 */ 31 if ( remoji.hasOwnProperty( 'postview_delay' ) ) { 32 setTimeout( remoji_postview, remoji.postview_delay * 1000 ); 33 } 34 35 /** 36 * Show large version preview of emoji 37 */ 38 function remoji_show_large() { 39 var remoji_name = $( this ).data( 'remoji-name' ); 40 var large_img = $( this ).children().attr( 'src' ); 41 $( '#remoji_preview' ).html( '<img src="' + large_img + '" />' ); 42 $( '#remoji_preview_text' ).html( remoji_name ); 43 } 44 45 function remoji_hide_large() { 46 $( '#remoji_preview' ).html( '' ); 47 $( '#remoji_preview_text' ).html( '' ); 48 } 49 50 /** 51 * Display the emoji picker panel 52 */ 53 function remoji_load_panel( e ) { 54 remoji_id = $( this ).data( 'remoji-id' ); 55 remoji_type = $( this ).data( 'remoji-type' ); 56 57 if ( $( '#remoji_panel' ).length ) { 58 remoji_locate_panel( this ); 59 } 60 else { 61 remoji_fetch_reaction_panel( this ); 62 } 63 } 64 65 /** 66 * Locate the panel based on current add button 67 */ 68 function remoji_locate_panel( that ) { 69 var position = $( that ).position(); 70 $( '#remoji_panel' ).insertAfter( that ).css( 'left', position.left ).show(); 71 } 72 73 /** 74 * REST fetch the emoji panel 75 */ 76 function remoji_fetch_reaction_panel( that ) { 77 $.get( remoji.show_reaction_panel_url, 78 function( res ) { 79 if ( res._res !== 'ok' ) { 80 $( '.remoji_error_bar[data-remoji-id=' + remoji_id + '][data-remoji-type=' + remoji_type + ']' ).css( 'display', 'inline-block' ).show().fadeOut( 2000 ); 81 return; 82 } 83 84 if ( $( '#remoji_panel' ).length ) { 85 return; 86 } 87 88 $( 'body' ).append( res.data ); 89 90 $( '.remoji_picker_item' ).click( remoji_submit_reaction ); 91 $( '.remoji_picker_item' ).hover( remoji_show_large, remoji_hide_large ); 92 93 remoji_locate_panel( that ); 94 } ); 95 } 96 97 /** 98 * Emoji react submission 99 */ 100 function remoji_submit_reaction( e ) { 101 var that = this; 102 103 var this_remoji_id = $( this ).data( 'remoji-id' ) ? $( this ).data( 'remoji-id' ) : remoji_id; 104 var this_remoji_type = $( this ).data( 'remoji-type' ) ? $( this ).data( 'remoji-type' ) : remoji_type; 105 var this_remoji_name = $( this ).data( 'remoji-name' ); 106 107 $.ajax( { 108 url: remoji.reaction_submit_url, 109 type: 'POST', 110 data: { emoji: this_remoji_name, related_id: this_remoji_id, related_type: this_remoji_type }, 111 dataType: 'json', 112 beforeSend: function ( xhr ) { 113 xhr.setRequestHeader( 'X-WP-Nonce', remoji.nonce ) ; 114 }, 115 success: function( res ) { 116 if ( res._res !== 'ok' ) { 117 if ( res._msg ) { 118 $( '.remoji_error_bar[data-remoji-id=' + this_remoji_id + '][data-remoji-type=' + this_remoji_type + ']' ).html( res._msg ); 119 } 120 $( '.remoji_error_bar[data-remoji-id=' + this_remoji_id + '][data-remoji-type=' + this_remoji_type + ']' ).css( 'display', 'inline-block' ).show().fadeOut( 2000 ); 121 } else { 122 // Add the emoji to emoji bar 123 var this_selector = '.remoji_container[data-remoji-id=' + this_remoji_id + '][data-remoji-type="' + this_remoji_type + '"][data-remoji-name="' + this_remoji_name + '"]'; 124 if ( $( this_selector ).length > 0 ) { 125 $( this_selector + ' .remoji_count' ).html( $( this_selector + ' .remoji_count' ).text() * 1 + 1 ); 126 } 127 else { 128 // Insert a new emoji 129 var new_ele = $( '<div />' ).addClass( 'remoji_container' ).attr( 'data-remoji-id', this_remoji_id ).attr( 'data-remoji-type', this_remoji_type ).attr( 'data-remoji-name', this_remoji_name ) 130 .append( $( '<img />' ).attr( 'src', res.src ) ) 131 .append( $( '<span />' ).addClass( 'remoji_count' ).html( '1' ) ); 132 new_ele.insertBefore( $( '.remoji_add_container[data-remoji-id=' + this_remoji_id + '][data-remoji-type=' + this_remoji_type + ']' ) ).click( remoji_submit_reaction ); 133 } 134 } 135 136 } 137 } ); 138 } 139 140 $( '.remoji_add_container' ).click( remoji_load_panel ); 141 $( '.remoji_container' ).click( remoji_submit_reaction ); 142 143 /** 144 * Hide the panel after clicked anywhere other than the add btn 145 */ 146 $( document ).mouseup( function(e) { 147 var container = $( "#remoji_panel" ); 148 var remoji_picker_item = $( '.remoji_picker_item' ); 149 var remoji_picker_item_img = $( '.remoji_picker_item img' ); 150 151 if ( container.is( ':hidden' ) ) { 152 return; 153 } 154 155 // If the target of the click isn't the container 156 if ( ! container.is( e.target ) && container.has( e.target ).length === 0 ) { 157 container.hide(); 158 return; 159 } 160 161 if ( remoji_picker_item.is( e.target ) || remoji_picker_item_img.is( e.target ) ) { 162 container.hide(); 163 } 164 } ); 165 166} ); } );
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.