|
|
|
@ -1,17 +1,15 @@ |
|
|
|
|
import Rx, { Observable } from 'rxjs'; |
|
|
|
|
import { CONTROLS } from './enums'; |
|
|
|
|
|
|
|
|
|
function Controls(container, { animating, count, maxCount, randomize, speed }, customNodes) { |
|
|
|
|
function Controls(container, { animating, count, maxCount, speed }, customNodes) { |
|
|
|
|
this.nodes = { |
|
|
|
|
animating: createAnimatingControl(animating), |
|
|
|
|
count: createCountControl(count, maxCount), |
|
|
|
|
randomize: createRandomizeControl(randomize), |
|
|
|
|
speed: createSpeedControl(speed), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
container.appendChild(this.nodes.count); |
|
|
|
|
container.appendChild(this.nodes.speed); |
|
|
|
|
container.appendChild(this.nodes.randomize); |
|
|
|
|
|
|
|
|
|
if (customNodes !== undefined) { |
|
|
|
|
customNodes.forEach(node => { container.appendChild(node); }); |
|
|
|
@ -21,7 +19,6 @@ function Controls(container, { animating, count, maxCount, randomize, speed }, c |
|
|
|
|
|
|
|
|
|
this.updateOptions({ key: CONTROLS.ANIMATING, value: animating }); |
|
|
|
|
this.updateOptions({ key: CONTROLS.COUNT, value: count }); |
|
|
|
|
this.updateOptions({ key: CONTROLS.RANDOMIZE, value: randomize }); |
|
|
|
|
this.updateOptions({ key: CONTROLS.SPEED, value: speed }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -49,16 +46,12 @@ Controls.prototype.mount = function(customNodes) { |
|
|
|
|
const count$ = Rx.Observable.fromEvent(this.nodes.count, 'input') |
|
|
|
|
.map(evt => ({ key: CONTROLS.COUNT, value: evt.target.value * 1 })); |
|
|
|
|
|
|
|
|
|
const randomize$ = Rx.Observable.fromEvent(this.nodes.randomize, 'change') |
|
|
|
|
.map(evt => ({ key: CONTROLS.RANDOMIZE, value: evt.target.checked })); |
|
|
|
|
|
|
|
|
|
const speed$ = Rx.Observable.fromEvent(this.nodes.speed, 'input') |
|
|
|
|
.map(evt => ({ key: CONTROLS.SPEED, value: evt.target.value * 1 })); |
|
|
|
|
|
|
|
|
|
const eventStack$ = Rx.Observable.merge( |
|
|
|
|
animating$, |
|
|
|
|
count$, |
|
|
|
|
randomize$, |
|
|
|
|
speed$ |
|
|
|
|
); |
|
|
|
|
|
|
|
|
@ -106,25 +99,6 @@ function createCountControl(value, max) { |
|
|
|
|
return label; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function createRandomizeControl(value) { |
|
|
|
|
const label = document.createElement('label'); |
|
|
|
|
label.className = 'controls-checkbox'; |
|
|
|
|
|
|
|
|
|
const text = document.createElement('span'); |
|
|
|
|
text.innerHTML = 'Randomize movement'; |
|
|
|
|
text.className = 'controls-checkbox-text'; |
|
|
|
|
|
|
|
|
|
const checkbox = document.createElement('input'); |
|
|
|
|
checkbox.type = 'checkbox'; |
|
|
|
|
checkbox.className = 'controls-checkbox-input'; |
|
|
|
|
checkbox.checked = value; |
|
|
|
|
|
|
|
|
|
label.appendChild(checkbox); |
|
|
|
|
label.appendChild(text); |
|
|
|
|
|
|
|
|
|
return label; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function createSpeedControl(value) { |
|
|
|
|
const label = document.createElement('label'); |
|
|
|
|
label.className = 'controls-range'; |
|
|
|
@ -135,7 +109,7 @@ function createSpeedControl(value) { |
|
|
|
|
const slider = document.createElement('input'); |
|
|
|
|
slider.type = 'range'; |
|
|
|
|
slider.min = 1; |
|
|
|
|
slider.max = 20; |
|
|
|
|
slider.max = 15; |
|
|
|
|
slider.value = value; |
|
|
|
|
slider.className = 'controls-range-input'; |
|
|
|
|
|
|
|
|
|