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
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function() {
/** Amount that each level of bookmarks is indented by (px). */
var BOOKMARK_INDENT = 20;
Polymer({
is: 'viewer-bookmark',
properties: {
/**
* A bookmark object, each containing a:
* - title
* - page (optional)
* - children (an array of bookmarks)
*/
bookmark: {
type: Object,
observer: 'bookmarkChanged_'
},
depth: {
type: Number,
observer: 'depthChanged'
},
childDepth: Number,
childrenShown: {
type: Boolean,
reflectToAttribute: true,
value: false
},
keyEventTarget: {
type: Object,
value: function() {
return this.$.item;
}
}
},
behaviors: [
Polymer.IronA11yKeysBehavior
],
keyBindings: {
'enter': 'onEnter_',
'space': 'onSpace_'
},
bookmarkChanged_: function() {
this.$.expand.style.visibility =
this.bookmark.children.length > 0 ? 'visible' : 'hidden';
},
depthChanged: function() {
this.childDepth = this.depth + 1;
this.$.item.style.webkitPaddingStart =
(this.depth * BOOKMARK_INDENT) + 'px';
},
onClick: function() {
if (this.bookmark.hasOwnProperty('page'))
this.fire('change-page', {page: this.bookmark.page});
},
onEnter_: function(e) {
// Don't allow events which have propagated up from the expand button to
// trigger a click.
if (e.detail.keyboardEvent.target != this.$.expand)
this.onClick();
},
onSpace_: function(e) {
// paper-icon-button stops propagation of space events, so there's no need
// to check the event source here.
this.onClick();
// Prevent default space scroll behavior.
e.detail.keyboardEvent.preventDefault();
},
toggleChildren: function(e) {
this.childrenShown = !this.childrenShown;
e.stopPropagation(); // Prevent the above onClick handler from firing.
}
});
})();
|