An open API service indexing awesome lists of open source software.

https://github.com/knowledgecode/jquery-view.js

a jQuery plugin that provides a "V" of MVC framework on the client-side JavaScript
https://github.com/knowledgecode/jquery-view.js

Last synced: 9 months ago
JSON representation

a jQuery plugin that provides a "V" of MVC framework on the client-side JavaScript

Awesome Lists containing this project

README

          

# jQuery-View.js
jQuery-View.js is a jQuery plugin. Work in jQuery or other compatible library (ex. jQMobi, Zepto).
"View" of jQuery-View means "V" of MVC framework, It is also syntax sugar of "on" and "off" methods for event bindings.

## Usage
Add the jquery-view.js below the jQuery in your html.


Then, the "view" object is added in jQuery.
It has two methods which are "on" and "off".

### $().view.on(object)
To bind events is below.

var events = {
'ready': function () {
console.log('dom loaded');
},

'load@window': function () {
console.log('window loaded');
},

'click@document': function () {
console.log('document clicked');
},

// This code doesn't work in less than IE9. Use "ready" instead.
'DOMContentLoaded@document': function () {
console.log('document DOMContentLoaded');
},

'click@.menu input': function (evt) {
evt.stopPropagation();
console.log(evt.srcElement.value + ' clicked');
}
};

// Register events
$().view.on(events);

The syntax is "eventname" + "@" + "selector".
Not accepted anything that does not conform to this syntax. However, when use a "DOMContentLoaded" event, use "ready" instead.

### $().view.off(object)
To unbind events is below.

// Unregister events.
$().view.off(events).

## License
jQuery-View is available under the terms of the MIT license.