forked from melloc01/angular-input-stars
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.html
More file actions
252 lines (240 loc) · 18.8 KB
/
demo.html
File metadata and controls
252 lines (240 loc) · 18.8 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Angular Input Stars</title>
<link rel="stylesheet" type="text/css" href="bower_components/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="angular-input-stars.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style>
.html.tag{
color: #cfc044;
}
.html.prop-name{
color: #e8fcff;
}
.html.prop-string{
color: #78cb48;
}
pre {
background-color: #404040;
}
</style>
</head>
<body >
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div class="container-fluid" ng-app="app" ng-controller="AppCtrl as App">
<div class="row">
<!--Example 1-->
<div class="col-xs-12 col-sm-6 col-lg-4 example-element">
<a class="view-code btn" data-toggle="collapse" data-target="#example1" aria-expanded="false" aria-controls="example1"><span data-toggle="tooltip" data-placement="bottom" title="View Code"><code></span></a>
<h3>Example 1</h3>
<p>This is a default version. The star comes from FontAwesome and it works as a fallback.</p>
<input-stars ng-model="prop1" on-star-click="clickHandler(prop1)" max="5"></input-stars>
<span class="tag tag-info">value: {{prop1}}</span>
<div class="collapse" id="example1">
<div class="card card-block">
<pre><span class="html tag"><input-stars</span> <span class="html prop-name">ng-model=</span><span class="html prop-string">"prop1"</span> <span class="html prop-name">on-star-click=</span><span class="html prop-string">"clickHandler(prop1)"</span> <span class="html prop-name">max=</span><span class="html prop-string">"5"></span><span class="html tag"></input-stars></span></pre>
</div>
</div>
</div>
<!--Example 2-->
<div class="col-xs-12 col-sm-6 col-lg-4 example-element">
<a class="view-code btn" data-toggle="collapse" data-target="#example2" aria-expanded="false" aria-controls="example2"><span data-toggle="tooltip" data-placement="bottom" title="View Code"><code></span></a>
<h3>Example 2</h3>
<p>You can change the icon when is empty with <code>icon-empty</code> and when is full with <code>icon-full</code></p>
<input-stars icon-empty="fa-heart-o" icon-full="fa-heart" ng-model="prop2" max="5"></input-stars>
<span class="tag tag-info">value: {{prop2}}</span>
<div class="collapse" id="example2">
<div class="card card-block">
<pre><span class="html tag"><input-stars</span> <span class="html prop-name">icon-empty=</span><span class="html prop-string">"fa-heart-o"</span> <span class="html prop-name">icon-full=</span><span class="html prop-string">"fa-heart"</span> <span class="html prop-name">ng-model=</span><span class="html prop-string">"prop2"</span> <span class="html prop-name">max=</span><span class="html prop-string">"5"></span><span class="html tag"></input-stars></span></pre>
</div>
</div>
</div>
<!--Example 3-->
<div class="col-xs-12 col-sm-6 col-lg-4 example-element">
<a class="view-code btn" data-toggle="collapse" data-target="#example3" aria-expanded="false" aria-controls="example3"><span data-toggle="tooltip" data-placement="bottom" title="View Code"><code></span></a>
<h3>Example 3</h3>
<p>You can bootstrap icons too</p>
<input-stars icon-base="glyphicon" icon-empty="glyphicon-remove" icon-full="glyphicon-ok" ng-model="prop3" max="5"></input-stars>
<span class="tag tag-info">value: {{prop3}}</span>
<div class="collapse" id="example3">
<div class="card card-block">
<pre><span class="html tag"><input-stars</span> <span class="html prop-name">icon-base=</span><span class="html prop-string">"glyphicon"</span> <span class="html prop-name">icon-empty=</span><span class="html prop-string">"glyphicon-remove"</span> <span class="html prop-name">icon-full=</span><span class="html prop-string">"glyphicon-ok"</span> <span class="html prop-name">ng-model=</span><span class="html prop-string">"prop3"</span> <span class="html prop-name">max=</span><span class="html prop-string">"5"</span><span class="html tag">></input-stars></span></pre>
</div>
</div>
</div>
<!--Example 4-->
<div class="col-xs-12 col-sm-6 col-lg-4 example-element">
<a class="view-code btn" data-toggle="collapse" data-target="#example4" aria-expanded="false" aria-controls="example4"><span data-toggle="tooltip" data-placement="bottom" title="View Code"><code></span></a>
<h3>Example 4</h3>
<p>You can choose if you want to use different icons when the user sets a rating</p>
<input-stars icon-empty="fa-heart-o" icon-full="fa-twitter" ng-model="prop3" max="5"></input-stars>
<span class="tag tag-info">value: {{prop4}}</span>
<div class="collapse" id="example4">
<div class="card card-block">
<pre><span class="html tag"><input-stars</span> <span class="html prop-name">icon-empty=</span><span class="html prop-string">"fa-heart-o"</span> <span class="html prop-name">icon-full=</span><span class="html prop-string">"fa-twitter"</span> <span class="html prop-name">ng-model=</span><span class="html prop-string">"prop3"</span> <spna class="html prop-name">max=</spna><span class="html prop-string">"5"</span><span class="html tag">></input-stars></span></pre>
</div>
</div>
</div>
<!--Example 5-->
<div class="col-xs-12 col-sm-6 col-lg-4 example-element">
<a class="view-code btn" data-toggle="collapse" data-target="#example5" aria-expanded="false" aria-controls="example5"><span data-toggle="tooltip" data-placement="bottom" title="View Code"><code></span></a>
<h3>Example 5</h3>
<p>Set the maximum rating with an scope variable</p>
<div class="form-inline">
<div class="form-group">
<label>Max. rating</label>
<input type="number" ng-model="maxDynamic" class="form-control" min="0"/>
</div>
</div>
<div class="col-xs-12">
<input-stars ng-model="prop4" max="{{maxDynamic}}"></input-stars>
<span class="tag tag-info">value: {{prop5}}</span>
</div>
<div class="collapse" id="example5">
<div class="card card-block">
<pre><span class="html tag"><input-stars</span> <span class="html prop-name">ng-model=</span><span class="html prop-string">"prop4"</span> <span class="html prop-name">max=</span><span class="html prop-string">"{{maxDynamic}}"</span><span class="html tag">></input-stars></span></pre>
</div>
</div>
</div>
<!--Example 6-->
<div class="col-xs-12 col-sm-6 col-lg-4 example-element">
<a class="view-code btn" data-toggle="collapse" data-target="#example6" aria-expanded="false" aria-controls="example6"><span data-toggle="tooltip" data-placement="bottom" title="View Code"><code></span></a>
<h3>Example 6</h3>
<p>You can use <a href="https://design.google.com/icons/">Material Icons</a> that uses ligature for its icons only with the attribute <code>ligature</code></p>
<input-stars icon-base="material-icons" icon-empty="sentiment_dissatisfied" icon-full="sentiment_satisfied" ng-model="prop6" max="5" ligature></input-stars>
<span class="tag tag-info">value: {{prop6}}</span>
<div class="collapse" id="example6">
<div class="card card-block">
<pre><span class="html tag"><input-stars</span> <span class="html prop-name">icon-base=</span><span class="html prop-string">"material-icons"</span> <spna class="html prop-name">icon-empty=</spna><span class="html prop-string">"sentiment_dissatisfied"</span> <span class="html prop-name">icon-full=</span><span class="html prop-string">"sentiment_satisfied"</span> <span class="html prop-name">ng-model=</span><span class="html prop-string">"prop5"</span> <span class="html prop-name">max=</span><span class="html prop-string">"5"</span> <span class="html prop-name">ligature</span><span class="html tag">></input-stars></span></pre>
</div>
</div>
</div>
<!--Example 7-->
<div class="col-xs-12 col-sm-6 col-lg-4 example-element" ng-init="enableReadonly = true">
<a class="view-code btn" data-toggle="collapse" data-target="#example7" aria-expanded="false" aria-controls="example7"><span data-toggle="tooltip" data-placement="bottom" title="View Code"><code></span></a>
<h3>Example 7</h3>
<p>You can make an input star readonly easily, just can simple add the <code>readonly</code> attribute</p>
<input-stars
ng-model="prop7"
max="5"
readonly
></input-stars>
<span class="tag tag-info">value: {{prop7}}</span>
<div class="collapse" id="example7">
<div class="card card-block">
<pre><span class="html tag"><input-stars</span> <span class="html prop-name">ng-model=</span><span class="html prop-string">"prop1"</span> <span class="html prop-name">max=</span><span class="html prop-string">"5"</span> <span class="html prop-name">readonly</span><span class="html tag">></input-stars></span></pre>
</div>
</div>
</div>
<!--Example 8-->
<div class="col-xs-12 col-sm-6 col-lg-4 example-element">
<a class="view-code btn" data-toggle="collapse" data-target="#example8" aria-expanded="false" aria-controls="example8"><span data-toggle="tooltip" data-placement="bottom" title="View Code"><code></span></a>
<h3>Example 8</h3>
<p>You play with a variable to chance the icons when the input is readonly</p>
<div ng-init="enableReadonly = true">
<em>
<input type="checkbox" ng-model="enableReadonly" > Toggle readonly
</em>
<span class="tag tag-info">{{ enableReadonly }}</span>
</div>
<input-stars
ng-model="prop2"
max="5"
ng-attr-readonly="{{ enableReadonly || false }}"
ng-attr-icon-empty="{{ enableReadonly ? 'fa-twitter' : 'fa-circle-o' }}"
ng-attr-icon-full="{{ enableReadonly ? 'fa-cog' : 'fa-twitter' }}"
></input-stars>
<span class="tag tag-info">value: {{prop2}}</span>
<div class="collapse" id="example8">
<div class="card card-block">
<pre><span class="html tag"><input-stars</span> <span class="html prop-name">ng-model=</span><span class="html prop-string">"prop1"</span> <span class="html prop-name">max=</span><span class="html prop-string">"5"</span> <span class="html prop-name">ng-attr-readonly=</span><span class="html prop-string">"{{ enableReadonly || false }}"</span> <span class="html prop-name">ng-attr-icon-empty=</span><span class="html prop-string">"{{ enableReadonly ? 'fa-twitter' : 'fa-circle-o' }}"</span> <span class="html prop-name"></span>ng-attr-icon-full=<span class="html prop-string">"{{ enableReadonly ? 'fa-cog' : 'fa-twitter' }}"</span><span class="html tag">></input-stars></span></pre>
</div>
</div>
</div>
<!--Example 9-->
<div class="col-xs-12 col-sm-6 col-lg-4 example-element">
<a class="view-code btn" data-toggle="collapse" data-target="#example9" aria-expanded="false" aria-controls="example9"><span data-toggle="tooltip" data-placement="bottom" title="View Code"><code></span></a>
<h3>Example 9</h3>
<p>Change the class on hover using the attribute <code>icon-hover="classname"</code></p>
<div ng-init="hoverClass = 'red'">
<em>
<input name="hover" type="radio" ng-model="hoverClass" value="red"> red
<input name="hover" type="radio" ng-model="hoverClass" value="blue"> blue
</em>
<span class="tag tag-info">{{ hoverClass }}</span>
</div>
<input-stars
ng-model="prop2"
max="5"
icon-hover="{{hoverClass}}"
></input-stars>
<span class="tag tag-info">value: {{prop2}}</span>
<div class="collapse" id="example9">
<div class="card card-block">
<pre><span class="html tag"><input-stars</span> <span class="html prop-name">ng-model=</span><span class="html prop-string">"prop2"</span> <span class="html prop-name">max=</span><span class="html prop-string">"5"</span> <span class="html prop-name">icon-hover=</span><span class="html prop-string">"{{hoverClass}}"</span><span class="html tag">></input-stars></span></pre>
</div>
</div>
</div>
<!--Example 10-->
<div class="col-xs-12 col-sm-6 col-lg-4 example-element">
<a class="view-code btn" data-toggle="collapse" data-target="#example10" aria-expanded="false" aria-controls="example10"><span data-toggle="tooltip" data-placement="bottom" title="View Code"><code></span></a>
<h3>Example 10</h3>
<p>Adding a click event to the element it's easy, just add <code>on-star-click="functionHandler()"</code> and that's it. (Check the console)</p>
<input-stars
ng-model="prop3"
max="5"
on-star-click="clickEventHandler()"
></input-stars>
<span class="tag tag-info">value: {{prop3}}</span>
<div class="collapse" id="example10">
<div class="card card-block">
<pre><span class="html tag"><input-stars</span> <span class="html prop-name">ng-model=</span><span class="html prop-string">"prop3"</span> <span class="html prop-name">max=</span><span class="html prop-string">"5"</span> <span class="html prop-name">on-star-click=</span><span class="html prop-string">"clickEventHandler()"</span><span class="html tag">></input-stars></span></pre>
</div>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js" integrity="sha384-THPy051/pYDQGanwU6poAc/hOdQxjnOEXzbT+OuUAFqNqFjL+4IGLBgCJC3ZOShY" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="bower_components/angular/angular.js"></script>
<script type="text/javascript" src="angular-input-stars.js"></script>
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
<script type="text/javascript">
if (window.angular === undefined)
alert('Maybe you should run bower install first :]');
angular.module('app', ['angular-input-stars']);
angular.module('app').controller('AppCtrl', AppCtrl);
AppCtrl.$inject = ['$scope'];
function AppCtrl ($scope) {
$scope.clickHandler= function (prop) {
console.log(prop);
};
$scope.clickEventHandler = function(){
console.log("Input was clicked with " + $scope.prop3 + " stars");
};
var vm = this;
$scope.prop1 = 1;
$scope.prop2 = 2;
$scope.prop3 = 3;
$scope.prop4 = 4;
$scope.prop5 = 2;
$scope.prop6 = 3;
$scope.prop7 = 3;
$scope.maxDynamic = 3;
}
</script>
</body>
</html>