| OLD | NEW |
| 1 (function() { | 1 (function() { |
| 2 | 2 |
| 3 var IOS = navigator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/); | 3 var IOS = navigator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/); |
| 4 var IOS_TOUCH_SCROLLING = IOS && IOS[1] >= 8; | 4 var IOS_TOUCH_SCROLLING = IOS && IOS[1] >= 8; |
| 5 var DEFAULT_PHYSICAL_COUNT = 3; | 5 var DEFAULT_PHYSICAL_COUNT = 3; |
| 6 var HIDDEN_Y = '-10000px'; | 6 var HIDDEN_Y = '-10000px'; |
| 7 var ITEM_WIDTH = 0; | 7 var ITEM_WIDTH = 0; |
| 8 var ITEM_HEIGHT = 1; | 8 var ITEM_HEIGHT = 1; |
| 9 var SECRET_TABINDEX = -100; | 9 var SECRET_TABINDEX = -100; |
| 10 | 10 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 * This value can be computed using the position returned by `getBoundingC
lientRect()` | 119 * This value can be computed using the position returned by `getBoundingC
lientRect()` |
| 120 * although it's preferred to use a constant value when possible. | 120 * although it's preferred to use a constant value when possible. |
| 121 * | 121 * |
| 122 * This property is useful when an external scrolling element is used and
there's | 122 * This property is useful when an external scrolling element is used and
there's |
| 123 * some offset between the scrolling element and the list. | 123 * some offset between the scrolling element and the list. |
| 124 * For example: a header is placed above the list. | 124 * For example: a header is placed above the list. |
| 125 */ | 125 */ |
| 126 scrollOffset: { | 126 scrollOffset: { |
| 127 type: Number, | 127 type: Number, |
| 128 value: 0 | 128 value: 0 |
| 129 }, |
| 130 |
| 131 /** |
| 132 * If set to true, focus on an element will be preserved after rerender. |
| 133 */ |
| 134 preserveFocus: { |
| 135 type: Boolean, |
| 136 value: false |
| 129 } | 137 } |
| 130 }, | 138 }, |
| 131 | 139 |
| 132 observers: [ | 140 observers: [ |
| 133 '_itemsChanged(items.*)', | 141 '_itemsChanged(items.*)', |
| 134 '_selectionEnabledChanged(selectionEnabled)', | 142 '_selectionEnabledChanged(selectionEnabled)', |
| 135 '_multiSelectionChanged(multiSelection)', | 143 '_multiSelectionChanged(multiSelection)', |
| 136 '_setOverflow(scrollTarget, scrollOffset)' | 144 '_setOverflow(scrollTarget, scrollOffset)' |
| 137 ], | 145 ], |
| 138 | 146 |
| (...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 } | 896 } |
| 889 el._templateInstance[this.as] = value; | 897 el._templateInstance[this.as] = value; |
| 890 } | 898 } |
| 891 }, | 899 }, |
| 892 | 900 |
| 893 /** | 901 /** |
| 894 * Called when the items have changed. That is, ressignments | 902 * Called when the items have changed. That is, ressignments |
| 895 * to `items`, splices or updates to a single item. | 903 * to `items`, splices or updates to a single item. |
| 896 */ | 904 */ |
| 897 _itemsChanged: function(change) { | 905 _itemsChanged: function(change) { |
| 906 var rendering = /^items(\.splices){0,1}$/.test(change.path); |
| 907 var lastFocusedIndex, focusedElement; |
| 908 if (rendering && this.preserveFocus) { |
| 909 lastFocusedIndex = this._focusedIndex; |
| 910 focusedElement = this.querySelector('* /deep/ *:focus'); |
| 911 } |
| 912 |
| 913 var preservingFocus = rendering && this.preserveFocus && focusedElement; |
| 914 |
| 898 if (change.path === 'items') { | 915 if (change.path === 'items') { |
| 899 this._virtualStart = 0; | 916 this._virtualStart = 0; |
| 900 this._physicalTop = 0; | 917 this._physicalTop = 0; |
| 901 this._virtualCount = this.items ? this.items.length : 0; | 918 this._virtualCount = this.items ? this.items.length : 0; |
| 902 this._collection = this.items ? Polymer.Collection.get(this.items) : nul
l; | 919 this._collection = this.items ? Polymer.Collection.get(this.items) : nul
l; |
| 903 this._physicalIndexForKey = {}; | 920 this._physicalIndexForKey = {}; |
| 904 this._firstVisibleIndexVal = null; | 921 this._firstVisibleIndexVal = null; |
| 905 this._lastVisibleIndexVal = null; | 922 this._lastVisibleIndexVal = null; |
| 906 this._physicalCount = this._physicalCount || 0; | 923 this._physicalCount = this._physicalCount || 0; |
| 907 this._physicalItems = this._physicalItems || []; | 924 this._physicalItems = this._physicalItems || []; |
| 908 this._physicalSizes = this._physicalSizes || []; | 925 this._physicalSizes = this._physicalSizes || []; |
| 909 this._physicalStart = 0; | 926 this._physicalStart = 0; |
| 910 if (this._scrollTop > this._scrollOffset) { | 927 if (this._scrollTop > this._scrollOffset && !preservingFocus) { |
| 911 this._resetScrollPosition(0); | 928 this._resetScrollPosition(0); |
| 912 } | 929 } |
| 913 this._removeFocusedItem(); | 930 this._removeFocusedItem(); |
| 914 this._debounceTemplate(this._render); | 931 this._debounceTemplate(this._render); |
| 915 | |
| 916 } else if (change.path === 'items.splices') { | 932 } else if (change.path === 'items.splices') { |
| 917 this._adjustVirtualIndex(change.value.indexSplices); | 933 this._adjustVirtualIndex(change.value.indexSplices); |
| 918 this._virtualCount = this.items ? this.items.length : 0; | 934 this._virtualCount = this.items ? this.items.length : 0; |
| 919 | 935 |
| 920 this._debounceTemplate(this._render); | 936 this._debounceTemplate(this._render); |
| 921 } else { | 937 } else { |
| 922 this._forwardItemPath(change.path.split('.').slice(1).join('.'), change.
value); | 938 this._forwardItemPath(change.path.split('.').slice(1).join('.'), change.
value); |
| 923 } | 939 } |
| 940 |
| 941 // If the list was in focus when updated, preserve the focus on item. |
| 942 if (preservingFocus) { |
| 943 Polymer.dom.flush(); |
| 944 focusedElement.blur(); // paper- elements breaks when focused twice. |
| 945 this._focusPhysicalItem( |
| 946 Math.min(this.items.length - 1, lastFocusedIndex)); |
| 947 if (!this._isIndexVisible(this._focusedIndex)) { |
| 948 this.scrollToIndex(this._focusedIndex); |
| 949 } |
| 950 } |
| 924 }, | 951 }, |
| 925 | 952 |
| 926 /** | 953 /** |
| 927 * @param {!Array<!PolymerSplice>} splices | 954 * @param {!Array<!PolymerSplice>} splices |
| 928 */ | 955 */ |
| 929 _adjustVirtualIndex: function(splices) { | 956 _adjustVirtualIndex: function(splices) { |
| 930 splices.forEach(function(splice) { | 957 splices.forEach(function(splice) { |
| 931 // deselect removed items | 958 // deselect removed items |
| 932 splice.removed.forEach(this._removeItem, this); | 959 splice.removed.forEach(this._removeItem, this); |
| 933 // We only need to care about changes happening above the current positi
on | 960 // We only need to care about changes happening above the current positi
on |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1605 this._focusPhysicalItem(this._focusedIndex + 1); | 1632 this._focusPhysicalItem(this._focusedIndex + 1); |
| 1606 }, | 1633 }, |
| 1607 | 1634 |
| 1608 _didEnter: function(e) { | 1635 _didEnter: function(e) { |
| 1609 this._focusPhysicalItem(this._focusedIndex); | 1636 this._focusPhysicalItem(this._focusedIndex); |
| 1610 this._selectionHandler(e.detail.keyboardEvent); | 1637 this._selectionHandler(e.detail.keyboardEvent); |
| 1611 } | 1638 } |
| 1612 }); | 1639 }); |
| 1613 | 1640 |
| 1614 })(); | 1641 })(); |
| OLD | NEW |