JUMON.js is simple DOM access library. This enables easily and readable access to DOM element from your code by binding DOM elements' attribute to Jumon object.
<form>
<input value="50" jumon-bind="width" jumon-type="Number">
<input value="100" jumon-bind="height" jumon-type="Number">
</form>
import { Jumon } from './jumon.js';
parameter = new Jumon();
// read text box's values
console.log(parameter.width);
console.log(parameter.height);
// update text box's value
parameter.width = 100;
parameter.height = 200;
Bind the element's value to Jumon instance's .propertyName
property.
Example:
<select jumon-bind="count">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
parameter = new Jumon();
console.log(parameter.count); // output: "1"
Enable auto type conversion to Number. If value is not a number, conversion result is "NaN".
Example:
<select jumon-bind="count" jumon-type="Number">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
parameter = new Jumon();
console.log(parameter.count); // output: 1
Bind the element's value to another element's attribue.
Example:
<input class="ratio" value="100" jumon-bind-to="#frame[height]">
<iframe src="https://example.com/" height="0"></iframe>
Bind the element's value to another element's attribue. the value is given to converter function, and then set its return value to the selected element's attribute.
Example:
<input class="ratio" value="100" jumon-bind-to="calcSize:#frame[height]">
<iframe src="https://example.com/" height="0"></iframe>
parameter = new Jumon();
parameter.calcSize(val => val * 2); // set the iframe's height to twice the value
Append the HTML which render method returns as the element's child.
Example:
<div jumon-bind-renderer="renderer:items">
</div>
parameter = new Jumon();
parameter.renderer = (param, index) => {
return `<div>${index}: ${param.title}</div>`;
}
parameter.items = [
{title: "foo"},
{title: "bar"},
];
Add EventListner to the element.
Example:
<button jumon-listen="click:update">update</button>
parameter = new Jumon();
parameter.update = (event) {
// When the button is clicked, this method is invoked.
};
2022, Hiromichi Matsushima (hylom) [email protected].
MIT License.