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 2013 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.
/**
* @fileoverview
* ButterBar class that is used to show the butter bar with various
* notifications.
*/
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
/**
* @constructor
*/
remoting.ButterBar = function() {
this.storageKey_ = '';
/** @type{remoting.ButterBar} */
var that = this;
/** @param {Object} syncValues */
var onSyncDataLoaded = function(syncValues) {
chrome.storage.local.get(
remoting.kIT2MeVisitedStorageKey,
that.onStateLoaded_.bind(that, syncValues));
};
chrome.storage.sync.get(
[remoting.ButterBar.kSurveyStorageKey_,
remoting.ButterBar.kHangoutsStorageKey_],
onSyncDataLoaded);
}
/**
* Shows butter bar with the specified |message| and updates |storageKey| after
* the bar is dismissed.
*
* @param {string} messageId
* @param {string|Array} substitutions
* @param {string} storageKey
* @private
*/
remoting.ButterBar.prototype.show_ =
function(messageId, substitutions, storageKey) {
this.storageKey_ = storageKey;
var messageElement = document.getElementById(remoting.ButterBar.kMessageId_);
l10n.localizeElementFromTag(messageElement, messageId, substitutions, true);
var acceptLink =
/** @type{Element} */ messageElement.getElementsByTagName('a')[0];
acceptLink.addEventListener(
'click', this.dismiss.bind(this, true), false);
document.getElementById(remoting.ButterBar.kDismissId_).addEventListener(
'click', this.dismiss.bind(this, false), false);
document.getElementById(remoting.ButterBar.kId_).hidden = false;
}
/**
* @param {Object} syncValues
* @param {Object} localValues
* @private
*/
remoting.ButterBar.prototype.onStateLoaded_ =
function(syncValues, localValues) {
/** @type {boolean} */
var surveyDismissed = !!syncValues[remoting.ButterBar.kSurveyStorageKey_];
/** @type {boolean} */
var hangoutsDismissed =
!!syncValues[remoting.ButterBar.kHangoutsStorageKey_];
/** @type {boolean} */
var it2meExpanded = !!localValues[remoting.kIT2MeVisitedStorageKey];
var showSurvey = !surveyDismissed;
var showHangouts = it2meExpanded && !hangoutsDismissed;
// If both messages can be shown choose only one randomly.
if (showSurvey && showHangouts) {
if (Math.random() > 0.5) {
showSurvey = false;
} else {
showHangouts = false;
}
}
if (showSurvey) {
this.show_(/*i18n-content*/'SURVEY_INVITATION',
['<a href="http://goo.gl/njH2q" target="_blank">', '</a>'],
remoting.ButterBar.kSurveyStorageKey_);
} else if (showHangouts) {
this.show_(/*i18n-content*/'HANGOUTS_INVITATION',
['<a id="hangouts-accept" ' +
'href="https://plus.google.com/hangouts/_?gid=818572447316">',
'</a>'],
remoting.ButterBar.kHangoutsStorageKey_);
}
};
/** @const @private */
remoting.ButterBar.kId_ = 'butter-bar';
/** @const @private */
remoting.ButterBar.kMessageId_ = 'butter-bar-message';
/** @const @private */
remoting.ButterBar.kDismissId_ = 'butter-bar-dismiss';
/** @const @private */
remoting.ButterBar.kSurveyStorageKey_ = 'feedback-survey-dismissed';
/** @const @private */
remoting.ButterBar.kHangoutsStorageKey_ = 'hangouts-notice-dismissed';
/**
* Hide the butter bar request and record some basic information about the
* current state of the world in synced storage. This may be useful in the
* future if we want to show the request again. At the moment, the data itself
* is ignored; only its presence or absence is important.
*
* @param {boolean} accepted True if the user clicked the "accept" link;
* false if they clicked the close icon.
*/
remoting.ButterBar.prototype.dismiss = function(accepted) {
var value = {};
value[this.storageKey_] = {
optIn: accepted,
date: new Date(),
version: chrome.runtime.getManifest().version
};
chrome.storage.sync.set(value);
document.getElementById(remoting.ButterBar.kId_).hidden = true;
};
|