| OLD | NEW |
| 1 /** | 1 /** |
| 2 * `Polymer.IronScrollTargetBehavior` allows an element to respond to scroll e
vents from a | 2 * `Polymer.IronScrollTargetBehavior` allows an element to respond to scroll e
vents from a |
| 3 * designated scroll target. | 3 * designated scroll target. |
| 4 * | 4 * |
| 5 * Elements that consume this behavior can override the `_scrollHandler` | 5 * Elements that consume this behavior can override the `_scrollHandler` |
| 6 * method to add logic on the scroll event. | 6 * method to add logic on the scroll event. |
| 7 * | 7 * |
| 8 * @demo demo/scrolling-region.html Scrolling Region | 8 * @demo demo/scrolling-region.html Scrolling Region |
| 9 * @demo demo/document.html Document Element | 9 * @demo demo/document.html Document Element |
| 10 * @polymerBehavior | 10 * @polymerBehavior |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 window.removeEventListener('scroll', this._boundScrollHandler); | 55 window.removeEventListener('scroll', this._boundScrollHandler); |
| 56 } else if (this._oldScrollTarget.removeEventListener) { | 56 } else if (this._oldScrollTarget.removeEventListener) { |
| 57 this._oldScrollTarget.removeEventListener('scroll', this._boundScrollH
andler); | 57 this._oldScrollTarget.removeEventListener('scroll', this._boundScrollH
andler); |
| 58 } | 58 } |
| 59 this._oldScrollTarget = null; | 59 this._oldScrollTarget = null; |
| 60 } | 60 } |
| 61 if (isAttached) { | 61 if (isAttached) { |
| 62 // Support element id references | 62 // Support element id references |
| 63 if (typeof scrollTarget === 'string') { | 63 if (typeof scrollTarget === 'string') { |
| 64 | 64 |
| 65 var ownerRoot = Polymer.dom(this).getOwnerRoot(); | 65 var host = this.domHost; |
| 66 this.scrollTarget = (ownerRoot && ownerRoot.$) ? | 66 this.scrollTarget = host && host.$ ? host.$[scrollTarget] : |
| 67 ownerRoot.$[scrollTarget] : Polymer.dom(this.ownerDocument).queryS
elector('#' + scrollTarget); | 67 Polymer.dom(this.ownerDocument).querySelector('#' + scrollTarget); |
| 68 | 68 |
| 69 } else if (this._scrollHandler) { | 69 } else if (this._scrollHandler) { |
| 70 | 70 |
| 71 this._boundScrollHandler = this._boundScrollHandler || this._scrollHan
dler.bind(this); | 71 this._boundScrollHandler = this._boundScrollHandler || this._scrollHan
dler.bind(this); |
| 72 // Add a new listener | 72 // Add a new listener |
| 73 if (scrollTarget === this._doc) { | 73 if (scrollTarget === this._doc) { |
| 74 window.addEventListener('scroll', this._boundScrollHandler); | 74 window.addEventListener('scroll', this._boundScrollHandler); |
| 75 if (this._scrollTop !== 0 || this._scrollLeft !== 0) { | 75 if (this._scrollTop !== 0 || this._scrollLeft !== 0) { |
| 76 this._scrollHandler(); | 76 this._scrollHandler(); |
| 77 } | 77 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 window.scrollTo(left, window.pageYOffset); | 156 window.scrollTo(left, window.pageYOffset); |
| 157 } else if (this._isValidScrollTarget()) { | 157 } else if (this._isValidScrollTarget()) { |
| 158 this.scrollTarget.scrollLeft = left; | 158 this.scrollTarget.scrollLeft = left; |
| 159 } | 159 } |
| 160 }, | 160 }, |
| 161 | 161 |
| 162 /** | 162 /** |
| 163 * Scrolls the content to a particular place. | 163 * Scrolls the content to a particular place. |
| 164 * | 164 * |
| 165 * @method scroll | 165 * @method scroll |
| 166 * @param {number} left The left position |
| 166 * @param {number} top The top position | 167 * @param {number} top The top position |
| 167 * @param {number} left The left position | |
| 168 */ | 168 */ |
| 169 scroll: function(top, left) { | 169 scroll: function(left, top) { |
| 170 if (this.scrollTarget === this._doc) { | 170 if (this.scrollTarget === this._doc) { |
| 171 window.scrollTo(top, left); | 171 window.scrollTo(left, top); |
| 172 } else if (this._isValidScrollTarget()) { | 172 } else if (this._isValidScrollTarget()) { |
| 173 this.scrollTarget.scrollLeft = left; |
| 173 this.scrollTarget.scrollTop = top; | 174 this.scrollTarget.scrollTop = top; |
| 174 this.scrollTarget.scrollLeft = left; | |
| 175 } | 175 } |
| 176 }, | 176 }, |
| 177 | 177 |
| 178 /** | 178 /** |
| 179 * Gets the width of the scroll target. | 179 * Gets the width of the scroll target. |
| 180 * | 180 * |
| 181 * @type {number} | 181 * @type {number} |
| 182 */ | 182 */ |
| 183 get _scrollTargetWidth() { | 183 get _scrollTargetWidth() { |
| 184 if (this._isValidScrollTarget()) { | 184 if (this._isValidScrollTarget()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 201 | 201 |
| 202 /** | 202 /** |
| 203 * Returns true if the scroll target is a valid HTMLElement. | 203 * Returns true if the scroll target is a valid HTMLElement. |
| 204 * | 204 * |
| 205 * @return {boolean} | 205 * @return {boolean} |
| 206 */ | 206 */ |
| 207 _isValidScrollTarget: function() { | 207 _isValidScrollTarget: function() { |
| 208 return this.scrollTarget instanceof HTMLElement; | 208 return this.scrollTarget instanceof HTMLElement; |
| 209 } | 209 } |
| 210 }; | 210 }; |
| OLD | NEW |