Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/browser/resources/ntp/apps.js

Issue 7291004: Wire up notifications to the New Tab page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 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 function getAppsCallback(data) { 9 function getAppsCallback(data) {
10 logEvent('received apps'); 10 logEvent('received apps');
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 function appNotificationChanged(id, lastNotification) { 152 function appNotificationChanged(id, lastNotification) {
153 // TODO(asargent/finnur) use this when we hook up notifications into the NTP. 153 // TODO(asargent/finnur) use this when we hook up notifications into the NTP.
154 } 154 }
155 155
156 // Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE histogram. 156 // Launches the specified app using the APP_LAUNCH_NTP_APP_RE_ENABLE histogram.
157 // This should only be invoked from the AppLauncherHandler. 157 // This should only be invoked from the AppLauncherHandler.
158 function launchAppAfterEnable(appId) { 158 function launchAppAfterEnable(appId) {
159 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]); 159 chrome.send('launchApp', [appId, APP_LAUNCH.NTP_APP_RE_ENABLE]);
160 } 160 }
161 161
162 // Shows the notification bubble for a given app (the one clicked on).
163 function showNotificationBubble(event) {
164 var item = findAncestorByClass(event.target, 'app-anchor');
165 var title = item.getAttribute('notification-title');
166 var message = item.getAttribute('notification-message');
167 var link = item.getAttribute('notification-link');
168 var link_message = item.getAttribute('notification-link-message');
169
170 if (!title || !message)
171 return;
172
173 // Set the content to the right text.
174 document.getElementById('notification_title').textContent = title;
Evan Stade 2011/06/30 23:20:33 $() instead of document.getElementById
Finnur 2011/07/01 00:33:55 Done.
175 document.getElementById('notification_message').textContent = message;
176 document.getElementById('notification_link').href = link;
177 document.getElementById('notification_link').textContent = link_message;
178
179 var target = event.target;
Evan Stade 2011/06/30 23:20:33 event.currentTarget will do what you want
Finnur 2011/07/01 00:33:55 Not sure what you mean here. event.target and even
Evan Stade 2011/07/02 00:27:50 if that is the case, how does this line from handl
180 while (target.parentElement && target.tagName != "A") {
181 target = target.parentElement;
182 }
183
184 // Move the bubble to the right location.
185 var bubble = document.getElementById('notification_bubble');
186 var x = target.parentElement.offsetLeft +
187 target.parentElement.offsetWidth - 20;
188 var y = target.parentElement.offsetTop + 20;
189 bubble.style.left = x + "px";
190 bubble.style.top = y + "px";
191
192 // Move the arrow and shadow to the right location.
193 var arrow = document.getElementById('arrow_contents');
194 var border = document.getElementById('arrow_border');
195 var shadow = document.getElementById('arrow_shadow');
196 y += 26;
197 x = x - arrow.style.width - 23;
Evan Stade 2011/06/30 23:20:33 -= ?
Finnur 2011/07/01 00:33:55 Done.
198 arrow.style.left = x + "px";
199 arrow.style.top = y + "px";
200 x -= 1;
201 border.style.left = x + "px";
202 border.style.top = y + "px";
Evan Stade 2011/07/02 00:27:50 I suggest wrapping all these in a single div so yo
203 x -= 1;
204 shadow.style.left = x + "px";
205 shadow.style.top = y + "px";
206
207 // Animate the bubble into view.
208 bubble.style.opacity = 1;
Evan Stade 2011/06/30 23:20:33 better to do this with a css class than manually e
Finnur 2011/07/01 00:33:55 I always find it a little silly to create a class
Evan Stade 2011/07/02 00:27:50 it definitely does if you have the right CSS selec
209 arrow.style.opacity = 1;
210 border.style.opacity = 1;
211 shadow.style.opacity = 1;
212
213 bubble.focus();
214 }
215
216 // Hide the notification bubble.
217 function hideNotificationBubble(event) {
218 // This will fade the bubble out of existence.
219 document.getElementById('notification_bubble').style.opacity = 0;
220 document.getElementById('arrow_border').style.opacity = 0;
221 document.getElementById('arrow_shadow').style.opacity = 0;
222 document.getElementById('arrow_contents').style.opacity = 0;
223 }
224
162 var apps = (function() { 225 var apps = (function() {
163 226
164 function createElement(app) { 227 function createElement(app) {
165 var div = document.createElement('div'); 228 var div = document.createElement('div');
166 div.className = 'app'; 229 div.className = 'app';
167 230
168 var a = div.appendChild(document.createElement('a')); 231 var a = div.appendChild(document.createElement('a'));
232 a.className = 'app-anchor';
169 a.setAttribute('app-id', app['id']); 233 a.setAttribute('app-id', app['id']);
170 a.setAttribute('launch-type', app['launch_type']); 234 a.setAttribute('launch-type', app['launch_type']);
235 if (typeof(app['notification']) != "undefined") {
236 a.setAttribute('notification-title', app['notification']['title']);
237 a.setAttribute('notification-message', app['notification']['body']);
238 if (typeof(app['notification']['linkUrl']) != "undefined" &&
239 typeof(app['notification']['linkText']) != "undefined") {
240 a.setAttribute('notification-link', app['notification']['linkUrl']);
241 a.setAttribute('notification-link-message',
242 app['notification']['linkText']);
243 }
244 }
171 a.draggable = false; 245 a.draggable = false;
172 a.xtitle = a.textContent = app['name'];
173 a.href = app['launch_url']; 246 a.href = app['launch_url'];
174 247
248 var span = a.appendChild(document.createElement('span'));
249 span.textContent = app['name'];
250
251 span = a.appendChild(document.createElement('span'));
252 span.className = "app_notification";
253 span.textContent =
254 typeof(app['notification']) != "undefined" &&
255 typeof(app['notification']['title']) != "undefined" ?
256 app['notification']['title'] : "";
257 span.onclick = handleClick;
258
259 document.getElementById("notification_close").onclick =
260 hideNotificationBubble;
261 document.getElementById("notification_bubble").setAttribute("tabIndex", 0);
262 document.getElementById("notification_bubble").onblur =
263 hideNotificationBubble;
264
175 return div; 265 return div;
176 } 266 }
177 267
178 /** 268 /**
179 * Launches an application. 269 * Launches an application.
180 * @param {string} appId Application to launch. 270 * @param {string} appId Application to launch.
181 * @param {MouseEvent} opt_mouseEvent Mouse event from the click that 271 * @param {MouseEvent} opt_mouseEvent Mouse event from the click that
182 * triggered the launch, used to detect modifier keys that change 272 * triggered the launch, used to detect modifier keys that change
183 * the tab's disposition. 273 * the tab's disposition.
184 */ 274 */
(...skipping 27 matching lines...) Expand all
212 return APP_LAUNCH.NTP_APPS_COLLAPSED; 302 return APP_LAUNCH.NTP_APPS_COLLAPSED;
213 else 303 else
214 return APP_LAUNCH.NTP_APPS_MAXIMIZED; 304 return APP_LAUNCH.NTP_APPS_MAXIMIZED;
215 } 305 }
216 306
217 /** 307 /**
218 * @this {!HTMLAnchorElement} 308 * @this {!HTMLAnchorElement}
219 */ 309 */
220 function handleClick(e) { 310 function handleClick(e) {
221 var appId = e.currentTarget.getAttribute('app-id'); 311 var appId = e.currentTarget.getAttribute('app-id');
312 if (appId == null) {
313 showNotificationBubble(e);
314 e.stopPropagation();
315 return false;
316 }
317
222 if (!appDragAndDrop.isDragging()) 318 if (!appDragAndDrop.isDragging())
223 launchApp(appId, e); 319 launchApp(appId, e);
224 return false; 320 return false;
225 } 321 }
226 322
227 // Keep in sync with LaunchType in extension_prefs.h 323 // Keep in sync with LaunchType in extension_prefs.h
228 var LaunchType = { 324 var LaunchType = {
229 LAUNCH_PINNED: 0, 325 LAUNCH_PINNED: 0,
230 LAUNCH_REGULAR: 1, 326 LAUNCH_REGULAR: 1,
231 LAUNCH_FULLSCREEN: 2, 327 LAUNCH_FULLSCREEN: 2,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 410
315 document.addEventListener('canExecute', function(e) { 411 document.addEventListener('canExecute', function(e) {
316 switch (e.command.id) { 412 switch (e.command.id) {
317 case 'apps-options-command': 413 case 'apps-options-command':
318 e.canExecute = currentApp && currentApp['options_url']; 414 e.canExecute = currentApp && currentApp['options_url'];
319 break; 415 break;
320 case 'apps-launch-command': 416 case 'apps-launch-command':
321 e.canExecute = true; 417 e.canExecute = true;
322 break; 418 break;
323 case 'apps-uninstall-command': 419 case 'apps-uninstall-command':
324 e.canExecute = !currentApp['can_uninstall']; 420 e.canExecute = currentApp && !currentApp['can_uninstall'];
325 break; 421 break;
326 } 422 }
327 }); 423 });
328 424
329 // Moves the element at position |from| in array |arr| to position |to|. 425 // Moves the element at position |from| in array |arr| to position |to|.
330 function arrayMove(arr, from, to) { 426 function arrayMove(arr, from, to) {
331 var element = arr.splice(from, 1); 427 var element = arr.splice(from, 1);
332 arr.splice(to, 0, element[0]); 428 arr.splice(to, 0, element[0]);
333 } 429 }
334 430
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 return; 773 return;
678 } 774 }
679 }, 775 },
680 776
681 showImages: function() { 777 showImages: function() {
682 $('apps-content').classList.add('visible'); 778 $('apps-content').classList.add('visible');
683 clearTimeout(this.imageTimer); 779 clearTimeout(this.imageTimer);
684 }, 780 },
685 781
686 createElement: function(app) { 782 createElement: function(app) {
783 var container = document.createElement('div');
687 var div = createElement(app); 784 var div = createElement(app);
785 container.appendChild(div);
688 var a = div.firstChild; 786 var a = div.firstChild;
689 787
690 a.onclick = handleClick; 788 a.onclick = handleClick;
691 a.ping = getAppPingUrl( 789 a.ping = getAppPingUrl(
692 'PING_BY_ID', this.showPromo, 'NTP_APPS_MAXIMIZED'); 790 'PING_BY_ID', this.showPromo, 'NTP_APPS_MAXIMIZED');
693 a.style.backgroundImage = url(app['icon_big']); 791 a.style.backgroundImage = url(app['icon_big']);
694 if (app.isNew) { 792 if (app.isNew) {
695 div.setAttribute('new', 'new'); 793 div.setAttribute('new', 'new');
696 // Delay changing the attribute a bit to let the page settle down a bit. 794 // Delay changing the attribute a bit to let the page settle down a bit.
697 setTimeout(function() { 795 setTimeout(function() {
(...skipping 14 matching lines...) Expand all
712 img.src = app['icon_big']; 810 img.src = app['icon_big'];
713 811
714 // User cannot change launch options or uninstall component extension. 812 // User cannot change launch options or uninstall component extension.
715 if (!app['is_component']) { 813 if (!app['is_component']) {
716 var settingsButton = div.appendChild(new cr.ui.ContextMenuButton); 814 var settingsButton = div.appendChild(new cr.ui.ContextMenuButton);
717 settingsButton.className = 'app-settings'; 815 settingsButton.className = 'app-settings';
718 settingsButton.title = localStrings.getString('appsettings'); 816 settingsButton.title = localStrings.getString('appsettings');
719 addContextMenu(div, app); 817 addContextMenu(div, app);
720 } 818 }
721 819
722 return div; 820 if (app.notifications && app.notifications.length > 0) {
821 var notif_div = document.createElement('div')
Evan Stade 2011/06/30 23:20:33 1. all variable names should be camel case 2. I d
Finnur 2011/07/01 00:33:55 This isn't about the bubble. It is about the text
822 container.appendChild(notif_div);
823 var title = document.createElement('span');
824 title.innerText = app.notifications[0].title;
825 notif_div.appendChild(title);
826 notif_div.appendChild(document.createElement('br'));
827
828 var body = document.createElement('span');
829 container.appendChild(body);
830 body.innerText = app.notifications[0].body;
831 notif_div.appendChild(body);
832 if (app.notifications[0].linkUrl) {
833 notif_div.appendChild(document.createElement('br'));
834 var link = document.createElement('a');
835 link.href = app.notifications[0].linkUrl;
836 link.innerText = app.notifications[0].linkText ?
837 app.notifications[0].linkText : "link";
838 notif_div.appendChild(link);
839 }
840 }
841
842 return container;
723 }, 843 },
724 844
725 createMiniviewElement: function(app) { 845 createMiniviewElement: function(app) {
726 var span = document.createElement('span'); 846 var span = document.createElement('span');
727 var a = span.appendChild(document.createElement('a')); 847 var a = span.appendChild(document.createElement('a'));
728 848
729 a.setAttribute('app-id', app['id']); 849 a.setAttribute('app-id', app['id']);
730 a.textContent = app['name']; 850 a.textContent = app['name'];
731 a.href = app['launch_url']; 851 a.href = app['launch_url'];
732 a.onclick = handleClick; 852 a.onclick = handleClick;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 a.href = localStrings.getString('web_store_url'); 905 a.href = localStrings.getString('web_store_url');
786 a.style.backgroundImage = url('chrome://theme/IDR_WEBSTORE_ICON_16'); 906 a.style.backgroundImage = url('chrome://theme/IDR_WEBSTORE_ICON_16');
787 a.className = 'item'; 907 a.className = 'item';
788 return a; 908 return a;
789 } 909 }
790 }; 910 };
791 })(); 911 })();
792 912
793 // Enable drag and drop reordering of the app launcher. 913 // Enable drag and drop reordering of the app launcher.
794 var appDragAndDrop = new DragAndDropController(apps); 914 var appDragAndDrop = new DragAndDropController(apps);
OLDNEW
« chrome/browser/resources/ntp/apps.css ('K') | « chrome/browser/resources/ntp/apps.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698