From 1af94894e418bb5ebdf2e877b72947333f5c2a2b Mon Sep 17 00:00:00 2001 From: geilt Date: Thu, 1 Sep 2016 16:44:19 -0700 Subject: [PATCH 1/3] Added depth variable to expandAll. Updated docs to reflect. --- .DS_Store | Bin 0 -> 8196 bytes README.md | 2 +- build/.DS_Store | Bin 0 -> 6148 bytes build/pretty-json-min.js | 2 +- build/tools/.DS_Store | Bin 0 -> 6148 bytes build/tools/jsmin.pyc | Bin 5733 -> 5733 bytes build/tools/mergejs.pyc | Bin 5417 -> 5417 bytes build/tools/toposort.pyc | Bin 5354 -> 5354 bytes css/.DS_Store | Bin 0 -> 6148 bytes src/.DS_Store | Bin 0 -> 6148 bytes src/node.js | 11 +++++++---- 11 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 .DS_Store create mode 100644 build/.DS_Store create mode 100644 build/tools/.DS_Store create mode 100644 css/.DS_Store create mode 100644 src/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3d608555af88b379fdd83ef5ec7db512d5f20fa9 GIT binary patch literal 8196 zcmeHL&2JM&6n~RAV24sR9}ZFJVbxqf1e6HUh!c*J6s#6vWuuTN0ki9!I72rxW_KNv zMv;8(q1SQ-`f=-_e*uCc>bX7j(0`zps>k%rhZEbO$4V8MbJ2WjP^zrpG}fXb%v>Rd@sm2;e8QZHHyRGGH073|Iy%1OEpG z@XVHy{g-oJkJ{QYU>SHX8IbY8#Uim_u%%Ij4y;rPfSAE1~7;q?9qH9HL(mH9!kYd&7hgo&76M+^@t_u z)YNaJuRk+z>U1_YsKgl>zVB^|rkDC@BPsgvhI(Ql4NSZ2r`zrJiV)FJ+YeS5ZC0Go zdBIbkaT<4+Zr)=&6wRV&@G#l*^nCYNm~K~`d^x7OXj=9;U1bRiSj5u3oRW$&w!c3! z=}zC6KA3d(XJ@A--RsvrJveZ_$!0HHnwh(^UO)Ky+4C3QegDIcFJGxG12ItwM)dPh z{kofwT`%U5;5F=(7X47g%af#=P_m38lF*zX)M!~UC7Fhd9wGnPOmtD^V@ zDeS?Oqua47>h0t=RMU56-Sem)y>p%%EaQrEumE=uui}1szB?lK(`nI|K%!^3G#i&6m&bb7`S*a?xi85;`eUf_YD;yf`F<7SIgX6B1y*lcQ9(Slo zZ^e}IjatmYrLC=mrfVJTb-7wK7Ex3d2}_ya>ziuzlVB2++QiL2(eqGp69pNjP#l=h4NNW_ zvcd(YI9S$w6NS&sU=}W;M|-ddkD&$M!gKfuUcxW%2mA$x9}gUrmtYIrBRupt};bbrij|~zrF}~ T+dp%2Y}oVPp8wKC-)Z>=q8)6= literal 0 HcmV?d00001 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/.DS_Store b/build/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b0c1848e3b68a5e7e3f6b53b894e1ffc08e430be GIT binary patch literal 6148 zcmeHK%We}f6ur&^(snbnfRNbCvPfx_0HtCVLP27I6cN-4Q50q}Lt`|IqnSxV6h+FK z1#8y4e*?ji4}dRW8IB)8X;Q?ls*rDVeLVI(*PavE9upC(_kt>sLqsLG#KJO)V@&o- zU$C5Mk)2HC2xybKG`JUu_CmC6unJfOPMZRHar@LGP7%$lUq2E)CM!3FyYO{*elkHx zw1P-ZJ|*PA2UzoMdPWCw)z7fLBXWJBY=+gQkYY+vZc;`sDLcwy59U~_*iRBfXZQ_h zgPwyckYR&fU=A^|pyg-|k|V!?7tMUv{*mMAaaq_8ITLunWGP|>0>5ZsJgJWyFSi)! z_tUP?J2aJOzRJY zi2l?)f0u{-mUI5Lh%=AJVKPJA-{Wy0`gPHZgLJ>C^X>5<>$IE;jU+q-wc*9#E>F47 zBc2VGl(n3T!{Juht=_DT%I8l%U8B;-G9^_y?XoZ{fCdAK7aX& z7l$z%0Ls=3PT?CWGtwP4lQ1rLrIiyN*A8bDunL@h1?2wV!X?%W zjy0;S1BJQ*01IeVhPwP@kQ~=w&EQxgdSFabftt$96@zIy+FcV@GdR|$>BP+CgPD<; z{E&e$H9FA61B}%a*upAc6_`^Xub&-x{@?lg{eO;SAFTpbf&WPXR@iCo)bU2'+''+''+'
    '+''+''+'';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/.DS_Store b/build/tools/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8a6fb442032b9a55cf773c355d9c810eec1a73ae GIT binary patch literal 6148 zcmeHKOHRWu5FJA$LJOkoSZ2wp5;q7{i^PIWdjRMUD5Rt+DJraT3=YKsxDC7+TPSwY zEkbBUvY+G3v;AJ0xF#agT~E)5+C&tgFgBW~YJ%@`sl<-!IRY9PBd0mt(wb5lRF%IZ8| z4P{QNjuXx#T0$19o{Rc7%vUp)C@Qle%HZ=9bzYaxdQ9Z$8Bm|jsYh494pzh*s925wy>rQzncuK3?ppUwJGU3sAq+) zi?%ZFSbo`4tS`s8P^ zQ9d203_L@JN(^*ld?O1;{DY_}NX+~J)WU))f+!4Z+4$Mz`~hke7+4t4S+XzB z@x7Pa5XS&){(5%-%m7U3j(GPlHoxyavV+PPkoXmad zWUC3q;&kR)l*772MJXT!_7ynH<;?s4CH;r_f1jk46p#Y{N&%ZJZWeRCQuWr+%XzPD t^jrF;u{O#Xq7@UP6?5UO_++Q9`8Dr%g+pS{nGZTqKLW0cObYyk0w0~I80`Q6 literal 0 HcmV?d00001 diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0c627a7db49741dd40fc8f015f2bb25c2a9e3d86 GIT binary patch literal 6148 zcmeHK%Sr=55bRD?4S31X;~YH+{=pEU;8lM>V-zBb8;H5@2l@g2O{|)3gNx(EgNSrP zPt8nM_wE+#JVZoi+vT~)R756lqOwylPFF)CCpSPXHO}NoHdk$Tzi2Ck{^Ath{YYAQ zkUM#lPw(F?5TPuW@KboR+o2`NKma2ZmP)o;ra$a`q4J}>NFCXep{jRuTAh#l literal 0 HcmV?d00001 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(); From 3248601cde31f1c09bd42979fcd207857ed2210e Mon Sep 17 00:00:00 2001 From: geilt Date: Thu, 1 Sep 2016 16:45:01 -0700 Subject: [PATCH 2/3] Updated .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8d4ae25..b13058c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ bower_components +.DS_Store From 411ab25831de616e95b46c9884bfefcb0a3e558a Mon Sep 17 00:00:00 2001 From: geilt Date: Thu, 1 Sep 2016 16:45:32 -0700 Subject: [PATCH 3/3] Removed .DS_Store --- .DS_Store | Bin 8196 -> 0 bytes build/.DS_Store | Bin 6148 -> 0 bytes build/tools/.DS_Store | Bin 6148 -> 0 bytes css/.DS_Store | Bin 6148 -> 0 bytes src/.DS_Store | Bin 6148 -> 0 bytes 5 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store delete mode 100644 build/.DS_Store delete mode 100644 build/tools/.DS_Store delete mode 100644 css/.DS_Store delete mode 100644 src/.DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 3d608555af88b379fdd83ef5ec7db512d5f20fa9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHL&2JM&6n~RAV24sR9}ZFJVbxqf1e6HUh!c*J6s#6vWuuTN0ki9!I72rxW_KNv zMv;8(q1SQ-`f=-_e*uCc>bX7j(0`zps>k%rhZEbO$4V8MbJ2WjP^zrpG}fXb%v>Rd@sm2;e8QZHHyRGGH073|Iy%1OEpG z@XVHy{g-oJkJ{QYU>SHX8IbY8#Uim_u%%Ij4y;rPfSAE1~7;q?9qH9HL(mH9!kYd&7hgo&76M+^@t_u z)YNaJuRk+z>U1_YsKgl>zVB^|rkDC@BPsgvhI(Ql4NSZ2r`zrJiV)FJ+YeS5ZC0Go zdBIbkaT<4+Zr)=&6wRV&@G#l*^nCYNm~K~`d^x7OXj=9;U1bRiSj5u3oRW$&w!c3! z=}zC6KA3d(XJ@A--RsvrJveZ_$!0HHnwh(^UO)Ky+4C3QegDIcFJGxG12ItwM)dPh z{kofwT`%U5;5F=(7X47g%af#=P_m38lF*zX)M!~UC7Fhd9wGnPOmtD^V@ zDeS?Oqua47>h0t=RMU56-Sem)y>p%%EaQrEumE=uui}1szB?lK(`nI|K%!^3G#i&6m&bb7`S*a?xi85;`eUf_YD;yf`F<7SIgX6B1y*lcQ9(Slo zZ^e}IjatmYrLC=mrfVJTb-7wK7Ex3d2}_ya>ziuzlVB2++QiL2(eqGp69pNjP#l=h4NNW_ zvcd(YI9S$w6NS&sU=}W;M|-ddkD&$M!gKfuUcxW%2mA$x9}gUrmtYIrBRupt};bbrij|~zrF}~ T+dp%2Y}oVPp8wKC-)Z>=q8)6= diff --git a/build/.DS_Store b/build/.DS_Store deleted file mode 100644 index b0c1848e3b68a5e7e3f6b53b894e1ffc08e430be..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%We}f6ur&^(snbnfRNbCvPfx_0HtCVLP27I6cN-4Q50q}Lt`|IqnSxV6h+FK z1#8y4e*?ji4}dRW8IB)8X;Q?ls*rDVeLVI(*PavE9upC(_kt>sLqsLG#KJO)V@&o- zU$C5Mk)2HC2xybKG`JUu_CmC6unJfOPMZRHar@LGP7%$lUq2E)CM!3FyYO{*elkHx zw1P-ZJ|*PA2UzoMdPWCw)z7fLBXWJBY=+gQkYY+vZc;`sDLcwy59U~_*iRBfXZQ_h zgPwyckYR&fU=A^|pyg-|k|V!?7tMUv{*mMAaaq_8ITLunWGP|>0>5ZsJgJWyFSi)! z_tUP?J2aJOzRJY zi2l?)f0u{-mUI5Lh%=AJVKPJA-{Wy0`gPHZgLJ>C^X>5<>$IE;jU+q-wc*9#E>F47 zBc2VGl(n3T!{Juht=_DT%I8l%U8B;-G9^_y?XoZ{fCdAK7aX& z7l$z%0Ls=3PT?CWGtwP4lQ1rLrIiyN*A8bDunL@h1?2wV!X?%W zjy0;S1BJQ*01IeVhPwP@kQ~=w&EQxgdSFabftt$96@zIy+FcV@GdR|$>BP+CgPD<; z{E&e$H9FA61B}%a*upAc6_`^Xub&-x{@?lg{eO;SAFTpbf&WPXR@iCo)bU2F%IZ8| z4P{QNjuXx#T0$19o{Rc7%vUp)C@Qle%HZ=9bzYaxdQ9Z$8Bm|jsYh494pzh*s925wy>rQzncuK3?ppUwJGU3sAq+) zi?%ZFSbo`4tS`s8P^ zQ9d203_L@JN(^*ld?O1;{DY_}NX+~J)WU))f+!4Z+4$Mz`~hke7+4t4S+XzB z@x7Pa5XS&){(5%-%m7U3j(GPlHoxyavV+PPkoXmad zWUC3q;&kR)l*772MJXT!_7ynH<;?s4CH;r_f1jk46p#Y{N&%ZJZWeRCQuWr+%XzPD t^jrF;u{O#Xq7@UP6?5UO_++Q9`8Dr%g+pS{nGZTqKLW0cObYyk0w0~I80`Q6 diff --git a/src/.DS_Store b/src/.DS_Store deleted file mode 100644 index 0c627a7db49741dd40fc8f015f2bb25c2a9e3d86..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%Sr=55bRD?4S31X;~YH+{=pEU;8lM>V-zBb8;H5@2l@g2O{|)3gNx(EgNSrP zPt8nM_wE+#JVZoi+vT~)R756lqOwylPFF)CCpSPXHO}NoHdk$Tzi2Ck{^Ath{YYAQ zkUM#lPw(F?5TPuW@KboR+o2`NKma2ZmP)o;ra$a`q4J}>NFCXep{jRuTAh#l