Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
polymer-ui-ratings
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiefu committed Jun 10, 2013
1 parent 2a7e419 commit a9a5d26
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
24 changes: 24 additions & 0 deletions polymer-ui-ratings/index.html
@@ -0,0 +1,24 @@

<!doctype html>
<!--
Copyright 2013 The Polymer Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<html>
<head>
<title>polymer-ui-ratings</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<!-- load toolkit -->
<script src="../../polymer/polymer.js"></script>
<!-- import elements-->
<link rel="import" href="polymer-ui-ratings.html">
<!-- -->
<link rel="stylesheet" href="../basic.css">
</head>
<body>
<polymer-ui-ratings value="3"></polymer-ui-ratings>
</div>
</body>
</html>
29 changes: 29 additions & 0 deletions polymer-ui-ratings/polymer-ui-ratings.css
@@ -0,0 +1,29 @@
/*
Copyright 2013 The Polymer Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
*/

@host {
* {
display: inline-block;
white-space: nowrap;
-webkit-user-select: none;
-moz-user-select: none;
}
}

#star {
display: inline-block;
vertical-align: middle;
width: 24px;
height: 24px;
margin: 0 5px;
background-size: 100% 100%;
background-image: url('star_blank.png');
cursor: pointer;
}

#star.full {
background-image: url('star_full.png');
}
70 changes: 70 additions & 0 deletions polymer-ui-ratings/polymer-ui-ratings.html
@@ -0,0 +1,70 @@
<!--
Copyright 2013 The Polymer Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<!--
/**
* @module Polymer Elements
*/
/**
* polymer-ratings allows users to rate items.
*
* Example:
*
* <polymer-ratings value="3"></polymer-ratings>
*
* By default g-ratings shows 5 stars but can be configured using "count" attribute:
*
* <polymer-ratings value="3" count="10"></polymer-ratings>
*
* @class g-ratings
*/
-->
<element name="polymer-ui-ratings" attributes="count value">
<link rel="stylesheet" href="polymer-ui-ratings.css">
<template>
<template repeat="{{stars}}">
<span id="star" index="{{index}}" class="{{starClass}}" touch-action="none" on-tap="updateValue"></span>
</template>
</template>
<script>
Polymer.register(this, {
/**
* Number of stars to display.
*
* @attribute count
* @type number
* @default 5
*/
count: 5,
/**
* Number of selected stars.
*
* @attribute value
* @type number
* @default 0
*/
value: 0,
ready: function() {
this.countChanged();
},
countChanged: function() {
this.stars = [];
for (var i = 0; i < this.count; i++) {
this.stars.push({index: i});
}
this.valueChanged();
},
valueChanged: function() {
this.stars && this.stars.forEach(function(s, i) {
s.starClass = i < this.value ? 'full' : '';
}.bind(this));
},
updateValue: function(event, detail, sender) {
var s = sender.templateInstance.model;
this.value = s.index + (s.starClass ? 0 : 1);
}
});
</script>
</element>
Binary file added polymer-ui-ratings/star_blank.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added polymer-ui-ratings/star_full.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a9a5d26

Please sign in to comment.