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 // The URL prefix used in the app link 'ping' attributes. | 9 // The URL prefix used in the app link 'ping' attributes. |
10 var PING_APP_LAUNCH_PREFIX = 'record-app-launch'; | 10 var PING_APP_LAUNCH_PREFIX = 'record-app-launch'; |
11 | 11 |
12 // The URL prefix used in the webstore link 'ping' attributes. | 12 // The URL prefix used in the webstore link 'ping' attributes. |
13 var PING_WEBSTORE_LAUNCH_PREFIX = 'record-webstore-launch'; | 13 var PING_WEBSTORE_LAUNCH_PREFIX = 'record-webstore-launch'; |
14 | 14 |
15 function getAppsCallback(data) { | 15 function getAppsCallback(data) { |
16 logEvent('received apps'); | 16 logEvent('received apps'); |
17 | 17 |
18 // In the case of prefchange-triggered updates, we don't receive this flag. | 18 // In the case of prefchange-triggered updates, we don't receive this flag. |
19 // Just leave it set as it was before in that case. | 19 // Just leave it set as it was before in that case. |
20 if ('showPromo' in data) | 20 if ('showPromo' in data) |
21 apps.showPromo = data.showPromo; | 21 apps.showPromo = data.showPromo; |
22 | 22 |
23 var appsSection = $('apps'); | 23 var appsSection = $('apps'); |
24 var appsSectionContent = $('apps-content'); | 24 var appsSectionContent = $('apps-content'); |
25 var appsMiniview = appsSection.getElementsByClassName('miniview')[0]; | 25 var appsMiniview = appsSection.getElementsByClassName('miniview')[0]; |
26 var appsPromo = $('apps-promo'); | 26 var appsPromo = $('apps-promo'); |
27 var appsPromoPing = PING_WEBSTORE_LAUNCH_PREFIX + '+' + apps.showPromo; | 27 var appsPromoPing = PING_WEBSTORE_LAUNCH_PREFIX + '+' + apps.showPromo; |
28 var webStoreEntry; | 28 var webStoreEntry, webStoreMiniEntry; |
29 | 29 |
30 // Hide menu options that are not supported on the OS or windowing system. | 30 // Hide menu options that are not supported on the OS or windowing system. |
31 | 31 |
32 // The "Launch as Window" menu option. | 32 // The "Launch as Window" menu option. |
33 $('apps-launch-type-window-menu-item').style.display = | 33 $('apps-launch-type-window-menu-item').style.display = |
34 (data.disableAppWindowLaunch ? 'none' : 'inline'); | 34 (data.disableAppWindowLaunch ? 'none' : 'inline'); |
35 | 35 |
36 // The "Create App Shortcut" menu option. | 36 // The "Create App Shortcut" menu option. |
37 $('apps-create-shortcut-command-menu-item').style.display = | 37 $('apps-create-shortcut-command-menu-item').style.display = |
38 (data.disableCreateAppShortcut ? 'none' : 'inline'); | 38 (data.disableCreateAppShortcut ? 'none' : 'inline'); |
39 | 39 |
40 appsMiniview.textContent = ''; | 40 appsMiniview.textContent = ''; |
41 appsSectionContent.textContent = ''; | 41 appsSectionContent.textContent = ''; |
42 | 42 |
43 data.apps.sort(function(a,b) { | 43 data.apps.sort(function(a,b) { |
44 return a.app_launch_index - b.app_launch_index; | 44 return a.app_launch_index - b.app_launch_index; |
45 }); | 45 }); |
46 | 46 |
47 clearClosedMenu(apps.menu); | 47 clearClosedMenu(apps.menu); |
48 if (data.apps.length == 0 && !data.showLauncher) { | 48 data.apps.forEach(function(app) { |
49 appsSection.classList.add('disabled'); | 49 appsSectionContent.appendChild(apps.createElement(app)); |
50 layoutSections(); | 50 }); |
51 } else { | |
52 data.apps.forEach(function(app) { | |
53 appsSectionContent.appendChild(apps.createElement(app)); | |
54 }); | |
55 | 51 |
56 webStoreEntry = apps.createWebStoreElement(); | 52 webStoreEntry = apps.createWebStoreElement(); |
| 53 webStoreEntry.querySelector('a').setAttribute('ping', appsPromoPing); |
| 54 appsSectionContent.appendChild(webStoreEntry); |
| 55 |
| 56 data.apps.slice(0, MAX_MINIVIEW_ITEMS).forEach(function(app) { |
| 57 appsMiniview.appendChild(apps.createMiniviewElement(app)); |
| 58 addClosedMenuEntryWithLink(apps.menu, apps.createClosedMenuElement(app)); |
| 59 }); |
| 60 if (data.apps.length < MAX_MINIVIEW_ITEMS) { |
| 61 webStoreMiniEntry = apps.createWebStoreMiniElement(); |
57 webStoreEntry.querySelector('a').setAttribute('ping', appsPromoPing); | 62 webStoreEntry.querySelector('a').setAttribute('ping', appsPromoPing); |
58 appsSectionContent.appendChild(webStoreEntry); | 63 appsMiniview.appendChild(webStoreMiniEntry); |
| 64 addClosedMenuEntryWithLink(apps.menu, |
| 65 apps.createWebStoreClosedMenuElement()); |
| 66 } |
59 | 67 |
60 data.apps.slice(0, MAX_MINIVIEW_ITEMS).forEach(function(app) { | 68 if (!(shownSections & MINIMIZED_APPS)) { |
61 appsMiniview.appendChild(apps.createMiniviewElement(app)); | 69 appsSection.classList.remove('disabled'); |
62 addClosedMenuEntryWithLink(apps.menu, apps.createClosedMenuElement(app)); | |
63 }); | |
64 | |
65 if (!(shownSections & MINIMIZED_APPS)) { | |
66 appsSection.classList.remove('disabled'); | |
67 } | |
68 } | 70 } |
69 addClosedMenuFooter(apps.menu, 'apps', MINIMIZED_APPS, Section.APPS); | 71 addClosedMenuFooter(apps.menu, 'apps', MINIMIZED_APPS, Section.APPS); |
70 | 72 |
71 apps.loaded = true; | 73 apps.loaded = true; |
72 if (apps.showPromo) | 74 if (apps.showPromo) |
73 document.documentElement.classList.add('apps-promo-visible'); | 75 document.documentElement.classList.add('apps-promo-visible'); |
74 else | 76 else |
75 document.documentElement.classList.remove('apps-promo-visible'); | 77 document.documentElement.classList.remove('apps-promo-visible'); |
76 $('apps-promo-link').setAttribute('ping', appsPromoPing); | 78 $('apps-promo-link').setAttribute('ping', appsPromoPing); |
77 maybeDoneLoading(); | 79 maybeDoneLoading(); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 }, | 333 }, |
332 | 334 |
333 createWebStoreElement: function() { | 335 createWebStoreElement: function() { |
334 var elm = createElement({ | 336 var elm = createElement({ |
335 'id': 'web-store-entry', | 337 'id': 'web-store-entry', |
336 'name': localStrings.getString('web_store_title'), | 338 'name': localStrings.getString('web_store_title'), |
337 'launch_url': localStrings.getString('web_store_url') | 339 'launch_url': localStrings.getString('web_store_url') |
338 }); | 340 }); |
339 elm.setAttribute('app-id', 'web-store-entry'); | 341 elm.setAttribute('app-id', 'web-store-entry'); |
340 return elm; | 342 return elm; |
| 343 }, |
| 344 |
| 345 createWebStoreMiniElement: function() { |
| 346 var span = document.createElement('span'); |
| 347 span.appendChild(this.createWebStoreClosedMenuElement()); |
| 348 return span; |
| 349 }, |
| 350 |
| 351 createWebStoreClosedMenuElement: function() { |
| 352 var a = document.createElement('a'); |
| 353 a.textContent = localStrings.getString('web_store_title'); |
| 354 a.href = localStrings.getString('web_store_url'); |
| 355 a.style.backgroundImage = url('chrome://theme/IDR_PRODUCT_LOGO_16'); |
| 356 a.className = 'item'; |
| 357 return a; |
341 } | 358 } |
342 }; | 359 }; |
343 })(); | 360 })(); |
OLD | NEW |