1// JavaScript Document� 2/*************************************************� 3Star Rating System� 4First Version: 21 November, 2006� 5Second Version: 17 May, 2007� 6Author: Ritesh Agrawal (http://php.scripts.psu.edu/rja171/widgets/rating.php)� 7Inspiration: Will Stuckey's star rating system (http://sandbox.wilstuckey.com/jquery-ratings/)� 8Half-Star Addition: Karl Swedberg� 9Demonstration: http://examples.learningjquery.com/rating/� 10Usage: $j('#rating').rating('url-to-post.php', {maxvalue:5, curvalue:0});� 11� 12arguments� 13url : required -- post changes to � 14options� 15 increment : 1, // value to increment by� 16 maxvalue: number of stars� 17 curvalue: number of selected stars� 18 � 19� 20************************************************/� 21� 22jQuery.fn.psvoting = function(url, options) {� 23 if(url == null) {� 24 return;� 25 }� 26 � 27 url = bwbpsAjaxRateImage + "?action=voteimage&" + url;� 28� 29 var settings = {� 30 url : url, // post changes to � 31 increment : 1, // value to increment by� 32 maxvalue : 5, // max number of stars� 33 curvalue : 0, // number of selected stars� 34 uponly : 0, // only show up voting link� 35 rating_cnt : 0� 36 };� 37� 38 if(options) {� 39 jQuery.extend(settings, options);� 40 };� 41� 42 var container = jQuery(this);� 43� 44 var startitle = "";� 45 jQuery.extend(container, {� 46 url: settings.url� 47 });� 48� 49 var innerbox = jQuery('<div></div>');� 50 � 51 container.empty().append(innerbox);� 52 � 53 var votetotal;� 54 var votinglinks;� 55 � 56 var voteinfo;� 57 � 58 //If the Postion is Top-Right (value == 0)� 59 if(!settings.rating_position){� 60 innerbox.addClass("bwbps-vote-data");� 61 � 62 var allowrate = settings.allow_rating ? 'bwbps-star' : 'bwbps-star bwbps-norate';� 63 � 64 � 65 � 66 votetotal = jQuery('<div class="bwbps-vote-total">' + settings.curvalue + '</div>');� 67 voteinfo = jQuery('<div class="bwbps-vote-info" style="display:none;"># votes: ' + settings.rating_cnt + '</div>');� 68� 69 � 70 innerbox.append(votetotal);� 71 � 72 votinglinks = jQuery('<div class="bwbps-vote-links"></div>');� 73 innerbox.append(votinglinks);� 74 � 75 } else {� 76 � 77 //For Position beneath caption - place Voting Links first, then Vote count� 78 votetotal = jQuery('<span class="bwbps-vote-total">[' + settings.curvalue + ']</span>');� 79 � 80 voteinfo = jQuery('<div class="bwbps-vote-info"># votes: ' + settings.rating_cnt + '</div>');� 81� 82 � 83 votinglinks = jQuery('<span></span>');� 84 � 85 innerbox.append(votinglinks);� 86 innerbox.append(votetotal);� 87 � 88 }� 89 � 90 innerbox.append(voteinfo);� 91 � 92 var voteupbutton;� 93 if(!settings.uponly){ � 94 voteupbutton = '<i class="fa fa-thumbs-up"></i>';� 95 } else {� 96 voteupbutton = 'Vote';� 97 }� 98 � 99 var upvote = jQuery('<a href="#up" title="Vote up"></a>').html(voteupbutton);� 100 � 101 � 102� 103 //Add the Up Vote� 104 upvote.click(function(){� 105 votetotal.empty();� 106 votetotal.addClass("bwbps-vote-small");� 107 votetotal.html('saving...');� 108 � 109 jQuery.post(container.url, {� 110 "rating": 1 � 111 }, function(data){ � 112 votetotal.addClass("bwbps-vote-small");� 113 votetotal.empty().html(data);� 114 });� 115 � 116 return false;� 117 � 118 });� 119 � 120 votinglinks.append(upvote);� 121 � 122 //Add the Down Vote if uponly is false� 123 if(!settings.uponly){� 124 � 125 votinglinks.append(" ");� 126 � 127 var downvote = jQuery('<a href="#up" title="Vote down"><i class="fa fa-thumbs-down"></i></a>');� 128� 129 //Add the Up Vote� 130 downvote.click(function(){� 131 � 132 votetotal.empty();� 133 votetotal.addClass("bwbps-vote-small");� 134 votetotal.html('saving...');� 135 � 136 jQuery.post(container.url, {� 137 "rating": -1 � 138 }, function(data){ � 139 votetotal.addClass("bwbps-vote-small");� 140 votetotal.empty().html(data);� 141 });� 142 � 143 return false;� 144 � 145 });� 146 � 147 votinglinks.append(downvote); � 148 }� 149 � 150� 151 � 152 //If the Postion is Top-Right (value == 0)� 153 if(!settings.rating_position){� 154 //Add mouseover to display info box (top-right position only);� 155 container� 156 .mouseover(function(){� 157 container.addClass('bwbps-voting-hover').end();� 158 container.removeClass('bwbps-voting-bkg').end();� 159 voteinfo.show();� 160 })� 161 .mouseout(function(){� 162 container.addClass('bwbps-voting-bkg').end();� 163 container.removeClass('bwbps-voting-hover').end();� 164 voteinfo.hide();� 165 });� 166 }� 167 � 168}� 169� 170� 171/*� 172 * STAR RATING� 173 *� 174 */� 175jQuery.fn.psrating = function(url, options) {� 176 � 177 if(url == null) return;� 178 url = bwbpsAjaxRateImage + "?action=rateimage&" + url;� 179 var settings = {� 180 url : url, // post changes to � 181 increment : 1, // value to increment by� 182 curvalue : 0 // number of selected stars� 183 };� 184 � 185 if(options) {� 186 jQuery.extend(settings, options);� 187 };� 188 jQuery.extend(settings, {cancel: (settings.maxvalue > 1) ? true : false});� 189 � 190 � 191 var container = jQuery(this);� 192 var startitle = "";� 193 � 194 jQuery.extend(container, {� 195 averageRating: settings.curvalue,� 196 url: settings.url� 197 });� 198 settings.increment = (settings.increment < .75) ? .5 : 1;� 199 � 200 var innerbox = $j('<div class="bwbps-rating"></div>');� 201 � 202 var allowrate = settings.allow_rating ? 'bwbps-star' : 'bwbps-star bwbps-norate';� 203 container.empty().append(innerbox);� 204 var s = 0;� 205 for(var i= 0; i <= settings.maxvalue ; i++){� 206 if (i == 0) {� 207 if(settings.cancel == true){� 208 //Switch these to show cancel� 209 //var div = '<div class="cancel"><a href="#0" title="Cancel Rating">Cancel Rating</a></div>';� 210 var div = '';� 211 innerbox.empty().append(div);� 212 }� 213 } else {� 214 � 215 startitle = settings.allow_rating ? "Give it " + i + "/" + settings.maxvalue : "Login required to rate.";� 216 �
217 var $div = $j('<div class="' + allowrate + '"></div>')� 218 .append('<a href="#'+i+'" title="'+ startitle +'">'+i+'</a>')� 219 .appendTo(innerbox);� 220 if (settings.increment == .5) {� 221 if (s%2) {� 222 $div.addClass('bwbps-star-left');� 223 } else {� 224 $div.addClass('bwbps-star-right');� 225 }� 226 }� 227 � 228 }� 229 i=i-1+settings.increment;� 230 s++;� 231 }� 232 � 233 //If the Postion is Top-Right (value == 0)� 234 if(!settings.rating_position){� 235 � 236 innerbox.addClass(' bwbps-rating-container'); //Class makes it nice and big� 237 � 238 var infobox = $j('<div class="bwbps-rating-infobox">' + settings.avg_rating + ' (' + settings.rating_cnt + ' votes)</div>').appendTo(innerbox).css('display', 'none').addClass('bwbps-rating-info');� 239 � 240 var infoclear = $j('<a></a>').click(function(){� 241 container.css('display','none');� 242 }� 243 ).appendTo(infobox).attr('title','hide rating');� 244 � 245 � 246 infoclear.append($j('<img>').attr('src',bwbpsPhotoSmashURL + "css/images/cancel-12.png").addClass('bwbps-rating-clearimg'));� 247 � 248 //Add mouseover to display info box (top-right position only);� 249 innerbox� 250 .mouseover(function(){� 251 innerbox.addClass('bwbps-rating-hover').end();� 252 infobox.show();� 253 })� 254 .mouseout(function(){� 255 � 256 var relatedTarget = event.relatedTarget ? event.relatedTarget : event.toElement; � 257 innerbox.removeClass('bwbps-rating-hover').end();� 258 infobox.hide();� 259 � 260 })� 261 ;� 262 � 263 } else {� 264 � 265 //Position is beneath capiton� 266 var infobox = $j('<p>' + settings.avg_rating + ' (' + settings.rating_cnt + ' votes)</p>')� 267 .css('clear', 'both')� 268 .appendTo(innerbox);� 269 � 270 }� 271 � 272 var stars = jQuery(innerbox).children('.bwbps-star');� 273 var cancel = jQuery(innerbox).children('.cancel');� 274 � 275 � 276 if(settings.allow_rating){� 277 stars� 278 .mouseover(function(){� 279 event.drain();� 280 event.fill(this);� 281 })� 282 .mouseout(function(){� 283 event.drain();� 284 event.reset();� 285 })� 286 .focus(function(){� 287 event.drain();� 288 event.fill(this);� 289 })� 290 .blur(function(){� 291 event.drain();� 292 event.reset();� 293 });� 294 � 295 stars.click(function(){� 296 if(settings.cancel == true){� 297 settings.curvalue = (stars.index(this) * settings.increment) + settings.increment;� 298 jQuery.post(container.url, {� 299 "rating": jQuery(this).children('a')[0].href.split('#')[1] � 300 � 301 }, function(data){ � 302 infobox.empty().html(data).append(infoclear);� 303 }� 304 );� 305 return false;� 306 } else if (settings.maxvalue == 1) {� 307 settings.curvalue = (settings.curvalue == 0) ? 1 : 0;� 308 $j(this).toggleClass('bwbps-on');� 309 jQuery.post(container.url, {� 310 "rating": jQuery(this).children('a')[0].href.split('#')[1] � 311 });� 312 return false;� 313 }� 314 return true;� 315 � 316 });� 317 � 318 } else {� 319 stars.click(function(){� 320 alert('Login is required to rate.');� 321 });� 322 � 323 }� 324� 325 // cancel button events� 326 if(cancel){� 327 cancel� 328 .mouseover(function(){� 329 event.drain();� 330 jQuery(this).addClass('on');� 331 })� 332 .mouseout(function(){� 333 event.reset();� 334 jQuery(this).removeClass('on');� 335 })� 336 .focus(function(){� 337 event.drain();� 338 jQuery(this).addClass('on');� 339 })� 340 .blur(function(){� 341 event.reset();� 342 jQuery(this).removeClass('on');� 343 });� 344 � 345 // click events.� 346 cancel.click(function(){� 347 event.drain();� 348 settings.curvalue = 0;� 349 jQuery.post(container.url, {� 350 "rating": jQuery(this).children('a')[0].href.split('#')[1] � 351 });� 352 return false;� 353 });� 354 }� 355 � 356 var event = {� 357 fill: function(el){ // fill to the current mouse position.� 358 var index = stars.index(el) + 1;� 359 stars� 360 .children('a').css('width', '100%').end()� 361 .slice(0,index).addClass('bwbps-hover').end();� 362 },� 363 drain: function() { // drain all the stars.� 364 stars�
365 .filter('.bwbps-on').removeClass('bwbps-on').end()� 366 .filter('.bwbps-hover').removeClass('bwbps-hover').end();� 367 },� 368 reset: function(){ // Reset the stars to the default index.� 369 stars.slice(0,settings.curvalue / settings.increment).addClass('bwbps-on').end();� 370 }� 371 }; � 372 event.reset();� 373 � 374 return(this); � 375� 376};� 377� 378function bwbpsToggleRatings(gal_id){� 379 if(gal_id){� 380 $j('.bwbps-rating-gal-' + gal_id).toggle();� 381 }� 382}
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.