views:

25

answers:

1

Hi! I'm working on script taken here to load a page in div but the script starts to run and in middle al funtions stop itself. If I move the lines of code up it run the first new lines and then it stops.

My code is:

function loadDemo(path) {
 $.get(path, function(data) {
  alert("Chiamata la funzione get per " + path + "!");
  data = data.replace(/<script.*>.*<\/script>/ig,""); // Remove script tags
  data = data.replace(/<\/?link.*>/ig,""); //Remove link tags
  data = data.replace(/<\/?html.*>/ig,""); //Remove html tag
  data = data.replace(/<\/?body.*>/ig,""); //Remove body tag
  data = data.replace(/<\/?head.*>/ig,""); //Remove head tag
  data = data.replace(/<\/?!doctype.*>/ig,""); //Remove doctype
  data = data.replace(/<title.*>.*<\/title>/ig,""); // Remove title tags
  data = data.replace(/<iframe(.+)src=(\"|\')(.+)(\"|\')>/ig, '<iframe$1src="'+'/'+section+'/'+'$3">');; // Change iframe src
  data = data.replace(/<img([^<>]+)src=(\"|\')([^\"\']+)(\"|\')([^<>]+)?>/ig, '<img$1src="'+'/'+section+'/'+'$3" $5/>');; // Change images src
  $('#dataframe').empty();
  data = $.trim(data);
  alert("A questo punto dovrei possedere i dati...");
  $('#dataframe').empty().html(data);
 });
}

$(document).ready(function() {
 if (window.location.hash == "") {
  window.location.hash = "homepage";
 }
 //Rewrite and prepare links of right-hand sub navigation
 $('#tabs a').each(function() {
  $(this).attr('target', 'dataframe');
  $(this).click(function(e) {
   alert("E' stato cliccato un bottone magico!");
   $(this).parents('ul').find('li').removeClass('ui-tabs-selected ui-state-active');
   $(this).parents('ul').find('li').addClass('ui-state-default');
   alert("Rimossa la classe!!");
   $(this).parent().addClass('ui-tabs-selected ui-state-active');
   alert("Aggiunta la classe!!!");
   alert("Il nuovo location sarà " + this.getAttribute('href').match((/\/([^\/\\]+)\.asp/))[1]);
   //Set the hash to the actual page without ".asp"
   window.location.hash = this.getAttribute('href').match((/\/([^\/\\]+)\.asp/))[1];
   alert("Ho aggiornato l'hash con " + window.location.hash);
   loadDemo(this.getAttribute('href'));
   alert("In teoria mi fermo qui..");
   e.preventDefault();
  });
 });

 alert(window.location.href);
 //If a hash is available, select the right-hand menu item and load it
 if(window.location.hash) {
  loadHash();
 }
 listenToHashChange();
});

$(window).bind('load', function() {
 //If we use it as docs page, go to the selected option
 if(window.location.hash) {
  gotoHash();
 }
});

function listenToHashChange() {
 var savedHash = window.location.hash;
 alert("SavedHash = " + savedHash);
 window.setInterval(function() {  
  if(savedHash != window.location.hash) {
   savedHash = window.location.hash;
   if(window.location.hash)
    gotoHash();
  }
 },200);
}
function loadHash() { 
 $('#tabs a').each(function() {
  if(this.getAttribute('href').indexOf('/'+window.location.hash.substr(1)+'.asp') != -1) {
   $(this).parents('ul').find('li').removeClass('ui-tabs-selected ui-state-active');
   $(this).parent().addClass('ui-tabs-selected ui-state-active');
   loadDemo(this.getAttribute('href'));
  }
 });
}
function gotoHash() {
 var hash = window.location.hash.substr(1).split('-');
 var go = hash[1] ? hash[1] : hash[0];
}

and the part that doesn't work is after doing $(this).parent().addClass('ui-tabs-selected ui-state-active');alert("Aggiunta la classe!!!");

Thank you very much for your answers!

Emanuele

A: 

I'm not jquery expert so it's more guess than answer but $(this).parent() is not going to return body that you already removed ?

zgorawski