Skip to content

Commit

Permalink
Build 0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
bseth99 committed Nov 28, 2013
1 parent 43bce77 commit 02ed80f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
40 changes: 32 additions & 8 deletions backbone-fiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,29 @@
* relationship and renders the view.
*/
function create( view, $el, options ) {

var inst = new view(_.extend( options, { el: $el[0] } )),
parent;
parent, fizzle = false;

$el.attr( 'data-cid', inst.cid );
_view_inst[inst.cid] = inst;

parent = $el.parents( '[data-view]' ).first();

if ( parent.length > 0 ) {
parent = parent.attr( 'data-cid' );
_view_inst[parent].addChild( inst );
inst.setParent( _view_inst[parent] );
if ( _view_inst[parent] ) {
_view_inst[parent].addChild( inst );
inst.setParent( _view_inst[parent] );
} else {
fizzle = true;
inst.remove();
}
}

inst.render();
if (!fizzle) { inst.render(); }
return inst;

}

/**
Expand Down Expand Up @@ -219,6 +226,13 @@
*/
renderedOnce: false,

/**
* Flag to force the view to render even if it has an empty collection
* and has not renderedOnce
*/
forceRender: false,


/**
* Enables dynamically adding new DOM elements that will be
* bound to a child view instance.
Expand Down Expand Up @@ -367,7 +381,7 @@
data = this.dataSerialized();
isa = data && $.isArray( data );

if ( this.renderedOnce && data || ( !this.renderedOnce && ( ( isa && data.length > 0 ) || !isa ) ) )
if ( ( this.forceRender || this.renderedOnce ) && data || ( !this.renderedOnce && ( ( isa && data.length > 0 ) || !isa ) ) )
{
this.$el.empty().html( this.template( data ) );
this.renderedOnce = true;
Expand Down Expand Up @@ -427,7 +441,7 @@

this.bindData();

if (dm && dm.trigger) {dm.trigger('ready', dm);}
if (dm && dm.trigger) { dm.trigger( 'ready', dm, this );}
return this;
},

Expand Down Expand Up @@ -534,7 +548,7 @@
_.compact(
_.map( this.children, function( cid ) {
var view;
if ( (view = Fiber.getViewFromCid( this.children[i] )) && view.instanceOf == type )
if ( (view = Fiber.getViewFromCid( cid )) && view.instanceOf == type )
return view;
})
)
Expand Down Expand Up @@ -570,6 +584,16 @@
}

return view;
},

/**
* Determines if an element is in my view and not a child's view.
*/
isMyElement: function( el ) {
var $el = (el instanceof $ ? el : $(el));

return $el.parents('[data-view]').first().attr('data-cid') == this.cid;

}

}]);
Expand Down
2 changes: 1 addition & 1 deletion backbone-fiber.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backbone-fiber",
"version": "0.1.2",
"version": "0.1.3",
"ignore": [
"bower_components",
"node_modules",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Backbone.Fiber",
"title": "",
"description": "",
"version": "0.1.2",
"version": "0.1.3",
"author": {
"name": "Ben Olson",
"url": "http://bseth99.github.com/"
Expand Down

0 comments on commit 02ed80f

Please sign in to comment.