OLD | NEW |
---|---|
1 /* Copyright 2015 The Chromium Authors. All rights reserved. | 1 /* Copyright 2015 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 // Single iframe for NTP tiles. | 5 // Single iframe for NTP tiles. |
6 (function() { | 6 (function() { |
7 'use strict'; | 7 'use strict'; |
8 | 8 |
9 | 9 |
10 /** | 10 /** |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 // Store the tiles on the current closure. | 251 // Store the tiles on the current closure. |
252 var cur = tiles; | 252 var cur = tiles; |
253 | 253 |
254 // Create empty tiles until we have NUMBER_OF_TILES. | 254 // Create empty tiles until we have NUMBER_OF_TILES. |
255 while (cur.childNodes.length < NUMBER_OF_TILES) { | 255 while (cur.childNodes.length < NUMBER_OF_TILES) { |
256 addTile({}); | 256 addTile({}); |
257 } | 257 } |
258 | 258 |
259 var parent = document.querySelector('#most-visited'); | 259 var parent = document.querySelector('#most-visited'); |
260 | 260 |
261 // Mark old tile DIV for removal after the transition animation is done. | 261 // Only fade in the new tiles if there were tiles before. |
262 var fadeIn = false; | |
262 var old = parent.querySelector('#mv-tiles'); | 263 var old = parent.querySelector('#mv-tiles'); |
263 if (old) { | 264 if (old) { |
jkrcal
2016/09/09 08:13:13
I am puzzled:
How come this is not true initially
Marc Treib
2016/09/09 08:56:28
When this runs for the first time, there is no div
jkrcal
2016/09/09 09:00:17
Huh, I've swapped the direction :) Sure, this make
| |
265 fadeIn = true; | |
266 // Mark old tile DIV for removal after the transition animation is done. | |
264 old.removeAttribute('id'); | 267 old.removeAttribute('id'); |
265 old.classList.add('mv-tiles-old'); | 268 old.classList.add('mv-tiles-old'); |
266 old.style.opacity = 0.0; | 269 old.style.opacity = 0.0; |
267 cur.addEventListener('webkitTransitionEnd', function(ev) { | 270 cur.addEventListener('webkitTransitionEnd', function(ev) { |
268 if (ev.target === cur) { | 271 if (ev.target === cur) { |
269 removeAllOldTiles(); | 272 removeAllOldTiles(); |
270 } | 273 } |
271 }); | 274 }); |
272 } | 275 } |
273 | 276 |
274 // Add new tileset. | 277 // Add new tileset. |
275 cur.id = 'mv-tiles'; | 278 cur.id = 'mv-tiles'; |
276 parent.appendChild(cur); | 279 parent.appendChild(cur); |
277 // We want the CSS transition to trigger, so need to add to the DOM before | 280 // getComputedStyle causes the initial style (opacity 0) to be applied, so |
278 // setting the style. | 281 // that when we then set it to 1, that triggers the CSS transition. |
279 setTimeout(function() { | 282 if (fadeIn) { |
Marc Treib
2016/09/08 18:17:48
This was the root problem: When the timeout functi
| |
280 cur.style.opacity = 1.0; | 283 window.getComputedStyle(cur).opacity; |
Marc Treib
2016/09/08 18:17:48
From https://timtaubert.de/blog/2012/09/css-transi
jkrcal
2016/09/09 08:13:13
This looks hacky :) I haven't found any cleaner so
Marc Treib
2016/09/09 08:56:28
It's not pretty, but I'd argue it's less hacky tha
jkrcal
2016/09/09 09:00:17
That's true, probably less hacky.
| |
281 }, 0); | 284 } |
285 cur.style.opacity = 1.0; | |
282 | 286 |
283 // Make sure the tiles variable contain the next tileset we may use. | 287 // Make sure the tiles variable contain the next tileset we may use. |
284 tiles = document.createElement('div'); | 288 tiles = document.createElement('div'); |
285 | 289 |
286 if (impressionUrl) { | 290 if (impressionUrl) { |
287 navigator.sendBeacon(impressionUrl); | 291 navigator.sendBeacon(impressionUrl); |
288 impressionUrl = null; | 292 impressionUrl = null; |
289 } | 293 } |
290 }; | 294 }; |
291 | 295 |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
611 var html = document.querySelector('html'); | 615 var html = document.querySelector('html'); |
612 html.dir = 'rtl'; | 616 html.dir = 'rtl'; |
613 } | 617 } |
614 | 618 |
615 window.addEventListener('message', handlePostMessage); | 619 window.addEventListener('message', handlePostMessage); |
616 }; | 620 }; |
617 | 621 |
618 | 622 |
619 window.addEventListener('DOMContentLoaded', init); | 623 window.addEventListener('DOMContentLoaded', init); |
620 })(); | 624 })(); |
OLD | NEW |