| 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. |
| 10 var PING_APP_LAUNCH_PREFIX = 'record-app-launch'; |
| 11 |
| 12 // The URL prefix used in the webstore link 'ping' attributes. |
| 13 var PING_WEBSTORE_LAUNCH_PREFIX = 'record-webstore-launch'; |
| 14 |
| 9 function getAppsCallback(data) { | 15 function getAppsCallback(data) { |
| 10 logEvent('received apps'); | 16 logEvent('received apps'); |
| 11 var appsSection = $('apps'); | 17 var appsSection = $('apps'); |
| 12 var appsSectionContent = $('apps-content'); | 18 var appsSectionContent = $('apps-content'); |
| 13 var appsMiniview = appsSection.getElementsByClassName('miniview')[0]; | 19 var appsMiniview = appsSection.getElementsByClassName('miniview')[0]; |
| 14 var appsPromo = $('apps-promo'); | 20 var appsPromo = $('apps-promo'); |
| 21 var appsPromoPing = PING_WEBSTORE_LAUNCH_PREFIX + '+' + data.showPromo; |
| 15 var webStoreEntry; | 22 var webStoreEntry; |
| 16 | 23 |
| 17 appsMiniview.textContent = ''; | 24 appsMiniview.textContent = ''; |
| 18 appsSectionContent.textContent = ''; | 25 appsSectionContent.textContent = ''; |
| 19 | 26 |
| 27 apps.showPromo = data.showPromo; |
| 28 |
| 20 data.apps.sort(function(a,b) { | 29 data.apps.sort(function(a,b) { |
| 21 return a.app_launch_index - b.app_launch_index | 30 return a.app_launch_index - b.app_launch_index; |
| 22 }); | 31 }); |
| 23 | 32 |
| 24 clearClosedMenu(apps.menu); | 33 clearClosedMenu(apps.menu); |
| 25 if (data.apps.length == 0 && !data.showLauncher) { | 34 if (data.apps.length == 0 && !data.showLauncher) { |
| 26 appsSection.classList.add('disabled'); | 35 appsSection.classList.add('disabled'); |
| 27 layoutSections(); | 36 layoutSections(); |
| 28 } else { | 37 } else { |
| 29 data.apps.forEach(function(app) { | 38 data.apps.forEach(function(app) { |
| 30 appsSectionContent.appendChild(apps.createElement(app)); | 39 appsSectionContent.appendChild(apps.createElement(app)); |
| 31 }); | 40 }); |
| 32 | 41 |
| 33 webStoreEntry = apps.createWebStoreElement(); | 42 webStoreEntry = apps.createWebStoreElement(); |
| 43 webStoreEntry.querySelector('a').setAttribute('ping', appsPromoPing); |
| 34 appsSectionContent.appendChild(webStoreEntry); | 44 appsSectionContent.appendChild(webStoreEntry); |
| 35 | 45 |
| 36 data.apps.slice(0, MAX_MINIVIEW_ITEMS).forEach(function(app) { | 46 data.apps.slice(0, MAX_MINIVIEW_ITEMS).forEach(function(app) { |
| 37 appsMiniview.appendChild(apps.createMiniviewElement(app)); | 47 appsMiniview.appendChild(apps.createMiniviewElement(app)); |
| 38 addClosedMenuEntryWithLink(apps.menu, apps.createClosedMenuElement(app)); | 48 addClosedMenuEntryWithLink(apps.menu, apps.createClosedMenuElement(app)); |
| 39 }); | 49 }); |
| 40 | 50 |
| 41 if (!(shownSections & MINIMIZED_APPS)) { | 51 if (!(shownSections & MINIMIZED_APPS)) { |
| 42 appsSection.classList.remove('disabled'); | 52 appsSection.classList.remove('disabled'); |
| 43 } | 53 } |
| 44 } | 54 } |
| 45 addClosedMenuFooter(apps.menu, 'apps', MINIMIZED_APPS, Section.APPS); | 55 addClosedMenuFooter(apps.menu, 'apps', MINIMIZED_APPS, Section.APPS); |
| 46 | 56 |
| 47 apps.loaded = true; | 57 apps.loaded = true; |
| 48 if (data.showPromo) | 58 if (data.showPromo) |
| 49 document.documentElement.classList.add('apps-promo-visible'); | 59 document.documentElement.classList.add('apps-promo-visible'); |
| 50 else | 60 else |
| 51 document.documentElement.classList.remove('apps-promo-visible'); | 61 document.documentElement.classList.remove('apps-promo-visible'); |
| 62 $('apps-promo-link').setAttribute('ping', appsPromoPing); |
| 52 maybeDoneLoading(); | 63 maybeDoneLoading(); |
| 53 | 64 |
| 54 if (data.apps.length > 0 && isDoneLoading()) { | 65 if (data.apps.length > 0 && isDoneLoading()) { |
| 55 if (!data.showPromo && data.apps.length >= MAX_APPS_PER_ROW[layoutMode]) | 66 if (!data.showPromo && data.apps.length >= MAX_APPS_PER_ROW[layoutMode]) |
| 56 webStoreEntry.classList.add('loner'); | 67 webStoreEntry.classList.add('loner'); |
| 57 else | 68 else |
| 58 webStoreEntry.classList.remove('loner'); | 69 webStoreEntry.classList.remove('loner'); |
| 59 | 70 |
| 60 updateMiniviewClipping(appsMiniview); | 71 updateMiniviewClipping(appsMiniview); |
| 61 layoutSections(); | 72 layoutSections(); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 e.canExecute = true; | 231 e.canExecute = true; |
| 221 break; | 232 break; |
| 222 } | 233 } |
| 223 }); | 234 }); |
| 224 | 235 |
| 225 return { | 236 return { |
| 226 loaded: false, | 237 loaded: false, |
| 227 | 238 |
| 228 menu: $('apps-menu'), | 239 menu: $('apps-menu'), |
| 229 | 240 |
| 241 showPromo: false, |
| 242 |
| 230 createElement: function(app) { | 243 createElement: function(app) { |
| 231 var div = createElement(app); | 244 var div = createElement(app); |
| 232 var a = div.firstChild; | 245 var a = div.firstChild; |
| 233 | 246 |
| 234 a.onclick = handleClick; | 247 a.onclick = handleClick; |
| 248 a.setAttribute('ping', PING_APP_LAUNCH_PREFIX + '+' + this.showPromo); |
| 235 a.style.backgroundImage = url(app['icon_big']); | 249 a.style.backgroundImage = url(app['icon_big']); |
| 236 if (hashParams['app-id'] == app['id']) { | 250 if (hashParams['app-id'] == app['id']) { |
| 237 div.setAttribute('new', 'new'); | 251 div.setAttribute('new', 'new'); |
| 238 // Delay changing the attribute a bit to let the page settle down a bit. | 252 // Delay changing the attribute a bit to let the page settle down a bit. |
| 239 setTimeout(function() { | 253 setTimeout(function() { |
| 240 // Make sure the new icon is scrolled into view. | 254 // Make sure the new icon is scrolled into view. |
| 241 document.body.scrollTop = document.body.scrollHeight; | 255 document.body.scrollTop = document.body.scrollHeight; |
| 242 | 256 |
| 243 // This will trigger the 'bounce' animation defined in apps.css. | 257 // This will trigger the 'bounce' animation defined in apps.css. |
| 244 div.setAttribute('new', 'installed'); | 258 div.setAttribute('new', 'installed'); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 264 }, | 278 }, |
| 265 | 279 |
| 266 createMiniviewElement: function(app) { | 280 createMiniviewElement: function(app) { |
| 267 var span = document.createElement('span'); | 281 var span = document.createElement('span'); |
| 268 var a = span.appendChild(document.createElement('a')); | 282 var a = span.appendChild(document.createElement('a')); |
| 269 | 283 |
| 270 a.setAttribute('app-id', app['id']); | 284 a.setAttribute('app-id', app['id']); |
| 271 a.textContent = app['name']; | 285 a.textContent = app['name']; |
| 272 a.href = app['launch_url']; | 286 a.href = app['launch_url']; |
| 273 a.onclick = handleClick; | 287 a.onclick = handleClick; |
| 288 a.setAttribute('ping', PING_APP_LAUNCH_PREFIX + '+' + this.showPromo); |
| 274 a.style.backgroundImage = url(app['icon_small']); | 289 a.style.backgroundImage = url(app['icon_small']); |
| 275 a.className = 'item'; | 290 a.className = 'item'; |
| 276 span.appendChild(a); | 291 span.appendChild(a); |
| 277 | 292 |
| 278 addContextMenu(span, app); | 293 addContextMenu(span, app); |
| 279 | 294 |
| 280 return span; | 295 return span; |
| 281 }, | 296 }, |
| 282 | 297 |
| 283 createClosedMenuElement: function(app) { | 298 createClosedMenuElement: function(app) { |
| 284 var a = document.createElement('a'); | 299 var a = document.createElement('a'); |
| 285 a.setAttribute('app-id', app['id']); | 300 a.setAttribute('app-id', app['id']); |
| 286 a.textContent = app['name']; | 301 a.textContent = app['name']; |
| 287 a.href = app['launch_url']; | 302 a.href = app['launch_url']; |
| 288 a.onclick = handleClick; | 303 a.onclick = handleClick; |
| 304 a.setAttribute('ping', PING_APP_LAUNCH_PREFIX + '+' + this.showPromo); |
| 289 a.style.backgroundImage = url(app['icon_small']); | 305 a.style.backgroundImage = url(app['icon_small']); |
| 290 a.className = 'item'; | 306 a.className = 'item'; |
| 291 return a; | 307 return a; |
| 292 }, | 308 }, |
| 293 | 309 |
| 294 createWebStoreElement: function() { | 310 createWebStoreElement: function() { |
| 295 var elm = createElement({ | 311 var elm = createElement({ |
| 296 'id': 'web-store-entry', | 312 'id': 'web-store-entry', |
| 297 'name': localStrings.getString('web_store_title'), | 313 'name': localStrings.getString('web_store_title'), |
| 298 'launch_url': localStrings.getString('web_store_url') | 314 'launch_url': localStrings.getString('web_store_url') |
| 299 }); | 315 }); |
| 300 elm.setAttribute('app-id', 'web-store-entry'); | 316 elm.setAttribute('app-id', 'web-store-entry'); |
| 301 return elm; | 317 return elm; |
| 302 } | 318 } |
| 303 }; | 319 }; |
| 304 })(); | 320 })(); |
| OLD | NEW |