Advertisement
Guest User

Untitled

a guest
Mar 12th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var nav = {
  2.  go: function(url, other_url, back) {
  3.   var url = ((other_url) ? other_url : $(url).attr('href'));
  4.  
  5.   $.get(url, function(data) {
  6.    var result = data;
  7.  
  8.    var title = result.match(/<title>(.*?)<\/title>/i);
  9.    var content = result.match(/<div id="page">([\s\S]*)<\/div>/i);
  10.    var scripts = result.match(/<script id="allscripts" type="text\/javascript">([\s\S]*)<\/script>/i);
  11.    var scripts_result = scripts ? scripts[1] : '';
  12.  
  13.    if(content) {
  14.     // изменяем title
  15.     document.title = title[1].toString();
  16.     // загружаем содержимое
  17.     $('#page').html(content[1].toString());
  18.  
  19.     // исполняем скрипты
  20.     if(scripts_result) {
  21.      eval(scripts_result);
  22.     }
  23.  
  24.     if(!back) {
  25.      window.history.ready = true;
  26.      history.pushState ? history.pushState({}, '', url) : location.hash = url;
  27.     }
  28.  
  29.     if($('#nav_value').html()) {
  30.      $('#nav_value').html(url);
  31.     } else {
  32.      $('body').append('<div style="display: none" id="nav_value">'+url+'</div>');
  33.     }
  34.    }
  35.   });
  36.  
  37.   return false;
  38.  }
  39. }
  40.  
  41. function ajax_page_back() { // Назад для старых и новых браузеров
  42.  if(history.pushState) {
  43.   $(window).bind('popstate', function(e) {  
  44.    var window_location_url_h = $('#nav_value').html();
  45.    if(window_location_url_h) {
  46.     nav.go('', window.location.href, true);
  47.    }
  48.   });
  49.  } else {
  50.   var lhref_interval = setInterval(function() {
  51.    var now_url = window.location.href.split('//');
  52.    var real_now_url = now_url[1].replace('socify.ru', '').replace(/\/(.*?)\#/gi, '');
  53.    var ajax_url = $('#nav_value').html();
  54.    if(ajax_url) {
  55.     if(real_now_url != ajax_url) {
  56.      nav.go('', real_now_url, true);
  57.      clearInterval(lhref_interval);
  58.      setTimeout(function() {
  59.       ajax_page_back();
  60.      }, 100);
  61.     }
  62.    }
  63.   }, 10);
  64.  }
  65. }
  66.  
  67. ajax_page_back();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement