-
Notifications
You must be signed in to change notification settings - Fork 8
/
butter_bar.js
98 lines (82 loc) · 2.86 KB
/
butter_bar.js
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
// 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_ = '';
chrome.storage.sync.get(
[remoting.ButterBar.kSurveyStorageKey_],
this.onStateLoaded_.bind(this));
}
/**
* 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
* @private
*/
remoting.ButterBar.prototype.onStateLoaded_ = function(syncValues) {
/** @type {boolean} */
var surveyDismissed = !!syncValues[remoting.ButterBar.kSurveyStorageKey_];
if (!surveyDismissed) {
this.show_(/*i18n-content*/'SURVEY_INVITATION',
['<a href="http://goo.gl/njH2q" target="_blank">', '</a>'],
remoting.ButterBar.kSurveyStorageKey_);
}
};
/** @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';
/**
* 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;
};