Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var nav = {
- go: function(url, other_url, back) {
- var url = ((other_url) ? other_url : $(url).attr('href'));
- $.get(url, function(data) {
- var result = data;
- var title = result.match(/<title>(.*?)<\/title>/i);
- var content = result.match(/<div id="page">([\s\S]*)<\/div>/i);
- var scripts = result.match(/<script id="allscripts" type="text\/javascript">([\s\S]*)<\/script>/i);
- var scripts_result = scripts ? scripts[1] : '';
- if(content) {
- // изменяем title
- document.title = title[1].toString();
- // загружаем содержимое
- $('#page').html(content[1].toString());
- // исполняем скрипты
- if(scripts_result) {
- eval(scripts_result);
- }
- if(!back) {
- window.history.ready = true;
- history.pushState ? history.pushState({}, '', url) : location.hash = url;
- }
- if($('#nav_value').html()) {
- $('#nav_value').html(url);
- } else {
- $('body').append('<div style="display: none" id="nav_value">'+url+'</div>');
- }
- }
- });
- return false;
- }
- }
- function ajax_page_back() { // Назад для старых и новых браузеров
- if(history.pushState) {
- $(window).bind('popstate', function(e) {
- var window_location_url_h = $('#nav_value').html();
- if(window_location_url_h) {
- nav.go('', window.location.href, true);
- }
- });
- } else {
- var lhref_interval = setInterval(function() {
- var now_url = window.location.href.split('//');
- var real_now_url = now_url[1].replace('socify.ru', '').replace(/\/(.*?)\#/gi, '');
- var ajax_url = $('#nav_value').html();
- if(ajax_url) {
- if(real_now_url != ajax_url) {
- nav.go('', real_now_url, true);
- clearInterval(lhref_interval);
- setTimeout(function() {
- ajax_page_back();
- }, 100);
- }
- }
- }, 10);
- }
- }
- ajax_page_back();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement