Housekeeping

This commit is contained in:
Josh Johnson 2016-04-04 22:52:49 +01:00
parent 0676828ac3
commit 64764559f5
2 changed files with 18 additions and 9 deletions

File diff suppressed because one or more lines are too long

View file

@ -372,7 +372,7 @@ export class Choices {
// Wrapper inner container with outer container // Wrapper inner container with outer container
wrap(containerInner, containerOuter); wrap(containerInner, containerOuter);
let list = strToEl('<ul class="choices__list choices__list--items"></ul>'); let list = strToEl('<div class="choices__list choices__list--items"></div>');
let input = strToEl('<input type="text" class="choices__input choices__input--cloned">'); let input = strToEl('<input type="text" class="choices__input choices__input--cloned">');
if (input.placeholder) { if (input.placeholder) {
@ -383,10 +383,10 @@ export class Choices {
input.disabled = true; input.disabled = true;
} }
containerOuter.appendChild(containerInner);
containerInner.appendChild(list); containerInner.appendChild(list);
containerInner.appendChild(input); containerInner.appendChild(input);
containerOuter.appendChild(containerInner);
this.containerOuter = containerOuter; this.containerOuter = containerOuter;
this.containerInner = containerInner; this.containerInner = containerInner;
this.input = input; this.input = input;
@ -398,15 +398,24 @@ export class Choices {
this.addItem(value); this.addItem(value);
}); });
// Trigger event listeners
document.addEventListener('keydown', this.onKeyDown);
this.list.addEventListener('click', this.onClick);
// Subscribe to store // Subscribe to store
this.store.subscribe(this.render); this.store.subscribe(this.render);
// Render any items // Render any items
this.render(); this.render();
// Trigger event listeners
this.addEventListeners();
}
addEventListeners() {
document.addEventListener('keydown', this.onKeyDown);
this.list.addEventListener('click', this.onClick);
}
removeEventListeners() {
document.removeEventListener('keydown', this.onKeyDown);
this.list.removeEventListener('click', this.onClick);
} }
/** /**
@ -432,7 +441,7 @@ export class Choices {
state.forEach((item) => { state.forEach((item) => {
if(item.active) { if(item.active) {
// Create new list element // Create new list element
let listItem = strToEl(`<li class="choices__item ${ item.selected ? 'is-selected' : '' }" data-choice-id="${ item.id }" data-choice-selected="${ item.selected }">${ item.value }</li>`); let listItem = strToEl(`<div class="choices__item ${ item.selected ? 'is-selected' : '' }" data-choice-id="${ item.id }" data-choice-selected="${ item.selected }">${ item.value }</div>`);
// Append it to list // Append it to list
this.list.appendChild(listItem); this.list.appendChild(listItem);