OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 cr.define('ntp4', function() { | 5 cr.define('ntp4', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 var localStrings = new LocalStrings; | 8 var localStrings = new LocalStrings; |
9 | 9 |
10 var APP_LAUNCH = { | 10 var APP_LAUNCH = { |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 */ | 289 */ |
290 loadIcon: function() { | 290 loadIcon: function() { |
291 if (this.appImgSrc_) { | 291 if (this.appImgSrc_) { |
292 this.appImg_.src = this.appImgSrc_; | 292 this.appImg_.src = this.appImgSrc_; |
293 this.appImg_.classList.remove('invisible'); | 293 this.appImg_.classList.remove('invisible'); |
294 this.appImgSrc_ = null; | 294 this.appImgSrc_ = null; |
295 } | 295 } |
296 this.classList.remove('icon-loading'); | 296 this.classList.remove('icon-loading'); |
297 }, | 297 }, |
298 | 298 |
299 // Shows a notification text below the app icon and stuffs the attributes | 299 /** |
300 // necessary to show the bubble when the user clicks on the notification | 300 * Creates a bubble node. |
301 // text. | 301 * @param {Object} notification The notification to show in the bubble. |
302 setupNotification_: function(notification) { | 302 * @param {boolean} full Whether we want the headline or just the content. |
303 // Remove the old notification from this node (if any). | 303 * @private |
304 if (this.appNotification_ && this.appNotification_.parentNode) | 304 */ |
305 this.appNotification_.parentNode.removeChild(this.appNotification_); | 305 createBubbleNode_: function(notification, full) { |
| 306 if (!full) { |
| 307 var titleItem = this.ownerDocument.createElement('span'); |
| 308 titleItem.textContent = notification['title']; |
| 309 return titleItem; |
| 310 } else { |
| 311 var container = this.ownerDocument.createElement('div'); |
306 | 312 |
307 if (notification) { | 313 var messageItem = this.ownerDocument.createElement('div'); |
308 // Add a new notification to this node. | 314 messageItem.textContent = notification['body']; |
309 var appNotification = this.ownerDocument.createElement('span'); | 315 container.appendChild(messageItem); |
310 appNotification.className = 'app-notification'; | 316 |
311 appNotification.textContent = notification['title']; | 317 if (notification['linkUrl'] && notification['linkText']) { |
312 appNotification.addEventListener('click', | 318 var anchor = this.ownerDocument.createElement('a'); |
313 this.onNotificationClick_.bind(this)); | 319 anchor.href = notification['linkUrl']; |
314 appNotification.notificationTitle = notification['title']; | 320 anchor.textContent = notification['linkText']; |
315 appNotification.notificationMessage = notification['body']; | 321 container.appendChild(anchor); |
316 if (typeof notification['linkUrl'] != 'undefined' && | |
317 typeof notification['linkText'] != 'undefined') { | |
318 appNotification.notificationLink = notification['linkUrl']; | |
319 appNotification.notificationLinkText = notification['linkText']; | |
320 } | 322 } |
321 this.appNotification_ = appNotification; | 323 |
322 this.appendChild(appNotification); | 324 return container; |
323 } | 325 } |
324 }, | 326 }, |
325 | 327 |
| 328 /** |
| 329 * Sets up a notification for the app icon. |
| 330 * @param {Object} notification The notification to show in the bubble. |
| 331 * @private |
| 332 */ |
| 333 setupNotification_: function(notification) { |
| 334 if (notification) { |
| 335 var infoBubble; |
| 336 if (!this.currentBubbleShowing_) { |
| 337 // Create a new bubble. |
| 338 infoBubble = new cr.ui.ExpandableBubble; |
| 339 infoBubble.anchorNode = this; |
| 340 } else { |
| 341 // Reuse the old bubble instead of popping up a new bubble over |
| 342 // the old one. |
| 343 infoBubble = this.currentBubbleShowing_; |
| 344 infoBubble.collapseBubble_(); |
| 345 } |
| 346 infoBubble.contentTitle = this.createBubbleNode_(notification, false); |
| 347 infoBubble.content = this.createBubbleNode_(notification, true); |
| 348 infoBubble.show(); |
| 349 |
| 350 this.currentBubbleShowing_ = infoBubble; |
| 351 } |
| 352 }, |
| 353 |
326 /** | 354 /** |
327 * Creates the apps-promo section of the app (should only be called for the | 355 * Creates the apps-promo section of the app (should only be called for the |
328 * webstore app). | 356 * webstore app). |
329 * @private | 357 * @private |
330 */ | 358 */ |
331 createAppsPromoExtras_: function() { | 359 createAppsPromoExtras_: function() { |
332 this.classList.add('webstore'); | 360 this.classList.add('webstore'); |
333 | 361 |
334 this.appsPromoExtras_ = $('apps-promo-extras-template').cloneNode(true); | 362 this.appsPromoExtras_ = $('apps-promo-extras-template').cloneNode(true); |
335 this.appsPromoExtras_.id = ''; | 363 this.appsPromoExtras_.id = ''; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 if (e.keyIdentifier == 'Enter') { | 447 if (e.keyIdentifier == 'Enter') { |
420 chrome.send('launchApp', | 448 chrome.send('launchApp', |
421 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, | 449 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, |
422 e.altKey, e.ctrlKey, e.metaKey, e.shiftKey, 0]); | 450 e.altKey, e.ctrlKey, e.metaKey, e.shiftKey, 0]); |
423 e.preventDefault(); | 451 e.preventDefault(); |
424 e.stopPropagation(); | 452 e.stopPropagation(); |
425 } | 453 } |
426 }, | 454 }, |
427 | 455 |
428 /** | 456 /** |
429 * Invoked when an app notification is clicked. This will show the | |
430 * notification bubble, containing the details of the notification. | |
431 * @param {Event} e The click event. | |
432 * @private | |
433 */ | |
434 onNotificationClick_: function(e) { | |
435 var title = this.appNotification_.notificationTitle; | |
436 var message = this.appNotification_.notificationMessage; | |
437 var link = this.appNotification_.notificationLink; | |
438 var linkMessage = this.appNotification_.notificationLinkText; | |
439 | |
440 if (!title || !message) | |
441 return; | |
442 | |
443 var container = this.ownerDocument.createElement('div'); | |
444 var titleItem = this.ownerDocument.createElement('strong'); | |
445 titleItem.textContent = title; | |
446 container.appendChild(titleItem); | |
447 var messageDiv = this.ownerDocument.createElement('div'); | |
448 messageDiv.textContent = message; | |
449 container.appendChild(messageDiv); | |
450 if (link && linkMessage) { | |
451 var anchor = this.ownerDocument.createElement('a'); | |
452 anchor.href = link; | |
453 anchor.textContent = linkMessage; | |
454 container.appendChild(anchor); | |
455 } | |
456 | |
457 var infoBubble = new cr.ui.Bubble; | |
458 infoBubble.appId = this.appData_.id; | |
459 infoBubble.anchorNode = e.target; | |
460 infoBubble.content = container; | |
461 infoBubble.handleCloseEvent = function() { | |
462 chrome.send('closeNotification', [this.appId]); | |
463 this.hide(); | |
464 }; | |
465 infoBubble.show(); | |
466 }, | |
467 | |
468 /** | |
469 * Adds a node to the list of targets that will launch the app. This list | 457 * Adds a node to the list of targets that will launch the app. This list |
470 * is also used in onMousedown to determine whether the app contents should | 458 * is also used in onMousedown to determine whether the app contents should |
471 * be shown as active (if we don't do this, then clicking anywhere in | 459 * be shown as active (if we don't do this, then clicking anywhere in |
472 * appContents, even a part that is outside the ideally clickable region, | 460 * appContents, even a part that is outside the ideally clickable region, |
473 * will cause the app icon to look active). | 461 * will cause the app icon to look active). |
474 * @param {HTMLElement} node The node that should be clickable. | 462 * @param {HTMLElement} node The node that should be clickable. |
475 */ | 463 */ |
476 addLaunchClickTarget_: function(node) { | 464 addLaunchClickTarget_: function(node) { |
477 node.classList.add('launch-click-target'); | 465 node.classList.add('launch-click-target'); |
478 node.addEventListener('click', this.onClick_.bind(this)); | 466 node.addEventListener('click', this.onClick_.bind(this)); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 }, | 541 }, |
554 | 542 |
555 /** | 543 /** |
556 * Uninstalls the app after it's been dropped on the trash. | 544 * Uninstalls the app after it's been dropped on the trash. |
557 */ | 545 */ |
558 removeFromChrome: function() { | 546 removeFromChrome: function() { |
559 chrome.send('uninstallApp', [this.appData_.id, true]); | 547 chrome.send('uninstallApp', [this.appData_.id, true]); |
560 | 548 |
561 this.tile.tilePage.cleanupDrag(); | 549 this.tile.tilePage.cleanupDrag(); |
562 this.tile.parentNode.removeChild(this.tile); | 550 this.tile.parentNode.removeChild(this.tile); |
| 551 |
| 552 if (this.currentBubbleShowing_) |
| 553 currentBubbleShowing_.hide(); |
563 }, | 554 }, |
564 | 555 |
565 /** | 556 /** |
566 * Called when a drag is starting on the tile. Updates dataTransfer with | 557 * Called when a drag is starting on the tile. Updates dataTransfer with |
567 * data for this tile. | 558 * data for this tile. |
568 */ | 559 */ |
569 setDragData: function(dataTransfer) { | 560 setDragData: function(dataTransfer) { |
570 dataTransfer.setData('Text', this.appData_.title); | 561 dataTransfer.setData('Text', this.appData_.title); |
571 dataTransfer.setData('URL', this.appData_.url); | 562 dataTransfer.setData('URL', this.appData_.url); |
572 }, | 563 }, |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 appNotificationChanged: appNotificationChanged, | 787 appNotificationChanged: appNotificationChanged, |
797 AppsPage: AppsPage, | 788 AppsPage: AppsPage, |
798 launchAppAfterEnable: launchAppAfterEnable, | 789 launchAppAfterEnable: launchAppAfterEnable, |
799 }; | 790 }; |
800 }); | 791 }); |
801 | 792 |
802 // TODO(estade): update the content handlers to use ntp namespace instead of | 793 // TODO(estade): update the content handlers to use ntp namespace instead of |
803 // making these global. | 794 // making these global. |
804 var appNotificationChanged = ntp4.appNotificationChanged; | 795 var appNotificationChanged = ntp4.appNotificationChanged; |
805 var launchAppAfterEnable = ntp4.launchAppAfterEnable; | 796 var launchAppAfterEnable = ntp4.launchAppAfterEnable; |
OLD | NEW |