OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 @license |
| 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS |
| 7 Code distributed by Google as part of the polymer project is also |
| 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS |
| 9 --> |
| 10 |
| 11 <script> |
| 12 function findElementInList(container, selector) { |
| 13 var i = 0; |
| 14 var children = container._children; |
| 15 var ms = Polymer.DomApi.matchesSelector; |
| 16 for (; i < children.length; i++) { |
| 17 if (children[i].nodeType === Node.ELEMENT_NODE && ms.call(children[i], sel
ector)) { |
| 18 return children[i]; |
| 19 } |
| 20 } |
| 21 return null; |
| 22 } |
| 23 |
| 24 function buildItem(index) { |
| 25 return { |
| 26 index: index |
| 27 }; |
| 28 } |
| 29 |
| 30 function buildDataSet(size) { |
| 31 var data = []; |
| 32 while (data.length < size) { |
| 33 data.push(buildItem(data.length)); |
| 34 } |
| 35 return data; |
| 36 } |
| 37 |
| 38 function simulateScroll(config, fn) { |
| 39 var list = config.list; |
| 40 var target = config.target; |
| 41 var delay = config.delay || 1; |
| 42 var contribution = config.contribution || 10; |
| 43 |
| 44 function scroll(dir, prevVal) { |
| 45 list.scrollTop = list.scrollTop + dir; |
| 46 if (list.scrollTop !== target && prevVal !== list.scrollTop) { |
| 47 setTimeout(scroll.bind(null, dir, list.scrollTop), delay); |
| 48 } else { |
| 49 setTimeout(fn.bind(null, list.scrollTop), 100); |
| 50 } |
| 51 } |
| 52 |
| 53 if (list.scrollTop < target) { |
| 54 scroll(Math.abs(contribution), -1); |
| 55 } else if (list.scrollTop > target) { |
| 56 scroll(-Math.abs(contribution), -1); |
| 57 } |
| 58 } |
| 59 |
| 60 function getFirstItemFromList(list) { |
| 61 var listRect = list.getBoundingClientRect(); |
| 62 return document.elementFromPoint(listRect.left + 1, listRect.top + 1); |
| 63 } |
| 64 |
| 65 function getLastItemFromList(list) { |
| 66 var listRect = list.getBoundingClientRect(); |
| 67 return document.elementFromPoint(listRect.left + 1, listRect.top + listRect.
height - 1); |
| 68 } |
| 69 </script> |
OLD | NEW |