(function(window, document, $, undefined) { $(document).on('ready load_ajax_content_done', function() { if( typeof apppCore === 'undefined' ) { window.apppCore = {}; } if( typeof apppCore.AddQueryVar === 'undefined' ) { apppCore.AddQueryVar = function( url, queryVar, value ) { // Using a positive lookahead (?=\=) to find the // given parameter, preceded by a ? or &, and followed // by a = with a value after than (using a non-greedy selector) // and then followed by a & or the end of the string var val = new RegExp('(\\?|\\&)' + queryVar + '=.*?(?=(&|$))'), qstring = /\?.+$/; // Check if the parameter exists if ( val.test( url ) ) { // if it does, replace it, using the captured group // to determine & or ? at the beginning return url.replace(val, '$1' + queryVar + '=' + value); } else if (qstring.test(url)) { // otherwise, if there is a query string at all // add the param to the end of it return url + '&' + queryVar + '=' + value; } else { // if there's no query string, add one return url + '?' + queryVar + '=' + value; } }; } $('#main a,.apptheme footer a, .apptheme .menu a').each(function() { var old_url = $(this).attr('href'); if( $(this).hasClass('external') || $(this).hasClass('system') || $(this).hasClass('external-media') ) { return; } if( old_url.indexOf('mailto:') == 0 || old_url.indexOf('tel:') == 0 ) return; var re = new RegExp('/' + window.location.host + '/'); if( ! re.test( old_url ) && old_url.indexOf( window.location.host) < 0 && old_url != '/' && old_url.indexOf('/') != 0 ) { return; } var new_url = apppCore.AddQueryVar( old_url, 'appp', '2' ); $(this).attr('href', new_url); }); }); })(window, document, jQuery);