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

Side by Side Diff: chrome/common/extensions/docs/static/js/scroll.js

Issue 102593005: Clean patch with DCC static content (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed tests for sidenav_data_source Created 7 years 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
OLDNEW
(Empty)
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.
4
5 // Scroll handling.
6 //
7 // Switches the sidebar between floating on the left and position:fixed
8 // depending on whether it's scrolled into view, and manages the scroll-to-top
9 // button: click logic, and when to show it.
10 (function() {
11
12 var sidebar = document.getElementById('gc-sidebar');
13 var scrollToTop = document.getElementById('scroll-to-top');
14 var offsetTop = sidebar.offsetTop;
15
16 function relayout() {
17 // Obviously, this code executes every time the window scrolls, so avoid
18 // putting things in here.
19 var isFloatingSidebar = sidebar.classList.contains('floating');
20 var isShowingScrollToTop = !scrollToTop.classList.contains('hidden');
21
22 var floatSidebar = false;
23 var showScrollToTop = false;
24
25 if (window.scrollY > offsetTop) {
26 // Scrolled past the top of the sidebar.
27 if (window.innerHeight >= sidebar.scrollHeight) {
28 // The whole sidebar fits in the window. Make it always visible.
29 floatSidebar = true;
30 } else {
31 // Whole sidebar doesn't fit, so show the scroll-to-top button instead.
32 showScrollToTop = true;
33 }
34 }
35
36 if (floatSidebar != isFloatingSidebar)
37 sidebar.classList.toggle('floating', floatSidebar);
38 if (isShowingScrollToTop != showScrollToTop)
39 scrollToTop.classList.toggle('hidden', !showScrollToTop);
40 }
41
42 window.addEventListener('scroll', relayout);
43 setTimeout(relayout, 0);
44
45 scrollToTop.addEventListener('click', function() {
46 window.scrollTo(0, 0);
47 });
48
49 }());
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/static/js/fatnav.js ('k') | chrome/common/extensions/docs/static/js/search.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698