Skip to content

Commit 16c38ce

Browse files
author
Jan Miksovsky
committed
Update components in preparation for 0.6.3 release
1 parent f98ee97 commit 16c38ce

File tree

2 files changed

+54
-31
lines changed

2 files changed

+54
-31
lines changed

basic-page-dots.html

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,30 +84,32 @@
8484
contribute: {
8585

8686
applySelection: function(item, selected) {
87+
var index = this.collective.indexOfItem(item);
88+
// See if the corresponding dot has already been created.
89+
// If not, the correct dot will be selected when it gets created.
8790
var dots = this.dots;
88-
if (dots && dots.length > 0) {
89-
var index = this.collective.indexOfItem(item);
91+
if (dots && dots.length > index) {
9092
var dot = this.dots[index];
9193
if (dot) {
9294
dot.classList.toggle('selected', selected);
9395
}
94-
} else {
95-
// HACK: Dots haven't been created yet, because binding hasn't updated.
96-
// Wait a tick and try again.
97-
var callee = arguments.callee;
98-
setTimeout(function() {
99-
callee.call(this, item, selected);
100-
}.bind(this));
10196
}
10297
},
10398

104-
// TODO: Move the requirement for a selction to basic-item-selection. This
105-
// should ideally pick the nearest item to the previously-selected item.
106-
// collectiveChanged: function() {
107-
// if (this.collective.selectedItem === null && this.collective.items != null && this.collective.selectFirst) {
108-
// this.collective.selectFirst();
109-
// }
110-
// },
99+
collectiveChanged: function() {
100+
// Apply any selection made before assimilation.
101+
if (this._prematureSelectedIndex
102+
&& 'selectedIndex' in this.collective
103+
&& this.collective.selectedIndex === -1) {
104+
this.collective.selectedIndex = this._prematureSelectedIndex;
105+
this._prematureSelectedIndex = null;
106+
}
107+
// TODO: Move the requirement for a selction to basic-item-selection. This
108+
// should ideally pick the nearest item to the previously-selected item.
109+
// if (this.collective.selectedItem === null && this.collective.items != null && this.collective.selectFirst) {
110+
// this.collective.selectFirst();
111+
// }
112+
},
111113

112114
// TODO: Seems like this ultimately belongs in Collective.
113115
itemsChanged: function() {
@@ -139,6 +141,18 @@
139141

140142
is: 'basic-page-dots',
141143

144+
properties: {
145+
146+
selectedIndex: {
147+
type: Number
148+
},
149+
150+
selectedItem: {
151+
type: Object
152+
}
153+
154+
},
155+
142156
ready: function() {
143157
this.$.dots.addEventListener('click', function(event) {
144158
this.dotClick(event);
@@ -153,10 +167,18 @@
153167
* @type Number
154168
*/
155169
get selectedIndex() {
156-
return this.collective.selectedIndex;
170+
// See note at basic-item-selection's selectedIndex getter.
171+
if (this._readied) {
172+
return this.collective.selectedIndex;
173+
}
157174
},
158175
set selectedIndex(index) {
159-
this.collective.selectedIndex = index;
176+
if ('selectedIndex' in this.collective) {
177+
this.collective.selectedIndex = index;
178+
} else {
179+
// Selection is being made before the collective supports it.
180+
this._prematureSelectedIndex = index;
181+
}
160182
},
161183

162184
/**
@@ -173,30 +195,31 @@
173195
},
174196

175197
_createDots: function(count) {
198+
var selectedIndex = this.selectedIndex;
176199
var dotContainer = this.$.dots;
177-
var existingDots = dotContainer.children;
178-
var existingDotCount = existingDots.length;
179-
if (count == existingDots.length) {
200+
var existingDotCount = dotContainer.children.length;
201+
if (count === existingDotCount) {
180202
return;
181-
} else if (existingDots.length > count) {
203+
} else if (existingDotCount > count) {
182204
// Remove extra dots.
183-
for (var i = count; i < existingDotCount; i++) {
184-
var existingDot = existingDots[i];
185-
Polymer.dom(dotContainer).removeChild(existingDot);
205+
while (dotContainer.children.length > count) {
206+
Polymer.dom(dotContainer).removeChild(dotContainer.children[0]);
186207
}
187208
} else {
188209
// Create needed dots.
189-
// var dotTemplate = this.$.dotTemplate;
190210
for (var i = existingDotCount; i < count; i++) {
191-
// var newDot = document.importNode(dotTemplate.content, true);
192211
var newDot = document.createElement('div');
193212
newDot.classList.add('dot');
194213
newDot.classList.add('style-scope');
195214
newDot.classList.add('basic-page-dots');
215+
newDot.classList.toggle('selected', i === selectedIndex);
196216
dotContainer.appendChild(newDot);
197217
}
198218
}
199-
}
219+
},
220+
221+
// Tracks selection before the collective supports it.
222+
_prematureSelectedIndex: null
200223

201224
});
202225
</script>

bower.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"name": "basic-page-dots",
33
"description": "Aspect which adds a set of small dots to a collective tracking a list of items.",
4-
"version": "0.6.2",
4+
"version": "0.6.3",
55
"license": "MIT",
66
"main": "basic-page-dots.html",
77
"dependencies": {
8-
"basic-aspect": "basic-web-components/basic-aspect#0.6.2",
8+
"basic-aspect": "basic-web-components/basic-aspect#0.6.3",
99
"polymer": "Polymer/polymer#^1.1"
1010
},
1111
"devDependencies": {
12-
"basic-framed-content": "basic-web-components/basic-framed-content#0.6.2",
12+
"basic-framed-content": "basic-web-components/basic-framed-content#0.6.3",
1313
"web-component-tester": "*"
1414
},
1515
"keywords": [

0 commit comments

Comments
 (0)