Skip to content

Commit 299212e

Browse files
committed
added star rating to root page
1 parent 39f3609 commit 299212e

File tree

5 files changed

+51
-18
lines changed

5 files changed

+51
-18
lines changed

.DS_Store

0 Bytes
Binary file not shown.

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"method-override": "^2.3.9",
3636
"mysql2": "^1.4.2",
3737
"path": "^0.12.7",
38-
"semantic-ui": "^2.2.13",
3938
"sequelize": "^4.8.2"
4039
}
4140
}

public/assets/css/blog-style.css

+9
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,16 @@ h1 { font-size: 1.5em; margin: 10px; }
221221
float: right;
222222
}
223223

224+
span.stars, span.stars span {
225+
display: inline-block;
226+
background: url(http://www.ulmanen.fi/stuff/stars.png) 0 -16px repeat-x;
227+
width: 80px;
228+
height: 16px;
229+
}
224230

231+
span.stars span {
232+
background-position: 0 0;
233+
}
225234

226235
/***** CSS Magic to Highlight Stars on Hover *****/
227236

views/index.handlebars

+37-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<!--page wrapper-->
2-
{{!-- <div class="container"> --}}
3-
4-
{{> navbar/navbar}}
2+
{{!--
3+
<div class="container"> --}} {{> navbar/navbar}}
54
<!--page header-->
65
<div class="row">
76
<div class="col header">
@@ -28,25 +27,46 @@
2827
<div class="row background-main">
2928

3029
{{#each topTen}}
31-
<div class="col-sm-4 blog-card">
30+
<div class="col-sm-4 blog-card">
3231
<div class="card-deck">
33-
<div class="card">
34-
<div class="card-body">
35-
<a class="colored-link" href="/blog/{{this.id}}">
36-
<h3 class="title">{{this.title}}</h3>
37-
</a>
38-
<p class="card-text">By: {{this.blog_author}}</p>
39-
<p class="card-text">Website: <a href="{{this.website}}" target="_blank">{{this.website}}</a></p>
40-
<p class="card-text">Description: {{this.description}}</p>
41-
<p class="card-text">Rating: {{this.rating}} </p>
32+
<div class="card">
33+
<div class="card-body">
34+
<a class="colored-link" href="/blog/{{this.id}}">
35+
<h3 class="title">{{this.title}}</h3>
36+
</a>
37+
<p class="card-text">By: {{this.blog_author}}</p>
38+
<p class="card-text">Website: <a href="{{this.website}}" target="_blank">{{this.website}}</a></p>
39+
<p class="card-text">Description: {{this.description}}</p>
40+
<p class="card-text">Rating: <span class="stars">{{this.cumulative_rating}}</span> </p>
41+
</div>
4242
</div>
4343
</div>
44-
</div>
45-
</div>
44+
</div>
4645
{{/each}}
4746

4847

4948

5049
</div>
51-
{{!-- </div> --}}
52-
{{> scripts/scripts}}
50+
51+
<!--show star rating-->
52+
<script>
53+
$.fn.stars = function () {
54+
return $(this).each(function () {
55+
// Get the value
56+
var val = parseFloat($(this).html());
57+
// Make sure that the value is in 0 - 5 range, multiply to get width
58+
val = Math.round(val * 2) / 2;
59+
var size = Math.max(0, (Math.min(5, val))) * 16;
60+
// Create stars holder
61+
var $span = $('<span />').width(size);
62+
// Replace the numerical value with stars
63+
$(this).html($span);
64+
});
65+
}
66+
$(function () {
67+
$('span.stars').stars();
68+
});
69+
</script>
70+
<!--end of star rating-->
71+
72+
{{> scripts/scripts}}

0 commit comments

Comments
 (0)