|
Line 0
Link Here
|
|
|
1 |
/* global borrowernumber MSG_YOUR_RATING MSG_AVERAGE_RATING */ |
| 2 |
// ----------------------------------------------------- |
| 3 |
// star-ratings code |
| 4 |
// ----------------------------------------------------- |
| 5 |
// hide 'rate' button if javascript enabled |
| 6 |
|
| 7 |
$(document).ready(function(){ |
| 8 |
$("input[name='rate_button']").remove(); |
| 9 |
|
| 10 |
var star_ratings = $(".star_rating"); |
| 11 |
|
| 12 |
star_ratings.barrating({ |
| 13 |
theme: 'fontawesome-stars', |
| 14 |
showSelectedRating: false, |
| 15 |
allowEmpty: true, |
| 16 |
deselectable: false, |
| 17 |
onSelect: function( value ) { |
| 18 |
var context = $("#" + this.$elem.data("context") ); |
| 19 |
$(".rating-loading", context ).show(); |
| 20 |
$.post("/cgi-bin/koha/opac-ratings-ajax.pl", { |
| 21 |
rating_old_value: $(".rating_value", context ).attr("value"), |
| 22 |
borrowernumber: borrowernumber, |
| 23 |
biblionumber: this.$elem.data('biblionumber'), |
| 24 |
rating_value: value, |
| 25 |
auth_error: value |
| 26 |
}, function (data) { |
| 27 |
$(".rating_value", context ).val(data.rating_value); |
| 28 |
if (data.rating_value) { |
| 29 |
$(".rating_value_text", context ).text( MSG_YOUR_RATING.format(data.rating_value) ); |
| 30 |
$(".cancel_rating_text", context ).show(); |
| 31 |
} else { |
| 32 |
$(".rating_value_text", context ).text(""); |
| 33 |
$(".cancel_rating_text", context ).hide(); |
| 34 |
} |
| 35 |
$(".rating_text", context ).text( MSG_AVERAGE_RATING.format(data.rating_avg, data.rating_total) ); |
| 36 |
$(".rating-loading", context ).hide(); |
| 37 |
}, "json"); |
| 38 |
} |
| 39 |
}); |
| 40 |
|
| 41 |
$("body").on("click", ".cancel_rating_text a", function(e){ |
| 42 |
e.preventDefault(); |
| 43 |
var context = "#" + $(this).data("context"); |
| 44 |
$(context).barrating("set", ""); |
| 45 |
}); |
| 46 |
}); |