Team:TU-Munich/TUM13 ajax.js

From 2013.igem.org

(Difference between revisions)
Line 19: Line 19:
     history.pushState(null, this.href.substring(21) + ' - 2013.igem.org', this.href);
     history.pushState(null, this.href.substring(21) + ' - 2013.igem.org', this.href);
     document.title = this.href.substring(21) + ' - 2013.igem.org';
     document.title = this.href.substring(21) + ' - 2013.igem.org';
 +
    ajaxLoad(this.href);
   });
   });

Revision as of 16:56, 25 October 2013

function ajaxBinding() {

 var links = new Array();
 var candidates = $('#bodyContent a, #footer-box a').not('.bx-controls a');
 for (i = 0; i < candidates.length; i++) {
   if ( candidates[i].href.search('https://2013.igem.org/Team:TU-Munich') != -1 && candidates[i].href.search('#') == -1 && candidates[i].href.search('Labjournal') == -1 ) {
     links.push(candidates[i]);
   }
 }

/*

 var debug = "";
 for (i=0; i<links.length; i++) {
   debug = debug + links[i] + "\n";
 }
 alert(debug);
  • /
 $(links).click(function(e){
   e.preventDefault();
   history.pushState(null, this.href.substring(21) + ' - 2013.igem.org', this.href);
   document.title = this.href.substring(21) + ' - 2013.igem.org';
   ajaxLoad(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="TUM13_ajax-loading.gif" />
');
 $(overlay).hide();
 $('#wikicontent').append(overlay);
 $(window).off('scroll', gotop);
 $('html, body').animate({scrollTop : 0},400,'swing',function(){
   $("a#gotop").fadeOut(400);
 });
 $(overlay).fadeIn(400);

}

function ajaxStateChange(e) {

 ajaxLoad(document.location);

}

$(window).bind('popstate', ajaxStateChange);

$(document).ready(ajaxBinding);

function ajaxReady() {

 ajaxBinding();
 myWikiReady();

}