jquery-modules
v0.5.2
Published
Simple jQuery application modules plugin
Downloads
16
Readme
jquery-modules
Simple modules plugin that gives your jQuery code structure you never had.
jQuery-modules features
- Shared service objects
- Encapsulated module jQuery root element as a container for all events and components
- Automatically cache component objects to module
- Define module actions available for events and module internal usage
- Define module events with automatic bind/unbind.
Usage
$(document).ready(function () {
$(document).module({
services: {
helpers: {
parseTaskName: function (name) {
// Do some parsing...
return name;
}
},
taskRepository: {
find: function (id) {},
list: function (params) {},
create: function (data) {},
update: function (task) {},
delete: function (task) {}
}
}
})
$("#app").module({
init: function () {
// Do your module initialization magic here... :)
},
// Search for all jQuery objects in module root and store the to the module object.
// All components will be stored in the module object with "$" prefix.
components: {
input: 'input#task-input'
},
// Services can be reused in other registred modules.
services: {
helpers: 'helpers',
taskRepository: 'taskRepository'
},
actions: {
createTask: function () {
var task = this.taskRepository.create({
name: this.helper.parseTaskName(this.$input.val())
});
// Call action and pass parameters
this.action('updateTaskList', task);
},
updateTaskList: function (task) {
// Update task list view
}
},
events: {
// Event type ( selector ) : handler action
'click(#createTask)': 'createTask'
}
});
});