Chromium Code Reviews| 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.setPromoActive(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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 }; | 154 }; |
| 144 | 155 |
| 145 // Keep in sync with LaunchContainer in extension.h | 156 // Keep in sync with LaunchContainer in extension.h |
| 146 var LaunchContainer = { | 157 var LaunchContainer = { |
| 147 LAUNCH_WINDOW: 0, | 158 LAUNCH_WINDOW: 0, |
| 148 LAUNCH_PANEL: 1, | 159 LAUNCH_PANEL: 1, |
| 149 LAUNCH_TAB: 2 | 160 LAUNCH_TAB: 2 |
| 150 }; | 161 }; |
| 151 | 162 |
| 152 var currentApp; | 163 var currentApp; |
| 164 var promoActive; | |
| 153 | 165 |
| 154 function addContextMenu(el, app) { | 166 function addContextMenu(el, app) { |
| 155 el.addEventListener('contextmenu', cr.ui.contextMenuHandler); | 167 el.addEventListener('contextmenu', cr.ui.contextMenuHandler); |
| 156 el.addEventListener('keydown', cr.ui.contextMenuHandler); | 168 el.addEventListener('keydown', cr.ui.contextMenuHandler); |
| 157 el.addEventListener('keyup', cr.ui.contextMenuHandler); | 169 el.addEventListener('keyup', cr.ui.contextMenuHandler); |
| 158 | 170 |
| 159 Object.defineProperty(el, 'contextMenu', { | 171 Object.defineProperty(el, 'contextMenu', { |
| 160 get: function() { | 172 get: function() { |
| 161 currentApp = app; | 173 currentApp = app; |
| 162 | 174 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 e.canExecute = true; | 232 e.canExecute = true; |
| 221 break; | 233 break; |
| 222 } | 234 } |
| 223 }); | 235 }); |
| 224 | 236 |
| 225 return { | 237 return { |
| 226 loaded: false, | 238 loaded: false, |
| 227 | 239 |
| 228 menu: $('apps-menu'), | 240 menu: $('apps-menu'), |
| 229 | 241 |
| 242 setPromoActive: function(isPromoActive) { | |
|
Aaron Boodman
2010/11/12 00:29:20
Nit: I think the setter is overkill here. You can
| |
| 243 promoActive = isPromoActive; | |
| 244 }, | |
| 245 | |
| 230 createElement: function(app) { | 246 createElement: function(app) { |
| 231 var div = createElement(app); | 247 var div = createElement(app); |
| 232 var a = div.firstChild; | 248 var a = div.firstChild; |
| 233 | 249 |
| 234 a.onclick = handleClick; | 250 a.onclick = handleClick; |
| 251 a.setAttribute('ping', PING_APP_LAUNCH_PREFIX + '+' + promoActive); | |
| 235 a.style.backgroundImage = url(app['icon_big']); | 252 a.style.backgroundImage = url(app['icon_big']); |
| 236 if (hashParams['app-id'] == app['id']) { | 253 if (hashParams['app-id'] == app['id']) { |
| 237 div.setAttribute('new', 'new'); | 254 div.setAttribute('new', 'new'); |
| 238 // Delay changing the attribute a bit to let the page settle down a bit. | 255 // Delay changing the attribute a bit to let the page settle down a bit. |
| 239 setTimeout(function() { | 256 setTimeout(function() { |
| 240 // Make sure the new icon is scrolled into view. | 257 // Make sure the new icon is scrolled into view. |
| 241 document.body.scrollTop = document.body.scrollHeight; | 258 document.body.scrollTop = document.body.scrollHeight; |
| 242 | 259 |
| 243 // This will trigger the 'bounce' animation defined in apps.css. | 260 // This will trigger the 'bounce' animation defined in apps.css. |
| 244 div.setAttribute('new', 'installed'); | 261 div.setAttribute('new', 'installed'); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 264 }, | 281 }, |
| 265 | 282 |
| 266 createMiniviewElement: function(app) { | 283 createMiniviewElement: function(app) { |
| 267 var span = document.createElement('span'); | 284 var span = document.createElement('span'); |
| 268 var a = span.appendChild(document.createElement('a')); | 285 var a = span.appendChild(document.createElement('a')); |
| 269 | 286 |
| 270 a.setAttribute('app-id', app['id']); | 287 a.setAttribute('app-id', app['id']); |
| 271 a.textContent = app['name']; | 288 a.textContent = app['name']; |
| 272 a.href = app['launch_url']; | 289 a.href = app['launch_url']; |
| 273 a.onclick = handleClick; | 290 a.onclick = handleClick; |
| 291 a.setAttribute('ping', PING_APP_LAUNCH_PREFIX + '+' + promoActive); | |
| 274 a.style.backgroundImage = url(app['icon_small']); | 292 a.style.backgroundImage = url(app['icon_small']); |
| 275 a.className = 'item'; | 293 a.className = 'item'; |
| 276 span.appendChild(a); | 294 span.appendChild(a); |
| 277 | 295 |
| 278 addContextMenu(span, app); | 296 addContextMenu(span, app); |
| 279 | 297 |
| 280 return span; | 298 return span; |
| 281 }, | 299 }, |
| 282 | 300 |
| 283 createClosedMenuElement: function(app) { | 301 createClosedMenuElement: function(app) { |
| 284 var a = document.createElement('a'); | 302 var a = document.createElement('a'); |
| 285 a.setAttribute('app-id', app['id']); | 303 a.setAttribute('app-id', app['id']); |
| 286 a.textContent = app['name']; | 304 a.textContent = app['name']; |
| 287 a.href = app['launch_url']; | 305 a.href = app['launch_url']; |
| 288 a.onclick = handleClick; | 306 a.onclick = handleClick; |
| 307 a.setAttribute('ping', PING_APP_LAUNCH_PREFIX + '+' + promoActive); | |
| 289 a.style.backgroundImage = url(app['icon_small']); | 308 a.style.backgroundImage = url(app['icon_small']); |
| 290 a.className = 'item'; | 309 a.className = 'item'; |
| 291 return a; | 310 return a; |
| 292 }, | 311 }, |
| 293 | 312 |
| 294 createWebStoreElement: function() { | 313 createWebStoreElement: function() { |
| 295 var elm = createElement({ | 314 var elm = createElement({ |
| 296 'id': 'web-store-entry', | 315 'id': 'web-store-entry', |
| 297 'name': localStrings.getString('web_store_title'), | 316 'name': localStrings.getString('web_store_title'), |
| 298 'launch_url': localStrings.getString('web_store_url') | 317 'launch_url': localStrings.getString('web_store_url') |
| 299 }); | 318 }); |
| 300 elm.setAttribute('app-id', 'web-store-entry'); | 319 elm.setAttribute('app-id', 'web-store-entry'); |
| 301 return elm; | 320 return elm; |
| 302 } | 321 } |
| 303 }; | 322 }; |
| 304 })(); | 323 })(); |
| OLD | NEW |