ccomparini / uiulars

ui abstraction ripped from wuwei invaders
Creative Commons Zero v1.0 Universal
0 stars 0 forks source link

uiulator - a simple way to display javascript data in html (in browser).

Here's a relatively simple self-referential example of how you can use this, and here's a more complicated dynamic example. More example links below.

How to use this:

Lay out your html as you like. Mark elements on which you'd like to display data with "data-shows". Mark elements which you want to use to set data with "data-controls", etc. - the possible "markers" are:

Then, in you js (someplace), apply the uiulator something like:

const myData = { x: 1, y: 2 };
const elements = document.querySelectorAll(".where-to-display");
const options = { /* see below */ };
uiulator(myData, elements, options);

"elements" may be a single element as returned by getElementbyId(), or a set of elements as an array or as returned by querySelectorAll(), or undefined to apply to all elements in the page (which is usually less efficient).

"options" is an optional object with or or more of:

There are 4 element "markers" which determine how the data are controlled or displayed:

Other examples are here:

... if I were smart I'd put those in fiddles or something. Maybe later.