1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('cr.ui.login', function() {
/**
* Constructs a slide manager for the user manager tutorial.
*
* @constructor
*/
function UserManagerTutorial() {
}
cr.addSingletonGetter(UserManagerTutorial);
UserManagerTutorial.prototype = {
/**
* Tutorial slides.
*/
slides_: ['slide-your-chrome',
'slide-friends',
'slide-guests',
'slide-complete',
'slide-not-you'],
/**
* Current tutorial step, index in the slides array.
* @type {number}
*/
currentStep_: 0,
/**
* Switches to the next tutorial step.
* @param {number} nextStepIndex Index of the next step.
*/
toggleStep_: function(nextStepIndex) {
if (nextStepIndex > this.slides_.length)
return;
var currentStepId = this.slides_[this.currentStep_];
var nextStepId = this.slides_[nextStepIndex];
var oldStep = $(currentStepId);
var newStep = $(nextStepId);
newStep.classList.remove('hidden');
if (nextStepIndex != this.currentStep_)
oldStep.classList.add('hidden');
this.currentStep_ = nextStepIndex;
// The last tutorial step is an information bubble that ends the tutorial.
if (this.currentStep_ == this.slides_.length - 1)
this.endTutorial_();
},
next_: function() {
var nextStep = this.currentStep_ + 1;
this.toggleStep_(nextStep);
},
skip_: function() {
this.endTutorial_();
$('user-manager-tutorial').hidden = true;
},
/**
* Add user button click handler.
* @private
*/
handleAddUserClick_: function(e) {
chrome.send('addUser');
$('user-manager-tutorial').hidden = true;
e.stopPropagation();
},
/**
* Add a button click handler to dismiss the last tutorial bubble.
* @private
*/
handleDismissBubbleClick_: function(e) {
$('user-manager-tutorial').hidden = true;
e.stopPropagation();
},
endTutorial_: function(e) {
$('inner-container').classList.remove('disabled');
},
decorate: function() {
// Transitions between the tutorial slides.
for (var i = 0; i < this.slides_.length; ++i) {
var buttonNext = $(this.slides_[i] + '-next');
var buttonSkip = $(this.slides_[i] + '-skip');
if (buttonNext)
buttonNext.addEventListener('click', this.next_.bind(this));
if (buttonSkip)
buttonSkip.addEventListener('click', this.skip_.bind(this));
}
$('slide-add-user').addEventListener('click',
this.handleAddUserClick_.bind(this));
$('dismiss-bubble-button').addEventListener('click',
this.handleDismissBubbleClick_.bind(this));
}
};
/**
* Initializes the tutorial manager.
*/
UserManagerTutorial.startTutorial = function() {
$('user-manager-tutorial').hidden = false;
// If there's only one pod, show the slides to the side of the pod.
// Otherwise, center the slides and disable interacting with the pods
// while the tutorial is showing.
if ($('pod-row').pods.length == 1) {
$('slide-your-chrome').classList.add('single-pod');
$('slide-complete').classList.add('single-pod');
}
$('pod-row').focusPod(); // No focused pods.
$('inner-container').classList.add('disabled');
};
/**
* Initializes the tutorial manager.
*/
UserManagerTutorial.initialize = function() {
UserManagerTutorial.getInstance().decorate();
};
// Export.
return {
UserManagerTutorial: UserManagerTutorial
};
});
|