Team:TU-Munich/TUM13 ajax.js
From 2013.igem.org
(Difference between revisions)
Line 24: | Line 24: | ||
}, | }, | ||
success: function(render) { | success: function(render) { | ||
- | |||
oldContent = $('#wikicontent').children().not('#ajax-overlay'); | oldContent = $('#wikicontent').children().not('#ajax-overlay'); | ||
newContent = $(render).find('#wikicontent').children(); | newContent = $(render).find('#wikicontent').children(); | ||
- | $('#top-section').replaceWith($(top)); /* | + | $('#top-section').replaceWith($(render).find('#top-section')); /* |
$(oldContent).remove(); | $(oldContent).remove(); | ||
$('#wikicontent').prepend(newContent); | $('#wikicontent').prepend(newContent); |
Revision as of 02:39, 22 October 2013
function ajaxBinding() {
var links = new Array(); for (i = 0; i < $('#bodyContent a').length; i++) { if ( $('#bodyContent a')[i].href.search('https://2013.igem.org/Team:TU-Munich') != -1 && $('#bodyContent a')[i].href.search('Labjournal') == -1 ) { links.push($('#bodyContent a')[i]); } }
$(links).click(function(e){ e.preventDefault(); History.pushState(null, this.href.substring(21) + ' - 2013.igem.org', this.href); });
}
function ajaxLoad(url) {
ajaxSrc = url; $.ajax({ url: ajaxSrc, type: "GET", error: function(xhr, status) { window.location = ajaxSrc; }, success: function(render) { oldContent = $('#wikicontent').children().not('#ajax-overlay'); newContent = $(render).find('#wikicontent').children(); $('#top-section').replaceWith($(render).find('#top-section')); /* $(oldContent).remove(); $('#wikicontent').prepend(newContent); $('#ajax-overlay').fadeOut(400, function(){ $('#ajax-overlay').remove(); }); */ ajaxReady(); } });overlay = $('
<img src="" />
');
$(overlay).hide(); $('#wikicontent').append(overlay); $(window).off('scroll', gotop); $('html').animate({scrollTop : 0},400,'swing',function(){ $(window).scroll(gotop); $("a#gotop").fadeOut(400); }); $(overlay).fadeIn(400);
}
function ajaxStateChange(e) {
ajaxLoad(History.getState().url);
}
History.Adapter.bind(window, 'statechange', ajaxStateChange);
$(document).ready(ajaxBinding);
function ajaxReady() {
ajaxBinding(); myWikiReady();
}