1 // Copyright 2013 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.
7 * ButterBar class that is used to show the butter bar with various
13 /** @suppress {duplicate} */
14 var remoting = remoting || {};
19 remoting.ButterBar = function() {
20 this.storageKey_ = '';
22 chrome.storage.sync.get(
23 [remoting.ButterBar.kSurveyStorageKey_],
24 this.onStateLoaded_.bind(this));
28 * Shows butter bar with the specified |message| and updates |storageKey| after
29 * the bar is dismissed.
31 * @param {string} messageId
32 * @param {string|Array} substitutions
33 * @param {string} storageKey
36 remoting.ButterBar.prototype.show_ =
37 function(messageId, substitutions, storageKey) {
38 this.storageKey_ = storageKey;
40 var messageElement = document.getElementById(remoting.ButterBar.kMessageId_);
41 l10n.localizeElementFromTag(messageElement, messageId, substitutions, true);
43 /** @type{Element} */ (messageElement.getElementsByTagName('a')[0]);
44 acceptLink.addEventListener(
45 'click', this.dismiss.bind(this, true), false);
47 document.getElementById(remoting.ButterBar.kDismissId_).addEventListener(
48 'click', this.dismiss.bind(this, false), false);
50 document.getElementById(remoting.ButterBar.kId_).hidden = false;
54 * @param {Object} syncValues
57 remoting.ButterBar.prototype.onStateLoaded_ = function(syncValues) {
58 /** @type {boolean} */
59 var surveyDismissed = !!syncValues[remoting.ButterBar.kSurveyStorageKey_];
61 if (!surveyDismissed) {
62 this.show_(/*i18n-content*/'SURVEY_INVITATION',
63 ['<a href="http://goo.gl/njH2q" target="_blank">', '</a>'],
64 remoting.ButterBar.kSurveyStorageKey_);
68 /** @const @private */
69 remoting.ButterBar.kId_ = 'butter-bar';
71 /** @const @private */
72 remoting.ButterBar.kMessageId_ = 'butter-bar-message';
73 /** @const @private */
74 remoting.ButterBar.kDismissId_ = 'butter-bar-dismiss';
76 /** @const @private */
77 remoting.ButterBar.kSurveyStorageKey_ = 'feedback-survey-dismissed';
80 * Hide the butter bar request and record some basic information about the
81 * current state of the world in synced storage. This may be useful in the
82 * future if we want to show the request again. At the moment, the data itself
83 * is ignored; only its presence or absence is important.
85 * @param {boolean} accepted True if the user clicked the "accept" link;
86 * false if they clicked the close icon.
88 remoting.ButterBar.prototype.dismiss = function(accepted) {
90 value[this.storageKey_] = {
93 version: chrome.runtime.getManifest().version
95 chrome.storage.sync.set(value);
97 document.getElementById(remoting.ButterBar.kId_).hidden = true;