OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 var Galore = Galore || {}; | |
6 | |
7 Galore.view = { | |
8 create: function(onLoad) { | |
9 var view = Object.create(this); | |
10 chrome.app.window.create('window.html', { | |
11 id: 'window', | |
12 frame: 'none', | |
13 defaultWidth: 512, minWidth: 512, maxWidth: 512, | |
14 defaultHeight: 736, minHeight: 736, maxHeight: 736, | |
15 }, function(appWindow) { | |
16 view.sections = {} | |
17 view.window = appWindow.contentWindow; | |
18 view.window.onload = this.loaded_.bind(view, onLoad); | |
19 }.bind(this)); | |
20 return view; | |
21 }, | |
22 | |
23 addNotificationButton: function(sectionId, sectionTitle, imageUrl, onClick) { | |
24 var section = this.section_(sectionId, sectionTitle); | |
25 var button = this.button_(section, onClick); | |
26 this.fetch_(imageUrl, button.querySelector('img')); | |
27 }, | |
28 | |
29 getPriority: function() { | |
30 var inputs = this.elements_('#priority input'); | |
31 var checked = Array.prototype.filter.call(inputs, function(input) { | |
32 return input.checked; | |
33 }); | |
34 return (checked && checked.length) ? Number(checked[0].value) : 0; | |
35 }, | |
36 | |
37 logEvent: function(message) { | |
38 var event = this.element_('#templates .event').cloneNode(true); | |
39 event.textContent = message; | |
40 this.element_('#events-scroll').appendChild(event).scrollIntoView(); | |
41 }, | |
42 | |
43 /** @private */ | |
44 loaded_: function(onLoad) { | |
45 this.element_('#close').onclick = this.window.close.bind(this.window); | |
46 if (onLoad) | |
47 onLoad.call(this); | |
48 }, | |
49 | |
50 /** @private */ | |
51 fetch_: function(url, image) { | |
52 var request = new XMLHttpRequest(); | |
53 request.open('GET', url, true); | |
54 request.responseType = 'blob'; | |
55 request.onload = this.fetched_.bind(this, request, image); | |
56 request.send(); | |
57 }, | |
58 | |
59 /** @private */ | |
60 fetched_: function(request, image) { | |
61 image.src = window.URL.createObjectURL(request.response); | |
62 }, | |
63 | |
64 /** @private */ | |
65 section_: function(id, title) { | |
66 if (!this.sections[id]) { | |
67 this.sections[id] = this.element_('#templates .section').cloneNode(true); | |
68 this.sections[id].querySelector('span').textContent = title; | |
69 this.element_('#sections').appendChild(this.sections[id]); | |
70 } | |
71 return this.sections[id]; | |
72 }, | |
73 | |
74 /** @private */ | |
75 button_: function(section, onClick) { | |
76 var button = this.element_('#templates button'); | |
77 button = button.cloneNode(true); | |
78 button.onclick = onClick; | |
79 section.appendChild(button); | |
80 return button; | |
81 }, | |
82 | |
83 /** @private */ | |
84 element_: function(selector) { | |
85 return this.window.document.querySelector(selector) | |
86 }, | |
87 | |
88 /** @private */ | |
89 elements_: function(selector) { | |
90 return this.window.document.querySelectorAll(selector) | |
91 } | |
92 }; | |
OLD | NEW |