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

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

Issue 3236001: Add the collapsed 'miniview' to the apps and most visisted sections. (Closed)
Patch Set: more unnecessary changes Created 10 years, 4 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
OLDNEW
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('recieved apps'); 6 logEvent('recieved apps');
7 var appsSection = $('apps-section'); 7 var appsSection = $('apps-section');
8 var appsSectionContent = $('apps-section-content'); 8 var appsSectionContent = $('apps-section-content');
9 var appsMiniview = appsSection.getElementsByClassName('miniview')[0];
arv (Not doing code reviews) 2010/08/31 20:54:22 I find querySelector to be easier to use
9 appsSectionContent.textContent = ''; 10 appsSectionContent.textContent = '';
11 appsMiniview.textContent = '';
10 12
11 data.apps.forEach(function(app) { 13 data.apps.forEach(function(app) {
12 appsSectionContent.appendChild(apps.createElement(app)); 14 appsSectionContent.appendChild(apps.createElement(app));
13 }); 15 });
14 16
15 appsSectionContent.appendChild(apps.createWebStoreElement()); 17 appsSectionContent.appendChild(apps.createWebStoreElement());
18
19 data.apps.slice(0, MAX_MINIVIEW_ITEMS).forEach(function(app) {
20 appsMiniview.appendChild(apps.createMiniviewElement(app));
21 });
16 } 22 }
17 23
18 var apps = { 24 var apps = {
19 /** 25 /**
20 * @this {!HTMLAnchorElement} 26 * @this {!HTMLAnchorElement}
21 */ 27 */
22 handleClick_: function() { 28 handleClick_: function() {
23 var launchType = ''; 29 var launchType = '';
24 var inputElements = document.querySelectorAll( 30 var inputElements = document.querySelectorAll(
25 '#apps-launch-control input'); 31 '#apps-launch-control input');
26 for (var i = 0, input; input = inputElements[i]; i++) { 32 for (var i = 0, input; input = inputElements[i]; i++) {
27 if (input.checked) { 33 if (input.checked) {
28 launchType = input.value; 34 launchType = input.value;
29 break; 35 break;
30 } 36 }
31 } 37 }
32 38
33 // TODO(arv): Handle zoom? 39 // TODO(arv): Handle zoom?
34 var rect = this.getBoundingClientRect(); 40 var rect = this.getBoundingClientRect();
35 var cs = getComputedStyle(this); 41 var cs = getComputedStyle(this);
36 var size = cs.backgroundSize.split(/\s+/); // background-size has the 42 var size = cs.backgroundSize.split(/\s+/); // background-size has the
37 // format '123px 456px'. 43 // format '123px 456px'.
38 var width = parseInt(size[0], 10); 44 var width = parseInt(size[0], 10);
39 var height = parseInt(size[1], 10); 45 var height = parseInt(size[1], 10);
40 // We are using background-position-x 50%. 46 // We are using background-position-x 50%.
41 var left = rect.left + ((rect.width - width) >> 1); // Integer divide by 2. 47 var left = rect.left + ((rect.width - width) >> 1); // Integer divide by 2.
42 var top = rect.top + parseInt(cs.backgroundPositionY, 10); 48 var top = rect.top + parseInt(cs.backgroundPositionY, 10);
43 49
44 chrome.send('launchApp', [this.id, launchType, 50 chrome.send('launchApp', [this.getAttribute("app_id"), launchType,
arv (Not doing code reviews) 2010/08/31 20:54:22 single quotes
45 String(left), String(top), 51 String(left), String(top),
46 String(width), String(height)]); 52 String(width), String(height)]);
47 return false; 53 return false;
48 }, 54 },
49 55
50 createElement_: function(app) { 56 createElement_: function(app) {
51 var div = document.createElement('div'); 57 var div = document.createElement('div');
52 div.className = 'app'; 58 div.className = 'app';
53 59
54 var front = div.appendChild(document.createElement('div')); 60 var front = div.appendChild(document.createElement('div'));
55 front.className = 'front'; 61 front.className = 'front';
56 62
57 var a = front.appendChild(document.createElement('a')); 63 var a = front.appendChild(document.createElement('a'));
58 a.id = app['id']; 64 a.setAttribute('app_id', app['id']);
59 a.xtitle = a.textContent = app['name']; 65 a.xtitle = a.textContent = app['name'];
60 a.href = app['launch_url']; 66 a.href = app['launch_url'];
61 67
62 return div; 68 return div;
63 }, 69 },
64 70
65 createElement: function(app) { 71 createElement: function(app) {
66 var div = this.createElement_(app); 72 var div = this.createElement_(app);
67 var front = div.firstChild; 73 var front = div.firstChild;
68 var a = front.firstChild; 74 var a = front.firstChild;
69 75
70 a.onclick = apps.handleClick_; 76 a.onclick = apps.handleClick_;
71 a.style.backgroundImage = url(app['icon']); 77 a.style.backgroundImage = url(app['icon_big']);
72 if (hashParams['app-id'] == app['id']) { 78 if (hashParams['app-id'] == app['id']) {
73 div.setAttribute('new', 'new'); 79 div.setAttribute('new', 'new');
74 // Delay changing the attribute a bit to let the page settle down a bit. 80 // Delay changing the attribute a bit to let the page settle down a bit.
75 setTimeout(function() { 81 setTimeout(function() {
76 div.setAttribute('new', 'installed'); 82 div.setAttribute('new', 'installed');
77 }, 500); 83 }, 500);
78 } 84 }
79 85
80 var settingsButton = front.appendChild(document.createElement('button')); 86 var settingsButton = front.appendChild(document.createElement('button'));
81 settingsButton.className = 'flip'; 87 settingsButton.className = 'flip';
(...skipping 22 matching lines...) Expand all
104 var closeButton = back.appendChild(document.createElement('button')); 110 var closeButton = back.appendChild(document.createElement('button'));
105 closeButton.title = localStrings.getString('close'); 111 closeButton.title = localStrings.getString('close');
106 closeButton.className = 'flip'; 112 closeButton.className = 'flip';
107 closeButton.onclick = settingsButton.onclick = function() { 113 closeButton.onclick = settingsButton.onclick = function() {
108 div.classList.toggle('config'); 114 div.classList.toggle('config');
109 }; 115 };
110 116
111 return div; 117 return div;
112 }, 118 },
113 119
120 createMiniviewElement: function(app) {
121 var span = document.createElement('span');
122 var a = span.appendChild(document.createElement('a'));
123
124 a.setAttribute('app_id', app['id']);
125 a.textContent = app['name'];
126 a.href = app['launch_url'];
127 a.onclick = apps.handleClick_;
128 a.style.backgroundImage = url(app['icon_small']);
129 a.className = 'item';
130 span.appendChild(a);
131 return span;
132 },
133
114 createWebStoreElement: function() { 134 createWebStoreElement: function() {
115 return this.createElement_({ 135 return this.createElement_({
116 'id': 'web-store-entry', 136 'id': 'web-store-entry',
117 'name': localStrings.getString('web_store_title'), 137 'name': localStrings.getString('web_store_title'),
118 'launch_url': localStrings.getString('web_store_url') 138 'launch_url': localStrings.getString('web_store_url')
119 }); 139 });
120 } 140 }
121 }; 141 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698