-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpolymate-demo-controllers.html
130 lines (118 loc) · 3.58 KB
/
polymate-demo-controllers.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
128
129
130
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="./polymate-behavior.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../paper-slider/paper-slider.html">
<link rel="import" href="../paper-icon-button/paper-icon-button-light.html">
<dom-module id="polymate-demo-controllers">
<template>
<style>
:host {
display: block;
font-size: 12px;
}
.basic,
#controllers {
display: flex;
}
#controllers {
margin-bottom: 20px;
}
.caption {
padding-left: 5px;
color: #a0a0a0;
}
.speed-container {
text-align: left;
padding-left: 10px;
}
</style>
<hr>
<div id="controllers">
<div class="speed-container">Speed: <span id="speedValue" class="caption"></span>
<paper-slider id="speed" value="1" pin max="7" snaps step=".001"></paper-slider>
</div>
<div class="basic">
<paper-button raised id="stop" on-click="_stop">Stop</paper-button>
<paper-button raised id="playPause" on-click="_togglePlayPause"><span>[[_playPause]]</span></paper-button>
<paper-button raised id="reverseDirection" on-click="reverseDirection">Reverse Direction</paper-button>
</div>
</div>
<hr>
</template>
<script>
/**
* `polymate-demo`
*
* demo helper for polymate-view
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class PolymerDemoControllers extends PolymateBehavior(Polymer.Element) {
static get is() { return 'polymate-demo-controllers'; }
static get properties() {
return {
/**
* @desc animation object from polymate view
* @type {Object}
*/
anim: Object,
/**
* @desc play or pause
* @type {String}
*/
_playPause: String
};
}
ready() {
super.ready();
let controller = this;
window.addEventListener('WebComponentsReady', function() {
if (!controller.anim) return;
if (controller.anim.isPaused) controller._disableStopAndReverse(controller);
controller._playPause = controller.anim.autoplay ? 'Pause' : 'Play';
controller.$.speed.addEventListener('value-change', function() {
controller.$.speedValue.textContent = controller.$.speed.value + 'x';
controller.anim.setSpeed(controller.$.speed.value);
});
});
}
/**
* @desc stop animation
* @return {Void}
*/
_stop() {
this.stop();
this._playPause = 'Play';
this._disableStopAndReverse(this);
}
/**
* @desc disable stop and reverse
* @param {Object} element
* @param {Boolean} enable
* @return {Void}
*/
_disableStopAndReverse(element, enable) {
element.$.stop.disabled = enable ? false : true;
element.$.reverseDirection.disabled = enable ? false : true;
}
/**
* @desc toggle play/pause animation
* @return {Void}
*/
_togglePlayPause() {
this._disableStopAndReverse(this, true);
if (this.anim.isPaused) {
this.play();
this._playPause = 'Pause';
} else {
this.pause();
this._playPause = 'Play';
}
}
}
window.customElements.define(PolymerDemoControllers.is, PolymerDemoControllers);
</script>
</dom-module>