Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > JavaScript: Общие вопросы > Проблема с history.js


Автор: sokpet 22.7.2010, 12:18
Добрый день.

помогите разобраться как правильно прицепить history.js. В хеде этот плагин естественно прописан. А вот как его подключить в файл, который отвечает за изменение контента без перехода по URL не могу сообразить.

Получилась вот такой код. Т.е. добавил код в начало, до линии, но скорее всего это не правильно. Помогите плиз.

Код

$(document).ready(function(){  

$.historyInit(pageload);  

$("a[@rel='history']").click(function(){  

var hash = this.href;  

hash = hash.replace(/^.*#/, '');  

$.historyLoad(hash);  

 return false;  

 });  

});

function pageload(hash)
{
var cache_not=Math.random();

 }
/*-------------*/

var AjaxContent = function(){
    var container_div = ''; 
    var content_div = ''; 
    return {
        getContent : function(url){
            $(container_div).animate({opacity:10}, //Turn the opacity to 0
                    function(){ // the callback, loads the content with ajax
                        $(container_div).load(url+" "+content_div +hash, //only loads the selected portion
                        function(){                           
                           $(container_div).animate({opacity:1}); //and finally bring back the opacity back to 1
                    }
                );        
            });
        },
        ajaxify_links: function(elements){
            $(elements).live('click',function(){
                AjaxContent.getContent(this.href);
                return false; //prevents the link from beign followed
            });
        },
        init: function(params){ //sets the initial parameters
            container_div = params.containerDiv; 
            content_div = params.contentDiv;
            return this; //returns the object in order to make it chainable
        }
    }
        
}();

$(document).ready(function() {

        AjaxContent.init({containerDiv:"#wrap_content",contentDiv:"#tv, #product_specs"}).ajaxify_links("#wrap_content [href]");
    });







 

Автор: sokpet 22.7.2010, 16:03
Поменял вот так, теперь в командной строке добавляется имя страницы как надоб но при использовании кнопок назад и вперед меняется только имя страницы а сама страница не обновляется...

Что не так?




Код

var AjaxContent = function(){
    var container_div = ''; 
    var content_div = ''; 
    return {
        getContent : function(url){
            $(container_div).animate({opacity:10}, //Turn the opacity to 0
                    function(){ // the callback, loads the content with ajax
                        $(container_div).load(url+" "+content_div, //only loads the selected portion
                        function(){                           
                           $(container_div).animate({opacity:1}); //and finally bring back the opacity back to 1
                    }
                );        
            });
        },
        ajaxify_links: function(elements){
            $(elements).live('click',function(){
                window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-0);
                AjaxContent.getContent(this.href);
                return false; //prevents the link from beign followed
            });
        },
        init: function(params){ //sets the initial parameters
            container_div = params.containerDiv; 
            content_div = params.contentDiv;
            return this; //returns the object in order to make it chainable
        }
    }
        
}();

$(document).ready(function() {

        AjaxContent.init({containerDiv:"#wrap_content",contentDiv:"#tv, #product_specs"}).ajaxify_links("#wrap_content [href]");
    });

Автор: sokpet 23.7.2010, 11:13
Помогите, плиииииииз.

Сайт готов (320 страниц), не хватает только этой детали, а без нее запускать проект не хочется.

Заранее спасибо.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)