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 = []; | |
6 MAX_APPS_PER_ROW[LayoutMode.SMALL] = 4; | |
7 MAX_APPS_PER_ROW[LayoutMode.NORMAL] = 6; | |
8 | |
5 function getAppsCallback(data) { | 9 function getAppsCallback(data) { |
6 logEvent('received apps'); | 10 logEvent('received apps'); |
7 var appsSection = $('apps'); | 11 var appsSection = $('apps'); |
8 var appsSectionContent = $('apps-maxiview'); | 12 var appsSectionContent = $('apps-content'); |
9 var appsMiniview = appsSection.getElementsByClassName('miniview')[0]; | 13 var appsMiniview = appsSection.getElementsByClassName('miniview')[0]; |
10 var appsPromo = $('apps-promo'); | 14 var appsPromo = $('apps-promo'); |
15 var webStoreEntry = null; | |
arv (Not doing code reviews)
2010/10/15 22:33:36
do you really need to assign null here?
| |
11 | 16 |
12 appsMiniview.textContent = ''; | 17 appsMiniview.textContent = ''; |
13 while (appsSectionContent.lastChild != appsPromo) { | 18 while (appsSectionContent.firstChild) { |
arv (Not doing code reviews)
2010/10/15 22:33:36
Since you are now removing all of them you can jus
| |
14 appsSectionContent.removeChild(appsSectionContent.lastChild); | 19 appsSectionContent.removeChild(appsSectionContent.firstChild); |
15 } | 20 } |
16 | 21 |
17 data.apps.sort(function(a,b) { | 22 data.apps.sort(function(a,b) { |
18 return a.app_launch_index - b.app_launch_index | 23 return a.app_launch_index - b.app_launch_index |
19 }); | 24 }); |
20 | 25 |
21 clearClosedMenu(apps.menu); | 26 clearClosedMenu(apps.menu); |
22 if (data.apps.length == 0) { | 27 if (data.apps.length == 0) { |
23 appsSection.classList.add('disabled'); | 28 appsSection.classList.add('disabled'); |
24 layoutSections(); | 29 layoutSections(); |
25 } else { | 30 } else { |
26 data.apps.forEach(function(app) { | 31 data.apps.forEach(function(app) { |
27 appsSectionContent.appendChild(apps.createElement(app)); | 32 appsSectionContent.appendChild(apps.createElement(app)); |
28 }); | 33 }); |
29 | 34 |
30 appsSectionContent.appendChild(apps.createWebStoreElement()); | 35 webStoreEntry = apps.createWebStoreElement(); |
36 appsSectionContent.appendChild(webStoreEntry); | |
31 | 37 |
32 data.apps.slice(0, MAX_MINIVIEW_ITEMS).forEach(function(app) { | 38 data.apps.slice(0, MAX_MINIVIEW_ITEMS).forEach(function(app) { |
33 appsMiniview.appendChild(apps.createMiniviewElement(app)); | 39 appsMiniview.appendChild(apps.createMiniviewElement(app)); |
34 addClosedMenuEntryWithLink(apps.menu, apps.createClosedMenuElement(app)); | 40 addClosedMenuEntryWithLink(apps.menu, apps.createClosedMenuElement(app)); |
35 }); | 41 }); |
36 | 42 |
37 if (!(shownSections & MINIMIZED_APPS)) { | 43 if (!(shownSections & MINIMIZED_APPS)) { |
38 appsSection.classList.remove('disabled'); | 44 appsSection.classList.remove('disabled'); |
39 } | 45 } |
40 } | 46 } |
41 addClosedMenuFooter(apps.menu, 'apps', MINIMIZED_APPS, Section.APPS); | 47 addClosedMenuFooter(apps.menu, 'apps', MINIMIZED_APPS, Section.APPS); |
42 | 48 |
43 apps.loaded = true; | 49 apps.loaded = true; |
44 if (data.showPromo) | 50 if (data.showPromo) |
45 document.documentElement.classList.add('apps-promo-visible'); | 51 document.documentElement.classList.add('apps-promo-visible'); |
46 else | 52 else |
47 document.documentElement.classList.remove('apps-promo-visible'); | 53 document.documentElement.classList.remove('apps-promo-visible'); |
48 maybeDoneLoading(); | 54 maybeDoneLoading(); |
49 | 55 |
50 if (data.apps.length > 0 && isDoneLoading()) { | 56 if (data.apps.length > 0 && isDoneLoading()) { |
57 if (!data.showPromo && data.apps.length >= MAX_APPS_PER_ROW[layoutMode]) | |
58 webStoreEntry.classList.add('loner'); | |
59 else | |
60 webStoreEntry.classList.remove('loner'); | |
61 | |
51 updateMiniviewClipping(appsMiniview); | 62 updateMiniviewClipping(appsMiniview); |
52 layoutSections(); | 63 layoutSections(); |
53 } | 64 } |
54 } | 65 } |
55 | 66 |
56 function appsPrefChangeCallback(data) { | 67 function appsPrefChangeCallback(data) { |
57 // Currently the only pref that is watched is the launch type. | 68 // Currently the only pref that is watched is the launch type. |
58 data.apps.forEach(function(app) { | 69 data.apps.forEach(function(app) { |
59 var appLink = document.querySelector('.app a[app-id=' + app['id'] + ']'); | 70 var appLink = document.querySelector('.app a[app-id=' + app['id'] + ']'); |
60 if (appLink) | 71 if (appLink) |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 var elm = createElement({ | 301 var elm = createElement({ |
291 'id': 'web-store-entry', | 302 'id': 'web-store-entry', |
292 'name': localStrings.getString('web_store_title'), | 303 'name': localStrings.getString('web_store_title'), |
293 'launch_url': localStrings.getString('web_store_url') | 304 'launch_url': localStrings.getString('web_store_url') |
294 }); | 305 }); |
295 elm.setAttribute('app-id', 'web-store-entry'); | 306 elm.setAttribute('app-id', 'web-store-entry'); |
296 return elm; | 307 return elm; |
297 } | 308 } |
298 }; | 309 }; |
299 })(); | 310 })(); |
OLD | NEW |