only.js: Write everything in javascript
only.js allows HTML and CSS to be written inline in Javascript code using JSON representation.
For example, this HTML:
<div> <p>Food:</p> <ul class="cake"> <li>Milk</li> <li>Spinach</li> <li>Tacos</li> <li>Peas</li> </ul></div>
can become this javascript:
only;
CSS
This CSS:
.cake { color: red; display: inline-block;}
becomes this javascript:
only;
or, put css style inline with javascript
only
Inline javascript
This allows you to put any code you want into your HTML representation directly, just like a templating engine but in Javascript:
only;
Will be displayed as:
Sat Jul 25 2015 15:40:38 GMT-0400 (Eastern Daylight Time)
Keep all code for one component together
This HTML+javascript+CSS, spread between three files:
<body> <!-- ... --> <button id="button1" class="button"></button> <!-- ... --></body>
//...//...
/* ... */.button { border-style: solid; border-width: 5px;}/* ... */
can become just one thing in one file:
//create buttonvar button = only; //add listenerbutton //add to pageonly
Reuse Elements Easily
To reuse an element, all you need to do is save it in a var:
//create reusable error messagevar errorMsg = div: p: "there has been an error" img: "" src: "error.png" style: "border-width:10;border-style:solid;"; //use it:only;
Another example
Simple user interaction:
var input = only;var submit = onlyvar response = only; //no need for an id on the buttonsubmit{ var name = inputvalue; responseinnerHTML = "Hello " + name " how are you today?";} only;