OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var MAX_APPS_PER_ROW = []; | 5 var MAX_APPS_PER_ROW = []; |
6 MAX_APPS_PER_ROW[LayoutMode.SMALL] = 4; | 6 MAX_APPS_PER_ROW[LayoutMode.SMALL] = 4; |
7 MAX_APPS_PER_ROW[LayoutMode.NORMAL] = 6; | 7 MAX_APPS_PER_ROW[LayoutMode.NORMAL] = 6; |
8 | 8 |
9 function getAppsCallback(data) { | 9 function getAppsCallback(data) { |
10 logEvent('received apps'); | 10 logEvent('received apps'); |
11 var appsSection = $('apps'); | 11 var appsSection = $('apps'); |
12 var appsSectionContent = $('apps-content'); | 12 var appsSectionContent = $('apps-content'); |
13 var appsMiniview = appsSection.getElementsByClassName('miniview')[0]; | 13 var appsMiniview = appsSection.getElementsByClassName('miniview')[0]; |
14 var appsPromo = $('apps-promo'); | 14 var appsPromo = $('apps-promo'); |
15 var webStoreEntry; | 15 var webStoreEntry; |
16 | 16 |
17 appsMiniview.textContent = ''; | 17 appsMiniview.textContent = ''; |
18 appsSectionContent.textContent = ''; | 18 appsSectionContent.textContent = ''; |
19 | 19 |
20 data.apps.sort(function(a,b) { | 20 data.apps.sort(function(a,b) { |
21 return a.app_launch_index - b.app_launch_index | 21 return a.app_launch_index - b.app_launch_index; |
22 }); | 22 }); |
23 | 23 |
24 clearClosedMenu(apps.menu); | 24 clearClosedMenu(apps.menu); |
25 if (data.apps.length == 0 && !data.showLauncher) { | 25 if (data.apps.length == 0 && !data.showLauncher) { |
26 appsSection.classList.add('disabled'); | 26 appsSection.classList.add('disabled'); |
27 layoutSections(); | 27 layoutSections(); |
28 } else { | 28 } else { |
29 data.apps.forEach(function(app) { | 29 data.apps.forEach(function(app) { |
30 appsSectionContent.appendChild(apps.createElement(app)); | 30 appsSectionContent.appendChild(apps.createElement(app)); |
31 }); | 31 }); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 top = rect.top + ((rect.height - width) >> 1); // Integer divide by 2. | 117 top = rect.top + ((rect.height - width) >> 1); // Integer divide by 2. |
118 if (getComputedStyle(element).direction == 'rtl') | 118 if (getComputedStyle(element).direction == 'rtl') |
119 left = rect.left + rect.width - width; | 119 left = rect.left + rect.width - width; |
120 else | 120 else |
121 left = rect.left; | 121 left = rect.left; |
122 } | 122 } |
123 | 123 |
124 chrome.send('launchApp', [appId, | 124 chrome.send('launchApp', [appId, |
125 String(left), String(top), | 125 String(left), String(top), |
126 String(width), String(height)]); | 126 String(width), String(height)]); |
127 | |
128 chrome.send('recordAppLaunch', [appId]); | |
Aaron Boodman
2010/11/10 20:38:00
It seems it would be safer to send 'recordAppLaunc
| |
129 } | |
130 | |
131 function recordAppLaunch(e) { | |
132 var appId = e.currentTarget.getAttribute('app-id'); | |
133 chrome.send('recordAppLaunch', [appId]); | |
127 } | 134 } |
128 | 135 |
129 /** | 136 /** |
130 * @this {!HTMLAnchorElement} | 137 * @this {!HTMLAnchorElement} |
131 */ | 138 */ |
132 function handleClick(e) { | 139 function handleClick(e) { |
133 var appId = e.currentTarget.getAttribute('app-id'); | 140 var appId = e.currentTarget.getAttribute('app-id'); |
134 launchApp(appId); | 141 launchApp(appId); |
135 return false; | 142 return false; |
136 } | 143 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 return { | 232 return { |
226 loaded: false, | 233 loaded: false, |
227 | 234 |
228 menu: $('apps-menu'), | 235 menu: $('apps-menu'), |
229 | 236 |
230 createElement: function(app) { | 237 createElement: function(app) { |
231 var div = createElement(app); | 238 var div = createElement(app); |
232 var a = div.firstChild; | 239 var a = div.firstChild; |
233 | 240 |
234 a.onclick = handleClick; | 241 a.onclick = handleClick; |
242 a.onmousedown = handleIfMiddleClick(recordAppLaunch); | |
235 a.style.backgroundImage = url(app['icon_big']); | 243 a.style.backgroundImage = url(app['icon_big']); |
236 if (hashParams['app-id'] == app['id']) { | 244 if (hashParams['app-id'] == app['id']) { |
237 div.setAttribute('new', 'new'); | 245 div.setAttribute('new', 'new'); |
238 // Delay changing the attribute a bit to let the page settle down a bit. | 246 // Delay changing the attribute a bit to let the page settle down a bit. |
239 setTimeout(function() { | 247 setTimeout(function() { |
240 // Make sure the new icon is scrolled into view. | 248 // Make sure the new icon is scrolled into view. |
241 document.body.scrollTop = document.body.scrollHeight; | 249 document.body.scrollTop = document.body.scrollHeight; |
242 | 250 |
243 // This will trigger the 'bounce' animation defined in apps.css. | 251 // This will trigger the 'bounce' animation defined in apps.css. |
244 div.setAttribute('new', 'installed'); | 252 div.setAttribute('new', 'installed'); |
(...skipping 19 matching lines...) Expand all Loading... | |
264 }, | 272 }, |
265 | 273 |
266 createMiniviewElement: function(app) { | 274 createMiniviewElement: function(app) { |
267 var span = document.createElement('span'); | 275 var span = document.createElement('span'); |
268 var a = span.appendChild(document.createElement('a')); | 276 var a = span.appendChild(document.createElement('a')); |
269 | 277 |
270 a.setAttribute('app-id', app['id']); | 278 a.setAttribute('app-id', app['id']); |
271 a.textContent = app['name']; | 279 a.textContent = app['name']; |
272 a.href = app['launch_url']; | 280 a.href = app['launch_url']; |
273 a.onclick = handleClick; | 281 a.onclick = handleClick; |
282 a.onmousedown = handleIfMiddleClick(recordAppLaunch); | |
274 a.style.backgroundImage = url(app['icon_small']); | 283 a.style.backgroundImage = url(app['icon_small']); |
275 a.className = 'item'; | 284 a.className = 'item'; |
276 span.appendChild(a); | 285 span.appendChild(a); |
277 | 286 |
278 addContextMenu(span, app); | 287 addContextMenu(span, app); |
279 | 288 |
280 return span; | 289 return span; |
281 }, | 290 }, |
282 | 291 |
283 createClosedMenuElement: function(app) { | 292 createClosedMenuElement: function(app) { |
284 var a = document.createElement('a'); | 293 var a = document.createElement('a'); |
285 a.setAttribute('app-id', app['id']); | 294 a.setAttribute('app-id', app['id']); |
286 a.textContent = app['name']; | 295 a.textContent = app['name']; |
287 a.href = app['launch_url']; | 296 a.href = app['launch_url']; |
288 a.onclick = handleClick; | 297 a.onclick = handleClick; |
298 a.onmousedown = handleIfMiddleClick(recordAppLaunch); | |
289 a.style.backgroundImage = url(app['icon_small']); | 299 a.style.backgroundImage = url(app['icon_small']); |
290 a.className = 'item'; | 300 a.className = 'item'; |
291 return a; | 301 return a; |
292 }, | 302 }, |
293 | 303 |
294 createWebStoreElement: function() { | 304 createWebStoreElement: function() { |
295 var elm = createElement({ | 305 var elm = createElement({ |
296 'id': 'web-store-entry', | 306 'id': 'web-store-entry', |
297 'name': localStrings.getString('web_store_title'), | 307 'name': localStrings.getString('web_store_title'), |
298 'launch_url': localStrings.getString('web_store_url') | 308 'launch_url': localStrings.getString('web_store_url') |
299 }); | 309 }); |
310 var link = elm.querySelector('a'); | |
311 link.onclick = recordAppLaunch; | |
312 link.onmousedown = handleIfMiddleClick(recordAppLaunch); | |
300 elm.setAttribute('app-id', 'web-store-entry'); | 313 elm.setAttribute('app-id', 'web-store-entry'); |
301 return elm; | 314 return elm; |
302 } | 315 } |
303 }; | 316 }; |
304 })(); | 317 })(); |
OLD | NEW |