-
Notifications
You must be signed in to change notification settings - Fork 75
/
index.html
127 lines (109 loc) · 3.87 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Five Star Rating</title>
<meta name="description" content="Five star rating component built with JavaScript and CSS, and packaged as a bower component.">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/style.min.css">
<link rel="stylesheet" href="css/rating.min.css">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" href="/favicon.png">
</head>
<body>
<header class="o-header">
<nav class="o-header-nav">
<a href="http://callmenick.com/_development/responsive-tabs/" class="o-header-nav__link"><i class="fa fa-arrow-left"></i> Previous Demo</a>
<a href="http://callmenick.com/post/five-star-rating-component-with-javascript-css" class="o-header-nav__link">Back To Article <i class="fa fa-star"></i></a>
</nav>
<div class="o-container">
<h1 class="o-header__title">Five Star Rating</h1>
</div>
</header>
<main class="o-content">
<div class="o-container">
<div class="o-section">
<div id="shop"></div>
</div>
<div class="o-section">
<div id="github-icons"></div>
</div>
</div>
</main>
<footer class="o-footer">
<div class="o-container">
<small>© 2015, callmenick.com</small>
</div>
</footer>
<script src="js/dist/rating.min.js"></script>
<script>
/**
* Demo in action!
*/
(function() {
'use strict';
// SHOP ELEMENT
var shop = document.querySelector('#shop');
// DUMMY DATA
var data = [
{
title: "Dope Hat",
description: "Dope hat dolor sit amet, consectetur adipisicing elit. Commodi consectetur similique ullam natus ut debitis praesentium.",
rating: 3
},
{
title: "Hot Top",
description: "Hot top dolor sit amet, consectetur adipisicing elit. Commodi consectetur similique ullam natus ut debitis praesentium.",
rating: 2
},
{
title: "Fresh Kicks",
description: "Fresh kicks dolor sit amet, consectetur adipisicing elit. Commodi consectetur similique ullam natus ut debitis praesentium.",
rating: null
}
];
// INITIALIZE
(function init() {
for (var i = 0; i < data.length; i++) {
addRatingWidget(buildShopItem(data[i]), data[i]);
}
})();
// BUILD SHOP ITEM
function buildShopItem(data) {
var shopItem = document.createElement('div');
var html = '<div class="c-shop-item__img"></div>' +
'<div class="c-shop-item__details">' +
'<h3 class="c-shop-item__title">' + data.title + '</h3>' +
'<p class="c-shop-item__description">' + data.description + '</p>' +
'<ul class="c-rating"></ul>' +
'</div>';
shopItem.classList.add('c-shop-item');
shopItem.innerHTML = html;
shop.appendChild(shopItem);
return shopItem;
}
// ADD RATING WIDGET
function addRatingWidget(shopItem, data) {
var ratingElement = shopItem.querySelector('.c-rating');
var currentRating = data.rating;
var maxRating = 5;
var callback = function(rating) { alert(rating); };
var r = rating(ratingElement, currentRating, maxRating, callback);
}
})();
</script>
<!-- EXTERNAL SCRIPTS FOR CALLMENICK.COM, PLEASE DO NOT INCLUDE -->
<script src="js/lib/githubicons.js"></script>
<script src="js/lib/carbonad.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-34160351-1', 'auto');
ga('send', 'pageview');
</script>
<!-- /EXTERNAL SCRIPTS -->
</body>
</html>