Team:TU-Munich/TUM13 ajax.js

From 2013.igem.org

(Difference between revisions)
Line 18: Line 18:
       },
       },
       success: function(render) {
       success: function(render) {
-
        $(window).unbind('statechange', ajaxStateChange);
 
-
        History.pushState(null, ajaxSrc.substring(21) + ' - 2013.igem.org', ajaxSrc);
 
-
        $(window).bind('statechange', ajaxStateChange);
 
         tmp = $('<div />').html(render);
         tmp = $('<div />').html(render);
         $(tmp).find('#wikicontent').children().appendTo($('#wikicontent'));
         $(tmp).find('#wikicontent').children().appendTo($('#wikicontent'));
Line 34: Line 31:
   function ajaxStateChange(e) {
   function ajaxStateChange(e) {
-
     alert('statechange');
+
     ajaxLoad(History.getState().url);
   }
   }
-
   $(window).bind('statechange', ajaxStateChange);
+
   History.Adapter.bind(window, 'statechange', ajaxStateChange);
   $(links).click(function(e){
   $(links).click(function(e){
     e.preventDefault();
     e.preventDefault();
-
     ajaxLoad(this.href);
+
     History.pushState(null, ajaxSrc.substring(21) + ' - 2013.igem.org', this.href);
   });
   });
});
});

Revision as of 21:11, 21 October 2013

$(document).ready(function(){

 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]);
   }
 }
 function ajaxLoad(url) {
   ajaxSrc = url;
   $.ajax({
     url: ajaxSrc,
     data: { action: 'render' },
     type: "GET",
     error: function(xhr, status) {
       window.location = ajaxSrc;
     },
     success: function(render) {
       tmp = $('<div />').html(render);
       $(tmp).find('#wikicontent').children().appendTo($('#wikicontent'));
     }
   });
   $(window).off('scroll', gotop);
   $('html').animate({scrollTop : 0},400,'swing',function(){
     $(window).scroll(gotop);
     $("a#gotop").fadeOut(400);
     $('#wikicontent').children().remove();
   });
 }
 function ajaxStateChange(e) {
   ajaxLoad(History.getState().url);
 }
 History.Adapter.bind(window, 'statechange', ajaxStateChange);
 $(links).click(function(e){
   e.preventDefault();
   History.pushState(null, ajaxSrc.substring(21) + ' - 2013.igem.org', this.href);
 });

});