OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @fileoverview Out of the box experience flow (OOBE). |
| 7 * This is the main code for the OOBE WebUI implementation. |
| 8 */ |
| 9 |
| 10 const steps = ['connect', 'eula', 'update']; |
| 11 |
| 12 cr.define('cr.ui', function() { |
| 13 function Oobe() { |
| 14 } |
| 15 |
| 16 cr.addSingletonGetter(Oobe); |
| 17 |
| 18 Oobe.localStrings_ = new LocalStrings(); |
| 19 |
| 20 Oobe.prototype = { |
| 21 /** |
| 22 * Current OOBE step, index in the steps array. |
| 23 * @type {number} |
| 24 */ |
| 25 currentStep_: 0, |
| 26 |
| 27 /** |
| 28 * Switches to the next OOBE step. |
| 29 * @param {number} nextStep Index of the next step. |
| 30 */ |
| 31 toggleStep_: function(nextStep) { |
| 32 var offset = nextStep - this.currentStep_; |
| 33 var oldstep = $(steps[this.currentStep_]); |
| 34 var oldheader = $('header-' + steps[this.currentStep_]); |
| 35 var newstep = $(steps[this.currentStep_ + offset]); |
| 36 var newheader = $('header-' + steps[this.currentStep_ + offset]); |
| 37 |
| 38 newstep.classList.remove('hidden'); |
| 39 |
| 40 // TODO(nkostylev): Support offset other than -1/1. |
| 41 if (offset == 1) { |
| 42 oldheader.classList.add('left'); |
| 43 oldstep.classList.add('left'); |
| 44 newheader.classList.remove('right'); |
| 45 newstep.classList.remove('right'); |
| 46 } else if (offset == -1) { |
| 47 oldheader.classList.add('right'); |
| 48 oldstep.classList.add('right'); |
| 49 newheader.classList.remove('left'); |
| 50 newstep.classList.remove('left'); |
| 51 } |
| 52 |
| 53 // Adjust inner container height based on new step's height. |
| 54 $('inner-container').style.height = |
| 55 $(steps[this.currentStep_ + offset]).offsetHeight; |
| 56 |
| 57 oldstep.addEventListener('webkitTransitionEnd', function f(e) { |
| 58 oldstep.removeEventListener('webkitTransitionEnd', f); |
| 59 oldstep.classList.add('hidden'); |
| 60 }); |
| 61 this.currentStep_ = nextStep; |
| 62 $('oobe').className = steps[this.currentStep_]; |
| 63 }, |
| 64 }; |
| 65 |
| 66 /** |
| 67 * Initializes the OOBE flow. This will cause all C++ handlers to |
| 68 * be invoked to do final setup. |
| 69 */ |
| 70 Oobe.initialize = function() { |
| 71 // Adjust inner container height based on first step's height |
| 72 $('inner-container').style.height = $(steps[0]).offsetHeight; |
| 73 |
| 74 $('continue-button').addEventListener('click', function(event) { |
| 75 // TODO(nkostylev): Callback screen handler. |
| 76 Oobe.toggleStep(1); |
| 77 }); |
| 78 $('back-button').addEventListener('click', function(event) { |
| 79 // TODO(nkostylev): Callback screen handler. |
| 80 Oobe.toggleStep(0); |
| 81 }); |
| 82 $('accept-button').addEventListener('click', function(event) { |
| 83 // TODO(nkostylev): Callback screen handler. |
| 84 Oobe.toggleStep(2); |
| 85 }); |
| 86 |
| 87 chrome.send('screenStateInitialize'); |
| 88 }; |
| 89 |
| 90 /** |
| 91 * Switches to the next OOBE step. |
| 92 * @param {number} nextStep Index of the next step. |
| 93 */ |
| 94 Oobe.toggleStep = function(nextStep) { |
| 95 Oobe.getInstance().toggleStep_(nextStep); |
| 96 }; |
| 97 |
| 98 // Export |
| 99 return { |
| 100 Oobe: Oobe |
| 101 }; |
| 102 }); |
| 103 |
| 104 var Oobe = cr.ui.Oobe; |
| 105 |
| 106 document.addEventListener('DOMContentLoaded', cr.ui.Oobe.initialize); |
OLD | NEW |