OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 addToPage(html) { | 5 function addToPage(html) { |
6 var div = document.createElement('div'); | 6 var div = document.createElement('div'); |
7 div.innerHTML = html; | 7 div.innerHTML = html; |
8 document.getElementById('content').appendChild(div); | 8 document.getElementById('content').appendChild(div); |
9 } | 9 } |
10 | 10 |
11 function showLoadingIndicator(isLastPage) { | 11 function showLoadingIndicator(isLastPage) { |
12 document.getElementById('loadingIndicator').className = | 12 if (isLastPage) { |
13 isLastPage ? 'hidden' : 'visible'; | 13 document.getElementById('loadingIndicator').className ='hidden'; |
14 updateLoadingIndicator(0); | |
15 } | |
16 else { | |
robliao
2014/08/07 17:58:07
} else {
sunangel
2014/08/07 20:57:57
Done.
| |
17 updateLoadingIndicator(1); | |
18 document.getElementById('loadingIndicator').className ='visible'; | |
19 } | |
14 } | 20 } |
15 | 21 |
16 // Maps JS theme to CSS class and then changes body class name. | 22 // Maps JS theme to CSS class and then changes body class name. |
17 // CSS classes must agree with distilledpage.css. | 23 // CSS classes must agree with distilledpage.css. |
18 function useTheme(theme) { | 24 function useTheme(theme) { |
19 var cssClass; | 25 var cssClass; |
20 if (theme == "sepia") { | 26 if (theme == "sepia") { |
21 cssClass = "sepia"; | 27 cssClass = "sepia"; |
22 } else if (theme == "dark") { | 28 } else if (theme == "dark") { |
23 cssClass = "dark"; | 29 cssClass = "dark"; |
24 } else { | 30 } else { |
25 cssClass = "light"; | 31 cssClass = "light"; |
26 } | 32 } |
27 document.body.className = cssClass; | 33 document.body.className = cssClass; |
28 } | 34 } |
35 | |
36 function updateLoadingIndicator(isNotLastPage) { | |
robliao
2014/08/07 17:58:07
isNotLastPage should be treated as true or false.
sunangel
2014/08/07 20:57:57
Done.
| |
37 if (isNotLastPage == 1 && this.alreadyRunning == 0) { | |
robliao
2014/08/07 17:58:07
No need to compare to == 1 or == 0.
http://www.ec
sunangel
2014/08/07 20:57:57
Done.
| |
38 var colorIndex = -1; | |
robliao
2014/08/07 17:58:07
Move this declaration into the if (loader) block.
sunangel
2014/08/07 20:57:57
Done.
| |
39 var colors = ["red", "yellow", "green", "blue"]; | |
robliao
2014/08/07 17:58:07
Put this in a private scope.
var updateLoadingInd
sunangel
2014/08/07 20:57:57
Wow did not know you could do scoping in javascrip
| |
40 var loader = document.getElementById("loader"); | |
41 if(loader) { | |
robliao
2014/08/07 17:58:07
if (loader)
sunangel
2014/08/07 20:57:57
Done.
| |
42 this.alreadyRunning = 1; | |
43 this.colorShuffle = setInterval(function() { | |
44 colorIndex = (colorIndex + 1) % colors.length; | |
45 loader.className = colors[colorIndex]; | |
46 }, 600); | |
47 } | |
48 } | |
49 else if (isNotLastPage == 0 && this.alreadyRunning == 1) { | |
50 clearInterval(this.colorShuffle); | |
robliao
2014/08/07 17:58:07
2 spaces for tabs in JS.
sunangel
2014/08/07 20:57:57
Done.
| |
51 } | |
52 } | |
53 | |
54 // Sets initial state of loading indicator to be not already running. | |
55 function init() { | |
56 this.alreadyRunning = 0; | |
robliao
2014/08/07 17:58:07
Instead of alreadyRunning, you can use the existen
sunangel
2014/08/07 20:57:57
Done.
| |
57 } | |
58 | |
59 window.onload = init; | |
OLD | NEW |