-5

Я изо всех сил пытаюсь заставить это работать совместимым с одной из более поздних версий библиотеки jquery. До того, как я использовал версию 1.3.2, но хотел бы обновить эту версию до версии 1.9.1. Я провел несколько тестов и обнаружил, что есть несколько разделов javascript, которые также необходимо обновить, но, похоже, не могут понять это, поэтому я передаю это всем вам - не могли бы вы помочь мне понять это?Javascript, не работающий с библиотекой jquery 1.9.1

EDIT: Я два из трех основных областей, которые дают мне неприятность ... я приведу их ниже с тем, где я думаю, что этот вопрос может быть ... одна из частей были решены, но я все еще борется с этими двумя частями ниже.

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?

+1

изменить это: '$ (a.attr ('href')); 'to' $ (a) .attr ('href'); ' – aldanux

+1

https://github.com/jquery/jquery-migrate/#readme – j08691

+0

Некоторые из функций, которые вы используете (например, 'live'), устарели и были удалены. – zzzzBov

ответ

1

FIRST, попробуйте этот

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) 
      }); 
     } 
    }); 
}); 
+0

Я все еще сталкиваюсь с тем же вопрос - где я отмечен/* ===== <- Здесь ===== * /, где я считаю, что моя проблема ... Кроме того, не уверен, насколько точным является jsfiddle для просмотра ошибок, но здесь является jsfiddle только javascript: http://jsfiddle.net/wR2pZ/3/ Если вы нажмете на jshints, вы увидите красные точки, где есть проблема ... Как я исправить это? – user2732875

+0

скопируйте мой первый блок, у вас больше не будет красных очков – Oliboy50

+0

Эта часть работает;) - Спасибо, не могли бы вы помочь с другими 2 частями? – user2732875

Смежные вопросы