-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathAroundList.js
139 lines (127 loc) · 3.3 KB
/
AroundList.js
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
131
132
133
134
135
136
137
138
139
/**
* Contains the declaration for the {@link module:layout/AroundList~AroundList} kind.
* @module layout/AroundList
*/
var
kind = require('enyo/kind');
var
List = require('./List'),
FlyweightRepeater = require('./FlyweightRepeater');
/**
* {@link module:layout/AroundList~AroundList} is a {@link module:layout/List~List}
* that allows content to be displayed around its rows.
*
* ```javascript
* var
* kind = require('enyo/kind'),
* AroundList = require('layout/AroundList');
*
* {kind: AroundList, onSetupItem: 'setupItem',
* aboveComponents: [
* {content: 'Content above the list'}
* ],
* components: [
* {content: 'List item'}
* ]
* }
* ```
*
* @class AroundList
* @extends module:layout/List~List
* @ui
* @public
*/
module.exports = kind(
/** @lends module:layout/AroundList~AroundList.prototype */ {
/**
* @private
*/
name: 'enyo.AroundList',
/**
* @private
*/
kind: List,
/**
* @private
*/
listTools: [
{name: 'port', classes: 'enyo-list-port enyo-border-box', components: [
{name: 'aboveClient'},
{name: 'generator', kind: FlyweightRepeater, canGenerate: false, components: [
{tag: null, name: 'client'}
]},
{name: 'holdingarea', allowHtml: true, classes: 'enyo-list-holdingarea'},
{name: 'page0', allowHtml: true, classes: 'enyo-list-page'},
{name: 'page1', allowHtml: true, classes: 'enyo-list-page'},
{name: 'belowClient'},
{name: 'placeholder'},
{name: 'swipeableComponents', style: 'position:absolute; display:block; top:-1000px; left:0px;'}
]}
],
/**
* A block of components to be rendered above the list.
*
* @type {Object[]}
* @default null
* @public
*/
aboveComponents: null,
/**
* A block of components to be rendered below the list.
*
* @type {Object[]}
* @default null
* @public
*/
belowComponents: null,
/**
* @method
* @private
*/
initComponents: function () {
List.prototype.initComponents.apply(this, arguments);
if (this.aboveComponents) {
this.$.aboveClient.createComponents(this.aboveComponents, {owner: this.owner});
}
if (this.belowComponents) {
this.$.belowClient.createComponents(this.belowComponents, {owner: this.owner});
}
},
/**
* @see module:layout/List~List#updateMetrics
* @private
*/
updateMetrics: function () {
this.defaultPageSize = this.rowsPerPage * (this.rowSize || 100);
this.pageCount = Math.ceil(this.count / this.rowsPerPage);
this.aboveHeight = this.$.aboveClient.getBounds().height;
this.belowHeight = this.$.belowClient.getBounds().height;
this.portSize = this.aboveHeight + this.belowHeight;
for (var i=0; i < this.pageCount; i++) {
this.portSize += this.getPageSize(i);
}
this.adjustPortSize();
},
/**
* @see module:layout/List~List#positionPage
* @private
*/
positionPage: function (pageNumber, target) {
target.pageNo = pageNumber;
var y = this.pageToPosition(pageNumber);
var o = this.bottomUp ? this.belowHeight : this.aboveHeight;
y += o;
target.applyStyle(this.pageBound, y + 'px');
},
/**
* Scrolls past the [aboveComponents]{@link module:layout/AroundList~AroundList#aboveComponents}
* or [belowComponents]{@link module:layout/AroundList~AroundList#belowComponents} components to
* reveal the list.
*
* @public
*/
scrollToContentStart: function () {
var y = this.bottomUp ? this.belowHeight : this.aboveHeight;
this.setScrollPosition(y);
}
});