-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrent-slide.html
More file actions
91 lines (90 loc) · 2.22 KB
/
current-slide.html
File metadata and controls
91 lines (90 loc) · 2.22 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
<link rel="import" href="../polymer/polymer.html" />
<dom-module id="current-slide">
<style>
ul {
padding-left: 0;
}
li {
display: inline-block;
width: 1em;
height: 1em;
border-radius: 1em;
background-color: #fff;
}
li[active] {
background-color: #000;
}
</style>
<template>
<ul>
<template is="dom-repeat" items="[[_slides]]">
<li active$="[[_equalIndex(index,active)]]"></li>
</template>
</ul>
</template>
</dom-module>
<script>
/**
* This component is useful for situations where you have a custom slide deck already
* implemented but require some visual feedback as to where in the deck a reader is at
* the current moment.
*
* Note: this component is visual-only and does not provide handlers for navigation of
* your slide deck. Navigation should be implemented elsewhere in your code with this
* component providing a visual indicator of your navigation's current state.
*/
Polymer({
is: "current-slide",
properties: {
/**
* Holds an array of empty values symbolising each slide.
*/
_slides: {
type: Array,
value: function() { return []; }
},
/**
* Sets the number of slides in your stack.
*/
count: {
type: Number,
value: 0,
observer: '_countChanged'
},
/**
* Defines which numbered slide is attributed with the "active" flag used for styling.
*/
active: {
type: Number,
value: 0
}
},
/**
* Updates the `_slides` array to contain `count` number of values whenever `count` changes.
*
* @param {Number} newValue the new value
* @param {Number} oldValue the value to replace
*/
_countChanged: function(newValue, oldValue) {
if (newValue < oldValue) {
for (; this._slides.length > newValue;) {
this.pop('_slides');
}
} else {
for (; this._slides.length < newValue;) {
this.push('_slides', '');
}
}
},
/**
* indicates equality between the first value, after incrementing once, and the second value.
*
* @param {Number} a value which, after incrementing once, is tested against `b`
* @param {Number} b value to test `a` against
* @return {Boolean} indicates equality
*/
_equalIndex: function(a, b) {
return (a + 1) == b;
}
})
</script>