| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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('sectioned', function() { | 5 cr.define('sectioned', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 function computeClasses(isCombined) { |
| 9 if (isCombined) |
| 10 return 'section expandable expanded'; |
| 11 return 'section'; |
| 12 } |
| 13 |
| 8 function onContinue() { | 14 function onContinue() { |
| 9 chrome.send('handleContinue'); | 15 chrome.send('handleContinue'); |
| 10 } | 16 } |
| 11 | 17 |
| 12 function onOpenSettings() { | 18 function onOpenSettings() { |
| 13 chrome.send('handleSetDefaultBrowser'); | 19 chrome.send('handleSetDefaultBrowser'); |
| 14 } | 20 } |
| 15 | 21 |
| 16 function onToggle(app) { | 22 function onToggle(app) { |
| 17 if (app.isCombined) { | 23 if (app.isCombined) { |
| 18 // Toggle sections. | 24 // Toggle sections. |
| 19 var sections = document.querySelectorAll('.section.expandable'); | 25 var sections = document.querySelectorAll('.section.expandable'); |
| 20 sections.forEach(function(section) { | 26 sections.forEach(function(section) { |
| 21 section.classList.toggle('expanded'); | 27 section.classList.toggle('expanded'); |
| 22 }); | 28 }); |
| 23 // Toggle screenshots. | 29 // Toggle screenshots. |
| 24 var screenshots = document.querySelectorAll('.screenshot-image'); | 30 var screenshots = document.querySelectorAll('.screenshot-image'); |
| 25 screenshots.forEach(function(screenshot) { | 31 screenshots.forEach(function(screenshot) { |
| 26 screenshot.classList.toggle('hidden'); | 32 screenshot.classList.toggle('hidden'); |
| 27 }); | 33 }); |
| 28 } | 34 } |
| 29 } | 35 } |
| 30 | 36 |
| 31 function computeClasses(isCombined) { | |
| 32 if (isCombined) | |
| 33 return 'section expandable expanded'; | |
| 34 return 'section'; | |
| 35 } | |
| 36 | |
| 37 function initialize() { | 37 function initialize() { |
| 38 var app = $('sectioned-app'); | 38 var app = $('sectioned-app'); |
| 39 | 39 |
| 40 app.isCombined = window.location.href.includes('variant=combined'); | 40 // Set variables. |
| 41 // Determines if the combined variant should be displayed. The combined |
| 42 // variant includes instructions on how to pin Chrome to the taskbar. |
| 43 app.isCombined = false; |
| 41 | 44 |
| 42 // Set handlers. | 45 // Set handlers. |
| 43 app.computeClasses = computeClasses; | 46 app.computeClasses = computeClasses; |
| 44 app.onContinue = onContinue; | 47 app.onContinue = onContinue; |
| 45 app.onOpenSettings = onOpenSettings; | 48 app.onOpenSettings = onOpenSettings; |
| 46 app.onToggle = onToggle.bind(this, app); | 49 app.onToggle = onToggle.bind(this, app); |
| 50 |
| 51 |
| 52 // Asynchronously check if Chrome is pinned to the taskbar. |
| 53 cr.sendWithPromise('getPinnedToTaskbarState').then( |
| 54 function(isPinnedToTaskbar) { |
| 55 // Allow overriding of the result via a query parameter. |
| 56 // TODO(pmonette): Remove these checks when they are no longer needed. |
| 57 /** @const */ var VARIANT_KEY = 'variant'; |
| 58 var VariantType = { |
| 59 DEFAULT_ONLY: 'defaultonly', |
| 60 COMBINED: 'combined' |
| 61 }; |
| 62 var params = new URLSearchParams(location.search.slice(1)); |
| 63 if (params.has(VARIANT_KEY)) { |
| 64 if (params.get(VARIANT_KEY) === VariantType.DEFAULT_ONLY) |
| 65 app.isCombined = false; |
| 66 else if (params.get(VARIANT_KEY) === VariantType.COMBINED) |
| 67 app.isCombined = true; |
| 68 } else { |
| 69 app.isCombined = !isPinnedToTaskbar; |
| 70 } |
| 71 }); |
| 47 } | 72 } |
| 48 | 73 |
| 49 return { | 74 return { |
| 50 initialize: initialize | 75 initialize: initialize |
| 51 }; | 76 }; |
| 52 }); | 77 }); |
| 53 | 78 |
| 54 document.addEventListener('DOMContentLoaded', sectioned.initialize); | 79 document.addEventListener('DOMContentLoaded', sectioned.initialize); |
| OLD | NEW |