Показать сообщение отдельно
  #8 (permalink)  
Старый 17.04.2015, 23:06
Интересующийся
Отправить личное сообщение для Foxeh Посмотреть профиль Найти все сообщения от Foxeh
 
Регистрация: 15.04.2015
Сообщений: 20

Заметил, что многократный клик по одной и той же странице, будто в цикле начинает добавлять элементы DOM объекта.


$(function() {
  String.prototype.decodeHTML = function() {
    return $("<div>", {html: "" + this}).html();
	
  };

  var $main = $("main"),
  
  init = function() {
      
  },
  
  ajaxLoad = function(html) {
    document.title = html
      .match(/<title>(.*?)<\/title>/)[1]
      .trim()
      .decodeHTML();


    init();
  },
  

  loadPage = function(href) {
	//console.log(($main.load).html());
	$main.load(href + " main>*", ajaxLoad);
	//console.log(href);


			//eval($("script").text());
			$("main").css("display", "none");
			$("main").fadeOut(600);
			$("main").fadeIn(600);
		 //console.log(($main));
		 	  	  	console.log($("script"));
			jQuery.each( $("script"), function( i, val ) {
			eval($(val).text());

			})


							
  };
  
  init();
  
  
  $(window).on("popstate", function(e) {
    if (e.originalEvent.state !== null) {
      loadPage(location.href);

	  
	 // console.log("5");
    }
  });

  $(document).on("click", ".transition", function() {
    var href = $(this).attr("href");
	

    if (href.indexOf(document.domain) > -1
      || href.indexOf(':') === -1)
    {
      history.pushState({}, '', href);
      loadPage(href);
      return false;
    }
  });
});
Ответить с цитированием