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

Side by Side Diff: third_party/polymer/v1_0/components-chromium/app-layout/helpers/helpers-extracted.js

Issue 2074813002: Roll Polymer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: chromium.patch Created 4 years, 6 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
OLDNEW
1 Polymer.AppLayout = Polymer.AppLayout || {}; 1 Polymer.AppLayout = Polymer.AppLayout || {};
2 2
3 Polymer.AppLayout._scrollEffects = Polymer.AppLayout._scrollEffects || {}; 3 Polymer.AppLayout._scrollEffects = Polymer.AppLayout._scrollEffects || {};
4 4
5 Polymer.AppLayout.scrollTimingFunction = function easeOutQuad(t, b, c, d) { 5 Polymer.AppLayout.scrollTimingFunction = function easeOutQuad(t, b, c, d) {
6 t /= d; 6 t /= d;
7 return -c * t*(t-2) + b; 7 return -c * t*(t-2) + b;
8 }; 8 };
9 9
10 /** 10 /**
11 * Registers a scroll effect to be used in elements that implement the 11 * Registers a scroll effect to be used in elements that implement the
12 * `Polymer.AppScrollEffectsBehavior` behavior. 12 * `Polymer.AppScrollEffectsBehavior` behavior.
13 * 13 *
14 * @param {string} effectName The effect name. 14 * @param {string} effectName The effect name.
15 * @param {Object} effectDef The effect definition. 15 * @param {Object} effectDef The effect definition.
16 */ 16 */
17 Polymer.AppLayout.registerEffect = function registerEffect(effectName, effectD ef) { 17 Polymer.AppLayout.registerEffect = function registerEffect(effectName, effectD ef) {
18 if (Polymer.AppLayout._scrollEffects[effectName] != null) { 18 if (Polymer.AppLayout._scrollEffects[effectName] != null) {
19 throw new Error('effect `'+ effectName + '` is already registered.'); 19 throw new Error('effect `'+ effectName + '` is already registered.');
20 } 20 }
21 Polymer.AppLayout._scrollEffects[effectName] = effectDef; 21 Polymer.AppLayout._scrollEffects[effectName] = effectDef;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 } else { 66 } else {
67 67
68 var timingFn = Polymer.AppLayout.scrollTimingFunction; 68 var timingFn = Polymer.AppLayout.scrollTimingFunction;
69 var startTime = Date.now(); 69 var startTime = Date.now();
70 var currentScrollTop = target === docEl ? window.pageYOffset : target.sc rollTop; 70 var currentScrollTop = target === docEl ? window.pageYOffset : target.sc rollTop;
71 var currentScrollLeft = target === docEl ? window.pageXOffset : target.s crollLeft; 71 var currentScrollLeft = target === docEl ? window.pageXOffset : target.s crollLeft;
72 var deltaScrollTop = scrollTop - currentScrollTop; 72 var deltaScrollTop = scrollTop - currentScrollTop;
73 var deltaScrollLeft = scrollLeft - currentScrollLeft; 73 var deltaScrollLeft = scrollLeft - currentScrollLeft;
74 var duration = 300; 74 var duration = 300;
75 75 var updateFrame = (function updateFrame() {
76 (function updateFrame() {
77 var now = Date.now(); 76 var now = Date.now();
78 var elapsedTime = now - startTime; 77 var elapsedTime = now - startTime;
79 78
80 if (elapsedTime < duration) { 79 if (elapsedTime < duration) {
81 scrollTo( 80 scrollTo(timingFn(elapsedTime, currentScrollLeft, deltaScrollLeft, d uration),
82 timingFn(elapsedTime, currentScrollLeft, deltaScrollLeft, durati on), 81 timingFn(elapsedTime, currentScrollTop, deltaScrollTop, duration ));
83 timingFn(elapsedTime, currentScrollTop, deltaScrollTop, duration ) 82 requestAnimationFrame(updateFrame);
84 ); 83 } else {
85 requestAnimationFrame(updateFrame.bind(this)); 84 scrollTo(scrollLeft, scrollTop);
86 } 85 }
87 }).call(this); 86 }).bind(this);
87
88 updateFrame();
88 } 89 }
89 90
90 } else if (options.behavior === 'silent') { 91 } else if (options.behavior === 'silent') {
91 92
92 docEl.classList.add(scrollClassName); 93 docEl.classList.add(scrollClassName);
93 94
94 // Browsers keep the scroll momentum even if the bottom of the scrolling c ontent 95 // Browsers keep the scroll momentum even if the bottom of the scrolling c ontent
95 // was reached. This means that calling scroll({top: 0, behavior: 'silent' }) when 96 // was reached. This means that calling scroll({top: 0, behavior: 'silent' }) when
96 // the momentum is still going will result in more scroll events and thus scroll effects. 97 // the momentum is still going will result in more scroll events and thus scroll effects.
97 // This seems to only apply when using document scrolling. 98 // This seems to only apply when using document scrolling.
98 // Therefore, when should we remove the class from the document element? 99 // Therefore, when should we remove the class from the document element?
99 100
100 clearInterval(Polymer.AppLayout._scrollTimer); 101 clearInterval(Polymer.AppLayout._scrollTimer);
101 102
102 Polymer.AppLayout._scrollTimer = setTimeout(function() { 103 Polymer.AppLayout._scrollTimer = setTimeout(function() {
103 docEl.classList.remove(scrollClassName); 104 docEl.classList.remove(scrollClassName);
104 Polymer.AppLayout._scrollTimer = null; 105 Polymer.AppLayout._scrollTimer = null;
105 }, 100); 106 }, 100);
106 107
107 scrollTo(scrollLeft, scrollTop); 108 scrollTo(scrollLeft, scrollTop);
108 109
109 } else { 110 } else {
110 111
111 scrollTo(scrollLeft, scrollTop); 112 scrollTo(scrollLeft, scrollTop);
112 113
113 } 114 }
114 }; 115 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698