Simple blocks - Frontend blocks
Description
FComponent is a small arhitecture framework for creating litte simple blocks. It may be usefull for simple integration to you MV* framework. For example backbone.
API
add(block, name)
register blocks
block
- Object of custom block definition. Block must haveadd
anddestroy
methods, otherwise methodadd
throws Error. You can also definename
of block or pass it as second param.
Type: Object {add:function(){}, destroy: function(){}}name
- name of block
Type: String
Default:block.name
Example:
var sblocks = ;sblocks;
init($root, arguments...)
Initialize all register blocks in $root
DOM element
$root
- dom element where find blocks
Type: jQuery DOM objectarguments
- additional params for initialize block
Example:
Define block in html
Initialize all blocks in body
var $ = ;var sblocks = ;sblocks;
Result html is:
Hello block Hello block2
item(name, $el, options, arguments...)
Method to init not marked html element as block
name
- name of using block$el
- DOM elementoptions
- options for initialize blockarguments
- additional params for initialize block
Example:
var $ = ;var sblock = ;var $el = ;;sblock;
html dom result:
Hello block Hello block2 Hello block3
destroy($root)
Destroy all initialize blocks in $root
DOM element
$root
- dom element where find blocks
Type: jQuery DOM object
Example:
var $ = ;var sblocks = ;sblocks;
api(name, funcname, $el, args...)
Call custom api for block
name
- name of blockfuncname
- name of callable function$el
- element where find dom element for initialize blocksarguments
- additional params
Example:
sblocks;/* after initializing apply method `api.val` to `$el` */$eltext === "0"; //truesblocks;$eltext === "2"; //true
html dom result:
Example of Backbone integration
View = BackboneView;
Changelog
- 0.0.2 - bug fixing
- 0.0.1 - public version