01.
(
function
() {
02.
"use strict"
;
03.
04.
var
appViewState = Windows.UI.ViewManagement.ApplicationViewState;
05.
var
ui = WinJS.UI;
06.
07.
ui.Pages.define(
"/pages/items/items.html"
, {
08.
09.
10.
initializeLayout:
function
(listView, viewState) {
11.
12.
13.
if
(viewState === appViewState.snapped) {
14.
listView.layout =
new
ui.ListLayout();
15.
}
else
{
16.
listView.layout =
new
ui.GridLayout();
17.
}
18.
},
19.
20.
itemInvoked:
function
(args) {
21.
var
groupKey = Data.groups.getAt(args.detail.itemIndex).key;
22.
WinJS.Navigation.navigate(
"/pages/split/split.html"
, { groupKey: groupKey });
23.
},
24.
25.
26.
27.
ready:
function
(element, options) {
28.
var
listView = element.querySelector(
".itemslist"
).winControl;
29.
listView.itemDataSource = Data.groups.dataSource;
30.
listView.itemTemplate = element.querySelector(
".itemtemplate"
);
31.
listView.oniteminvoked =
this
.itemInvoked.bind(
this
);
32.
33.
this
.initializeLayout(listView, Windows.UI.ViewManagement.ApplicationView.value);
34.
listView.element.focus();
35.
},
36.
37.
38.
updateLayout:
function
(element, viewState, lastViewState) {
39.
40.
41.
42.
43.
var
listView = element.querySelector(
".itemslist"
).winControl;
44.
if
(lastViewState !== viewState) {
45.
if
(lastViewState === appViewState.snapped || viewState === appViewState.snapped) {
46.
var
handler =
function
(e) {
47.
listView.removeEventListener(
"contentanimating"
, handler,
false
);
48.
e.preventDefault();
49.
}
50.
listView.addEventListener(
"contentanimating"
, handler,
false
);
51.
var
firstVisible = listView.indexOfFirstVisible;
52.
this
.initializeLayout(listView, viewState);
53.
listView.indexOfFirstVisible = firstVisible;
54.
}
55.
}
56.
}
57.
});
58.
})();