Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1967)

Unified Diff: chrome/browser/resources/contextual_search/promo.js

Issue 1133403004: Revert of [Contextual Search] Remove opt-in code. (patchset #6 id:100001 of https://codereview.chro… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2403
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/contextual_search/promo.js
diff --git a/chrome/browser/resources/contextual_search/promo.js b/chrome/browser/resources/contextual_search/promo.js
new file mode 100644
index 0000000000000000000000000000000000000000..8e17d909aeaecacca5bab9ebfd93017d60a204dd
--- /dev/null
+++ b/chrome/browser/resources/contextual_search/promo.js
@@ -0,0 +1,58 @@
+/* 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.
+*/
+
+<include src="../../../../ui/webui/resources/js/util.js">
+<include src="../../../../ui/webui/resources/js/load_time_data.js">
+
+/**
+ * The amount of delay to use in the opt-in action in order to give time for
+ * the fade-out animation to execute, before navigating to the opt-in URL,
+ * in milliseconds.
+ * @const
+ */
+var OPT_IN_DELAY_MS = 65;
+
+/**
+ * Once the DOM is loaded, determine if the header image is to be kept and
+ * register a handler to add the 'hide' class to the container element in order
+ * to hide it.
+ */
+document.addEventListener('DOMContentLoaded', function(event) {
+ if (config['hideHeader']) {
+ removeHeaderImages();
+ }
+ $('optin-button').addEventListener('click', function() {
+ $('container').classList.add('hide');
+ setTimeout(function() {
+ location.hash = 'optin';
+ }, OPT_IN_DELAY_MS);
+ });
+ $('optout-button').addEventListener('click', function() {
+ location.hash = 'optout';
+ });
+});
+
+/**
+ * Returns the height of the content. Method called from Chrome to properly size
+ * the view embedding it.
+ * @return {number} The height of the content, in pixels.
+ */
+function getContentHeight() {
+ return $('container').clientHeight;
+}
+
+/**
+ * Removes all header images from the promo.
+ */
+function removeHeaderImages() {
+ var images = document.querySelectorAll('.header-image');
+ for (var i = 0, length = images.length; i < length; i++) {
+ var image = images[i];
+ var parent = image.parentElement;
+ if (parent) {
+ parent.removeChild(image);
+ }
+ }
+}
« no previous file with comments | « chrome/browser/resources/contextual_search/promo.html ('k') | chrome/browser/search/contextual_search_promo_source_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698