Home

# Class goog.ui.Ratings

A UI Control used for rating things, i.e. videos on Google Video.

extends goog.ui.Component

Instance Method Summary

`decorateInternal(?Element el)`

Decorate a HTML structure already in the document. Expects the structure:

    - div
    - select
    - option 1 #text = 1 star
    - option 2 #text = 2 stars
    - option 3 #text = 3 stars
    - option N (where N is max number of ratings)

The div can contain other elements for graceful degredation, but they will be hidden when the decoration occurs.

| `disposeInternal()` Disposes of the component. Calls {@code exitDocument}, which is expected to remove event handlers and clean up the component. Propagates the call to the component's children, if any. Removes the component's DOM from the document unless it was decorated.
| `enterDocument()` Render the rating widget inside the provided element. This will override the current content of the element.
| `exitDocument()` Should be called when the widget is removed from the document but may be reused. This removes all the listeners the widget has attached and destroys the DOM nodes it uses.
| `getAttachedFormField() ⇒ (HTMLInputElement|HTMLSelectElement|null)` Returns the attached input or select element to the ratings widget.
| `getClassName_(number i, boolean on) ⇒ string` Get the class name for a given rating. All stars have the class: goog-ratings-star. Other possible classnames dependent on position and state are: goog-ratings-firststar-on goog-ratings-firststar-off goog-ratings-midstar-on goog-ratings-midstar-off goog-ratings-laststar-on goog-ratings-laststar-off
| `getCssClass() ⇒ string` Returns the base CSS class used by subcomponents of this component.
| `getHighlightedIndex() ⇒ number` Returns the index of the currently highlighted rating, -1 if the mouse isn't currently over the widget
| `getHighlightedValue() ⇒ ?string` Returns the value of the currently highlighted rating, null if the mouse isn't currently over the widget
| `getRatings() ⇒ ?Array.<string>` Gets the array of ratings that the component
| `getSelectedIndex() ⇒ number`
| `getValue() ⇒ ?string` Returns the rating value of the currently selected rating
| `highlightIndex_(number n)` Highlights the ratings up to the selected index
| `onClick_(?goog.events.BrowserEvent e)` Handle the mouse moving over a star.
| `onKeyDown_(?goog.events.BrowserEvent e)` Handle the key down event. 0 = unselected in this case, 1 = the first rating
| `onMouseOut_(?goog.events.BrowserEvent e)` Handle the mouse moving over a star.
| `onMouseOver_(?goog.events.BrowserEvent e)` Handle the mouse moving over a star.
| `setAttachedFormField((HTMLInputElement|HTMLSelectElement|null) field)` Attaches an input or select element to the ratings widget. The value or index of the field will be updated along with the ratings widget.
| `setRatings(?Array.<string> ratings)` Sets the array of ratings that the comonent
| `setSelectedIndex(number index)` Sets the selected index. If the provided index is greater than the number of ratings then the max is set. 0 is the first item, -1 is no selection.