1/** 2 * jQuery Ajax Rater Plugin 3 * 4 * This rater is based on the code Ritesh Agrawal did. Unfortunatly his CSS and the hover technique breaks in some browsers. 5 * So i thought, why not use the best CSS star-rater known to man kind and throw it in the mix. 6 * I have used the CSS and technique from Komodo Media since it is stable and tested on many, many browsers. 7 * 8 * This rater compared, has no cancel button. But i think we can live with that :) 9 * To avoid conflicts i have changed the function name. 10 * 11 * Licensed under The MIT License 12 * 13 * @version 1.0 14 * @since 03.01.2007 15 * @author Kjell Bublitz <[email protected] 16 * @link http://www.m3nt0r.de/devel/raterDemo/ Demonstration and Documentation 17 * @link http://php.scripts.psu.edu/rja171/widgets/rating.php Based on Ritesh Agrawal Star Rating System 18 * @link http://komodomedia.com/blog/index.php/2007/01/20/css-star-rating-redux/ The Komodo Media CSS Rater Blogpost 19 * @license http://www.opensource.org/licenses/mit-license.php MIT 20 * @package jQuery Plugins 21 * @subpackage Rater 22 */ 23 24/** 25 * Usage: $('#rating').rater('your_servlet', {style:'basic', maxvalue:5, curvalue:0}); 26 * 27 * @param url The address you want to post the result to. 28 * @param options The style and value attributes 29 * 30 * Valid options: 31 * --------------------------------------- 32 * style: 'basic', 'inline' OR 'small' 33 * maxvalue: the maximum value / number of stars 34 * curvalue: the initial value / selected stars 35 */ 36jQuery.fn.rater = function(url, options) 37{ 38 if(url == null) return; 39 var settings = { 40 url : url, // post changes to 41 maxvalue : 5, // max number of stars 42 curvalue : 0, // number of selected stars 43 slug : '' // page slug - MAX 44 }; 45 46 if(options) { jQuery.extend(settings, options); }; 47 jQuery.extend(settings, {cancel: (settings.maxvalue > 1) ? true : false}); 48 49 var container = jQuery(this); 50 jQuery.extend(container, { averageRating: settings.curvalue, url: settings.url }); 51 52 if(!settings.style || settings.style == null || settings.style == 'basic') { 53 var raterwidth = settings.maxvalue * 25; 54 var ratingparent = '<ul class="star-rating" style="width:'+raterwidth+'px">'; 55 } 56 if(settings.style == 'small') { 57 var raterwidth = settings.maxvalue * 10; 58 var ratingparent = '<ul class="star-rating small-star" style="width:'+raterwidth+'px">'; 59 } 60 if(settings.style == 'inline') { 61 var raterwidth = settings.maxvalue * 10; 62 var ratingparent = '<span class="inline-rating"><ul class="star-rating small-star" style="width:'+raterwidth+'px">'; 63 } 64 container.append(ratingparent); 65 66 // create rater 67 var starWidth, starIndex, listitems = ''; 68 var curvalueWidth = Math.floor(100 / settings.maxvalue * settings.curvalue); 69 for(var i = 0; i <= settings.maxvalue ; i++) { 70 if (i == 0) { 71 listitems+='<li class="current-rating" style="width:'+curvalueWidth+'%;">'+settings.curvalue+'/'+settings.maxvalue+'</li>'; 72 } else { 73 starWidth = Math.floor(100 / settings.maxvalue * i); 74 starIndex = (settings.maxvalue - i) + 2; 75 listitems+='<li class="star"><a href="#'+i+'" title="'+i+'/'+settings.maxvalue +'" style="width:'+starWidth+'%;z-index:'+starIndex+'">'+i+'</a></li>'; 76 } 77 } 78 container.find('.star-rating').append(listitems); // i am using find here, because the span wrapped in the small style would break children() 79 80 if(settings.maxvalue > 1) // add a container for the ajax result 81 { 82 container.append('<span class="star-rating-result"></span>'); 83 } 84 var stars = jQuery(container).find('.star-rating').children('.star'); 85 stars.click(function() 86 { 87 if(settings.maxvalue == 1) // on / off 88 { 89 settings.curvalue = (settings.curvalue == 0) ? 1 : 0; 90 jQuery(container).find('.star-rating').children('.current-rating').css({width:(settings.curvalue*100)+'%'}); 91 jQuery.post(container.url, { "rating": settings.curvalue, "slug": settings.slug }); 92 return false; 93 } 94 else 95 { 96 settings.curvalue = stars.index(this) + 1; 97 raterValue = jQuery(this).children('a')[0].href.split('#')[1]; 98 jQuery.post(container.url, { "rating": raterValue, "slug": settings.slug }, function(response){ 99 container.children('.star-rating-result').html(response) 100 }); 101 return false; 102 } 103 return true; 104 }); 105 106 return this; // strict warning: anonymous function does not always return a value. fix? 107}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.