website
This commit is contained in:
parent
cbba5f8113
commit
edfd488300
2 changed files with 37 additions and 12 deletions
|
|
@ -42,10 +42,13 @@ endfor
|
||||||
<const>e</const><sup>(<const>c</const> × fontSize)</sup>
|
<const>e</const><sup>(<const>c</const> × fontSize)</sup>
|
||||||
</formula>
|
</formula>
|
||||||
<formula>
|
<formula>
|
||||||
leading = <const>l</const> × fontSize
|
leading = <num>1.4</num> × fontSize
|
||||||
</formula>
|
</formula>
|
||||||
<formula title="Base of natural logarithm">
|
<formula>
|
||||||
<const>e</const> ≈ <num>2.718</num>
|
<const title="Constant a">a</const> = <num data-binding="var-a">-0.016</num>
|
||||||
|
<const title="Constant b">b</const> = <num data-binding="var-b">0.21</num>
|
||||||
|
<const title="Constant c">c</const> = <num data-binding="var-c">-0.18</num>
|
||||||
|
<const title="Base of natural logarithm">e</const> ≈ <num>2.718</num>
|
||||||
</formula>
|
</formula>
|
||||||
</p>
|
</p>
|
||||||
<p class="small-window">
|
<p class="small-window">
|
||||||
|
|
@ -473,8 +476,7 @@ bindings.configure('style', null, null, function (style) {
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
bindings.bindAllInputs('.control input')
|
bindings.bindAllInputs('[data-binding]')
|
||||||
bindings.bindAllInputs('.control select')
|
|
||||||
|
|
||||||
// double-click base tracking to reset
|
// double-click base tracking to reset
|
||||||
$('input[type="range"][data-binding="base-tracking"]').addEventListener(
|
$('input[type="range"][data-binding="base-tracking"]').addEventListener(
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ function Binding(name){
|
||||||
this.name = name
|
this.name = name
|
||||||
this.value = undefined
|
this.value = undefined
|
||||||
this.inputs = []
|
this.inputs = []
|
||||||
|
this.outputs = []
|
||||||
this.listeners = []
|
this.listeners = []
|
||||||
this.parser = undefined
|
this.parser = undefined
|
||||||
this.formatter = passThrough
|
this.formatter = passThrough
|
||||||
|
|
@ -30,6 +31,13 @@ Binding.prototype.addInput = function(el) {
|
||||||
el.addEventListener('input', _onInput, {passive:true})
|
el.addEventListener('input', _onInput, {passive:true})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binding.prototype.addOutput = function(el) {
|
||||||
|
this.outputs.push(el)
|
||||||
|
if (this.value !== undefined) {
|
||||||
|
el.innerText = this.formatter(this.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// listener signature:
|
// listener signature:
|
||||||
// function(nextval string, prevval string, b Binding)void
|
// function(nextval string, prevval string, b Binding)void
|
||||||
|
|
@ -40,7 +48,6 @@ Binding.prototype.addListener = function(listener) {
|
||||||
|
|
||||||
|
|
||||||
Binding.prototype.setValue = function(nextval, origin) {
|
Binding.prototype.setValue = function(nextval, origin) {
|
||||||
// console.log('Binding.setValue nextval:', nextval, {origin})
|
|
||||||
var prevval = this.value
|
var prevval = this.value
|
||||||
if (this.parser) {
|
if (this.parser) {
|
||||||
nextval = this.parser(nextval, prevval)
|
nextval = this.parser(nextval, prevval)
|
||||||
|
|
@ -50,11 +57,15 @@ Binding.prototype.setValue = function(nextval, origin) {
|
||||||
}
|
}
|
||||||
var binding = this
|
var binding = this
|
||||||
this.value = nextval
|
this.value = nextval
|
||||||
|
var value = binding.formatter(nextval)
|
||||||
this.inputs.forEach(function(input) {
|
this.inputs.forEach(function(input) {
|
||||||
if (input.el !== origin) {
|
if (input.el !== origin) {
|
||||||
input.el.value = binding.formatter(nextval)
|
input.el.value = value
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
this.outputs.forEach(function(el) {
|
||||||
|
el.innerText = value
|
||||||
|
})
|
||||||
this.listeners.forEach(function(listener) {
|
this.listeners.forEach(function(listener) {
|
||||||
listener(nextval, prevval, this)
|
listener(nextval, prevval, this)
|
||||||
})
|
})
|
||||||
|
|
@ -75,23 +86,35 @@ Bindings.prototype.getBinding = function(name, input) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Bindings.prototype.bindInput = function(name, input) {
|
Bindings.prototype.bindInput = function(name, input) {
|
||||||
// console.log('bindInput', name, input)
|
|
||||||
var binding = this.getBinding(name)
|
var binding = this.getBinding(name)
|
||||||
binding.addInput(input)
|
binding.addInput(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bindings.prototype.bindOutput = function(name, el) {
|
||||||
|
var binding = this.getBinding(name)
|
||||||
|
binding.addOutput(el)
|
||||||
|
}
|
||||||
|
|
||||||
Bindings.prototype.bindAllInputs = function(queryOrInputElementList) {
|
Bindings.prototype.bindAllInputs = function(queryOrInputElementList) {
|
||||||
var bindings = this
|
var bindings = this
|
||||||
|
|
||||||
var inputs = (
|
var elements = (
|
||||||
typeof queryOrInputElementList == 'string' ? $$(queryOrInputElementList) :
|
typeof queryOrInputElementList == 'string' ? $$(queryOrInputElementList) :
|
||||||
queryOrInputElementList
|
queryOrInputElementList
|
||||||
)
|
)
|
||||||
|
|
||||||
inputs.forEach(function(input) {
|
elements.forEach(function(el) {
|
||||||
var bindingName = input.dataset.binding
|
var bindingName = el.dataset.binding
|
||||||
if (bindingName) {
|
if (bindingName) {
|
||||||
bindings.bindInput(bindingName, input)
|
if (
|
||||||
|
el.tagName == 'INPUT' ||
|
||||||
|
el.tagName == 'TEXTAREA' ||
|
||||||
|
el.tagName == 'SELECT'
|
||||||
|
) {
|
||||||
|
bindings.bindInput(bindingName, el)
|
||||||
|
} else {
|
||||||
|
bindings.bindOutput(bindingName, el)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue