Team:TU-Munich/TUM13 ajax.js

From 2013.igem.org

(Difference between revisions)
Line 19: Line 19:
   $.ajax({
   $.ajax({
     url: ajaxSrc,
     url: ajaxSrc,
-
    data: { action: 'render' },
 
     type: "GET",
     type: "GET",
     error: function(xhr, status) {
     error: function(xhr, status) {
Line 25: Line 24:
     },
     },
     success: function(render) {
     success: function(render) {
-
       tmp = $('<div />').html(render);
+
       tmp = $(render);
 +
      $('#top-section').replaceWith($(tmp).find('#top-section'));
       $(tmp).find('#wikicontent').children().appendTo($('#wikicontent'));
       $(tmp).find('#wikicontent').children().appendTo($('#wikicontent'));
       ajaxReady();
       ajaxReady();
     }
     }
   });
   });
 +
  overlay = $('<div id="ajax-overlay"><img src="https://static.igem.org/mediawiki/2013/b/b4/TUM13_ajax-loading.gif" /></div>');
 +
  $(overlay).hide();
 +
  $('#wikicontent').append(overlay);
   $(window).off('scroll', gotop);
   $(window).off('scroll', gotop);
   $('html').animate({scrollTop : 0},400,'swing',function(){
   $('html').animate({scrollTop : 0},400,'swing',function(){
Line 35: Line 38:
     $("a#gotop").fadeOut(400);
     $("a#gotop").fadeOut(400);
   });
   });
-
  overlay = $('<div id="ajax-overlay"><img src="https://static.igem.org/mediawiki/2013/b/b4/TUM13_ajax-loading.gif" /></div>');
 
-
  $(overlay).hide();
 
-
  $('#wikicontent').append(overlay);
 
   $(overlay).fadeIn(400);
   $(overlay).fadeIn(400);
}
}

Revision as of 02:05, 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) {
     tmp = $(render);
     $('#top-section').replaceWith($(tmp).find('#top-section'));
     $(tmp).find('#wikicontent').children().appendTo($('#wikicontent'));
     ajaxReady();
   }
 });
overlay = $('
<img src="TUM13_ajax-loading.gif" />
');
 $(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();

}