From e825c73d8a7ee344d040e1c17e0e063af0eeacf1 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Wed, 28 Nov 2018 16:58:48 +0000 Subject: [PATCH] Bug 10659: Upgrade jQuery star ratings plugin This patch replaces our current jQuery star ratings plugin with a newer plugin which will be compatible with newer versions of jQuery: http://antenna.io/demo/jquery-bar-rating/examples/ To test you should have one or more records in your catalog with star ratings. - Apply the patch and set the OpacStarRatings system preference to "results and details" - Perform a search in the catalog which will return one or more titles which have ratings. - Confirm that the ratings appear correctly and the ratings are read-only. - Open the "normal" detail page for that record. - Confirm that the star rating appears correctly. - Test setting and re-setting your star rating. Confirm that it is saved. - Confirm that the "cancel rating" link appears when you have a rating set, and that it disappears after you click it. - Test that the "only details" and disabled options of the OpacStarRatings preference work as they should. - Confirm that information about the plugin appears on the About page in the staff client, replacing the old star ratings plugin information. Signed-off-by: Pierre-Marc Thibault --- koha-tmpl/intranet-tmpl/prog/en/modules/about.tt | 6 +- .../opac-tmpl/bootstrap/css/jquery.rating.css | 14 - koha-tmpl/opac-tmpl/bootstrap/css/src/opac.scss | 86 +++++ .../opac-tmpl/bootstrap/en/modules/opac-detail.tt | 102 +++--- .../opac-tmpl/bootstrap/en/modules/opac-results.tt | 31 +- .../opac-tmpl/bootstrap/images/spinner-small.gif | Bin 0 -> 1849 bytes .../bootstrap/lib/jquery/plugins/jquery.rating.js | 392 --------------------- .../lib/jquery/plugins/jquery.barrating.min.js | 2 + 8 files changed, 156 insertions(+), 477 deletions(-) delete mode 100644 koha-tmpl/opac-tmpl/bootstrap/css/jquery.rating.css create mode 100644 koha-tmpl/opac-tmpl/bootstrap/images/spinner-small.gif delete mode 100644 koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.rating.js create mode 100644 koha-tmpl/opac-tmpl/lib/jquery/plugins/jquery.barrating.min.js diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt index 9b33535fdd..2616a6efc3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt @@ -980,10 +980,10 @@ -

jQuery Star Rating Plugin

-

jQuery Star Rating Plugin v3.14 by Fyneworks.com is licensed under the MIT License and the GPL License.

+

jQuery Bar Rating Plugin

+

jQuery Bar Rating Plugin v1.22 by Antenna.io is licensed under the MIT License.

-

Copyright © 2008 Fyneworks.com

+

Copyright © 2012-2016 Kazik Pietruszewski

jQuery insertAtCaret Plugin

jQuery insertAtCaret Plugin v1.0 by the phpMyAdmin devel team is licensed under the GPL License.

diff --git a/koha-tmpl/opac-tmpl/bootstrap/css/jquery.rating.css b/koha-tmpl/opac-tmpl/bootstrap/css/jquery.rating.css deleted file mode 100644 index 461f01533b..0000000000 --- a/koha-tmpl/opac-tmpl/bootstrap/css/jquery.rating.css +++ /dev/null @@ -1,14 +0,0 @@ -/* jQuery.Rating Plugin CSS - http://www.fyneworks.com/jquery/star-rating/ */ -div.rating-cancel,div.star-rating{float:left;width:15px;height:15px;text-indent:-999em;cursor:pointer;display:block;background:transparent;overflow:hidden} -div.rating-cancel,div.rating-cancel a{background:url(../images/star-ratings-sprite.png) no-repeat 0 -49px} -div.star-rating,div.star-rating a{background:url(../images/star-ratings-sprite.png) no-repeat 0 0px} -div.rating-cancel a{display:block;width:16px;height:100%;background-position:0 -49px;border:0} -div.star-rating a{display:block;width:16px;height:100%;background-position:0 0px;border:0} -div.star-rating-on a{background-position:0 -32px!important} -div.rating-cancel.star-rating-hover a{background-position:0 -65px} -div.star-rating-hover a{background-position:0 -16px} -/* Read Only CSS */ -div.star-rating-readonly a{cursor:default !important} -/* Partial Star CSS */ -div.star-rating{background:transparent!important;overflow:hidden!important} -/* END jQuery.Rating Plugin CSS */ diff --git a/koha-tmpl/opac-tmpl/bootstrap/css/src/opac.scss b/koha-tmpl/opac-tmpl/bootstrap/css/src/opac.scss index 5db72ee5ca..9dee8831e4 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/css/src/opac.scss +++ b/koha-tmpl/opac-tmpl/bootstrap/css/src/opac.scss @@ -3252,4 +3252,90 @@ button.closebtn { max-height: 200px; } +/* jQuery Bar Rating plugin for star ratings */ + +$star-default: #D2D2D2; +$star-active: #C24A4A; +$star-selected: #EDB867; + +.br-wrapper { + display: inline-block; +} + +.br-theme-fontawesome-stars { + + .br-widget { + height: 28px; + white-space: nowrap; + + a { + -webkit-font-smoothing: antialiased; + font: normal normal normal 20px/1 FontAwesome; + margin-right: 2px; + text-decoration: none; + text-rendering: auto; + + &::after { + color: $star-default; + content: "\f005"; + } + + &.br-active { + &::after { + color: $star-active; + } + } + + &.br-selected { + &::after { + color: $star-selected; + } + } + } + + + .br-current-rating { + display: none; + } + } + + .br-readonly { + a { + cursor: default; + } + } + +} + +#cancel_rating_text { + a { + color: #C24A4A; + } +} + +@media print { + .br-theme-fontawesome-stars { + + .br-widget { + a { + &::after { + color: #000000; + content: "\f006"; + } + + &.br-active::after, + &.br-selected::after { + color: #000000; + content: "\f005"; + } + } + + } + + } +} + +/* END jQuery Bar Rating plugin for star ratings */ + + @import "responsive"; diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index d8a93cbba9..05ff1bc4c9 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -32,15 +32,9 @@ [% INCLUDE 'doc-head-open.inc' %] [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog › Details for: [% title | html %][% FOREACH subtitl IN subtitle %][% IF Koha.Preference('marcflavour')=='UNIMARC' %],[% END %] [% subtitl.subfield | html %][% END %] [% INCLUDE 'doc-head-close.inc' %] -[% IF ( bidi ) %] - [% BLOCK cssinclude %][% Asset.css("css/right-to-left.css") | $raw %][% END %] -[% END %] -[% IF ( OpacStarRatings != 'disable' ) %] - [% BLOCK cssinclude %][% Asset.css("css/jquery.rating.css") | $raw %][% END %] -[% END %] -[% INCLUDE greybox.inc %] [% Asset.css("lib/emoji-picker/css/emoji.css") | $raw %] +[% BLOCK cssinclude %][% END %] [% INCLUDE 'bodytag.inc' bodyid='opac-detail' bodyclass='scrollto' %] [% INCLUDE 'masthead.inc' %] @@ -477,17 +471,21 @@ [% SET rating_avg = ratings.get_avg_rating() %] [% rating_avg_int = BLOCK %][% rating_avg | format("%.0f") %][% END %] - [% FOREACH i IN [ 1 2 3 4 5 ] %] - [% IF rating_avg_int == i && borrowernumber %] - - [% ELSIF rating_avg_int == i %] - - [% ELSIF borrowernumber %] - - [% ELSE %] - - [% END %] + + [% IF ( borrowernumber ) %] + [% END %] + [% FOREACH i IN [ 1 2 3 4 5 ] %] + [% IF rating_avg_int == i %] + + [% ELSE %] + + [% END %] + [% END %] + + @@ -497,12 +495,14 @@ [% UNLESS ( rating_readonly ) %]  [% END %]  [% IF my_rating %] - your rating: [% my_rating.rating_value | html %], + Your rating: [% my_rating.rating_value | html %]. + Cancel rating. [% ELSE %] + [% END %] - average rating: [% rating_avg | html %] ([% ratings.count | html %] votes) + Average rating: [% rating_avg | html %] ([% ratings.count | html %] votes) [% END # / IF OpacStarRatings != 'disable' %] @@ -1379,6 +1379,7 @@ [% BLOCK jsinclude %] [% INCLUDE 'datatables.inc' %] [% INCLUDE 'columns_settings.inc' %] +[% INCLUDE greybox.inc %] [% IF ( SocialNetworks ) %] // [% END %] -[% IF ( OpacStarRatings != 'disable' ) %][% Asset.js("lib/jquery/plugins/jquery.rating.js") | $raw %][% END %] +[% IF ( OpacStarRatings != 'disable' ) %][% Asset.js("lib/jquery/plugins/jquery.barrating.min.js") | $raw %][% END %] [% IF ( OpacHighlightedWords ) %][% Asset.js("lib/jquery/plugins/jquery.highlight-3.js") | $raw %][% END %] @@ -1618,46 +1619,41 @@ $('input[name="rate_button"]').remove(); - $(function () { - $(".auto-submit-star").rating({ - cancel: _("Cancel rating"), - callback: function (value, link) { - - // if the new value equals the old value, dont execute callback... - // just do nothing! - if ($("#rating_value").attr("value") != value) { - - $(function () { - - $.post("/cgi-bin/koha/opac-ratings-ajax.pl", { + var rating_enabled = ( $("#star_rating").data("rating-enabled") == "1" ) ? false : true; + $('#star_rating').barrating({ + theme: 'fontawesome-stars', + showSelectedRating: false, + allowEmpty: true, + deselectable: false, + readonly: rating_enabled, + onSelect: function(value, text) { + $("#rating-loading").show(); + $.post("/cgi-bin/koha/opac-ratings-ajax.pl", { rating_old_value: $("#rating_value").attr("value"), borrowernumber: "[% borrowernumber | html %]", biblionumber: "[% biblio.biblionumber | html %]", rating_value: value, auth_error: value - }, function (data) { - - if (data.auth_status != 'ok') { - window.alert(_("Your CGI session cookie is not current. Please refresh the page and try again.")); - } else { - $("#rating_value").val(data.rating_value); - - if (data.rating_value) { - $("#rating_value_text").text(_("your rating: %s, ").format(data.rating_value)); - } else { - $("#rating_value_text").text(''); - } - - $("#rating_text").text(_("average rating: %s (%s votes)").format(data.rating_avg, data.rating_total)); - - } - }, "json"); - }); - }; + }, function (data) { + $("#rating_value").val(data.rating_value); + if (data.rating_value) { + $("#rating_value_text").text(_("Your rating: %s, ").format(data.rating_value)); + $("#cancel_rating_text").show(); + } else { + $("#rating_value_text").text(''); + $("#cancel_rating_text").hide(); + } + $("#rating_text").text(_("Average rating: %s (%s votes)").format(data.rating_avg, data.rating_total)); + $("#rating-loading").hide(); + }, "json"); } - }); }); - // ----------------------------------------------------- + + $("#cancel_rating_text a").on("click", function(e){ + e.preventDefault(); + $("#star_rating").barrating("set", ""); + }); + [% END # / IF ( OpacStarRatings != 'disable' )%] [% IF ( IDreamBooksReviews || IDreamBooksReadometer ) %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt index e35af158c1..c4af74537d 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt @@ -18,15 +18,10 @@ You did not specify any search criteria. [% END %] [% INCLUDE 'doc-head-close.inc' %] -[% IF ( OpacStarRatings == 'all' || Koha.Preference('Babeltheque') ) %] - [% BLOCK cssinclude %] - [% Asset.css("css/jquery.rating.css") | $raw %] - [% END %] -[% END %] - +[% BLOCK cssinclude %][% END %] [% INCLUDE 'bodytag.inc' bodyid='results' bodyclass='scrollto' %] [% INCLUDE 'masthead.inc' %] @@ -503,15 +498,21 @@ [% IF ( OpacStarRatings == 'all' ) %]
- [% SET rating_avg = SEARCH_RESULT.ratings.get_avg_rating() %] - [% rating_avg_int = BLOCK %][% rating_avg | format("%.0f") %][% END %] - [% FOREACH i IN [ 1 2 3 4 5 ] %] - [% IF rating_avg_int == i %] - - [% ELSE %] - - [% END %] - [% END %] + [% SET rating_avg = SEARCH_RESULT.ratings.get_avg_rating() %] + [% rating_avg_int = BLOCK %][% rating_avg | format("%.0f") %][% END %] +
+
+ [% FOREACH i IN [ 1 2 3 4 5 ] %] + [% IF rating_avg_int == i %] + + [% ELSIF rating_avg_int > i %] + + [% ELSE %] + + [% END %] + [% END %] +
+
[% IF SEARCH_RESULT.ratings.count > 0 %]   ([% SEARCH_RESULT.ratings.count | html %] votes) diff --git a/koha-tmpl/opac-tmpl/bootstrap/images/spinner-small.gif b/koha-tmpl/opac-tmpl/bootstrap/images/spinner-small.gif new file mode 100644 index 0000000000000000000000000000000000000000..9fb03395ae028dceb604ebd3641a43caa9fa22bf GIT binary patch literal 1849 zcma*odr(tX9tZI2z31lM+(&Y_A`Ou`mk=}wi3zU|#p+D}L0}Q6Ld!!EF|470fr_wg zMDjog@>HsekE$)(qF@X7nB8tcjLc~5xGS^H?y$R^(GKfq>vmyxJF7F@N5UWbS9WI4 zpXV{>GvD9&&B@-e-L%OD5s3U9L7qH$f*{Dk!h*}?x_9s1wr$%Q8XAH#J9qBndH&3q zGvnjq9LM$c_F@=jFc|ji*%Ms-|3~b<>4L0XuV}k!=(kg8+8!IuawueR2=+~VnP&0} zGwhk_o?D)kMCiw&tQS#O3dUf}VbJI|asmq_v)oM@fij=BTQulpmRcU5a#2hIWz z*m(0R-_bWCYx*KUK3b)~aLP#~TfC)i00G@q>B<+e6~^Q5y52c$I+s?S7M9W)qAV~$ z3dkh06lDKYx6eD9)TAAIjm#*mrepXcS<`1`0Yzhm?G&ZPWZ>?I*vI1^t$s3 zdG}-Me4*;3k@P;ka8ACoTmJ(uCTWcp_|yPXCFm;^bvrxsM>XcR29KQRrt^k+x+~3X zM&kuz*j(yXN+b*Aq9E@quM1K-*V4@N41(!?Yck{j&NJEmT0#0n=E1#)UB0a658!mv zCu_cITm$7#NB%r%f1mkg_kp~ms?xH*e$`Xrzm{10<5FN34mRiL^)1$I9sZiOxa0nl z#-S5&VF7I+z%R5xfJZ@km*sOB>S#LSEWR3#`X=HGqLI_qi~Ov7!|m!})kqXJlq(1^ z>u$bs>pB-H*C*a`U@5RGV4W_xBKHH#^7Tv!kh0B(eTr&=z-027fBi#eW35ou z@v;BqXAwN(`%AoV1wg!IyiCnQpR*2AQT?6nhgbSYvhn+7&FUzEC|+MJf?~o-NY!c; zLtw<)N2+oMK-bo)3JI}6l3kxh_9(+^RvLOmgKD(Lc-5R{M)iXwwVX?ot(xM0RyOsU z9k%_kqU=+b?X9wRrk>{-y6iWNvjL&RwR;Q)%PF7T$gH30h*wJPpZV4)V<>S2foCIF zt60n)MuY_50t|yniPsV+BJqSyoMlTz>(t>bE6J$OE{?vx!F)FF((z9p{k~WG!Hs`P zzzKg=g{sbb_R{+FRKE8SOyx5DbJ6XFr|YgJdu-zd9d~Taz;#`WWd7BQv$7%3ciZdC zNr{Abi5SMS4vfI0Qp#CgtZ<3Z9+Z>}#!9C~cj zaGtiEPXFDp2NSE_G`aU$Q=T=9tfK>?mc58)?=M?pW^nD~t%niOGlLfzj|?A zCFY2`(-W`qfF?!p)K-jONt|Y=Bn=>>Xg4a7IyAIckK>!+aDo!U4u#h=hhEK!rmp<5 z@-a1)3meNn3^X#y!`7nm7n0P~?iZV*CEf2WfgNwe8fKf!nI;*NacFGdi%9&BIfXTj zh?zwPQZxkmz2-u}xfW)K*!WC@Efhf@ElM#mco4%nsvRgK3u+B5tWO=jrT$x`jZEXr zD5cFt=}&SY(xmz{CU?NZkewMzi<*e;&ZCxV+F^NL$2aR`Tc{3q&$T~9bNeTm(l#CZ ze9$_t6*HYDzaNolpKrxbC`zYTQ*pr-Esb@+Es49Nuu_ClKdlCXr#7&SZz(Auq)88b HL@VPzU#kpc literal 0 HcmV?d00001 diff --git a/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.rating.js b/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.rating.js deleted file mode 100644 index f4a22d54cd..0000000000 --- a/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.rating.js +++ /dev/null @@ -1,392 +0,0 @@ -/* - ### jQuery Star Rating Plugin v3.14 - 2012-01-26 ### - * Home: http://www.fyneworks.com/jquery/star-rating/ - * Code: http://code.google.com/p/jquery-star-rating-plugin/ - * - * Dual licensed under the MIT and GPL licenses: - * http://www.opensource.org/licenses/mit-license.php - * http://www.gnu.org/licenses/gpl.html - ### -*/ - -/*# AVOID COLLISIONS #*/ -;if(window.jQuery) (function($){ -/*# AVOID COLLISIONS #*/ - - // IE6 Background Image Fix - if ($.browser.msie) try { document.execCommand("BackgroundImageCache", false, true)} catch(e) { }; - // Thanks to http://www.visualjquery.com/rating/rating_redux.html - - // plugin initialization - $.fn.rating = function(options){ - if(this.length==0) return this; // quick fail - - // Handle API methods - if(typeof arguments[0]=='string'){ - // Perform API methods on individual elements - if(this.length>1){ - var args = arguments; - return this.each(function(){ - $.fn.rating.apply($(this), args); - }); - }; - // Invoke API method handler - $.fn.rating[arguments[0]].apply(this, $.makeArray(arguments).slice(1) || []); - // Quick exit... - return this; - }; - - // Initialize options for this call - var options = $.extend( - {}/* new object */, - $.fn.rating.options/* default options */, - options || {} /* just-in-time options */ - ); - - // Allow multiple controls with the same name by making each call unique - $.fn.rating.calls++; - - // loop through each matched element - this - .not('.star-rating-applied') - .addClass('star-rating-applied') - .each(function(){ - - // Load control parameters / find context / etc - var control, input = $(this); - var eid = (this.name || 'unnamed-rating').replace(/\[|\]/g, '_').replace(/^\_+|\_+$/g,''); - var context = $(this.form || document.body); - - // FIX: http://code.google.com/p/jquery-star-rating-plugin/issues/detail?id=23 - var raters = context.data('rating'); - if(!raters || raters.call!=$.fn.rating.calls) raters = { count:0, call:$.fn.rating.calls }; - var rater = raters[eid]; - - // if rater is available, verify that the control still exists - if(rater) control = rater.data('rating'); - - if(rater && control)//{// save a byte! - // add star to control if rater is available and the same control still exists - control.count++; - - //}// save a byte! - else{ - // create new control if first star or control element was removed/replaced - - // Initialize options for this rater - control = $.extend( - {}/* new object */, - options || {} /* current call options */, - ($.metadata? input.metadata(): ($.meta?input.data():null)) || {}, /* metadata options */ - { count:0, stars: [], inputs: [] } - ); - - // increment number of rating controls - control.serial = raters.count++; - - // create rating element - rater = $(''); - input.before(rater); - - // Mark element for initialization (once all stars are ready) - rater.addClass('rating-to-be-drawn'); - - // Accept readOnly setting from 'disabled' property - if(input.attr('disabled') || input.hasClass('disabled')) control.readOnly = true; - - // Accept required setting from class property (class='required') - if(input.hasClass('required')) control.required = true; - - // Create 'cancel' button - rater.append( - control.cancel = $('') - .mouseover(function(){ - $(this).rating('drain'); - $(this).addClass('star-rating-hover'); - //$(this).rating('focus'); - }) - .mouseout(function(){ - $(this).rating('draw'); - $(this).removeClass('star-rating-hover'); - //$(this).rating('blur'); - }) - .click(function(){ - $(this).rating('select'); - }) - .data('rating', control) - ); - - }; // first element of group - - // insert rating star - var star = $(''); - rater.append(star); - - // inherit attributes from input element - if(this.id) star.attr('id', this.id); - if(this.className) star.addClass(this.className); - - // Half-stars? - if(control.half) control.split = 2; - - // Prepare division control - if(typeof control.split=='number' && control.split>0){ - var stw = ($.fn.width ? star.width() : 0) || control.starWidth; - var spi = (control.count % control.split), spw = Math.floor(stw/control.split); - star - // restrict star's width and hide overflow (already in CSS) - .width(spw) - // move the star left by using a negative margin - // this is work-around to IE's stupid box model (position:relative doesn't work) - .find('a').css({ 'margin-left':'-'+ (spi*spw) +'px' }) - }; - - // readOnly? - if(control.readOnly)//{ //save a byte! - // Mark star as readOnly so user can customize display - star.addClass('star-rating-readonly'); - //} //save a byte! - else//{ //save a byte! - // Enable hover css effects - star.addClass('star-rating-live') - // Attach mouse events - .mouseover(function(){ - $(this).rating('fill'); - $(this).rating('focus'); - }) - .mouseout(function(){ - $(this).rating('draw'); - $(this).rating('blur'); - }) - .click(function(){ - $(this).rating('select'); - }) - ; - //}; //save a byte! - - // set current selection - if(this.checked) control.current = star; - - // set current select for links - if(this.nodeName=="A"){ - if($(this).hasClass('selected')) - control.current = star; - }; - - // hide input element - input.hide(); - - // backward compatibility, form element to plugin - input.change(function(){ - $(this).rating('select'); - }); - - // attach reference to star to input element and vice-versa - star.data('rating.input', input.data('rating.star', star)); - - // store control information in form (or body when form not available) - control.stars[control.stars.length] = star[0]; - control.inputs[control.inputs.length] = input[0]; - control.rater = raters[eid] = rater; - control.context = context; - - input.data('rating', control); - rater.data('rating', control); - star.data('rating', control); - context.data('rating', raters); - }); // each element - - // Initialize ratings (first draw) - $('.rating-to-be-drawn').rating('draw').removeClass('rating-to-be-drawn'); - - return this; // don't break the chain... - }; - - /*--------------------------------------------------------*/ - - /* - ### Core functionality and API ### - */ - $.extend($.fn.rating, { - // Used to append a unique serial number to internal control ID - // each time the plugin is invoked so same name controls can co-exist - calls: 0, - - focus: function(){ - var control = this.data('rating'); if(!control) return this; - if(!control.focus) return this; // quick fail if not required - // find data for event - var input = $(this).data('rating.input') || $( this.tagName=='INPUT' ? this : null ); - // focus handler, as requested by focusdigital.co.uk - if(control.focus) control.focus.apply(input[0], [input.val(), $('a', input.data('rating.star'))[0]]); - }, // $.fn.rating.focus - - blur: function(){ - var control = this.data('rating'); if(!control) return this; - if(!control.blur) return this; // quick fail if not required - // find data for event - var input = $(this).data('rating.input') || $( this.tagName=='INPUT' ? this : null ); - // blur handler, as requested by focusdigital.co.uk - if(control.blur) control.blur.apply(input[0], [input.val(), $('a', input.data('rating.star'))[0]]); - }, // $.fn.rating.blur - - fill: function(){ // fill to the current mouse position. - var control = this.data('rating'); if(!control) return this; - // do not execute when control is in read-only mode - if(control.readOnly) return; - // Reset all stars and highlight them up to this element - this.rating('drain'); - this.prevAll().andSelf().filter('.rater-'+ control.serial).addClass('star-rating-hover'); - },// $.fn.rating.fill - - drain: function() { // drain all the stars. - var control = this.data('rating'); if(!control) return this; - // do not execute when control is in read-only mode - if(control.readOnly) return; - // Reset all stars - control.rater.children().filter('.rater-'+ control.serial).removeClass('star-rating-on').removeClass('star-rating-hover'); - },// $.fn.rating.drain - - draw: function(){ // set value and stars to reflect current selection - var control = this.data('rating'); if(!control) return this; - // Clear all stars - this.rating('drain'); - // Set control value - if(control.current){ - control.current.data('rating.input').attr('checked','checked'); - control.current.prevAll().andSelf().filter('.rater-'+ control.serial).addClass('star-rating-on'); - } - else - $(control.inputs).removeAttr('checked'); - // Show/hide 'cancel' button - control.cancel[control.readOnly || control.required?'hide':'show'](); - // Add/remove read-only classes to remove hand pointer - this.siblings()[control.readOnly?'addClass':'removeClass']('star-rating-readonly'); - },// $.fn.rating.draw - - - - - - select: function(value,wantCallBack){ // select a value - - // ***** MODIFICATION ***** - // Thanks to faivre.thomas - http://code.google.com/p/jquery-star-rating-plugin/issues/detail?id=27 - // - // ***** LIST OF MODIFICATION ***** - // ***** added Parameter wantCallBack : false if you don't want a callback. true or undefined if you want postback to be performed at the end of this method' - // ***** recursive calls to this method were like : ... .rating('select') it's now like .rating('select',undefined,wantCallBack); (parameters are set.) - // ***** line which is calling callback - // ***** /LIST OF MODIFICATION ***** - - var control = this.data('rating'); if(!control) return this; - // do not execute when control is in read-only mode - if(control.readOnly) return; - // clear selection - control.current = null; - // programmatically (based on user input) - if(typeof value!='undefined'){ - // select by index (0 based) - if(typeof value=='number') - return $(control.stars[value]).rating('select',undefined,wantCallBack); - // select by literal value (must be passed as a string - if(typeof value=='string') - //return - $.each(control.stars, function(){ - if($(this).data('rating.input').val()==value) $(this).rating('select',undefined,wantCallBack); - }); - } - else - control.current = this[0].tagName=='INPUT' ? - this.data('rating.star') : - (this.is('.rater-'+ control.serial) ? this : null); - - // Update rating control state - this.data('rating', control); - // Update display - this.rating('draw'); - // find data for event - var input = $( control.current ? control.current.data('rating.input') : null ); - // click callback, as requested here: http://plugins.jquery.com/node/1655 - - // **** MODIFICATION ***** - // Thanks to faivre.thomas - http://code.google.com/p/jquery-star-rating-plugin/issues/detail?id=27 - // - //old line doing the callback : - //if(control.callback) control.callback.apply(input[0], [input.val(), $('a', control.current)[0]]);// callback event - // - //new line doing the callback (if i want :) - if((wantCallBack ||wantCallBack == undefined) && control.callback) control.callback.apply(input[0], [input.val(), $('a', control.current)[0]]);// callback event - //to ensure retro-compatibility, wantCallBack must be considered as true by default - // **** /MODIFICATION ***** - - },// $.fn.rating.select - - - - - - readOnly: function(toggle, disable){ // make the control read-only (still submits value) - var control = this.data('rating'); if(!control) return this; - // setread-only status - control.readOnly = toggle || toggle==undefined ? true : false; - // enable/disable control value submission - if(disable) $(control.inputs).attr("disabled", "disabled"); - else $(control.inputs).removeAttr("disabled"); - // Update rating control state - this.data('rating', control); - // Update display - this.rating('draw'); - },// $.fn.rating.readOnly - - disable: function(){ // make read-only and never submit value - this.rating('readOnly', true, true); - },// $.fn.rating.disable - - enable: function(){ // make read/write and submit value - this.rating('readOnly', false, false); - }// $.fn.rating.select - - }); - - /*--------------------------------------------------------*/ - - /* - ### Default Settings ### - eg.: You can override default control like this: - $.fn.rating.options.cancel = 'Clear'; - */ - $.fn.rating.options = { //$.extend($.fn.rating, { options: { - cancel: 'Cancel Rating', // advisory title for the 'cancel' link - cancelValue: '', // value to submit when user click the 'cancel' link - split: 0, // split the star into how many parts? - - // Width of star image in case the plugin can't work it out. This can happen if - // the jQuery.dimensions plugin is not available OR the image is hidden at installation - starWidth: 16//, - - //NB.: These don't need to be pre-defined (can be undefined/null) so let's save some code! - //half: false, // just a shortcut to control.split = 2 - //required: false, // disables the 'cancel' button so user can only select one of the specified values - //readOnly: false, // disable rating plugin interaction/ values cannot be changed - //focus: function(){}, // executed when stars are focused - //blur: function(){}, // executed when stars are focused - //callback: function(){}, // executed when a star is clicked - }; //} }); - - /*--------------------------------------------------------*/ - - /* - ### Default implementation ### - The plugin will attach itself to file inputs - with the class 'multi' when the page loads - */ - $(function(){ - $('input[type=radio].star').rating(); - }); - - - -/*# AVOID COLLISIONS #*/ -})(jQuery); -/*# AVOID COLLISIONS #*/ diff --git a/koha-tmpl/opac-tmpl/lib/jquery/plugins/jquery.barrating.min.js b/koha-tmpl/opac-tmpl/lib/jquery/plugins/jquery.barrating.min.js new file mode 100644 index 0000000000..c65b39f88c --- /dev/null +++ b/koha-tmpl/opac-tmpl/lib/jquery/plugins/jquery.barrating.min.js @@ -0,0 +1,2 @@ +!function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof module&&module.exports?module.exports=t(require("jquery")):t(jQuery)}(function(t){var e=function(){function e(){var e=this,n=function(){var n=["br-wrapper"];""!==e.options.theme&&n.push("br-theme-"+e.options.theme),e.$elem.wrap(t("
",{"class":n.join(" ")}))},i=function(){e.$elem.unwrap()},a=function(n){return t.isNumeric(n)&&(n=Math.floor(n)),t('option[value="'+n+'"]',e.$elem)},r=function(){var n=e.options.initialRating;return n?a(n):t("option:selected",e.$elem)},o=function(){var n=e.$elem.find('option[value="'+e.options.emptyValue+'"]');return!n.length&&e.options.allowEmpty?(n=t("