Backbone UI
perka.github.com
perka.github.com
Using custom widgets instead of native often leads to usability issues. In this case, when the a checkbox gains focus, a SPACE BAR scrolls the page instead of toggling its state.
Backbone.UI.Button = an anchor tag with a span inside rather than a button tag. Backbone.UI.Checkbox = an anchor containing some divs rather than an input[type=checkbox]. Radio group and Pulldown give similar output.
Go right ahead and test it out at:
edit: there are also connectors for Angular-Sencha-Touch and Angular-jQuery-Mobile and an attempt at an Angular-Bootstrap connector...hopefully they'll all keep growing
And yet three separate libraries with DOM abstractions are required.
Why should I trust your opinion of the DOM if you require so much third-party code?
It's been on my todo list for a while now to remove the JQuery dependency from Backbone UI, since we're now only using it mainly for event handling and positioning.
JQuery was an obvious choice when this project was born over a year ago. I've since formalized my preferred method of DOM generation into the Laconic library, but have yet to do the same for the last bits of JQuery still being used.
Then we turn around and use that framework to clumsily tie back together presentation and logic. Wonderful.
Templates aren't a hack. They are they method to create extensible objects in the presentation layer. Backbone UI users seems to be forgetting Backbone's original intent.
Instead write your libraries to HTML standards, and provide links to polyfills that they'll need. Don't assume everyone is targeting IE6.
> Backbone UI depends on Backbone, Underscore, jQuery, and laconic.
That's a disaster waiting to happen.
It would be okay if the consumer code is dependent on all the libraries. But if one of your framework is dependent on certain version of library and another one depends on another version of the said library, that is disaster waiting to happen. It would be hard to upgrade one framework , hence making it hard to move forward since your code is all tangled to all the frameworks.
But what stands out is the quality of documentation. Very impressive and clear.
JQuery+Backbone+TwitterBootstrap = Fun+Joy.
Sandbox: http://datapimp.github.com/luca
Your average jQuery plugin has you modifying state via invoking the plugin again on a selector with like a string argument that represents a function - this always felt clunky to me.
However, by using Backbone views to wrap logic, componentInstance.hide() or whatever else is doable, and IMO a lot more elegant. Nice work!
I'm dabbling with some of the same in our codebase, and we were meant to release a grid component that I now fear has grown too big and hairy.
Not so sure on the idea of breaking it up this far; Buttons and checkboxes are single html-elements, so if you follow this approach fully you get a lot of views for a complex app — that'll be a performance issue.
I'm just now looking into alternatives to the dreadful jQuery Mobile for a Backbone-based app.
But if you're generating the UI from JavaScript, it really doesn't cooperate.
It also has various performance problems, especially on Android (since its authors appear to prefer iOS). It creating tons of DOM elements doesn't help either.
jQM appears built to generate lots of DOM with JavaScript from static HTML pages.
Fantastic JavaScript -- but styling mechanism leaves a lot to be desired. I understand beautiful graphics are not the scope of this work, however, the CSS-only approach might not be flexible enough for most designers.
Is this normal? Can anyone comment on this, please? How would one go about dressing this up?
Again, thanks for the great work!
Where you absolutely cannot avoid a graphic (like having an icon or something), the use of pictographic fonts is becoming increasingly popular. Mostly due to reasons of scalability to different resolutions on different devices.
I had to go to the url, delete /signup etc. to find out. You might want to make your logo take you home.
String.prototype.$tag = (args...) ->
args.unshift "<#{@toString()}/>"
$.apply window, args
("ul".$tag
class: "someUL"
html: "li".$tag
text: "some text in an li"
class: "some class"
click: ->
console.log "some click event").appendTo 'body'Using html templates is good separation of concerns and js just isn't very good at expressing html structure. Jade would have been a much better choice IMO. Laconic does a good job of minimizing the problems with using js to programatically build dom in js but still doesn't come close to a proper templating language.
I realize that templates are a popular choice for many, but I view them as an unneccesary layer of indirection. Sort of like printing out an email, hand writing a response, and scanning it back in as a reply. Once your markup has been converted to a document object model, why not embrace it?
Using a bunch of calls to appendChild() and setAttribute() results in code that is difficult to read, because it's so low-level. You can't "see" the generated HTML, just like in assembly you can't really "see" the code structure.
Whereas using templates lets you "see" your HTML, with an easy-to-understand structure. So it's the natural, default choice for ease-of-use and maintenance.
Myself, I much prefer imperative.
Then you have to include some bulky library that parses these scripts and compiles them to a function that you'll use later. All this happens pretty fast, but not any faster than just using the DOM apis.
I can't find the link, but I believe there is a proposal to standardize client side templating, so hopefully that will make the process a bit cleaner.
//synchronous
body.innerHTML = render('blog.html',data)
//asynchronous
render('blog.html',data,body)
render=function(url,data,obj){
if url in cache: use cache
var http = xmlhttprequest()
http.get(url,obj?async:sync)
http.onready:
parse data in html
if obj: obj.innerHTML = html
else: return html
} <link href="mytemplate.mustache" rel="template" type="text/mustache" onload="showSnippet()" /> <link hef='blog.html' rel='template' id='myblog' defer>
But still, we don't want to load 50 templates at the same time if the app is big then use one or two in that session, that's why loading them on demand with httprequest might be a better solution.*Besides, being static in nature they would be cached on the server and client for instant access.
Use like thus:
var tmpl = document.getElementById('myblog').template;This is still ugly, in that debugging templates is an impossible pain the arse because there's no useful line information. On the plus side they're much easier to read than a chain of DOM manipulations.
It's arguable whether this is "better". I usually have to interact with the DOM programmatically anyway (attaching events, for example), so why not build the DOM in javascript as well?