-5

我正在努力让它与 jquery 库的更高版本之一兼容。之前我用的是1.3.2版本,但是暂时想把那个版本更新到1.9.1。我进行了一些测试,发现有一些 javascript 部分也需要更新,但似乎无法弄清楚 - 所以我把它交给大家 - 你能帮我解决这个问题吗?

编辑: 我有三分之二给我带来麻烦的主要领域...我将在下面向他们提供我认为问题可能出在哪里...其中一个部分已解决,但仍在为这两个部分苦苦挣扎以下。

JAVASCRIPT - 第 1 部分

$(document).ready(function () {

    $('.rate_widget').each(function (i) {
        var widget = this;
        var out_data = {
            widget_id: $(widget).attr('id'),
            fetch: 1
        };
        $.post(
            '--Ratings/ratings.php',
        out_data,

        function (INFO) {
            $(widget).data('fsr', INFO);
            set_votes(widget);
        },
            'json');
    });

    $('.ratings_stars').hover(

    function () {
        $(this).prevAll().andSelf().addClass('ratings_over');
        $(this).nextAll().removeClass('ratings_vote');
    },

    function () {
        $(this).prevAll().andSelf().removeClass('ratings_over');
        set_votes($(this).parent());
    });

    $('.ratings_stars').bind('click', function () {
        var star = this;
        var widget = $(this).parent();

        var clicked_data = {
            clicked_on: $(star).attr('class'),
            widget_id: $(star).parent().attr('id')
        };
        $.post(
            '--Ratings/ratings.php',
        clicked_data,

        function (INFO) {
            widget.data('fsr', INFO);
            set_votes(widget);
        },
            'json');
    });

});

function set_votes(widget) {

    var avg = $(widget).data('fsr').whole_avg;
    var votes = $(widget).data('fsr').number_votes;
    var exact = $(widget).data('fsr').dec_avg;

    window.console && console.log('and now in set_votes, it thinks the fsr is ' + $(widget).data('fsr').number_votes); /* ===== <-- Here ===== */

    $(widget).find('.star_' + avg).prevAll().andSelf().addClass('ratings_vote');
    $(widget).find('.star_' + avg).nextAll().removeClass('ratings_vote');
    $(widget).find('.total_votes').text(votes + ' votes recorded (' + exact + ' rating)');
}

JAVASCRIPT - 第 2 部分

$(function () {
    $('input.field').focus(function () {
        if (this.title == this.value) {
            this.value = '';
        }
    })
        .blur(function () {
        if (this.value == '') { /* ===== <-- Here ===== */
            this.value = this.title;
        }
    });
    var currentPage = 1;
    $('#slider_profile .buttons_profile span').live('click', function () {
        var timeout = setTimeout(function () {
            $("img").trigger("slidermove") /* ===== <-- Here ===== */
        }, 100);

        var fragments_count = $(this).parents('#slider_profile:eq(0)').find('.fragment_profile').length;
        var fragment_width = $(this).parents('#slider_profile:eq(0)').find('.fragment_profile').width();
        var perPage = 1;
        var numPages = Math.ceil(fragments_count / perPage);
        var stepMove = fragment_width * perPage;
        var container = $(this).parents('#slider_profile:eq(0)').find('.con_profile');
        var firstPosition = 0;
        var lastPosition = -((numPages - 1) * stepMove);
        if ($(this).hasClass('next')) {
            currentPage++;
            if (currentPage > numPages) {
                currentPage = 1;
                container.animate({
                    'left': firstPosition
                });
                return;
            }; /* ===== <-- Here ===== */
            container.animate({
                'left': -((currentPage - 1) * stepMove)
            });
        }; /* ===== <-- Here ===== */

        if ($(this).hasClass('prev')) {
            currentPage--;
            if (currentPage < 1) {
                currentPage = numPages;
                container.animate({
                    'left': lastPosition
                });
                return;
            }; /* ===== <-- Here ===== */
            container.animate({
                'left': -((currentPage - 1) * stepMove)
            });
        }; /* ===== <-- Here ===== */
    });
});

我在我认为需要解决的问题旁边标记(<--此处)的位置也可能完全错误。因此,考虑到所有这些,有人可以帮我弄清楚如何使这些部件与最新版本的 jquery 1.9.1 之一一起工作吗?

4

1 回答 1

1

首先,试试这个

JAVASCRIPT - 第 1 部分

$(document).ready(function () {
    $('a.head').click(function () {
        var a = $(this);
        var section = a.attr('href');
        section.removeClass('section');
        $('.section').hide();
        section.addClass('section');
        if (section.is(':visible')) {
            section.slideToggle(); /* ===== <-- 400 is the default duration ===== */
        } else {
            section.slideToggle();
        }
    });
});

JAVASCRIPT - 第 2 部分

$(document).ready(function () {
    $('.rate_widget').each(function () {
        var widget = $(this);
        var out_data = {
            widget_id: widget.attr('id'),
            fetch: 1
        };
        $.post(
            '--Ratings/ratings.php',
        out_data,

        function (INFO) {
            widget.data('fsr', INFO);
            set_votes(widget);
        },
            'json');
    });

    $('.ratings_stars').hover(function () {
        $(this).prevAll().andSelf().addClass('ratings_over');
        $(this).nextAll().removeClass('ratings_vote');
    }, function () {
        $(this).prevAll().andSelf().removeClass('ratings_over');
        set_votes($(this).parent());
    });

    $('.ratings_stars').bind('click', function () {
        var star = $(this);
        var widget = star.parent();
        var clicked_data = {
            clicked_on: star.attr('class'),
            widget_id: star.parent().attr('id')
        };
        $.post(
            '--Ratings/ratings.php',
        clicked_data,

        function (INFO) {
            widget.data('fsr', INFO);
            set_votes(widget);
        },
            'json');
    });

});

function set_votes(widget) {

    var avg = widget.data('fsr').whole_avg;
    var votes = widget.data('fsr').number_votes;
    var exact = widget.data('fsr').dec_avg;

    console.log('and now in set_votes, it thinks the fsr is ' + widget.data('fsr').number_votes);

    widget.find('.star_' + avg).prevAll().andSelf().addClass('ratings_vote');
    widget.find('.star_' + avg).nextAll().removeClass('ratings_vote');
    widget.find('.total_votes').text(votes + ' votes recorded (' + exact + ' rating)');
}

JAVASCRIPT - 第 3 部分

$(function () {
    $('input.field').focus(function () {
        if (this.title == this.value) {
            this.value = '';
        }
    }).blur(function () {
        if (this.value === '') { /* ===== <-- Here ===== */
            this.value = this.title;
        }
    });
    var currentPage = 1;
    $(document).on('click', $('#slider_profile .buttons_profile span'), function () {
        var timeout = setTimeout(function () {
            $("img").trigger("slidermove"); /* ===== <-- Here ===== */
        }, 100);

        var fragments_count = $(this).parents('#slider_profile:eq(0)').find('.fragment_profile').length;
        var fragment_width = $(this).parents('#slider_profile:eq(0)').find('.fragment_profile').width();
        var perPage = 1;
        var numPages = Math.ceil(fragments_count / perPage);
        var stepMove = fragment_width * perPage;
        var container = $(this).parents('#slider_profile:eq(0)').find('.con_profile');
        var firstPosition = 0;
        var lastPosition = -((numPages - 1) * stepMove);
        if ($(this).hasClass('next')) {
            currentPage++;
            if (currentPage > numPages) {
                currentPage = 1;
                container.animate({
                    'left': firstPosition
                });
                return;
            }
            container.animate({
                'left': -((currentPage - 1) * stepMove)
            });
        }

        if ($(this).hasClass('prev')) {
            currentPage--;
            if (currentPage < 1) {
                currentPage = numPages;
                container.animate({
                    'left': lastPosition
                });
                return;
            }
            container.animate({
                'left': -((currentPage - 1) * stepMove)
            });
        }
    });
});
于 2013-09-13T14:04:42.947 回答