Index: remoting/webapp/butter_bar.js |
diff --git a/remoting/webapp/butter_bar.js b/remoting/webapp/butter_bar.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cb16420d880c3b6edb375d8d09bc1e13e8d434ae |
--- /dev/null |
+++ b/remoting/webapp/butter_bar.js |
@@ -0,0 +1,130 @@ |
+// 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 |
+ * Functions and event handlers to invite the user to participate in a survey |
+ * to help improve the product. |
Jamie
2013/05/23 20:31:46
Is this comment still correct?
Sergey Ulanov
2013/05/29 23:36:11
Done.
|
+ */ |
+ |
+'use strict'; |
+ |
+/** @suppress {duplicate} */ |
+var remoting = remoting || {}; |
+ |
+var kButterBarId = 'butter-bar'; |
+ |
+var kSurveyInvitationId = 'survey-invitation'; |
+var kSurveyAcceptId = 'survey-accept'; |
+var kSurveyDismissId = 'survey-dismiss'; |
+ |
+var kHangoutsInvitationId = 'hangouts-invitation'; |
+var kHangoutsAcceptId = 'hangouts-accept'; |
+var kHangoutsDismissId = 'hangouts-dismiss'; |
+ |
+var kSurveyStorageKey = 'feedback-survey-dismissed'; |
+var kHangoutsStorageKey = 'hangouts-notice-dismissed'; |
Jamie
2013/05/23 20:31:46
I realize this was my error originally, but by dec
Sergey Ulanov
2013/05/29 23:36:11
Done.
|
+ |
+/** @enum {number} */ |
+remoting.ButterBarMode = { |
+ NONE: 0, |
+ SURVEY: 1, |
+ HANGOUTS: 2 |
+}; |
+ |
+/** |
+ * Hide the survey request and record some basic information about the current |
Jamie
2013/05/23 20:31:46
s/survey request/butter-bar/ (and similar elsewher
Sergey Ulanov
2013/05/29 23:36:11
Done.
|
+ * 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 {string} storageKey Storage key used to store dismissal state. |
+ * @param {boolean} optIn True if the user clicked the "Take the survey" link; |
+ * false if they clicked the close icon. |
Jamie
2013/05/23 20:31:46
|optIn| doesn't really make sense as a parameter n
Sergey Ulanov
2013/05/29 23:36:11
Done. Also changed the key that we use to store th
Jamie
2013/05/30 01:10:16
It will mean that users who have previously dismis
Sergey Ulanov
2013/05/30 22:04:54
No, the value is not actually used in any way. We
Jamie
2013/05/31 00:12:41
Ah yes, good point. Still, if we ever want to make
Sergey Ulanov
2013/06/03 19:11:48
Ok, renamed it back to optIn.
|
+ */ |
+remoting.dismissButterBar = function(storageKey, optIn) { |
+ var value = {}; |
+ value[storageKey] = { |
+ optIn: optIn, |
+ date: new Date(), |
+ version: chrome.runtime.getManifest().version |
+ }; |
+ chrome.storage.sync.set(value); |
+ |
+ remoting.showButterBar(remoting.ButterBarMode.NONE); |
+}; |
+ |
+/** |
+ * Show the butter bar if there is a message to show. |
+ */ |
+remoting.initButterBar = function() { |
+ document.getElementById(kHangoutsAcceptId).addEventListener( |
+ 'click', remoting.dismissButterBar.bind(null, kHangoutsStorageKey, true), |
+ false); |
+ document.getElementById(kHangoutsDismissId).addEventListener( |
+ 'click', remoting.dismissButterBar.bind(null, kHangoutsStorageKey, false), |
+ false); |
+ |
+ document.getElementById(kSurveyAcceptId).addEventListener( |
+ 'click', remoting.dismissButterBar.bind(null, kSurveyStorageKey, true), |
+ false); |
+ document.getElementById(kSurveyDismissId).addEventListener( |
+ 'click', remoting.dismissButterBar.bind(null, kSurveyStorageKey, false), |
+ false); |
Jamie
2013/05/23 20:31:46
It's a shame to duplicate the action elements and
Sergey Ulanov
2013/05/29 23:36:11
Done.
|
+ |
+ /** @param {boolean} surveyDismissed |
+ * @param {boolean} hangoutsDismissed |
+ * @param {boolean} it2meExpanded */ |
+ var onStateLoaded = function(surveyDismissed, hangoutsDismissed, |
+ it2meExpanded) { |
+ var showSurvey = !surveyDismissed; |
+ var showHangouts = it2meExpanded && !hangoutsDismissed; |
+ if (showSurvey && !showHangouts) { |
+ remoting.showButterBar(remoting.ButterBarMode.SURVEY); |
+ } else if (showHangouts && !showSurvey) { |
+ remoting.showButterBar(remoting.ButterBarMode.HANGOUTS); |
+ } else if (showSurvey && showHangouts) { |
+ if (Math.random() > 0.5) { |
+ remoting.showButterBar(remoting.ButterBarMode.SURVEY); |
+ } else { |
+ remoting.showButterBar(remoting.ButterBarMode.HANGOUTS); |
+ } |
+ } |
+ }; |
+ /** @param {Object} value */ |
+ var onSyncDataLoaded = function(value) { |
+ /** @type {boolean} */ |
+ var surveyDismissed = !!value[kSurveyStorageKey]; |
+ /** @type {boolean} */ |
+ var hangoutsDismissed = !!value[kHangoutsStorageKey]; |
+ chrome.storage.local.get(remoting.kIT2MeVisitedStorageKey, function(value) { |
Jamie
2013/05/23 20:31:46
Optional: I'm not a big fan of anonymous functions
Sergey Ulanov
2013/05/29 23:36:11
Done
|
+ /** @type {boolean} */ |
+ var it2meExpanded = !!value[remoting.kIT2MeVisitedStorageKey]; |
+ onStateLoaded(surveyDismissed, hangoutsDismissed, it2meExpanded); |
+ }); |
+ }; |
+ chrome.storage.sync.get( |
+ [kSurveyStorageKey, kHangoutsStorageKey], onSyncDataLoaded); |
+} |
+ |
+/** |
+ * Shows butter bar in the specified |mode|. |
+ * |
+ * @param {remoting.ButterBarMode} mode |
+ */ |
+remoting.showButterBar = function(mode) { |
+ if (mode == remoting.ButterBarMode.NONE) { |
+ document.getElementById(kButterBarId).hidden = true; |
+ return; |
+ } |
+ |
+ document.getElementById(kButterBarId).hidden = false; |
+ if (mode == remoting.ButterBarMode.SURVEY) { |
+ document.getElementById(kSurveyInvitationId).hidden = false; |
+ document.getElementById(kHangoutsInvitationId).hidden = true; |
+ } else { |
+ document.getElementById(kSurveyInvitationId).hidden = true; |
+ document.getElementById(kHangoutsInvitationId).hidden = false; |
+ } |
Jamie
2013/05/23 20:31:46
This can be more simply expressed as three express
Sergey Ulanov
2013/05/29 23:36:11
Removed most of this code.
|
+}; |