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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 174 |
175 initialize: function() { | 175 initialize: function() { |
176 assert(this.appData_.id, 'Got an app without an ID'); | 176 assert(this.appData_.id, 'Got an app without an ID'); |
177 this.id = this.appData_.id; | 177 this.id = this.appData_.id; |
178 | 178 |
179 this.className = 'app'; | 179 this.className = 'app'; |
180 | 180 |
181 var appContents = this.ownerDocument.createElement('div'); | 181 var appContents = this.ownerDocument.createElement('div'); |
182 appContents.className = 'app-contents'; | 182 appContents.className = 'app-contents'; |
183 | 183 |
| 184 var appImgContainer = this.ownerDocument.createElement('div'); |
| 185 appImgContainer.className = 'app-img-container'; |
| 186 this.appImgContainer_ = appImgContainer; |
| 187 |
184 if (!this.appData_.icon_big_exists && this.appData_.icon_small_exists) | 188 if (!this.appData_.icon_big_exists && this.appData_.icon_small_exists) |
185 this.useSmallIcon_ = true; | 189 this.useSmallIcon_ = true; |
186 | 190 |
187 var appImg = this.ownerDocument.createElement('img'); | 191 var appImg = this.ownerDocument.createElement('img'); |
188 appImg.src = this.useSmallIcon_ ? this.appData_.icon_small : | 192 appImg.src = this.useSmallIcon_ ? this.appData_.icon_small : |
189 this.appData_.icon_big; | 193 this.appData_.icon_big; |
| 194 appImgContainer.appendChild(appImg); |
| 195 |
190 if (this.useSmallIcon_) { | 196 if (this.useSmallIcon_) { |
191 var imgDiv = this.ownerDocument.createElement('div'); | 197 var imgDiv = this.ownerDocument.createElement('div'); |
192 imgDiv.className = 'app-icon-div'; | 198 imgDiv.className = 'app-icon-div'; |
193 imgDiv.appendChild(appImg); | 199 imgDiv.appendChild(appImgContainer); |
194 imgDiv.addEventListener('click', this.onClick_.bind(this)); | 200 imgDiv.addEventListener('click', this.onClick_.bind(this)); |
195 this.imgDiv_ = imgDiv; | 201 this.imgDiv_ = imgDiv; |
196 appContents.appendChild(imgDiv); | 202 appContents.appendChild(imgDiv); |
197 } else { | 203 } else { |
198 appImg.addEventListener('click', this.onClick_.bind(this)); | 204 appImgContainer.addEventListener('click', this.onClick_.bind(this)); |
199 appContents.appendChild(appImg); | 205 appContents.appendChild(appImgContainer); |
200 } | 206 } |
201 this.appImg_ = appImg; | 207 this.appImg_ = appImg; |
202 | 208 |
203 var appSpan = this.ownerDocument.createElement('span'); | 209 var appSpan = this.ownerDocument.createElement('span'); |
204 appSpan.textContent = this.appData_.name; | 210 appSpan.textContent = this.appData_.name; |
205 appSpan.addEventListener('click', this.onClick_.bind(this)); | 211 appSpan.addEventListener('click', this.onClick_.bind(this)); |
206 appContents.appendChild(appSpan); | 212 appContents.appendChild(appSpan); |
207 this.appendChild(appContents); | 213 this.appendChild(appContents); |
| 214 this.appContents_ = appContents; |
208 | 215 |
209 this.addEventListener('keydown', cr.ui.contextMenuHandler); | 216 this.addEventListener('keydown', cr.ui.contextMenuHandler); |
210 this.addEventListener('keyup', cr.ui.contextMenuHandler); | 217 this.addEventListener('keyup', cr.ui.contextMenuHandler); |
211 | 218 |
212 // This hack is here so that appContents.contextMenu will be the same as | 219 // This hack is here so that appContents.contextMenu will be the same as |
213 // this.contextMenu. | 220 // this.contextMenu. |
214 var self = this; | 221 var self = this; |
215 appContents.__defineGetter__('contextMenu', function() { | 222 appContents.__defineGetter__('contextMenu', function() { |
216 return self.contextMenu; | 223 return self.contextMenu; |
217 }); | 224 }); |
(...skipping 14 matching lines...) Expand all Loading... |
232 | 239 |
233 this.appsPromoExtras_ = $('apps-promo-extras-template').cloneNode(true); | 240 this.appsPromoExtras_ = $('apps-promo-extras-template').cloneNode(true); |
234 this.appsPromoExtras_.id = ''; | 241 this.appsPromoExtras_.id = ''; |
235 this.appsPromoHeading_ = | 242 this.appsPromoHeading_ = |
236 this.appsPromoExtras_.querySelector('.apps-promo-heading'); | 243 this.appsPromoExtras_.querySelector('.apps-promo-heading'); |
237 this.appsPromoLink_ = | 244 this.appsPromoLink_ = |
238 this.appsPromoExtras_.querySelector('.apps-promo-link'); | 245 this.appsPromoExtras_.querySelector('.apps-promo-link'); |
239 this.appsPromoHide_ = | 246 this.appsPromoHide_ = |
240 this.appsPromoExtras_.querySelector('.apps-promo-hide'); | 247 this.appsPromoExtras_.querySelector('.apps-promo-hide'); |
241 | 248 |
| 249 this.appsPromoLogo_ = this.ownerDocument.createElement('img'); |
| 250 this.appsPromoLogo_.className = 'apps-promo-logo'; |
| 251 this.appImgContainer_.appendChild(this.appsPromoLogo_); |
| 252 |
242 this.appsPromoHide_.addEventListener('click', | 253 this.appsPromoHide_.addEventListener('click', |
243 this.onHidePromoClicked_.bind(this)); | 254 this.onHidePromoClicked_.bind(this)); |
244 | 255 |
245 this.appendChild(this.appsPromoExtras_); | 256 this.appendChild(this.appsPromoExtras_); |
246 this.appsPromoExtras_.hidden = false; | 257 this.appsPromoExtras_.hidden = false; |
247 // TODO(estade): A ping url needs to be set for the app icon. | |
248 }, | 258 }, |
249 | 259 |
250 /** | 260 /** |
251 * Handles when the "No, thanks" promo link is clicked. | 261 * Handles when the "No, thanks" promo link is clicked. |
252 * @private | 262 * @private |
253 */ | 263 */ |
254 onHidePromoClicked_: function(e) { | 264 onHidePromoClicked_: function(e) { |
255 chrome.send('hideAppsPromo'); | 265 chrome.send('hideAppsPromo'); |
256 this.setAppsPromoData(null); | 266 this.setAppsPromoData(null); |
257 }, | 267 }, |
258 | 268 |
259 /** | 269 /** |
260 * Sets the apps promo appearance. If |data| is null, there is no promo. If | 270 * Sets the apps promo appearance. If |data| is null, there is no promo. If |
261 * |data| is non-null, it contains strings to be shown for the promo. The | 271 * |data| is non-null, it contains strings to be shown for the promo. The |
262 * promo is only shown when the webstore app icon is alone on a page. | 272 * promo is only shown when the webstore app icon is alone on a page. |
263 * @param {Object} data A dictionary that contains apps promo strings. | 273 * @param {Object} data A dictionary that contains apps promo strings. |
264 */ | 274 */ |
265 setAppsPromoData: function(data) { | 275 setAppsPromoData: function(data) { |
266 if (data) { | 276 if (data) { |
267 this.classList.add('has-promo'); | 277 this.classList.add('has-promo'); |
268 } else { | 278 } else { |
269 this.classList.remove('has-promo'); | 279 this.classList.remove('has-promo'); |
270 return; | 280 return; |
271 } | 281 } |
272 | 282 |
273 this.appsPromoHeading_.textContent = data.promoHeader; | 283 this.appsPromoHeading_.textContent = data.promoHeader; |
274 this.appsPromoLink_.href = data.promoLink; | 284 this.appsPromoLink_.href = data.promoLink; |
275 this.appsPromoLink_.textContent = data.promoButton; | 285 this.appsPromoLink_.textContent = data.promoButton; |
276 this.appsPromoHide_.textContent = data.promoExpire; | 286 this.appsPromoHide_.textContent = data.promoExpire; |
| 287 this.appsPromoLogo_.src = data.promoLogo; |
277 }, | 288 }, |
278 | 289 |
279 /** | 290 /** |
280 * Set the size and position of the app tile. | 291 * Set the size and position of the app tile. |
281 * @param {number} size The total size of |this|. | 292 * @param {number} size The total size of |this|. |
282 * @param {number} x The x-position. | 293 * @param {number} x The x-position. |
283 * @param {number} y The y-position. | 294 * @param {number} y The y-position. |
284 * animate. | 295 * animate. |
285 */ | 296 */ |
286 setBounds: function(size, x, y) { | 297 setBounds: function(size, x, y) { |
287 var imgSize = size * APP_IMG_SIZE_FRACTION; | 298 var imgSize = size * APP_IMG_SIZE_FRACTION; |
288 this.appImg_.style.width = this.appImg_.style.height = | 299 this.appImgContainer_.style.width = this.appImgContainer_.style.height = |
289 this.useSmallIcon_ ? '32px' : imgSize + 'px'; | 300 this.useSmallIcon_ ? '32px' : imgSize + 'px'; |
290 | 301 |
291 | |
292 this.style.width = this.style.height = size + 'px'; | 302 this.style.width = this.style.height = size + 'px'; |
293 if (this.isStore_) | 303 if (this.isStore_) |
294 this.appsPromoExtras_.style.left = size + (imgSize - size) / 2 + 'px'; | 304 this.appsPromoExtras_.style.left = size + (imgSize - size) / 2 + 'px'; |
295 | 305 |
296 this.style.left = x + 'px'; | 306 this.style.left = x + 'px'; |
297 this.style.right = x + 'px'; | 307 this.style.right = x + 'px'; |
298 this.style.top = y + 'px'; | 308 this.style.top = y + 'px'; |
299 }, | 309 }, |
300 | 310 |
301 /** | 311 /** |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 var store = document.querySelector('.webstore'); | 514 var store = document.querySelector('.webstore'); |
505 if (store) | 515 if (store) |
506 store.setAppsPromoData(data); | 516 store.setAppsPromoData(data); |
507 }; | 517 }; |
508 | 518 |
509 return { | 519 return { |
510 APP_LAUNCH: APP_LAUNCH, | 520 APP_LAUNCH: APP_LAUNCH, |
511 AppsPage: AppsPage, | 521 AppsPage: AppsPage, |
512 }; | 522 }; |
513 }); | 523 }); |
OLD | NEW |