Rating-Widget

Documentation


HTML page layout using Rating-Widget

Your HTML page layout should look something like that:

<html>
<head>
<!-- ... your HTML content ... -->
</head>

<body>
<!-- ... your HTML body content ... -->

<div class="rw-ui-container rw-urid-17"></div>

<!-- ... more of your HTML body content ... -->

<div class="rw-ui-container rw-urid-36"></div>

<!-- ... more of your HTML body content ... -->

<div class="rw-js-container">
<script type="text/javascript">
function RW_Async_Init(){
RW.init("your-unique-user-key");
RW.render();
}

if (typeof(RW) == "undefined"){
(function(){
var rw = document.createElement("script");
rw.type = "text/javascript"; rw.async = true;
rw.src = "http://js.rating-widget.com/external.min.js?v=259&t=js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(rw, s);
})();
}
}
</script>
</div>

</body>
</html>

Asynchronous initiation function of the Rating-Widget library

The Rating-Widget library is supports & uses async load for optimization reasons. When the Rating-Widget javascript external file is fully loaded, it's automatically invokes the RW_Async_Init(). Because of that, the rendering must be done inside the function (or after it's invoked).


Constants of the RW object

The RW JavaScript object has various constants that may be helpful. Only constants documented in this section should be relied upon. Specifically, any constants beginning with an underscore are subject to change and should not be used.

Name Value Description
MIN 1 Minimal rate value.
MAX 5 Maximal rate value.
MIN_STARS 1 Minimal stars number (for star rating).
MAX_STARS 20 Maximal stars number (for star rating).
CALL_RATINGS_MAX_LEN 1000 HTTP GET request query string max length.
PREFIX "rw" Rating-Widget prefix.
CUSTOM "custom" Custom thumb & star rating style.
Usage:
if (i == RW.MAX){ ...

Enumerable types of the RW object

The RW JavaScript object has various types that may be helpful. Only types documented in this section should be relied upon. Specifically, any types beginning with an underscore are subject to change and should not be used.

Type Description
TYPE: { STAR: "star", NERO: "nero", } Optional rating-widget types.
STAR: Stars rating
NERO: Thumbs rating (like or dislike)
SIZE: { SMALL: "small", MEDIUM: "medium", LARGE: "large" } Optional sizes.
SMALL: 16px x 16px star icon size
MEDIUM: 20px x 20px star icon size
LARGE: 30px x 30px star icon size
COLOR: { YELLOW: "yellow", RED: "red", GREEN: "green", BLUE: "blue", CUSTOM: "custom" } Optional colors.
(*) Deprecated
DIR: { LTR : "ltr", RTL : "rtl" } Optional directions.
ALIGN.HOR: { LEFT: "left", CENTER: "center", RIGHT: "right" } Optional horizontal alignments.
ALIGN.VER: { TOP: "top", MIDDLE: "middle", BOTTOM: "bottom" } Optional vertical alignment.
FREQUENCY: { ONCE: -1, UNLIMITED: 0, DAILY: 1 WEEKLY: 7 MONTHLY: 30 YEARLY: 365 } Optional voting frequencies.
ONCE: User can vote only once
UNLIMITED: User can contribute unlimited votes
WEEKLY: User can contribute one vote each week
MONTHLY: User can contribute one vote each month
YEARLY: User can contribute one vote each year
Usage:
switch (c){
case RW.ALIGN.VER:
...

Options-object type, of the RW object

The RW JavaScript options-object has various members that may be helpful. Only members documented in this section should be relied upon. Specifically, any members beginning with an underscore are subject to change and should not be used.

Name Type Description Default
lng string Rating-Widget language. "en"
url string Rated element page url. ""
title string Rated element title. ""
type RW.TYPE Rating-Widget type (stars or thumbs). RW.TYPE.STAR
rclass string Rating class (e.g. "post", so latter you can initialize star rating options by rating class). ""
size RW.SIZE Rating-Widget size. RW.SIZE.SMALL
theme string Rating-Widget ratings theme name. ""
color(*) Deprecated RW.COLOR Star color. RW.COLOR.YELLOW
style string Rating-Widget thumb & star ratings style (graphics). ""
imgUrl { object Custom star rating image url.
ltr string Custom Left-To-Right rating image url. ""
rtl string Custom Right-To-Left rating image url. ""
},
readOnly boolean If true, then the Rating-Widget is read-only/static. false
frequency RW.FREQUENCY The frequency the user can contribute a vote to the rating. By default, user can only vote once (RW.FREQUENCY.ONCE). RW.FREQUENCY.ONCE
reVote boolean If false, then the user can NOT change his vote. true
showInfo boolean Specify whether to show info messages or just a stripped star rating system. true
showTooltip boolean Specify whether to show mouseOver tooltip or not. true
showAverage boolean Specify whether to show the average rate of the rating. When false, the voter will only see his own vote. true
boost { object Rate boosting options. Shift the initial rating data.
votes int Votes number. 0
rate int Votes average rate. 5
},
beforeRate {bool | unsigned int} function(vote, rating) Optional handler that invokes between users click on the widget to the backend rate itself. null
afterRate void function(success, vote, rating, first, msg) Optional rating system callback. Invoked after the rating process. null
advanced { object Advanced options.
font { object Advanced font options.
color string Font color. "#000000"
type string Font type/family. "arial"
bold boolean Is bold font weight. false
italic boolean Is italic font style. false
},
layout { object Advanced layout options.
lineHeight string Widget text line height. "16px"
dir RW.DIR Layout direction. DIR.LTR
align { object Advanced alignment options.
hor RW.ALIGN.HOR Horizontal alignment. RW.ALIGN.HOR.RIGHT
ver RW.ALIGN.VER Vertical alignment. RW.ALIGN.VER.RIGHT
}
},
text { object Advanced text options.
rate array of string Various types of rates. e.g. in English,
["Awful", "Poor", "Average", "Good", "Excellent"]
Language Dependent
vote string The word that will appear for "Vote". "Vote"
votes string The word that will appear for "Votes". "Votes"
thanks string The expression which will appear for "Thank You". "Thank you"
},
star { object Advanced star options.
stars int Specify the number of stars for the star rating system (between 1 to 20). 5
},
css { object Advanced CSS stylesheet options.
container string Rating widget container inline style. ""
}
}

Methods of the RW object

The RW JavaScript object has various methods that may be helpful. Only methods documented in this section should be relied upon. Specifically, any methods beginning with an underscore are subject to change and should not be used.

Method Description
init(uid, options, vid)Initialization of the RW object. This method must be invoked first and only once in a page.uid {char[32]} your Rating-Widget user-key.options {object} a set of default options for all the Rating-Widget instances in the page (Optional).vid {unsigned int} voter unique id (Optional). E.g. logged user id.
initRating(urid, options)Set specified options to selected Rating-Widget instance. If calling this method, it must be invoked before calling to render().urid {unsigned int} selected Rating-Widget id.options {object} a set of options for the Rating-Widget.
initClass(class, options)Set specified options to all ratings with the specified rating class. If calling this method, it must be invoked before calling to render().class {string} rating class.options {object} a set of options for the Rating-Widget.
render(callback, optimized)Render all Rating-Widget instances of the page.callback {function()} optional callback after render.optimized {object} optimize external CSS stylesheet, defaults to true.
getRating(urid)Get specified Rating-Widget RW.Rating class instance.urid {unsigned int} user rating id.
getDefaultFontSize(size)Return the default font size corresponding to specified widget size.
(*) Deprecatedsize {RW.SIZE} Rating-Widget size.
getDefaultLineHeight(size)Return the default line height corresponding to specified widget size.
(*) Deprecatedsize {RW.SIZE} Rating-Widget size.
Usage:
RW.init("someuseruniqueidsomeuseruniqueid");
RW.initRating(36, {
lng: "ru",
advanced: {
layout: {
dir: RW.DIR.RTL
}
}
});
RW.render();

Properties of the RW.Rating class

The RW.Rating JavaScript class has various properties that may be helpful. Only properties documented in this section should be relied upon. Specifically, any properties beginning with an underscore are subject to change and should not be used.
All the properties are read-only and must not be modified directly.

Name Type Description
rid unsigned int Unique rating id.
urid unsigned int User rating id.
uid char[32] Unique user-key/id.
votes unsigned int Total votes number.
rate unsigned int Total rate - the sum of all votes together (not the average).
type RW.TYPE Rating type.
rated boolean Indicates whether the rating widget was already rated since it's loaded.
callState {"ready", "calling", "finished"} Current back-end server call state.
options object Rating system options-object.
advanced object Rating system advanced-options-object (alias of options.advanced).
beforeRate {bool | unsigned int} function(vote, rating) Optional handler that invokes between users click on the widget to the backend rate itself.
afterRate void function(success, vote, rating, first, msg) Optional rating callback. Invoked after the rating process.
Usage:
var myRatingWidget = RW.getRating(36);
if (myRatingWidget.votes == 1000){
...

Methods of the RW.Rating class

The RW.Rating JavaScript class has various methods that may be helpful. Only methods documented in this section should be relied upon. Specifically, any methods beginning with an underscore are subject to change and should not be used.

Method Description
constructor(data, elements, options)Class constructor.data {object} widget metadata (uid, urid, rid, votes, rate).elements {array of DOMElement} array of all UI instances (<div> containers) of the specified widget.options {object} rating options-object.
render()Renders the Rating-Widget UI instances (<div> containers).
refresh()Refresh rating view - update UI rate and label.
doRate(vote)Imitates user rating/voting action.vote {unsigned int} Rate/Grade (0 < vote < 6).
toggleBold()Toggle label boldness.
toggleItalic()Toggle label italicness.
setReadOnly(readOnly)Set if the rating is active or read-only.readOnly {boolean} Is read-only.
setFontType(family)Set font family.family {string} Font-family (e.g. "verdana").
setFontColor(color)Set label color.color {string} Color (e.g. "#00ff00", "red").
setFontSize(size)Set font size.size {string} Color (e.g. "30px", "1.2em").
setDirection(dir)Set containers direction.dir {RW.DIR} Direction (e.g. RW.DIR.RTL).
setAlignment(ver, hor)Set widgets alignment.ver {RW.ALIGN.VER} Vertical alignment (e.g. RW.ALIGN.VER.TOP).hor {RW.ALIGN.HOR} Horizontal alignment (e.g. RW.ALIGN.HOR.CENTER).
setLineHeight(height)Set line height.height {string} Line height (e.g. "20px").
setSize(size)Set widget's size.
Notice that if you won't explicitly specify the optimized parameter to be false when executing RW.render, your star icons will disappear!size {RW.SIZE} Color (e.g. RW.SIZE.MEDIUM).
setStyle(style, url)Set widget's style.
Notice that if you aren't using the custom image option and if you won't explicitly specify the optimized parameter to be false when executing RW.render, your star/thumb icons will disappear!style {string} Style (e.g. "oxygen_green"). Check out all available styles list.url {object} Optional custom image url object, relevant only when style = RW.CUSTOM.
setLanguage(lng)Set widget's language.
Notice that if you won't explicitly specify the optimized parameter to be false when executing RW.render, the language won't be loaded correctly!lng {string} Language (e.g. "ru"). Check out all available languages list.
setStars(num)Set star rating stars number.num {string} Stars number.
setCSS(item, style)Set rating inline style.item {string} The item of the rating that you wish to change it's style (currently only "container" is the only supported element).style {string} Inline style.
Usage:
var myRatingWidget = RW.getRating(36);
myRatingWidget.setFontSize("24px");
myRatingWidget.toggleBold();

The beforeRate() handler signiture

{bool | uint} beforeRate(uint vote, RW.Rating rating);

Params:
Name Type Description
vote unsigned int The grade/rate of the specified rate (0 < vote < 6).
rating RW.Rating The rated Rating-Widget control class instance.

Return:
Value Type Description
false bool If you like the rating process to stop - the rate won't reach the backend server.
true bool If you like the rating process to continue to the backend server.
vid (voter-id) unsigned int Your current logged in user unique id.

The afterRate() callback signiture

void afterRate(bool success, uint | bool vote, RW.Rating rating, bool first, string msg);

Params:
Name Type Description
success bool Is successful rate.
vote unsigned int | bool The rate of the specified rate (0 < vote < 6). If it's a thumb rating, returns true on Like, false on Dislike.
rating RW.Rating The rated Rating-Widget control class instance.
first bool Is it the first time that the user rates current Rating-Widget.
msg string Contain the error msg, on rating failure (when success = false).

Supported Languages

Code Language
"af" Afrikaans
"ar" Arabic - العربية
"bn" Bengali - বাংলা
"bg" Bulgarian - български
"ca" Catalan - Català
"ch" Chinese - 汉语/漢語
"cs" Czech - Čeština
"hr" Croatian - Hrvatski
"da" Danish - Dansk
"en" English (Default)
"et" Estonian - Eesti keel
"fi" Finnish - Suomi
"fr" French - Français
"ka" Georgian - ქართული
"de" German - Deutsch
"el" Greek - Ελληνικά
"he" Hebrew - עברית
"hi" Hindi - हिंदी
"hu" Hungarian - Magyar
"id" Indonesian - Bahasa Indonesia
"it" Italian - Italiano
"jp" Japanese - 日本語
"ko" Korean - 한국어/조선말
"lh" Lithuanian - Lietuvių
"mt" Maltese - Malti
"mn" Mongolian - Mongγol Kele
"nl" Nederlands - Dutch
"no" Norwegian - Norsk
"fa" Persian - فارسی
"pl" Polish - Polska
"pt" Portuguese - Português
"ro" Romanian - Română
"ru" Russian - Русский
"sr" Serbian - Српски
"sk" Slovak - Slovenčina
"sl" Slovenian - Slovenščina
"sv" Swedish - Svenska
"es" Spanish - Español
"ta" Tamil - தமிழ்
"tr" Turkish - Türkçe
"vi" Vietnamese - Tiếng Việt
"uk" Ukrainian - Українська Мова

Star Rating Styles

Sprite Name Element Author Icon Pack
"ratingwidget" Star Stanislav Macha Rating-Widget
"oxygen" Star Oxygen Team Oxygen
"oxygen1" Star Oxygen Team Oxygen
"crystal" Star YellowIcon Crystal Project
"christmas" Star jj-maxer Merry Christmas
"darkglass" Star Alessandro Rei Dark Glass
"oxygen_green" Star Oxygen Team Oxygen
"oxygen1_green" Star Oxygen Team Oxygen
"crystal_green" Star YellowIcon Crystal Project
"christmas_green" Star jj-maxer Merry Christmas
"darkglass_green" Star Alessandro Rei Dark Glass
"oxygen_red" Star Oxygen Team Oxygen
"oxygen1_red" Star Oxygen Team Oxygen
"crystal_red" Star YellowIcon Crystal Project
"christmas_red" Star jj-maxer Merry Christmas
"darkglass_red" Star Alessandro Rei Dark Glass
"oxygen_blue" Star Oxygen Team Oxygen
"oxygen1_blue" Star Oxygen Team Oxygen
"crystal_blue" Star YellowIcon Crystal Project
"christmas_blue" Star jj-maxer Merry Christmas
"darkglass_blue" Star Alessandro Rei Dark Glass
"flat_yellow" Star Stanislav Macha Rating-Widget
"flat_green" Star Stanislav Macha Rating-Widget
"flat_red" Star Stanislav Macha Rating-Widget
"flat_blue" Star Stanislav Macha Rating-Widget
"flat_magenta" Star Stanislav Macha Rating-Widget
"flat_brown" Star Stanislav Macha Rating-Widget
"yellow" Star Vova Feldman Rating-Widget
"green" Star Vova Feldman Rating-Widget
"red" Star Vova Feldman Rating-Widget
"blue" Star Vova Feldman Rating-Widget
"gray" Star Vova Feldman Rating-Widget
"quartz" Star Andy Gongea Quartz
"quartz_green" Star Andy Gongea Quartz
"quartz_red" Star Andy Gongea Quartz
"quartz_blue" Star Andy Gongea Quartz
"flames" Flame Giuseppe Battaglia
"smiley" Smiley Daya Curley
"crystal_correct" Correct Everaldo Coelho Crystal Clear Actions
"heart" Heart Vova Feldman Rating-Widget
"lean_heart" Heart Everaldo Coelho Lin
"barrels" Barrel Mladenovic Igor Rating-Widget
"apple_screen" Screen Apple Leopard
"phuzion_diskonkey" DiskOnKey Asher Phuzion
"emblem_art" Art schollidesign Human-O2
"everaldo_house" House Everaldo Coelho Kids
"newyear_tree" New-Year Tree Icojoy New Year Icojoy
"payment_coin" Coin Web Icon Set Payment Icon Set
"farmfresh_football" Football FatCow Farm-Fresh Web
"sportset_soccer" Soccer Ball Kevin Andersson Sportset
"sportset_tennis" Tennis Ball Kevin Andersson Sportset
"animals_butterfly" Butterfly VisualPharm (Ivan Boyko) Animals
"phuzion_bug" Bug Asher Phuzion
"animals_elephant" Elephant VisualPharm (Ivan Boyko) Animals
"crystal_penguin" Penguin Everaldo Coelho Crystal Clear Actions
"crystal_skype" Skype Logo YellowIcon Crystal Project
"crystal_user" User Everaldo Coelho Crystal Clear Actions
"darkglass_cookie" Tennis Ball YellowIcon Crystal Project
"jelly_red" Red Jellybeans Stanislav Mácha Rating-Widget
"santa_hat" Christmas Santa Hat PelFusion + IconDock Christmas
"christmas_yellow_ball" Christmas Yellow Ball 1 Icojoy New Year
"christmas_yellow_deco_ball" Christmas Yellow Ball 2 Icojoy New Year
"christmas_red_ball" Christmas Red Ball 1 Icojoy New Year
"christmas_red_deco_ball" Christmas Red Ball 2 Icojoy New Year
"christmas_blue_ball" Christmas Blue Ball 1 Icojoy New Year
"christmas_blue_deco_ball" Christmas Blue Ball 2 Icojoy New Year

Thumb Rating Styles

Sprite Name Element Author Icon Pack
"thumbs" Thumbs Vova Feldman Rating-Widget
"thumbs2" Thumbs Jochem van der Veer Rating-Widget
"arrows" Arrows Vova Feldman Rating-Widget
"arrows1" Arrows Vova Feldman Rating-Widget
"check" Checkboxes Trevor Hatfield Rating-Widget
"thumbs_bp" Thumbs Vova Feldman Rating-Widget
"masks" Thumbs David Shenberger Rating-Widget
"christmas" Thumbs Vova Feldman + IconDock Rating-Widget
"candles" Thumbs Yoram Zara Avelim

Examples using the RW object

Notice: All the examples must be placed in the scope of RW_Async_Init() function.

Setting all the Rating-Widget star ratings to be read-only:
RW.init("someuseruniqueidsomeuseruniqueid",{readOnly: true});
RW.render();
Customizing 2 Rating-Widgets differently:
RW.init("someuseruniqueidsomeuseruniqueid");
RW.initRating(36, {type: RW.TYPE.STAR, style: "oxygen", size: RW.SIZE.LARGE});
RW.initRating(17, {type: RW.TYPE.NERO, style: "thumbs", advanced: {text: {thanks: "Thanks Dude!"}}});
RW.render();
Forcing log-in before rating:
RW.init("someuseruniqueidsomeuseruniqueid",{
beforeRate: function(vote, rating){
if (!is_logged_in()){
return false;
}else{
return get_user_id();
}
}
});
RW.render();
Setting custom image sprite:

Notice: Click here to learn how to build your custom icons sprite.

RW.init("someuseruniqueidsomeuseruniqueid",{
type: RW.TYPE.STAR,
style: RW.CUSTOM,
imgUrl: {
ltr: "http://yourdomain.com/your.left2right.sprite.png",
rtl: "http://yourdomain.com/your.right2left.sprite.png",
}
});
RW.render();
Rewarding the 1,000th rater:
RW.init("someuseruniqueidsomeuseruniqueid",{
afterRate: function(success, first, vote, rating, msg){
if (success && first && rating.votes == 1000){
alert("You are the BEST! Thanks!");
}
}
});
RW.render();
Setting all posts ratings to star ratings, and all comments ratings to thumb ratings:
<html>
<head>
<!-- ... your HTML content ... -->
</head>

<body>
<!-- ... your HTML body content ... -->

<div class="post">
<!-- ... your post body content ... -->
<div class="rw-ui-container rw-urid-17 rw-class-post"></div>
<!-- ... more of your post body content ... -->
</div>


<!-- ... more of your HTML body content ... -->

<div class="comment">
<!-- ... your comment body content ... -->
<div class="rw-ui-container rw-urid-171 rw-class-comment"></div>
<!-- ... more of your comment body content ... -->
</div>


<!-- ... more of your HTML body content ... -->

<div class="comment">
<!-- ... your comment body content ... -->
<div class="rw-ui-container rw-urid-172 rw-class-comment"></div>
<!-- ... more of your comment body content ... -->
</div>


<!-- ... more of your HTML body content ... -->

<div class="post">
<!-- ... your post body content ... -->
<div class="rw-ui-container rw-urid-36 rw-class-post"></div>
<!-- ... more of your post body content ... -->
</div>


<!-- ... more of your HTML body content ... -->

<div class="comment">
<!-- ... your comment body content ... -->
<div class="rw-ui-container rw-urid-361 rw-class-comment"></div>
<!-- ... more of your comment body content ... -->
</div>


<!-- ... more of your HTML body content ... -->

<div class="rw-js-container">
<script type="text/javascript">
function RW_Async_Init(){
RW.init("someuseruniqueidsomeuseruniqueid");
RW.initClass("post", {type: RW.TYPE.STAR});
RW.initClass("comment", {type: RW.TYPE.NERO});
RW.render();
}

if (typeof(RW) == "undefined"){
(function(){
var rw = document.createElement("script");
rw.type = "text/javascript"; rw.async = true;
rw.src = "http://js.rating-widget.com/external.min.js?v=259&t=js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(rw, s);
})();
}
}
</script>
</div>

</body>
</html>
Feedback Form