(function(window, $){ 'use strict'; if(!$){ return; } function replaceAccountPanel(url, pushHistory){ var current = $('#rightcol .rightcol_inner').first(); if(!current.length){ window.location.href = url; return; } current.addClass('modern-panel-is-loading'); $.ajax({ url: url, type: 'GET', cache: false, success: function(markup){ var incoming = $('
').html(markup).find('#rightcol .rightcol_inner').first(); if(!incoming.length){ window.location.href = url; return; } current.replaceWith(incoming); if(pushHistory && window.history && window.history.pushState){ window.history.pushState({ accountPanel: true }, '', url); } var panel = $('#rightcol').first(); if(panel.length){ $('html, body').animate({ scrollTop: panel.offset().top - 18 }, 180); } }, error: function(){ current.removeClass('modern-panel-is-loading'); } }); } $(document).on('click', 'body.modern-account-page #rightcol .pagination a', function(event){ if($(this).closest('#modern-won-results').length){ return; } var url = $(this).attr('href'); if(!url || url === '#'){ return; } event.preventDefault(); replaceAccountPanel(url, true); }); if(window.history && window.history.pushState){ window.addEventListener('popstate', function(event){ if(event.state && event.state.accountPanel){ replaceAccountPanel(window.location.href, false); } }); } })(window, window.jQuery);