Browse files

Refs #4 Adding the jquery plugin

  • Loading branch information...
1 parent cf7aa41 commit bbf268ab278ea7dc8adc99a7ab8116aac50244a8 @burzum burzum committed Oct 10, 2011
View
45 webroot/css/jquery.ui.stars.css
@@ -0,0 +1,45 @@
+/*!
+ * jQuery UI Stars v3.0.1
+ * http://plugins.jquery.com/project/Star_Rating_widget
+ *
+ * Copyright (c) 2010 Marek "Orkan" Zajac (orkans@gmail.com)
+ * Dual licensed under the MIT and GPL licenses.
+ * http://docs.jquery.com/License
+ *
+ * $Rev: 164 $
+ * $Date:: 2010-05-01 #$
+ * $Build: 35 (2010-05-01)
+ *
+ */
+.ui-stars-star,
+.ui-stars-cancel {
+ float: left;
+ display: block;
+ overflow: hidden;
+ text-indent: -999em;
+ cursor: pointer;
+}
+.ui-stars-star a,
+.ui-stars-cancel a {
+ width: 16px;
+ height: 15px;
+ display: block;
+ background: url(jquery.ui.stars.gif) no-repeat 0 0;
+}
+.ui-stars-star a {
+ background-position: 0 -32px;
+}
+.ui-stars-star-on a {
+ background-position: 0 -48px;
+}
+.ui-stars-star-hover a {
+ background-position: 0 -64px;
+}
+.ui-stars-cancel-hover a {
+ background-position: 0 -16px;
+}
+.ui-stars-star-disabled,
+.ui-stars-star-disabled a,
+.ui-stars-cancel-disabled a {
+ cursor: default !important;
+}
View
BIN webroot/css/jquery.ui.stars.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
1 webroot/css/jquery.ui.stars.min.css
@@ -0,0 +1 @@
+.ui-stars-star,.ui-stars-cancel{float:left;display:block;overflow:hidden;text-indent:-999em;cursor:pointer;}.ui-stars-star a,.ui-stars-cancel a{width:16px;height:15px;display:block;background:url(jquery.ui.stars.gif) no-repeat 0 0;}.ui-stars-star a{background-position:0 -32px;}.ui-stars-star-on a{background-position:0 -48px;}.ui-stars-star-hover a{background-position:0 -64px;}.ui-stars-cancel-hover a{background-position:0 -16px;}.ui-stars-star-disabled,.ui-stars-star-disabled a,.ui-stars-cancel-disabled a{cursor:default!important;}
View
316 webroot/js/jquery.ui.stars.js
@@ -0,0 +1,316 @@
+/*!
+ * jQuery UI Stars v3.0.1
+ * http://plugins.jquery.com/project/Star_Rating_widget
+ *
+ * Copyright (c) 2010 Marek "Orkan" Zajac (orkans@gmail.com)
+ * Dual licensed under the MIT and GPL licenses.
+ * http://docs.jquery.com/License
+ *
+ * $Rev: 164 $
+ * $Date:: 2010-05-01 #$
+ * $Build: 35 (2010-05-01)
+ *
+ * Depends:
+ * jquery.ui.core.js
+ * jquery.ui.widget.js
+ *
+ */
+(function($) {
+
+$.widget('ui.stars', {
+ options: {
+ inputType: 'radio', // [radio|select]
+ split: 0, // decrease number of stars by splitting each star into pieces [2|3|4|...]
+ disabled: false, // set to [true] to make the stars initially disabled
+ cancelTitle: 'Cancel Rating',
+ cancelValue: 0, // default value of Cancel btn.
+ cancelShow: true,
+ disableValue: true, // set to [false] to not disable the hidden input when Cancel btn is clicked, so the value will present in POST data.
+ oneVoteOnly: false,
+ showTitles: false,
+ captionEl: null, // jQuery object - target for text captions
+ callback: null, // function(ui, type, value, event)
+
+ /*
+ * CSS classes
+ */
+ starWidth: 16, // width of the star image
+ cancelClass: 'ui-stars-cancel',
+ starClass: 'ui-stars-star',
+ starOnClass: 'ui-stars-star-on',
+ starHoverClass: 'ui-stars-star-hover',
+ starDisabledClass: 'ui-stars-star-disabled',
+ cancelHoverClass: 'ui-stars-cancel-hover',
+ cancelDisabledClass: 'ui-stars-cancel-disabled'
+ },
+
+ _create: function() {
+ var self = this, o = this.options, starId = 0;
+ this.element.data('former.stars', this.element.html());
+
+ o.isSelect = o.inputType == 'select';
+ this.$form = $(this.element).closest('form');
+ this.$selec = o.isSelect ? $('select', this.element) : null;
+ this.$rboxs = o.isSelect ? $('option', this.$selec) : $(':radio', this.element);
+
+ /*
+ * Map all inputs from $rboxs array to Stars elements
+ */
+ this.$stars = this.$rboxs.map(function(i)
+ {
+ var el = {
+ value: this.value,
+ title: (o.isSelect ? this.text : this.title) || this.value,
+ isDefault: (o.isSelect && this.defaultSelected) || this.defaultChecked
+ };
+
+ if(i==0) {
+ o.split = typeof o.split != 'number' ? 0 : o.split;
+ o.val2id = [];
+ o.id2val = [];
+ o.id2title = [];
+ o.name = o.isSelect ? self.$selec.get(0).name : this.name;
+ o.disabled = o.disabled || (o.isSelect ? $(self.$selec).attr('disabled') : $(this).attr('disabled'));
+ }
+
+ /*
+ * Consider it as a Cancel button?
+ */
+ if(el.value == o.cancelValue) {
+ o.cancelTitle = el.title;
+ return null;
+ }
+
+ o.val2id[el.value] = starId;
+ o.id2val[starId] = el.value;
+ o.id2title[starId] = el.title;
+
+ if(el.isDefault) {
+ o.checked = starId;
+ o.value = o.defaultValue = el.value;
+ o.title = el.title;
+ }
+
+ var $s = $('<div/>').addClass(o.starClass);
+ var $a = $('<a/>').attr('title', o.showTitles ? el.title : '').text(el.value);
+
+ /*
+ * Prepare division settings
+ */
+ if(o.split) {
+ var oddeven = (starId % o.split);
+ var stwidth = Math.floor(o.starWidth / o.split);
+ $s.width(stwidth);
+ $a.css('margin-left', '-' + (oddeven * stwidth) + 'px');
+ }
+
+ starId++;
+ return $s.append($a).get(0);
+ });
+
+ /*
+ * How many Stars?
+ */
+ o.items = starId;
+
+ /*
+ * Remove old content
+ */
+ o.isSelect ? this.$selec.remove() : this.$rboxs.remove();
+
+ /*
+ * Append Stars interface
+ */
+ this.$cancel = $('<div/>').addClass(o.cancelClass).append( $('<a/>').attr('title', o.showTitles ? o.cancelTitle : '').text(o.cancelValue) );
+ o.cancelShow &= !o.disabled && !o.oneVoteOnly;
+ o.cancelShow && this.element.append(this.$cancel);
+ this.element.append(this.$stars);
+
+ /*
+ * Initial selection
+ */
+ if(o.checked === undefined) {
+ o.checked = -1;
+ o.value = o.defaultValue = o.cancelValue;
+ o.title = '';
+ }
+
+ /*
+ * The only FORM element, that has been linked to the stars control. The value field is updated on each Star click event
+ */
+ this.$value = $("<input type='hidden' name='"+o.name+"' value='"+o.value+"' />");
+ this.element.append(this.$value);
+
+
+ /*
+ * Attach stars event handler
+ */
+ this.$stars.bind('click.stars', function(e) {
+ if(!o.forceSelect && o.disabled) return false;
+
+ var i = self.$stars.index(this);
+ o.checked = i;
+ o.value = o.id2val[i];
+ o.title = o.id2title[i];
+ self.$value.attr({disabled: o.disabled ? 'disabled' : '', value: o.value});
+
+ fillTo(i, false);
+ self._disableCancel();
+
+ !o.forceSelect && self.callback(e, 'star');
+ })
+ .bind('mouseover.stars', function() {
+ if(o.disabled) return false;
+ var i = self.$stars.index(this);
+ fillTo(i, true);
+ })
+ .bind('mouseout.stars', function() {
+ if(o.disabled) return false;
+ fillTo(self.options.checked, false);
+ });
+
+
+ /*
+ * Attach cancel event handler
+ */
+ this.$cancel.bind('click.stars', function(e) {
+ if(!o.forceSelect && (o.disabled || o.value == o.cancelValue)) return false;
+
+ o.checked = -1;
+ o.value = o.cancelValue;
+ o.title = '';
+
+ self.$value.val(o.value);
+ o.disableValue && self.$value.attr({disabled: 'disabled'});
+
+ fillNone();
+ self._disableCancel();
+
+ !o.forceSelect && self.callback(e, 'cancel');
+ })
+ .bind('mouseover.stars', function() {
+ if(self._disableCancel()) return false;
+ self.$cancel.addClass(o.cancelHoverClass);
+ fillNone();
+ self._showCap(o.cancelTitle);
+ })
+ .bind('mouseout.stars', function() {
+ if(self._disableCancel()) return false;
+ self.$cancel.removeClass(o.cancelHoverClass);
+ self.$stars.triggerHandler('mouseout.stars');
+ });
+
+
+ /*
+ * Attach onReset event handler to the parent FORM
+ */
+ this.$form.bind('reset.stars', function(){
+ !o.disabled && self.select(o.defaultValue);
+ });
+
+
+ /*
+ * Clean up to avoid memory leaks in certain versions of IE 6
+ */
+ $(window).unload(function(){
+ self.$cancel.unbind('.stars');
+ self.$stars.unbind('.stars');
+ self.$form.unbind('.stars');
+ self.$selec = self.$rboxs = self.$stars = self.$value = self.$cancel = self.$form = null;
+ });
+
+
+ /*
+ * Star selection helpers
+ */
+ function fillTo(index, hover) {
+ if(index != -1) {
+ var addClass = hover ? o.starHoverClass : o.starOnClass;
+ var remClass = hover ? o.starOnClass : o.starHoverClass;
+ self.$stars.eq(index).prevAll('.' + o.starClass).andSelf().removeClass(remClass).addClass(addClass);
+ self.$stars.eq(index).nextAll('.' + o.starClass).removeClass(o.starHoverClass + ' ' + o.starOnClass);
+ self._showCap(o.id2title[index]);
+ }
+ else fillNone();
+ };
+ function fillNone() {
+ self.$stars.removeClass(o.starOnClass + ' ' + o.starHoverClass);
+ self._showCap('');
+ };
+
+
+ /*
+ * Finally, set up the Stars
+ */
+ this.select(o.value);
+ o.disabled && this.disable();
+
+ },
+
+ /*
+ * Private functions
+ */
+ _disableCancel: function() {
+ var o = this.options, disabled = o.disabled || o.oneVoteOnly || (o.value == o.cancelValue);
+ if(disabled) this.$cancel.removeClass(o.cancelHoverClass).addClass(o.cancelDisabledClass);
+ else this.$cancel.removeClass(o.cancelDisabledClass);
+ this.$cancel.css('opacity', disabled ? 0.5 : 1);
+ return disabled;
+ },
+ _disableAll: function() {
+ var o = this.options;
+ this._disableCancel();
+ if(o.disabled) this.$stars.filter('div').addClass(o.starDisabledClass);
+ else this.$stars.filter('div').removeClass(o.starDisabledClass);
+ },
+ _showCap: function(s) {
+ var o = this.options;
+ if(o.captionEl) o.captionEl.text(s);
+ },
+
+ /*
+ * Public functions
+ */
+ value: function() {
+ return this.options.value;
+ },
+ select: function(val) {
+ var o = this.options, e = (val == o.cancelValue) ? this.$cancel : this.$stars.eq(o.val2id[val]);
+ o.forceSelect = true;
+ e.triggerHandler('click.stars');
+ o.forceSelect = false;
+ },
+ selectID: function(id) {
+ var o = this.options, e = (id == -1) ? this.$cancel : this.$stars.eq(id);
+ o.forceSelect = true;
+ e.triggerHandler('click.stars');
+ o.forceSelect = false;
+ },
+ enable: function() {
+ this.options.disabled = false;
+ this._disableAll();
+ },
+ disable: function() {
+ this.options.disabled = true;
+ this._disableAll();
+ },
+ destroy: function() {
+ this.$form.unbind('.stars');
+ this.$cancel.unbind('.stars').remove();
+ this.$stars.unbind('.stars').remove();
+ this.$value.remove();
+ this.element.unbind('.stars').html(this.element.data('former.stars')).removeData('stars');
+ return this;
+ },
+ callback: function(e, type) {
+ var o = this.options;
+ o.callback && o.callback(this, type, o.value, e);
+ o.oneVoteOnly && !o.disabled && this.disable();
+ }
+});
+
+$.extend($.ui.stars, {
+ version: '3.0.1'
+});
+
+})(jQuery);
View
18 webroot/js/jquery.ui.stars.min.js
@@ -0,0 +1,18 @@
+/*
+ * jQuery UI Stars v3.0.1
+ * http://plugins.jquery.com/project/Star_Rating_widget
+ *
+ * Copyright (c) 2010 Marek "Orkan" Zajac (orkans@gmail.com)
+ * Dual licensed under the MIT and GPL licenses.
+ * http://docs.jquery.com/License
+ *
+ * $Rev: 164 $
+ * $Date:: 2010-05-01 #$
+ * $Build: 35 (2010-05-01)
+ *
+ * Depends:
+ * jquery.ui.core.js
+ * jquery.ui.widget.js
+ *
+ */
+(function(A){A.widget("ui.stars",{options:{inputType:"radio",split:0,disabled:false,cancelTitle:"Cancel Rating",cancelValue:0,cancelShow:true,disableValue:true,oneVoteOnly:false,showTitles:false,captionEl:null,callback:null,starWidth:16,cancelClass:"ui-stars-cancel",starClass:"ui-stars-star",starOnClass:"ui-stars-star-on",starHoverClass:"ui-stars-star-hover",starDisabledClass:"ui-stars-star-disabled",cancelHoverClass:"ui-stars-cancel-hover",cancelDisabledClass:"ui-stars-cancel-disabled"},_create:function(){var C=this,F=this.options,B=0;this.element.data("former.stars",this.element.html());F.isSelect=F.inputType=="select";this.$form=A(this.element).closest("form");this.$selec=F.isSelect?A("select",this.element):null;this.$rboxs=F.isSelect?A("option",this.$selec):A(":radio",this.element);this.$stars=this.$rboxs.map(function(I){var J={value:this.value,title:(F.isSelect?this.text:this.title)||this.value,isDefault:(F.isSelect&&this.defaultSelected)||this.defaultChecked};if(I==0){F.split=typeof F.split!="number"?0:F.split;F.val2id=[];F.id2val=[];F.id2title=[];F.name=F.isSelect?C.$selec.get(0).name:this.name;F.disabled=F.disabled||(F.isSelect?A(C.$selec).attr("disabled"):A(this).attr("disabled"))}if(J.value==F.cancelValue){F.cancelTitle=J.title;return null}F.val2id[J.value]=B;F.id2val[B]=J.value;F.id2title[B]=J.title;if(J.isDefault){F.checked=B;F.value=F.defaultValue=J.value;F.title=J.title}var H=A("<div/>").addClass(F.starClass);var K=A("<a/>").attr("title",F.showTitles?J.title:"").text(J.value);if(F.split){var G=(B%F.split);var L=Math.floor(F.starWidth/F.split);H.width(L);K.css("margin-left","-"+(G*L)+"px")}B++;return H.append(K).get(0)});F.items=B;F.isSelect?this.$selec.remove():this.$rboxs.remove();this.$cancel=A("<div/>").addClass(F.cancelClass).append(A("<a/>").attr("title",F.showTitles?F.cancelTitle:"").text(F.cancelValue));F.cancelShow&=!F.disabled&&!F.oneVoteOnly;F.cancelShow&&this.element.append(this.$cancel);this.element.append(this.$stars);if(F.checked===undefined){F.checked=-1;F.value=F.defaultValue=F.cancelValue;F.title=""}this.$value=A("<input type='hidden' name='"+F.name+"' value='"+F.value+"' />");this.element.append(this.$value);this.$stars.bind("click.stars",function(H){if(!F.forceSelect&&F.disabled){return false}var G=C.$stars.index(this);F.checked=G;F.value=F.id2val[G];F.title=F.id2title[G];C.$value.attr({disabled:F.disabled?"disabled":"",value:F.value});D(G,false);C._disableCancel();!F.forceSelect&&C.callback(H,"star")}).bind("mouseover.stars",function(){if(F.disabled){return false}var G=C.$stars.index(this);D(G,true)}).bind("mouseout.stars",function(){if(F.disabled){return false}D(C.options.checked,false)});this.$cancel.bind("click.stars",function(G){if(!F.forceSelect&&(F.disabled||F.value==F.cancelValue)){return false}F.checked=-1;F.value=F.cancelValue;F.title="";C.$value.val(F.value);F.disableValue&&C.$value.attr({disabled:"disabled"});E();C._disableCancel();!F.forceSelect&&C.callback(G,"cancel")}).bind("mouseover.stars",function(){if(C._disableCancel()){return false}C.$cancel.addClass(F.cancelHoverClass);E();C._showCap(F.cancelTitle)}).bind("mouseout.stars",function(){if(C._disableCancel()){return false}C.$cancel.removeClass(F.cancelHoverClass);C.$stars.triggerHandler("mouseout.stars")});this.$form.bind("reset.stars",function(){!F.disabled&&C.select(F.defaultValue)});A(window).unload(function(){C.$cancel.unbind(".stars");C.$stars.unbind(".stars");C.$form.unbind(".stars");C.$selec=C.$rboxs=C.$stars=C.$value=C.$cancel=C.$form=null});function D(G,I){if(G!=-1){var J=I?F.starHoverClass:F.starOnClass;var H=I?F.starOnClass:F.starHoverClass;C.$stars.eq(G).prevAll("."+F.starClass).andSelf().removeClass(H).addClass(J);C.$stars.eq(G).nextAll("."+F.starClass).removeClass(F.starHoverClass+" "+F.starOnClass);C._showCap(F.id2title[G])}else{E()}}function E(){C.$stars.removeClass(F.starOnClass+" "+F.starHoverClass);C._showCap("")}this.select(F.value);F.disabled&&this.disable()},_disableCancel:function(){var C=this.options,B=C.disabled||C.oneVoteOnly||(C.value==C.cancelValue);if(B){this.$cancel.removeClass(C.cancelHoverClass).addClass(C.cancelDisabledClass)}else{this.$cancel.removeClass(C.cancelDisabledClass)}this.$cancel.css("opacity",B?0.5:1);return B},_disableAll:function(){var B=this.options;this._disableCancel();if(B.disabled){this.$stars.filter("div").addClass(B.starDisabledClass)}else{this.$stars.filter("div").removeClass(B.starDisabledClass)}},_showCap:function(B){var C=this.options;if(C.captionEl){C.captionEl.text(B)}},value:function(){return this.options.value},select:function(D){var C=this.options,B=(D==C.cancelValue)?this.$cancel:this.$stars.eq(C.val2id[D]);C.forceSelect=true;B.triggerHandler("click.stars");C.forceSelect=false},selectID:function(D){var C=this.options,B=(D==-1)?this.$cancel:this.$stars.eq(D);C.forceSelect=true;B.triggerHandler("click.stars");C.forceSelect=false},enable:function(){this.options.disabled=false;this._disableAll()},disable:function(){this.options.disabled=true;this._disableAll()},destroy:function(){this.$form.unbind(".stars");this.$cancel.unbind(".stars").remove();this.$stars.unbind(".stars").remove();this.$value.remove();this.element.unbind(".stars").html(this.element.data("former.stars")).removeData("stars");return this},callback:function(C,B){var D=this.options;D.callback&&D.callback(this,B,D.value,C);D.oneVoteOnly&&!D.disabled&&this.disable()}});A.extend(A.ui.stars,{version:"3.0.1"})})(jQuery);

0 comments on commit bbf268a

Please sign in to comment.