Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rating] Individual icons and colors instead of fixed star+heart only #303

Merged
merged 2 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/definitions/modules/rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ $.fn.rating = function(parameters) {
layout: function() {
var
maxRating = module.get.maxRating(),
html = $.fn.rating.settings.templates.icon(maxRating)
icon = module.get.icon(),
html = $.fn.rating.settings.templates.icon(maxRating, icon)
;
module.debug('Generating icon html dynamically');
$module
Expand Down Expand Up @@ -215,6 +216,13 @@ $.fn.rating = function(parameters) {
},

get: {
icon: function(){
var icon = $module.data(metadata.icon);
if (icon) {
$module.removeData(metadata.icon);
}
return icon || settings.icon;
},
initialRating: function() {
if($module.data(metadata.rating) !== undefined) {
$module.removeData(metadata.rating);
Expand Down Expand Up @@ -460,7 +468,9 @@ $.fn.rating.settings = {
name : 'Rating',
namespace : 'rating',

slent : false,
icon : 'star',

silent : false,
debug : false,
verbose : false,
performance : true,
Expand All @@ -482,7 +492,8 @@ $.fn.rating.settings = {

metadata: {
rating : 'rating',
maxRating : 'maxRating'
maxRating : 'maxRating',
icon : 'icon'
},

className : {
Expand All @@ -497,13 +508,13 @@ $.fn.rating.settings = {
},

templates: {
icon: function(maxRating) {
icon: function(maxRating, iconClass) {
var
icon = 1,
html = ''
;
while(icon <= maxRating) {
html += '<i class="icon"></i>';
html += '<i class="'+iconClass+' icon"></i>';
icon++;
}
return html;
Expand Down
94 changes: 39 additions & 55 deletions src/definitions/modules/rating.less
Original file line number Diff line number Diff line change
Expand Up @@ -75,61 +75,45 @@
}


/*-------------------
Star
--------------------*/

/* Inactive */
.ui.star.rating .icon {
width: @starIconWidth;
height: @starIconHeight;
background: @starInactiveBackground;
color: @starInactiveColor;
text-shadow: @starInactiveTextShadow;
}

/* Active Star */
.ui.star.rating .active.icon {
background: @starActiveBackground !important;
color: @starActiveColor !important;
text-shadow: @starActiveTextShadow !important;
}

/* Selected Star */
.ui.star.rating .icon.selected,
.ui.star.rating .icon.selected.active {
background: @starSelectedBackground !important;
color: @starSelectedColor !important;
text-shadow: @starSelectedTextShadow !important;
}


/*-------------------
Heart
--------------------*/

.ui.heart.rating .icon {
width: @heartIconWidth;
height: @heartIconHeight;
background: @heartInactiveBackground;
color: @heartInactiveColor;
text-shadow: @heartInactiveTextShadow !important;
}

/* Active Heart */
.ui.heart.rating .active.icon {
background: @heartActiveBackground !important;
color: @heartActiveColor !important;
text-shadow: @heartActiveTextShadow !important;
}

/* Selected Heart */
.ui.heart.rating .icon.selected,
.ui.heart.rating .icon.selected.active {
background: @heartSelectedBackground !important;
color: @heartSelectedColor !important;
text-shadow: @heartSelectedTextShadow !important;
}
/*--------------
Colors
-------------- */

.ratingColor(@color; @lightColor;) {
@_ratingActiveShadow: "@{color}";
@_ratingActive: "@{lightColor}";
@_ratingSelectedShadow: "@{color}Hover";
@_ratingSelected: "@{lightColor}Hover";
.ui.@{color}.rating .active.icon {
color: @@_ratingActive;
text-shadow: 0px -@shadowWidth 0px @@_ratingActiveShadow,
-@shadowWidth 0px 0px @@_ratingActiveShadow,
0px @shadowWidth 0px @@_ratingActiveShadow,
@shadowWidth 0px 0px @@_ratingActiveShadow;
}
.ui.@{color}.rating .icon.selected,
.ui.@{color}.rating .icon.selected.active {
color: @@_ratingSelected;
text-shadow: 0px -@shadowWidth 0px @@_ratingSelectedShadow,
-@shadowWidth 0px 0px @@_ratingSelectedShadow,
0px @shadowWidth 0px @@_ratingSelectedShadow,
@shadowWidth 0px 0px @@_ratingSelectedShadow;
}
}

.ratingColor(~'red',~'lightRed');
.ratingColor(~'orange',~'lightOrange');
.ratingColor(~'yellow',~'lightYellow');
.ratingColor(~'olive',~'lightOlive');
.ratingColor(~'green',~'lightGreen');
.ratingColor(~'teal',~'lightTeal');
.ratingColor(~'blue',~'lightBlue');
.ratingColor(~'violet',~'lightViolet');
.ratingColor(~'purple',~'lightPurple');
.ratingColor(~'pink',~'lightPink');
.ratingColor(~'brown',~'lightBrown');
.ratingColor(~'grey',~'lightGrey');
.ratingColor(~'black',~'lightBlack');


/*******************************
Expand Down
Loading