diff --git a/.gitignore b/.gitignore
index 8d4ae25..b13058c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
bower_components
+.DS_Store
diff --git a/README.md b/README.md
index 0eb6502..8d21374 100644
--- a/README.md
+++ b/README.md
@@ -54,7 +54,7 @@ Methods
--
Node
-expandAll: recursive open & render all nodes. (lazy render: the node will render only if it's expanded)
+expandAll(depth): recursive open & render all nodes. If an integer is passed in the function it will open only to that depth. (lazy render: the node will render only if it's expanded)
collapseAll: close (Hide) all nodes.
diff --git a/build/pretty-json-min.js b/build/pretty-json-min.js
index bb1b3e5..e4c2ae6 100644
--- a/build/pretty-json-min.js
+++ b/build/pretty-json-min.js
@@ -6,7 +6,7 @@
var PrettyJSON={view:{},tpl:{}};PrettyJSON.util={isObject:function(v){return Object.prototype.toString.call(v)==='[object Object]';},pad:function(str,length){str=String(str);while(str.length'+''+''+''+''+''+'';PrettyJSON.tpl.Leaf=''+''+' <%-data%><%= coma %>'+'';PrettyJSON.view.Node=Backbone.View.extend({tagName:'span',data:null,level:1,path:'',type:'',size:0,isLast:true,rendered:false,events:{'click .node-bracket':'collapse','mouseover .node-container':'mouseover','mouseout .node-container':'mouseout'},initialize:function(opt){this.options=opt;this.data=this.options.data;this.level=this.options.level||this.level;this.path=this.options.path;this.isLast=_.isUndefined(this.options.isLast)?this.isLast:this.options.isLast;this.dateFormat=this.options.dateFormat;var m=this.getMeta();this.type=m.type;this.size=m.size;this.childs=[];this.render();if(this.level==1)
this.show();},getMeta:function(){var val={size:_.size(this.data),type:_.isArray(this.data)?'array':'object',};return val;},elements:function(){this.els={container:$(this.el).find('.node-container'),contentWrapper:$(this.el).find('.node-content-wrapper'),top:$(this.el).find('.node-top'),ul:$(this.el).find('.node-body'),down:$(this.el).find('.node-down')};},render:function(){this.tpl=_.template(PrettyJSON.tpl.Node);$(this.el).html(this.tpl);this.elements();var b=this.getBrackets();this.els.top.html(b.top);this.els.down.html(b.bottom);this.hide();return this;},renderChilds:function(){var count=1;_.each(this.data,function(val,key){var isLast=(count==this.size);count=count+1;var path=(this.type=='array')?this.path+'['+key+']':this.path+'.'+key;var opt={key:key,data:val,parent:this,path:path,level:this.level+1,dateFormat:this.dateFormat,isLast:isLast};var child=(PrettyJSON.util.isObject(val)||_.isArray(val))?new PrettyJSON.view.Node(opt):new PrettyJSON.view.Leaf(opt);child.on('mouseover',function(e,path){this.trigger("mouseover",e,path);},this);child.on('mouseout',function(e){this.trigger("mouseout",e);},this);var li=$('');var colom=' : ';var left=$('');var right=$('').append(child.el);(this.type=='array')?left.html(''):left.html(key+colom);left.append(right);li.append(left);this.els.ul.append(li);child.parent=this;this.childs.push(child);},this);},isVisible:function(){return this.els.contentWrapper.is(":visible");},collapse:function(e){e.stopPropagation();this.isVisible()?this.hide():this.show();this.trigger("collapse",e);},show:function(){if(!this.rendered){this.renderChilds();this.rendered=true;}
-this.els.top.html(this.getBrackets().top);this.els.contentWrapper.show();this.els.down.show();},hide:function(){var b=this.getBrackets();this.els.top.html(b.close);this.els.contentWrapper.hide();this.els.down.hide();},getBrackets:function(){var v={top:'{',bottom:'}',close:'{ ... }'};if(this.type=='array'){v={top:'[',bottom:']',close:'[ ... ]'};};v.bottom=(this.isLast)?v.bottom:v.bottom+',';v.close=(this.isLast)?v.close:v.close+',';return v;},mouseover:function(e){e.stopPropagation();this.trigger("mouseover",e,this.path);},mouseout:function(e){e.stopPropagation();this.trigger("mouseout",e);},expandAll:function(){_.each(this.childs,function(child){if(child instanceof PrettyJSON.view.Node){child.show();child.expandAll();}},this);this.show();},collapseAll:function(){_.each(this.childs,function(child){if(child instanceof PrettyJSON.view.Node){child.hide();child.collapseAll();}},this);if(this.level!=1)
+this.els.top.html(this.getBrackets().top);this.els.contentWrapper.show();this.els.down.show();},hide:function(){var b=this.getBrackets();this.els.top.html(b.close);this.els.contentWrapper.hide();this.els.down.hide();},getBrackets:function(){var v={top:'{',bottom:'}',close:'{ ... }'};if(this.type=='array'){v={top:'[',bottom:']',close:'[ ... ]'};};v.bottom=(this.isLast)?v.bottom:v.bottom+',';v.close=(this.isLast)?v.close:v.close+',';return v;},mouseover:function(e){e.stopPropagation();this.trigger("mouseover",e,this.path);},mouseout:function(e){e.stopPropagation();this.trigger("mouseout",e);},expandAll:function(depth,currentDepth){if(!currentDepth)currentDepth=0;if(depth&&depth<=currentDepth++)return;_.each(this.childs,function(child){if(child instanceof PrettyJSON.view.Node){child.show();child.expandAll(depth,currentDepth);}},this);this.show();},collapseAll:function(){_.each(this.childs,function(child){if(child instanceof PrettyJSON.view.Node){child.hide();child.collapseAll();}},this);if(this.level!=1)
this.hide();}});PrettyJSON.view.Leaf=Backbone.View.extend({tagName:'span',data:null,level:0,path:'',type:'string',isLast:true,events:{"mouseover .leaf-container":"mouseover","mouseout .leaf-container":"mouseout"},initialize:function(opt){this.options=opt;this.data=this.options.data;this.level=this.options.level;this.path=this.options.path;this.type=this.getType();this.dateFormat=this.options.dateFormat;this.isLast=_.isUndefined(this.options.isLast)?this.isLast:this.options.isLast;this.render();},getType:function(){var m='string';var d=this.data;if(_.isNumber(d))m='number';else if(_.isBoolean(d))m='boolean';else if(_.isDate(d))m='date';else if(_.isNull(d))m='null'
return m;},getState:function(){var coma=this.isLast?'':',';var state={data:this.data,level:this.level,path:this.path,type:this.type,coma:coma};return state;},render:function(){var state=this.getState();if(state.type=='date'&&this.dateFormat){state.data=PrettyJSON.util.dateFormat(this.data,this.dateFormat);}
if(state.type=='null'){state.data='null';}
diff --git a/build/tools/jsmin.pyc b/build/tools/jsmin.pyc
index 1a7e946..16e759e 100644
Binary files a/build/tools/jsmin.pyc and b/build/tools/jsmin.pyc differ
diff --git a/build/tools/mergejs.pyc b/build/tools/mergejs.pyc
index 4e8b61a..c8cb692 100644
Binary files a/build/tools/mergejs.pyc and b/build/tools/mergejs.pyc differ
diff --git a/build/tools/toposort.pyc b/build/tools/toposort.pyc
index c1bbbdc..3148af6 100644
Binary files a/build/tools/toposort.pyc and b/build/tools/toposort.pyc differ
diff --git a/src/node.js b/src/node.js
index a704218..f6301ac 100644
--- a/src/node.js
+++ b/src/node.js
@@ -21,12 +21,12 @@ PrettyJSON.view.Node = Backbone.View.extend({
'mouseout .node-container': 'mouseout'
},
initialize:function(opt) {
- this.options = opt;
+ this.options = opt;
this.data = this.options.data;
this.level = this.options.level || this.level;
this.path = this.options.path;
this.isLast = _.isUndefined(this.options.isLast) ?
- this.isLast : this.options.isLast;
+ this.isLast : this.options.isLast;
this.dateFormat = this.options.dateFormat;
var m = this.getMeta();
@@ -177,11 +177,14 @@ PrettyJSON.view.Node = Backbone.View.extend({
e.stopPropagation();
this.trigger("mouseout",e);
},
- expandAll:function (){
+ expandAll:function (depth, currentDepth){
+ if(!currentDepth) currentDepth = 0;
+ if(depth && depth <= currentDepth++) return;
+
_.each(this.childs, function(child){
if(child instanceof PrettyJSON.view.Node){
child.show();
- child.expandAll();
+ child.expandAll(depth, currentDepth);
}
},this);
this.show();