Помогите с плагином адреса jQuery - PullRequest
4 голосов
/ 13 сентября 2010

У меня есть сайт с загруженным контентом ajax.Теперь я хочу реализовать плагин для адреса jQuery для улучшения работы пользователей и SEO-сканирования.

С этой строкой $.address.value($(this).attr('href')); работает функция смены адреса, но как я могу сделать поддержку истории, сканирование и так далее?

Что-то с $.address.change(function(event){...}); мне нужно сделать, но что?Я пытался вставить в него $("#content").load(toLoad,'',showNewContent) и другие тысячи вещей, к сожалению, безрезультатно.

Документация действительно плохая: http://www.asual.com/jquery/address/docs/

Это мой код:

$('a:not([href^=http])').click(function() {

    var toLoad = $(this).attr('href') + " #ajaxedContent";

    $("#content").fadeOut(600,loadContent);

    $("#load").remove();
    $('#logo').append('<div id="load"></div>');
    $("#load").fadeIn(100);

    $.address.value($(this).attr('href'));

    function loadContent() {
        $("#content").load(toLoad,'',showNewContent)
    }

    function showNewContent() {
        // Capture the final dimensions of the content element and animate, finally fade content in
        $("#limit").animate({height: $("#content").height()},600,'easeInOutQuad',function() {
            $("#content").fadeIn(600,hideLoader);
            callback();
        });
    }

    function hideLoader() {
        $("#load").fadeOut(300);
    }

    return false;
});

Базовая реализация выглядит следующим образом:

$.address.change(function(event) {
    // do something depending on the event.value property, e.g.
    // $('#content').load(event.value + '.xml');
});

$('a').click(function() {
    $.address.value($(this).attr('href'));
});

Любая помощь будет принята с благодарностью.Спасибо.

1 Ответ

3 голосов
/ 20 сентября 2010

Так работает:

$.address.init(function(event) {

    $('a:not([href^=http])').address();

}).change(function(event) {

    var toLoad = event.path + " #ajaxedContent";

    $("#content").fadeOut(600,loadContent);

    $("#load").remove();
    $('#logo').append('<div id="load"></div>');
    $("#load").fadeIn(100);

    function loadContent() {
        $("#content").load(toLoad,'',showNewContent)
    }

    function showNewContent() {
        // Capture the final dimensions of the content element and animate, finally fade content in
        $("#limit").animate({height: $("#content").height()},600,'easeInOutQuad',function() {
            $("#content").fadeIn(600,hideLoader);
            callback();
        });
    }

    function hideLoader() {
        $("#load").fadeOut(300);
    }

    return false;
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...