1jQuery( function($) { 2 3 var settings = slicewp_cross_site_tracking || {}; 4 5 var cookie_aff = get_cookie( 'slicewp_external_aff' ); 6 var query_aff = get_query_arg( settings.affiliate_keyword ); 7 8 if ( cookie_aff == '' && query_aff == '' ) 9 return false; 10 11 // Set the external affiliate ID cookie if it's in the URL, but not in the cookie. 12 if ( 13 cookie_aff == '' && query_aff != '' || 14 cookie_aff != '' && query_aff != '' && settings.affiliate_credit == 'last' 15 ) { 16 17 set_cookie( 'slicewp_external_aff', query_aff ); 18 cookie_aff = query_aff; 19 20 } 21 22 // Convert all links to promotional links. 23 $("a[href^='" + settings.website_url + "']").each( function() { 24 25 $(this).attr( 'href', add_query_arg( settings.affiliate_keyword, cookie_aff, $(this).attr( 'href' ) ) ); 26 27 }); 28 29 30 /** 31 * Adds an argument name, value pair to a given URL string 32 * 33 * @param string param 34 * @param string value 35 * @param string url 36 * 37 * @return string 38 * 39 */ 40 function add_query_arg( param, value, url ) { 41 42 var re = new RegExp("[\\?&]" + param + "=([^&#]*)"), match = re.exec(url), delimiter, newString; 43 44 if (match === null) { 45 // append new param 46 var hasQuestionMark = /\?/.test(url); 47 delimiter = hasQuestionMark ? "&" : "?"; 48 newString = url + delimiter + param + "=" + value; 49 } else { 50 delimiter = match[0].charAt(0); 51 newString = url.replace(re, delimiter + param + "=" + value); 52 } 53 54 return newString; 55 } 56 57 58 /** 59 * Returns the value of the query argument requested from the current URL, if present 60 * 61 * @param string arg 62 * 63 * @return string 64 * 65 */ 66 function get_query_arg( arg ) { 67 68 var query = window.location.search.slice(1); 69 var parts = query.split('&'); 70 var obj = {}; 71 72 parts.map( function( part ) { 73 74 part = part.split('='); 75 76 obj[part[0]] = part[1]; 77 78 }); 79 80 return ( typeof obj[arg] != 'undefined' ? obj[arg] : '' ); 81 82 } 83 84 85 /** 86 * Set a cookie 87 * 88 * @param string name 89 * @param string value 90 * 91 */ 92 function set_cookie( name, value ) { 93 94 var d = new Date(); 95 d.setTime( d.getTime() + ( settings.cookie_duration * 24 * 60 * 60 * 1000 ) ); 96 var expires = "expires=" + d.toUTCString(); 97 98 document.cookie = name + "=" + value + "; " + expires + "; " + "path=/;"; 99 100 } 101 102 103 /** 104 * Get a cookie 105 * 106 * @param string name 107 * 108 * @return string 109 * 110 */ 111 function get_cookie( name ) { 112 113 var name = name + "="; 114 var ca = document.cookie.split(';'); 115 116 for( var i=0; i<ca.length; i++ ) { 117 var c = ca[i]; 118 while( c.charAt(0)==' ' ) c = c.substring(1); 119 if(c.indexOf(name) == 0) return c.substring(name.length,c.length); 120 } 121 122 return false; 123 124 } 125 126});
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.