-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathslide-page.html
executable file
·91 lines (86 loc) · 3.04 KB
/
slide-page.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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../core-icons/core-icons.html">
<link href="../core-animated-pages/core-animated-pages.html" rel="import">
<link href="../core-animated-pages/transitions/cross-fade.html" rel="import">
<link href="../core-animated-pages/transitions/slide-from-right.html" rel="import">
<link rel="import" href="../paper-shadow/paper-shadow.html">
<link rel="import" href="../paper-fab/paper-fab.html">
<link rel="stylesheet" href="animate.css"/>
<!--
Element providing solution to build one page slide base on polymer.
##### Example
<slide-page>
<section>page-1</section>
<section>page-2</section>
<section>page-3</section>
</slide-page>
@element slide-page
@blurb Element providing solution to build one page slide base on polymer.
@status 0.0.1
@homepage https://github.com/unbug/slide-page
-->
<polymer-element name="slide-page" on-keydown="{{keypressHandler}}">
<template>
<link rel="stylesheet" href="slide-page.css"/>
<div class="right" layout vertical center end-justified><span>Powered by Polymer</span><paper-shadow z="5"></paper-shadow></div>
<core-animated-pages id="pages" transitions="slide-from-right" selected="{{pageIndex}}">
<content></content>
</core-animated-pages>
<section class="nav" layout horizontal end-justified>
<div layout horizontal><paper-fab start-justified icon="icons:arrow-back" id="preBtn" on-click="{{prePage}}"><paper-shadow z="5"></paper-shadow></paper-fab></div>
<div layout horizontal><paper-fab icon="icons:arrow-forward" id="nextBtn" on-click="{{nextPage}}"><paper-shadow z="5"></paper-shadow></paper-fab></div>
</section>
</template>
<script>
Polymer('slide-page',{
pageIndex: 0,
pageMax: 0,
ready: function(){
this.tabIndex = 0;
this.pageMax = this.children.length-1;
this.$.pages.focus();
this.pageIndex = parseInt(window.location.hash.replace('#','') || 0);
this.toggleBtns();
console.log(this.pageMax);
},
keypressHandler: function(event, detail, sender){
var code = event.keyCode,
leftK = [37],
rightK = [32,39];
if(rightK.indexOf(code)!=-1){
this.nextPage();
}else if(leftK.indexOf(code)!=-1){
this.prePage();
}
},
prePage: function(){
this.pageIndex -= 1;
if(this.pageIndex <= 0) {
this.pageIndex = 0;
}
window.location.hash = this.pageIndex;
this.toggleBtns();
},
nextPage: function() {
this.pageIndex += 1;
if(this.pageIndex >= this.pageMax) {
this.pageIndex = this.pageMax;
}
window.location.hash = this.pageIndex;
this.toggleBtns();
},
toggleBtns: function(){
if(this.pageIndex >= this.pageMax) {
this.$.nextBtn.hidden = true;
}else{
this.$.nextBtn.removeAttribute('hidden');
}
if(this.pageIndex <= 0) {
this.$.preBtn.hidden = true;
}else{
this.$.preBtn.removeAttribute('hidden');
}
}
});
</script>
</polymer-element>