1var thirstyFunctions; 2 3jQuery( document ).ready( function($) { 4 5 thirstyFunctions = { 6 7 /** 8 * Function that holds all of the necessary events to trigger a record link stat. 9 * 10 * @since 3.2.0 11 */ 12 recordLinkStatEvents : function() { 13 14 // record link on normal click 15 if ( thirsty_global_vars.enable_record_stats == 'yes' ) 16 $( 'body' ).on( 'click' , 'a' , thirstyFunctions.recordLinkStat ); 17 }, 18 19 /** 20 * Record link clicks AJAX event trigger. 21 * 22 * @since 3.0.0 23 * @since 3.2.0 Removed event trigger. Added keyword variable in the AJAX trigger. 24 * @since 3.3.0 Add javascript redirect feature. 25 * @since 3.3.1 Make sure the duplicate click prevention only works on affiliate links. 26 * @since 3.3.7 Add fail script for enhanced js redirect to still work on AJAX failure. 27 * @since 3.4.0 Make sure query strings are added back when enhanced js redirect is active. 28 */ 29 recordLinkStat : function( e ) { 30 31 var $link = $(this), 32 href = $link.attr( 'href' ), 33 linkID = $link.data( 'linkid' ), 34 keyword = $link[0].innerText, 35 qs = href ? href.split('?')[1] : '', // get the url query strings 36 imgsrc, 37 newWindow; 38 39 if ( ! keyword ) keyword = $link.text(); 40 41 // if link clicked is not an affiliate link, then skip. 42 if ( ! thirstyFunctions.isThirstyLink( href ) && ! linkID ) return; 43 44 // prevent duplicate clicks. 45 if ( $link.data( "clicked" ) ) { 46 e.preventDefault(); 47 return; 48 } 49 $link.data( "clicked" , true ); 50 51 // get image filename and use it as keyword. 52 if ( ! keyword && $link.find( 'img' ).length ) { 53 54 imgsrc = $link.find( 'img' ).prop( 'src' ).split('/'); 55 keyword = imgsrc[ imgsrc.length - 1 ]; 56 } 57 58 if ( thirsty_global_vars.enable_js_redirect === 'yes' && $link.data( 'nojs' ) != true ) { 59 60 e.preventDefault(); 61 62 if ( $link.prop( 'target' ) == '_blank' && ! thirstyFunctions.disableNewWindow() ) 63 newWindow = window.open( '' , '_blank' ); 64 } 65 66 $.post( thirsty_global_vars.ajax_url , { 67 action : 'ta_click_data_redirect', 68 href : href, 69 page : window.location.href, 70 link_id : linkID, 71 keyword : keyword, 72 qs : qs 73 } , function( redirect_url ) { 74 75 $link.data( "clicked" , false ); 76 77 if ( thirsty_global_vars.enable_js_redirect !== 'yes' || $link.data( 'nojs' ) == true ) 78 return; 79 80 if ( newWindow ) 81 newWindow.location.href = redirect_url ? redirect_url : href; 82 else 83 window.location.href = redirect_url ? redirect_url : href; 84 85 } ).fail( function() { 86 87 $link.data( "clicked" , false ); 88 89 if ( thirsty_global_vars.enable_js_redirect !== 'yes' || $link.data( 'nojs' ) == true ) 90 return; 91 92 if ( newWindow ) 93 newWindow.location.href = href; 94 else 95 window.location.href = href; 96 97 } ); 98 }, 99 100 /** 101 * Check if we need to disable new window for enhanced javascript redirects. 102 * This is intended to fix issue on browsing sites with FB/Messenger webview browser on iPhones. 103 * 104 * @since 3.3.6 105 * @since 3.6 Add support for Instagram, Pinterest, Twitter, Electron and Steam. 106 */ 107 disableNewWindow : function() { 108 109 var strings = [ 'FBAN' , 'MessengerForiOS' , 'FBAV' , 'Instagram' , 'Pinterest' , 'Twitter' , 'Electron' , 'Steam' ]; 110 111 for ( var x in strings ) { 112 if ( navigator.userAgent.indexOf( strings[x] ) >= 0 ) 113 return true; 114 } 115 116 return false;
117 }, 118 119 /** 120 * Function to check if the loaded link is a ThirstyAffiliates link or not. 121 * 122 * @since 3.0.0 123 * @since 3.1.2 Make function detect root relative URLs. 124 */ 125 isThirstyLink : function( href ) { 126 127 if ( ! href ) 128 return; 129 130 href = href.replace( 'http:' , '{protocol}' ).replace( 'https:' , '{protocol}' ); 131 132 var link_uri = href.replace( thirsty_global_vars.home_url , '' ).replace( '{protocol}' , '' ), 133 link_prefix, new_href; 134 135 link_uri = link_uri.indexOf( '/' ) == 0 ? link_uri.replace( '/' , '' ) : link_uri; 136 link_prefix = link_uri.substr( 0 , link_uri.indexOf( '/' ) ), 137 new_href = href.replace( '/' + link_prefix + '/' , '/' + thirsty_global_vars.link_prefix + '/' ).replace( '{protocol}' , window.location.protocol ); 138 139 return ( link_prefix && $.inArray( link_prefix , link_prefixes ) > -1 ) ? new_href : false; 140 }, 141 142 /** 143 * Function to check if the loaded link is a ThirstyAffiliates link or not. 144 * 145 * @since 3.0.0 146 * @since 3.3.0 Add data-nojs attribute support. 147 * @since 3.3.5 Make sure href property of links available before fetching the query strings. 148 */ 149 linkFixer : function() { 150 151 if ( thirsty_global_vars.link_fixer_enabled !== 'yes' ) 152 return; 153 154 var $allLinks = $( 'body a' ), 155 hrefs = [], 156 href, linkClass, isShortcode, isImage , key; 157 158 // fetch all links that are thirstylinks 159 for ( key = 0; key < $allLinks.length; key++ ) { 160 161 href = $( $allLinks[ key ] ).attr( 'href' ); 162 linkClass = $( $allLinks[ key ] ).attr( 'class' ); 163 isShortcode = $( $allLinks[ key ] ).data( 'shortcode' ); 164 isImage = $( $allLinks[ key ] ).has( 'img' ).length; 165 href = thirstyFunctions.isThirstyLink( href ); 166 167 if ( href && ! isShortcode ) 168 hrefs.push({ key : key , class : linkClass , href : href , is_image : isImage }); 169 170 $( $allLinks[ key ] ).removeAttr( 'data-shortcode' ); 171 } 172 173 // skip if there are no affiliate links 174 if ( hrefs.length < 1 ) 175 return; 176 177 $.post( thirsty_global_vars.ajax_url , { 178 action : 'ta_link_fixer', 179 hrefs : hrefs, 180 post_id : thirsty_global_vars.post_id 181 }, function( response ) { 182 183 if ( response.status == 'success' ) { 184 185 for ( var x in response.data ) { 186 187 // make sure response data is valid before proceeding. 188 if ( typeof response.data[ x ] != 'object' ) continue; 189 190 var key = response.data[ x ][ 'key' ], 191 hrefProp = $( $allLinks[ key ] ).prop( 'href' ), 192 qs = hrefProp ? hrefProp.split('?')[1] : '', // get the url query strings 193 href = response.data[ x ][ 'href' ], 194 title = response.data[ x ][ 'title' ], 195 className = response.data[ x ][ 'class' ], 196 connector; 197 198 if ( qs && response.data[ x ][ 'pass_qs' ] ) { 199 connector = href.indexOf( '?' ) < 0 ? '?' : '&'; 200 href = href + connector + qs; 201 } 202 203 // update protocol to replace it with the one used on the site. 204 href = href.replace( 'http:' , window.location.protocol ).replace( 'https:' , window.location.protocol ); 205 206 // add the title if present, if not then remove the attribute entirely. 207 if ( title ) 208 $( $allLinks[ key ] ).prop( 'title' , title ); 209 else 210 $( $allLinks[ key ] ).removeAttr( 'title' ); 211 212 // if disable_thirstylink_class is set to yes then remove the thirstylink and thirstylinkimg classes. 213 if ( thirsty_global_vars.disable_thirstylink_class == 'yes' ) 214 className = className.replace( 'thirstylinkimg' , '' ).replace( 'thirstylink' , '' ).trim(); 215 216 if ( className ) 217 $( $allLinks[ key ] ).prop( 'class' , className ); 218 else 219 $( $allLinks[ key ] ).removeAttr( 'class' ); 220 221 // map the other attributes. 222 $( $allLinks[ key ] ).prop( 'href' , href ) 223 .prop( 'rel' , response.data[ x ][ 'rel' ] ) 224 .prop( 'target' , response.data[ x ][ 'target' ] ) 225 .attr( 'data-linkid' , response.data[ x ][ 'link_
225id' ] ); 226 227 // tag links as "nojs" to disable JS redirect for them. 228 if ( thirsty_global_vars.enable_js_redirect === 'yes' ) 229 $( $allLinks[ key ] ).attr( 'data-nojs' , response.data[ x ][ 'nojs' ] ); 230 231 } 232 } 233 }, 'json' ); 234 } 235 } 236 237 var link_prefixes = $.map( thirsty_global_vars.link_prefixes , function(value , index) { 238 return [value]; 239 }); 240 241 // Initiate record link click stat function 242 thirstyFunctions.recordLinkStatEvents(); 243 244 // Initialize uncloak links function 245 thirstyFunctions.linkFixer(); 246});
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.