- In your html, you annotate objects (e.g. a button) with the '.actionable' class
- Then provide a set of arguments in the html alongside, e.g.
<div class="kwargs">
<!-- replace #money with the output from /user/3/money/create -->
<input name="type" value="replace" />
<input name="target" value="#money" />
<input name="url" value="/user/3/money/create" />
</div>
- The library then parses the html of .actionable objects, and automatically creates the relevant jQuery bindings for you. In other words, you define the behavior in html, without having to write any custom javascript.
We're experimenting with a few ways of extending this on Memrise (Spencer Davis gets most of the credit here). It's early days, but we're an ajax-heavy site, and devolving certain kinds of basic, repetitive functionality to html feels natural and simple. And, by adding new handler types to the library, it becomes much, much easier to create reusable widgets that we can sprinkle throughout the site.
P.S. Currently, most of this work is still on a development branch that will be live within a couple of days.
I see the idea:
1) Write htmls (with some rules, e.g. add '.actionable' class)
2) Library turn them to js codes.
Benefits:
1) Write zero js codes.
2) Make basic and repetitive functionalities eaiser.
But, just wondering, why don't you wrap codes which deal with basic and repetitive functionalities into js functions then reuse them, but write a library to turn htmls codes to js codes?
My question is, html has its job and js has its, too. Is it a good idea to mix them?
It's a good question. I don't think I'll have an informed opinion until we've experienced what it's like to work in this way for a while.
But:
- Joseph Perla's suggestions are usually good
- It just feels better to me... Maybe because it's easier to auto-generate html (e.g. from a Django template). Maybe because now many of our pages won't need any javascript. Maybe because all the custom logic is in one place rather than spread over the html and the javascript. Maybe because writing javascript is harder than html :)
I don't understand what this means. Can you please explain how this works?