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 function getAppsCallback(data) { | 5 function getAppsCallback(data) { |
6 logEvent('received apps'); | 6 logEvent('received apps'); |
7 var appsSection = $('apps'); | 7 var appsSection = $('apps'); |
8 var appsSectionContent = $('apps-maxiview'); | 8 var appsSectionContent = $('apps-maxiview'); |
9 var appsMiniview = appsSection.getElementsByClassName('miniview')[0]; | 9 var appsMiniview = appsSection.getElementsByClassName('miniview')[0]; |
10 appsSectionContent.textContent = ''; | 10 appsSectionContent.textContent = ''; |
11 appsMiniview.textContent = ''; | 11 appsMiniview.textContent = ''; |
12 | 12 |
| 13 clearClosedMenu(apps.menu); |
13 if (data.apps.length == 0) { | 14 if (data.apps.length == 0) { |
14 appsSection.classList.add('disabled'); | 15 appsSection.classList.add('disabled'); |
15 layoutSections(); | 16 layoutSections(); |
16 } else { | 17 } else { |
17 data.apps.forEach(function(app) { | 18 data.apps.forEach(function(app) { |
18 appsSectionContent.appendChild(apps.createElement(app)); | 19 appsSectionContent.appendChild(apps.createElement(app)); |
19 }); | 20 }); |
20 | 21 |
21 appsSectionContent.appendChild(apps.createWebStoreElement()); | 22 appsSectionContent.appendChild(apps.createWebStoreElement()); |
22 | 23 |
23 data.apps.slice(0, MAX_MINIVIEW_ITEMS).forEach(function(app) { | 24 data.apps.slice(0, MAX_MINIVIEW_ITEMS).forEach(function(app) { |
24 appsMiniview.appendChild(apps.createMiniviewElement(app)); | 25 appsMiniview.appendChild(apps.createMiniviewElement(app)); |
| 26 addClosedMenuEntryWithLink(apps.menu, apps.createClosedMenuElement(app)); |
25 }); | 27 }); |
26 | 28 |
27 appsSection.classList.remove('disabled'); | 29 if (!(shownSections & MINIMIZED_APPS)) { |
| 30 appsSection.classList.remove('disabled'); |
| 31 } |
28 } | 32 } |
| 33 addClosedMenuFooter(apps.menu, 'apps', MINIMIZED_APPS, Section.APPS); |
29 | 34 |
30 apps.loaded = true; | 35 apps.loaded = true; |
31 maybeDoneLoading(); | 36 maybeDoneLoading(); |
32 | 37 |
33 if (data.apps.length > 0 && isDoneLoading()) { | 38 if (data.apps.length > 0 && isDoneLoading()) { |
34 updateMiniviewClipping(appsMiniview); | 39 updateMiniviewClipping(appsMiniview); |
35 layoutSections(); | 40 layoutSections(); |
36 } | 41 } |
37 } | 42 } |
38 | 43 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 case 'apps-launch-command': | 197 case 'apps-launch-command': |
193 case 'apps-uninstall-command': | 198 case 'apps-uninstall-command': |
194 e.canExecute = true; | 199 e.canExecute = true; |
195 break; | 200 break; |
196 } | 201 } |
197 }); | 202 }); |
198 | 203 |
199 return { | 204 return { |
200 loaded: false, | 205 loaded: false, |
201 | 206 |
| 207 menu: $('apps-menu'), |
| 208 |
202 createElement: function(app) { | 209 createElement: function(app) { |
203 var div = createElement(app); | 210 var div = createElement(app); |
204 var a = div.firstChild; | 211 var a = div.firstChild; |
205 | 212 |
206 a.onclick = handleClick; | 213 a.onclick = handleClick; |
207 a.style.backgroundImage = url(app['icon_big']); | 214 a.style.backgroundImage = url(app['icon_big']); |
208 if (hashParams['app-id'] == app['id']) { | 215 if (hashParams['app-id'] == app['id']) { |
209 div.setAttribute('new', 'new'); | 216 div.setAttribute('new', 'new'); |
210 // Delay changing the attribute a bit to let the page settle down a bit. | 217 // Delay changing the attribute a bit to let the page settle down a bit. |
211 setTimeout(function() { | 218 setTimeout(function() { |
212 // This will trigger the 'bounce' animation defined in apps.css. | 219 // This will trigger the 'bounce' animation defined in apps.css. |
213 div.setAttribute('new', 'installed'); | 220 div.setAttribute('new', 'installed'); |
214 }, 500); | 221 }, 500); |
215 div.addEventListener('webkitAnimationEnd', function(e) { | 222 div.addEventListener('webkitAnimationEnd', function(e) { |
216 div.removeAttribute('new'); | 223 div.removeAttribute('new'); |
217 | 224 |
218 // If we get new data (eg because something installs in another tab, | 225 // If we get new data (eg because something installs in another tab, |
219 // or because we uninstall something here), don't run the install | 226 // or because we uninstall something here), don't run the install |
220 // animation again. | 227 // animation again. |
221 document.documentElement.setAttribute("install-animation-enabled", | 228 document.documentElement.setAttribute("install-animation-enabled", |
222 "false"); | 229 "false"); |
223 }); | 230 }); |
224 if ($('apps').classList.contains('hidden')) | 231 if ($('apps').classList.contains('hidden') && |
| 232 !(shownSections & MINIMIZED_APPS)) |
225 toggleSectionVisibilityAndAnimate('APPS'); | 233 toggleSectionVisibilityAndAnimate('APPS'); |
226 } | 234 } |
227 | 235 |
228 var settingsButton = div.appendChild(new cr.ui.ContextMenuButton); | 236 var settingsButton = div.appendChild(new cr.ui.ContextMenuButton); |
229 settingsButton.className = 'app-settings'; | 237 settingsButton.className = 'app-settings'; |
230 settingsButton.title = localStrings.getString('appsettings'); | 238 settingsButton.title = localStrings.getString('appsettings'); |
231 | 239 |
232 addContextMenu(div, app); | 240 addContextMenu(div, app); |
233 | 241 |
234 return div; | 242 return div; |
235 }, | 243 }, |
236 | 244 |
237 createMiniviewElement: function(app) { | 245 createMiniviewElement: function(app) { |
238 var span = document.createElement('span'); | 246 var span = document.createElement('span'); |
239 var a = span.appendChild(document.createElement('a')); | 247 var a = span.appendChild(document.createElement('a')); |
240 | 248 |
241 a.setAttribute('app-id', app['id']); | 249 a.setAttribute('app-id', app['id']); |
242 a.textContent = app['name']; | 250 a.textContent = app['name']; |
243 a.href = app['launch_url']; | 251 a.href = app['launch_url']; |
244 a.onclick = handleClick; | 252 a.onclick = handleClick; |
245 a.style.backgroundImage = url(app['icon_small']); | 253 a.style.backgroundImage = url(app['icon_small']); |
246 a.className = 'item'; | 254 a.className = 'item'; |
247 span.appendChild(a); | 255 span.appendChild(a); |
248 | 256 |
249 addContextMenu(span, app); | 257 addContextMenu(span, app); |
250 | 258 |
251 return span; | 259 return span; |
252 }, | 260 }, |
253 | 261 |
| 262 createClosedMenuElement: function(app) { |
| 263 var a = document.createElement('a'); |
| 264 a.setAttribute('app-id', app['id']); |
| 265 a.textContent = app['name']; |
| 266 a.href = app['launch_url']; |
| 267 a.onclick = handleClick; |
| 268 a.style.backgroundImage = url(app['icon_small']); |
| 269 a.className = 'item'; |
| 270 return a; |
| 271 }, |
| 272 |
254 createWebStoreElement: function() { | 273 createWebStoreElement: function() { |
255 return createElement({ | 274 return createElement({ |
256 'id': 'web-store-entry', | 275 'id': 'web-store-entry', |
257 'name': localStrings.getString('web_store_title'), | 276 'name': localStrings.getString('web_store_title'), |
258 'launch_url': localStrings.getString('web_store_url') | 277 'launch_url': localStrings.getString('web_store_url') |
259 }); | 278 }); |
260 } | 279 } |
261 }; | 280 }; |
262 })(); | 281 })(); |
OLD | NEW |