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

Side by Side Diff: chrome/browser/resources/shared/js/cr/ui/overlay.js

Issue 9844024: Set maxHeight of all overlay pages at startup and on resize (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file exists to share common overlay behaviors. 5 // This file exists to share common overlay behaviors.
6 6
7 cr.define('cr.ui.overlay', function() { 7 cr.define('cr.ui.overlay', function() {
8 8
9 /** 9 /**
10 * Gets the top, visible overlay. It makes the assumption that if multiple 10 * Gets the top, visible overlay. It makes the assumption that if multiple
(...skipping 27 matching lines...) Expand all
38 document.addEventListener('keydown', function(e) { 38 document.addEventListener('keydown', function(e) {
39 if (e.keyCode == 27) { // Escape 39 if (e.keyCode == 27) { // Escape
40 var overlay = getTopOverlay(); 40 var overlay = getTopOverlay();
41 if (!overlay) 41 if (!overlay)
42 return; 42 return;
43 43
44 cr.dispatchSimpleEvent(overlay, 'cancelOverlay'); 44 cr.dispatchSimpleEvent(overlay, 'cancelOverlay');
45 } 45 }
46 }); 46 });
47 47
48 window.addEventListener('resize', function() { 48 window.addEventListener('resize', setMaxHeightAllPages);
49 var overlay = getTopOverlay();
50 var page = overlay ? overlay.querySelector('.page:not([hidden])') : null;
51 if (!page)
52 return;
53 49
54 page.style.maxHeight = Math.min(0.9 * window.innerHeight, 640) + 'px'; 50 setMaxHeightAllPages();
55 });
56 } 51 }
57 52
58 /** 53 /**
54 * Sets the max-height of all pages in all overlays, based on the window
55 * height.
56 */
57 function setMaxHeightAllPages() {
58 var pages = document.querySelectorAll('.overlay .page');
59
60 var maxHeight = Math.min(0.9 * window.innerHeight, 640) + 'px';
61 for (var i = 0; i < pages.length; i++)
62 pages[i].style.maxHeight = maxHeight;
63 }
64
65 /**
59 * Adds behavioral hooks for the given overlay. 66 * Adds behavioral hooks for the given overlay.
60 * @param {HTMLElement} overlay The .overlay. 67 * @param {HTMLElement} overlay The .overlay.
61 */ 68 */
62 function setupOverlay(overlay) { 69 function setupOverlay(overlay) {
63 // Close the overlay on clicking any of the pages' close buttons. 70 // Close the overlay on clicking any of the pages' close buttons.
64 var closeButtons = overlay.querySelectorAll('.page > .close-button'); 71 var closeButtons = overlay.querySelectorAll('.page > .close-button');
65 for (var i = 0; i < closeButtons.length; i++) { 72 for (var i = 0; i < closeButtons.length; i++) {
66 closeButtons[i].addEventListener('click', function(e) { 73 closeButtons[i].addEventListener('click', function(e) {
67 cr.dispatchSimpleEvent(overlay, 'cancelOverlay'); 74 cr.dispatchSimpleEvent(overlay, 'cancelOverlay');
68 }); 75 });
(...skipping 28 matching lines...) Expand all
97 } 104 }
98 105
99 return { 106 return {
100 globalInitialization: globalInitialization, 107 globalInitialization: globalInitialization,
101 setupOverlay: setupOverlay, 108 setupOverlay: setupOverlay,
102 }; 109 };
103 }); 110 });
104 111
105 document.addEventListener('DOMContentLoaded', 112 document.addEventListener('DOMContentLoaded',
106 cr.ui.overlay.globalInitialization); 113 cr.ui.overlay.globalInitialization);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698