forked from bjalford/polymer-pattern-sliding-pages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy-detail.html
110 lines (88 loc) · 1.98 KB
/
my-detail.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
<!doctype html>
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../app-route/app-route.html">
<link rel="import" href="../iron-icons/iron-icons.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<!--
Detail view
-->
<dom-module id="my-detail">
<template>
<style>
.title,.placeholder {
font-weight: bold;
font-size: 24px;
padding: 16px;
height: 40px;
line-height: 40px;
}
.title {
background: lightblue;
}
.placeholder {
background: lightgrey;
}
:host[in-transition] .title,.placeholder {
display: none;
}
:host[in-transition] .placeholder {
display: block;
}
</style>
<app-route route="[[route]]" pattern="/:id" data="{{data}}"></app-route>
<app-route route="[[prepareRoute]]" pattern="/:id" data="{{prepareData}}"></app-route>
<div class="title">
<paper-icon-button icon="icons:arrow-back" on-tap="back"></paper-icon-button>
Detail [[data.id]]
</div>
<div class="placeholder">
Detail loading...
</div>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'my-detail',
properties: {
route: Object,
inTransition: {
type: Boolean,
value: false,
reflectToAttribute: true,
},
},
observers: [
'onIdChanged(data.id)'
],
back: function(e) {
this.fire('request-change-page', {
path: 'lister',
animation: 'backward',
});
},
prepareTransition: function(route) {
// Keep this short
return new Promise((resolve) => {
this.prepareRoute = route;
// Wait until route is decomposed
this.async(() => {
if (this.data.id !== this.prepareData.id) {
// Set in transition mode if the ID is going to change
this.inTransition = true;
}
resolve();
});
});
},
onIdChanged: function(id) {
if (!id) {
// Ignore initialization call
return;
}
// Simulate some loading
setTimeout(() => this.inTransition = false, 1000);
},
});
})();
</script>