I've started putting together a new HTML5 Javascript framework that is only compatible with HTML5 browsers. I'm able to have a much smaller library that way, and I'm able to do stuff I couldn't otherwise. Like...
Because I'm using built-in Javascript methods (written in C) for many things I do, I am taking advantage of the speed of modern HTML5 browsers, without the bloat of code that makes up for missing features. Array.prototype.slice is used to convert NodeLists and Argument objects into arrays with $.toArray(); querySelector and querySelectorAll are used to quickly find the first or all matches for a given selector string. The built-in Array.prototype.forEach is used for iterating over arrays.
I can add methods to the prototype of Node and HTMLElement, giving all elements in my document functionality that I feel are common enough to be needed.
And much much more.
simpl5 Element WrapperI've also create a jQuery-like class (called simpli5) which is basically an Array (uses all the native Array methods like concat, splice, forEach, map, etc.) and forwards all my calls I specify onto the elements in the array.
I like the class model a lot. It is actually compatible with earlier browsers as well. And I do use getters/setters now that I can. I also created an EventDispatcher class that provides the addEventListener/removeEventListener/dispatchEvent, and the shortcut methods on/un.
var Bar = new Class({
extend: Foo,
init: function() {
// I've found this to be the simplest most optimized (least hacky) way for overrides
// even though the syntax with a string isn't ideal. And I've looked around.
this.callSuper('init', 'Bar');
},
// override only the getter to make it read-only
get name() {
return this._name;
}
});
The part I'm most excited about is my component model. It allows you to make DOM elements become new classes. I can take a common <button id="myButton"></button> (HTMLButtonElement) element and make it become my ToggleButton component. You will even get a "true" when doing: document.getElementById('myButton') instanceof ToggleButton. The following is a simple Button component.
// create a new button and add it into the document
var button = new Button();
button.label = "Hello World";
document.body.prepend(button);
// turn all existing <button></button> elements into Button components
document.find('button').make(Button);
This is just the start. I've been borrowing ideas and code from libraries such as jQuery, mootools, prototype, and Extjs. The library is still only partial with many missing features, but it will mature, and the beginning I've got has been quite exciting.
“HTML5 browsers”, you better start using browser names, cause, like every other web “standard”, HTML5 is not cross-browsers consistent.
Right now I’m testing against Chrome, Safari, and Firefox. And yes, there are some few differences, but there is a LOT less to deal with. Maybe it’s a little early for many to really be interested in HTML5-only.
[...] Source http://jacwright.com/blog/428/simpli5-an-html5-javascript-framework/ [...]
[...] Simpli5 has been coming along nicely as I've been able to put time into it. I'm very excited to announce data-binding. [...]
This is top stuff, I was just researching writing my own HTML 5 Javascript library with inheritance, property change events and binding for targeting mobile webkit. Looks like I don’t need to as I found this! good work.
Cheers
Simon
Would love to have help.
I’ve forked the repo. I’ll have a play and get to know the guts of it then i’d be happy to help.
Cheers
Simon
This is a brilliant library, innovative, and well architected – well done :D
When I have some free resources, this is top of my list for UX projects to support.
Would you be interested in consulting work at all? Whereabouts are you based? Maybe we can have a chat over email? :)
Keep up the good work!
Matthew Painter
CTO Kusiri