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
3 // found in the LICENSE file.
5 cr.define('cr.ui.login', function() {
7 * Constructs a slide manager for the user manager tutorial.
11 function UserManagerTutorial() {
14 cr.addSingletonGetter(UserManagerTutorial);
16 UserManagerTutorial.prototype = {
20 slides_: ['slide-welcome',
28 * Current tutorial step, index in the slides array.
34 * Switches to the next tutorial step.
35 * @param {number} nextStepIndex Index of the next step.
37 toggleStep_: function(nextStepIndex) {
38 if (nextStepIndex > this.slides_.length)
41 var currentStepId = this.slides_[this.currentStep_];
42 var nextStepId = this.slides_[nextStepIndex];
43 var oldStep = $(currentStepId);
44 var newStep = $(nextStepId);
46 newStep.classList.remove('hidden');
48 if (nextStepIndex != this.currentStep_)
49 oldStep.classList.add('hidden');
51 this.currentStep_ = nextStepIndex;
53 // The last tutorial step is an information bubble that ends the tutorial.
54 if (this.currentStep_ == this.slides_.length - 1)
59 var nextStep = this.currentStep_ + 1;
60 this.toggleStep_(nextStep);
65 $('user-manager-tutorial').hidden = true;
69 * Add user button click handler.
72 handleAddUserClick_: function(e) {
73 chrome.send('addUser');
74 $('user-manager-tutorial').hidden = true;
75 // Prevent further propagation of click event. Otherwise, the click event
76 // handler of document object will set wallpaper to user's wallpaper when
77 // there is only one existing user. See http://crbug.com/166477
81 endTutorial_: function(e) {
82 $('inner-container').classList.remove('disabled');
85 decorate: function() {
86 // Transitions between the tutorial slides.
87 for (var i = 0; i < this.slides_.length; ++i) {
88 var buttonNext = $(this.slides_[i] + '-next');
89 var buttonSkip = $(this.slides_[i] + '-skip');
91 buttonNext.addEventListener('click', this.next_.bind(this));
93 buttonSkip.addEventListener('click', this.skip_.bind(this));
95 $('slide-add-user').addEventListener('click',
96 this.handleAddUserClick_.bind(this));
101 * Initializes the tutorial manager.
103 UserManagerTutorial.startTutorial = function() {
104 $('user-manager-tutorial').hidden = false;
106 // If there's only one pod, show the slides to the side of the pod.
107 // Otherwise, center the slides and disable interacting with the pods
108 // while the tutorial is showing.
109 if ($('pod-row').pods.length == 1) {
110 $('slide-welcome').classList.add('single-pod');
111 $('slide-your-chrome').classList.add('single-pod');
112 $('slide-complete').classList.add('single-pod');
115 $('pod-row').focusPod(); // No focused pods.
116 $('inner-container').classList.add('disabled');
120 * Initializes the tutorial manager.
122 UserManagerTutorial.initialize = function() {
123 UserManagerTutorial.getInstance().decorate();
128 UserManagerTutorial: UserManagerTutorial