-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.js
80 lines (70 loc) · 2.55 KB
/
app.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
define([
"delite/register", "dstore/Memory", "deliteful/list/ItemRenderer", "delite/handlebars", "ecma402/Intl",
"delite/theme!delite/themes/{{theme}}/global.css", "deliteful/ViewStack", "deliteful/SidePane",
"deliteful/LinearLayout", "deliteful/Button", "deliteful/list/List", "deliteful/ProgressIndicator",
"requirejs-domready/domReady!"
], function (register, Memory, ItemRenderer, handlebars, Intl) {
register.parse();
document.body.style.display = "";
var script;
// Makes a request to the Flickr API to get recent photos with the specified tag.
// When the request completes, the "photosReceived" function will be called with json objects
// describing each photo.
function getPhotos(tags) {
requestDone(); // abort current request if any
pi.active = true;
var url = (window.location.protocol || "http:") +
"//api.flickr.com/services/feeds/photos_public.gne?format=json&jsoncallback=photosReceived&tags=" +
tags + "&tagmode=all";
script = document.createElement("script");
script.type = 'text/javascript';
script.src = url;
script.async = true;
script.charset = 'utf-8';
document.getElementsByTagName('head')[0].appendChild(script);
}
// Must be called to cleanup the current JSONP request (i.e. remove the "script" element).
function requestDone() {
if (script && script.parentNode) {
script.parentNode.removeChild(script);
script = null;
}
pi.active = false;
}
photosReceived = function (json) {
// cleanup request
requestDone();
// show the photos in the list by simply setting the list's source
photolist.source = new Memory({data: json.items});
};
refreshPhotoList = function () {
photolist.source = new Memory();
getPhotos("bridges,famous");
};
photolist.itemRenderer = register("d-photo-item", [HTMLElement, ItemRenderer], {
template: handlebars.compile("<template>" +
"<div attach-point='renderNode'>" +
"<div class='photoThumbnailBg'>" +
"<img class='photoThumbnail' src='{{item.media.m}}'>" +
"</div>" +
"<div class='photoSummary'>" +
"<div class='photoTitle'>{{item.title}}</div>" +
"<div class='publishedTime'>{{this.formatDate(this.item.published)}}</div>" +
"<div class='author'>{{item.author}}</div>" +
"</div>" +
"</div>" +
"</template>"),
// Formats a date in ISO 8601 format into a more readable format.
formatDate: function (d) {
return d && new Intl.DateTimeFormat("en-us", {
year: "numeric",
month: "long",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric"
}).format(new Date(d));
}
});
refreshPhotoList();
});