Pergunta

I'm struggling trying to get this to work an be compatible with one of the later versions of the jquery library. Before I was using the version 1.3.2, but would like to update that version to 1.9.1 for the time being. I ran some tests and found out there is a few sections of javascript that also need to be updated but can't seem to figure it out - so I'm handing this over to you all - could you please help me figure this out?

EDIT: I have two out of three main areas that are giving me troubles...I'll provide them below with where I think the issue may be... one of the parts have been solved but am still struggling with these two parts below.

JAVASCRIPT - Part 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 - Part 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 ===== */
    });
});

I could also be completely wrong in the locations where I marked ( <-- Here ) next to where I believe is the problems that need to be fixed. So with all that in mind, could someone help me figure out how to make these parts work with one of the latest versions of jquery 1.9.1 ?

Foi útil?

Solução

FIRST, try this

JAVASCRIPT - Part 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 - PART 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 - PART 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)
            });
        }
    });
});
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top