annotate media/js/downloads/rating.js @ 265:1ba2c6bf6eb7

Closing #98. Animated GIFs were losing their transparency and animated properties when saved as avatars. Reworked the avatar save process to only run the avatar through PIL if it is too big. This preserves the original uploaded file if it is within the desired size settings. This may still mangle big animated gifs. If this becomes a problem, then maybe look into calling the PIL Image.resize() method directly. Moved the PIL image specific functions from bio.forms to a new module: core.image for better reusability in the future.
author Brian Neal <bgneal@gmail.com>
date Fri, 24 Sep 2010 02:12:09 +0000
parents 2ba1a6d3b984
children
rev   line source
gremmie@1 1 function dlRatingOver(event)
gremmie@1 2 {
gremmie@1 3 var div = $(this).parent('div');
gremmie@1 4 var stars = $('img', div);
gremmie@1 5 for (var i = 0; i <= event.data; ++i)
gremmie@1 6 {
gremmie@1 7 var star = $(stars[i]);
bgneal@255 8 star.attr('src', '/media/downloads/stars/rating_over.gif');
gremmie@1 9 }
gremmie@1 10 }
gremmie@1 11
gremmie@1 12 function dlRatingOut(event)
gremmie@1 13 {
gremmie@1 14 var div = $(this).parent('div');
gremmie@1 15 var stars = $('img', div);
gremmie@1 16 for (var i = 0; i <= event.data; ++i)
gremmie@1 17 {
gremmie@1 18 var star = $(stars[i]);
bgneal@255 19 star.attr('src', '/media/downloads/stars/rating_' + star.attr('class') + '.gif');
gremmie@1 20 }
gremmie@1 21 }
gremmie@1 22
gremmie@1 23 function dlRatingClick(event)
gremmie@1 24 {
gremmie@1 25 var star = $(this);
gremmie@1 26 var id = star.attr('id');
gremmie@1 27 if (id.match(/star-(\d+)-(\d+)/))
gremmie@1 28 {
bgneal@150 29 $.ajax({
bgneal@150 30 url: '/downloads/rate/',
bgneal@150 31 type: 'POST',
bgneal@150 32 data: { id: RegExp.$1, rating: parseInt(RegExp.$2) + 1},
bgneal@150 33 dataType: 'text',
bgneal@150 34 success: function(rating) {
gremmie@1 35 rating = parseFloat(rating);
gremmie@1 36 if (rating < 0)
gremmie@1 37 {
gremmie@1 38 alert("You've already rated this download.");
gremmie@1 39 return;
gremmie@1 40 }
gremmie@1 41 alert('Thanks for rating this download!');
gremmie@1 42 var div = star.parent('div');
gremmie@1 43 var stars = $('img', div);
gremmie@1 44 rating = parseFloat(rating);
gremmie@1 45 for (var i = 0; i < 5; ++i)
gremmie@1 46 {
gremmie@1 47 var s = $(stars[i]);
gremmie@1 48 s.removeClass(s.attr('class'));
gremmie@1 49 if (rating >= 1.0)
gremmie@1 50 {
bgneal@255 51 s.attr('src', '/media/downloads/stars/rating_on.gif');
gremmie@1 52 s.addClass('on')
gremmie@1 53 rating -= 1.0;
gremmie@1 54 }
gremmie@1 55 else if (rating >= 0.5)
gremmie@1 56 {
bgneal@255 57 s.attr('src', '/media/downloads/stars/rating_half.gif');
gremmie@1 58 s.addClass('half')
gremmie@1 59 rating = 0;
gremmie@1 60 }
gremmie@1 61 else
gremmie@1 62 {
bgneal@255 63 s.attr('src', '/media/downloads/stars/rating_off.gif');
gremmie@1 64 s.addClass('off')
gremmie@1 65 }
gremmie@1 66 }
gremmie@1 67 },
bgneal@150 68 error: function (xhr, textStatus, ex) {
bgneal@150 69 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
bgneal@150 70 xhr.responseText);
bgneal@150 71 }
bgneal@150 72 });
gremmie@1 73 }
gremmie@1 74 }
gremmie@1 75
gremmie@1 76 $(document).ready(function() {
gremmie@1 77 $('.rating').each(function(n) {
gremmie@1 78 var div = $(this);
gremmie@1 79 var id = div.attr('id');
gremmie@1 80 var numeric_id = -1;
gremmie@1 81 if (id.match(/rating-(\d+)/))
gremmie@1 82 {
gremmie@1 83 numeric_id = RegExp.$1;
gremmie@1 84 }
gremmie@1 85 var rating = div.html();
gremmie@1 86 div.html('');
gremmie@1 87 for (var i = 0; i < 5; ++i)
gremmie@1 88 {
gremmie@1 89 var star = $('<img />');
gremmie@1 90 if (rating >= 1)
gremmie@1 91 {
bgneal@255 92 star.attr('src', '/media/downloads/stars/rating_on.gif');
gremmie@1 93 star.addClass('on')
gremmie@1 94 --rating;
gremmie@1 95 }
gremmie@1 96 else if (rating >= 0.5)
gremmie@1 97 {
bgneal@255 98 star.attr('src', '/media/downloads/stars/rating_half.gif');
gremmie@1 99 star.addClass('half')
gremmie@1 100 rating = 0;
gremmie@1 101 }
gremmie@1 102 else
gremmie@1 103 {
bgneal@255 104 star.attr('src', '/media/downloads/stars/rating_off.gif');
gremmie@1 105 star.addClass('off')
gremmie@1 106 }
gremmie@1 107 star.attr('alt', 'star');
gremmie@1 108 star.attr('id', 'star-' + numeric_id + '-' + i);
gremmie@1 109 star.bind('mouseover', i, dlRatingOver);
gremmie@1 110 star.bind('mouseout', i, dlRatingOut);
gremmie@1 111 star.click(dlRatingClick);
gremmie@1 112 div.append(star);
gremmie@1 113 }
gremmie@1 114 });
gremmie@1 115 });