diff --git a/demos/rating/default.html b/demos/rating/default.html new file mode 100644 index 00000000000..a1358074127 --- /dev/null +++ b/demos/rating/default.html @@ -0,0 +1,44 @@ + + + + + jQuery UI Slider - Default functionality + + + + + + + + + + +
+ +
+

+ +

+
+ +
+ + + +
+

The default settings for the rating widget.

+
+ + + diff --git a/demos/rating/index.html b/demos/rating/index.html new file mode 100644 index 00000000000..ba119441243 --- /dev/null +++ b/demos/rating/index.html @@ -0,0 +1,18 @@ + + + + + jQuery UI Rating Demo + + + + +
+

Examples

+ +
+ + + diff --git a/themes/base/images/star.gif b/themes/base/images/star.gif new file mode 100644 index 00000000000..0e5b813e66e Binary files /dev/null and b/themes/base/images/star.gif differ diff --git a/themes/base/jquery.ui.base.css b/themes/base/jquery.ui.base.css index a359c2ba490..45b95c03dfc 100644 --- a/themes/base/jquery.ui.base.css +++ b/themes/base/jquery.ui.base.css @@ -17,6 +17,7 @@ @import url("jquery.ui.menu.css"); @import url("jquery.ui.menubar.css"); @import url("jquery.ui.progressbar.css"); +@import url("jquery.ui.rating.css"); @import url("jquery.ui.resizable.css"); @import url("jquery.ui.selectable.css"); @import url("jquery.ui.slider.css"); diff --git a/themes/base/jquery.ui.rating.css b/themes/base/jquery.ui.rating.css new file mode 100755 index 00000000000..5c7adf2ba45 --- /dev/null +++ b/themes/base/jquery.ui.rating.css @@ -0,0 +1,41 @@ +/* + * jQuery UI Rating @VERSION + * + * Copyright 2011, AUTHORS.txt (http: //jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http: //jquery.org/license + * + * http: //docs.jquery.com/UI/Rating#theming + */ +.ui-rating{ + height: 16px; +} +.ui-rating .ui-rating-star{ + width: 16px; + height: 16px; + font-size: 2px; + float: left; + text-decoration: none; + vertical-align: bottom; + background-image: url(images/star.gif); + background-repeat: no-repeat; + background-position: 0 -32px; +} +.ui-rating-current .ui-rating-full{ + background-position: 0 0; +} +.ui-rating-current .ui-rating-partial{ + background-position: 0 -16px; +} +.ui-rating .ui-rating-cancel-empty{ + background-position: 0 -64px; +} +.ui-rating .ui-rating-cancel-full{ + background-position: 0 -80px; +} +.ui-rating .ui-rating-hover{ + background-position: 0 -48px; +} +.ui-rating-cancel-empty.ui-rating-hover{ + background-position: 0 -80px; +} \ No newline at end of file diff --git a/ui/jquery.ui.rating.js b/ui/jquery.ui.rating.js new file mode 100644 index 00000000000..cc3bcec7087 --- /dev/null +++ b/ui/jquery.ui.rating.js @@ -0,0 +1,227 @@ +/* + * jQuery UI Rating 1.9 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Rating + * + * Depends: + * jquery.ui.core.js + * jquery.ui.widget.js + */ +(function( $, undefined ) { + +$.widget("ui.rating", { + version: "@VERSION", + + options: { + value: null, + max: null, + readOnly: false, + + // callbacks + change: null + }, + + min: 0, + + _create: function() { + var self = this; + + var ratingDiv = $( "
"); + var ratingStar = $( ""); + + var element = self.element.wrap( ratingDiv ).parent(); + + $.extend(self, { + originalElement: this.element, + element: element + }); + + if (isNaN(parseFloat(self.options.value))) + { + self.options.value = parseFloat(self.originalElement.val()); + } + + if (isNaN(parseInt(self.options.max))) + { + self.options.max = 0; + } + + $.each( $( "option", self.originalElement ), function( index, option ) { + var val = parseInt( $( option ).val(), 0 ); + + self.options.max = ( val > self.options.max ) ? val : self.options.max; + }); + + for ( index = 1; index <= self.options.max; index++ ) { + ratingStar.clone().attr( 'id', 'rating_star_rating_' + index ).text( "Give it a " + index ).data( "rating", index ).appendTo( self.element ); + } + + self.originalElement.hide(); + + // self.oldValue = self._getValue(); + self._refreshValue(); + + // self.oldReadOnly = self._getReadOnly(); + self._setReadOnly(); + }, + + _destroy: function() { + this.originalElement.siblings().remove().end().show().unwrap( this.element ); + + this.element = this.originalElement; + + delete this.originalElement; + delete this.oldValue; + delete this.oldReadOnly; + }, + + _events: { + 'click .ui-rating-star': function( event ) { + event.preventDefault(); + + this.options.value = $( event.target ).data( "rating" ); + + this._refreshValue(); + }, + + mouseover: function( event ) { + var $target = $( event.target ); + + if ( $target.is( ".ui-rating-star" ) ) { + this.element.removeClass( "ui-rating-current" ); + + // create referece object for stars + var ratingStars = $( ".ui-rating-star", this.element ); + + // add hover class to the current and preceding stars + ratingStars.removeClass( "ui-rating-hover" ).filter(function( index ) { + return index <= ratingStars.index( $target ); + }).addClass( "ui-rating-hover" ); + + this._trigger( "change", null, this.ui() ); + } + }, + + mouseleave: function( event ) { + this.element.addClass( "ui-rating-current" ).find( ".ui-rating-hover" ).removeClass( "ui-rating-hover" ); + + this._trigger( "change", null, this.ui() ); + } + }, + + _eventsReadOnly: { + 'click .ui-rating-star': function( event ) { + event.preventDefault(); + } + }, + + _setOption: function( key, value ) { + if ( key === "value" ) { + this.options.value = value; + + this._refreshValue(); + } + + if ( key === "readOnly") { + this.options.readOnly = value; + + this._setReadOnly( value ); + } + + this._super( "_setOption", key, value ); + }, + + _getValue: function() { + var val = this.options.value; + + // normalize invalid value + if ( typeof val !== "number" ) { + val = 0; + } + + return Math.min( this.options.max, Math.max( this.min, val ) ); + }, + + _refreshValue: function() { + var value = this._getValue(); + + if ( this.oldValue !== value ) { + this.oldValue = value; + + $( ".ui-rating-star", this.element ).removeClass( "ui-rating-full ui-rating-partial" ).each( function( index ) { + index++; + + var starClass = ""; + + if ( index <= value ) { + starClass = "ui-rating-full"; + } else if ( index - value < 1 ) { + starClass = "ui-rating-partial"; + } + + $( this ).addClass( starClass ); + }); + + this.originalElement.val( value ); + + this._trigger( "change", null, this.ui() ); + } + }, + + _getReadOnly: function() { + var val = this.options.readOnly; + + // normalize invalid boolean + if ( typeof val !== "boolean" ) + { + val = false; + } + + return val; + }, + + _setReadOnly: function() { + var readOnly = this._getReadOnly(); + + if ( this.oldReadOnly !== readOnly ) { + this.oldReadOnly = readOnly; + + if (readOnly === true) { + // make read only + this.element.addClass( "ui-rating-readonly ui-rating-current" ).find( ".ui-rating-hover" ).removeClass( "ui-rating-hover" ); + + this.bindings.unbind( "." + this.widgetName ); + + this._bind( this.element, this._eventsReadOnly); + } else { + // make non-read only + this.element.removeClass('ui-rating-readonly'); + + this.bindings.unbind( "." + this.widgetName ); + + this._bind( this.element, this._events ); + } + + this._trigger( "change", null, this.ui() ); + } + }, + + ui: function() { + return { + element: this.element, + originalElement: this.originalElement, + value: this.options.value, + oldValue: this.oldValue, + min: this.min, + max: this.options.max, + oldReadOnly: this.options.readOnly, + readOnly: this.options.readOnly + }; + } +}); + +}( jQuery ));