Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf3e6b48

Browse files
committed
Cleanup
Fixes marianoguerra review comments -Removed redundant lookupsMoved indexOf to mod scope
1 parent26c9b24 commitf3e6b48

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed

‎js/demo.no.requirejs.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
functionconvert(input,output){
1414
varnode=JsonHuman.format(input,{
15-
showArrayIndex:true,
15+
showArrayIndex:false,
1616
hyperlinks :{
1717
enable :true,
1818
keys:['url','main'],

‎src/json.human.js‎

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
}(this,function(){
1212
"use strict";
1313

14+
varindexOf=[].indexOf||function(item){for(vari=0,l=this.length;i<l;i++){if(iinthis&&this[i]===item)returni;}return-1;};
15+
1416
functionmakePrefixer(prefix){
1517
returnfunction(name){
1618
returnprefix+"-"+name;
@@ -114,12 +116,13 @@
114116

115117
function_format(data,options,parentKey){
116118

117-
varresult,container,key,keyNode,valNode,len,childs,tr,
119+
varresult,container,key,keyNode,valNode,len,childs,tr,value,
118120
isEmpty=true,
119121
accum=[],
120122
type=getType(data);
121123

122-
varindexOf=[].indexOf||function(item){for(vari=0,l=this.length;i<l;i++){if(iinthis&&this[i]===item)returni;}return-1;};
124+
// Initialized & used only in case of objects & arrays
125+
varhyperlinksEnabled,aTarget,hyperlinkKeys;
123126

124127
switch(type){
125128
caseBOOL:
@@ -141,20 +144,29 @@
141144
break;
142145
caseOBJECT:
143146
childs=[];
147+
148+
aTarget=options.hyperlinks.target;
149+
hyperlinkKeys=options.hyperlinks.keys;
150+
151+
// Is Hyperlink Key
152+
hyperlinksEnabled=
153+
options.hyperlinks.enable&&
154+
hyperlinkKeys&&
155+
hyperlinkKeys.length>0;
156+
144157
for(keyindata){
145158
isEmpty=false;
146159

147-
valNode=_format(data[key],options,key);
160+
value=data[key];
161+
162+
valNode=_format(value,options,key);
148163
keyNode=sn("th",OBJ_KEY_CLASS_NAME,key);
149164

150-
// Is Hyperlink Key
151-
if(options.hyperlinks.enable&&
152-
options.hyperlinks.keys&&
153-
options.hyperlinks.keys.length>0&&
154-
typeof(data[key])==='string'&&
155-
indexOf.call(options.hyperlinks.keys,key)>=0){
165+
if(hyperlinksEnabled&&
166+
typeof(value)==='string'&&
167+
indexOf.call(hyperlinkKeys,key)>=0){
156168

157-
valNode=scn("td",OBJ_VAL_CLASS_NAME,linkNode(valNode,data[key],options.hyperlinks.target));
169+
valNode=scn("td",OBJ_VAL_CLASS_NAME,linkNode(valNode,value,aTarget));
158170
}else{
159171
valNode=scn("td",OBJ_VAL_CLASS_NAME,valNode);
160172
}
@@ -178,26 +190,32 @@
178190
caseARRAY:
179191
if(data.length>0){
180192
childs=[];
193+
varshowArrayIndices=options.showArrayIndex;
194+
195+
aTarget=options.hyperlinks.target;
196+
hyperlinkKeys=options.hyperlinks.keys;
181197

182198
// Hyperlink of arrays?
183-
varhyperlinks=parentKey&&options.hyperlinks.enable&&
184-
options.hyperlinks.keys&&
185-
options.hyperlinks.keys.length>0&&
186-
indexOf.call(options.hyperlinks.keys,parentKey)>=0;
199+
hyperlinksEnabled=parentKey&&options.hyperlinks.enable&&
200+
hyperlinkKeys&&
201+
hyperlinkKeys.length>0&&
202+
indexOf.call(hyperlinkKeys,parentKey)>=0;
187203

188204
for(key=0,len=data.length;key<len;key+=1){
189205

190206
keyNode=sn("th",ARRAY_KEY_CLASS_NAME,key);
191-
if(hyperlinks&&typeof(data[key])==="string"){
192-
valNode=_format(data[key],options,key);
193-
valNode=scn("td",ARRAY_VAL_CLASS_NAME,linkNode(valNode,data[key],options.hyperlinks.target));
207+
value=data[key];
208+
209+
if(hyperlinksEnabled&&typeof(value)==="string"){
210+
valNode=_format(value,options,key);
211+
valNode=scn("td",ARRAY_VAL_CLASS_NAME,linkNode(valNode,value,aTarget));
194212
}else{
195-
valNode=scn("td",ARRAY_VAL_CLASS_NAME,_format(data[key],options,key));
213+
valNode=scn("td",ARRAY_VAL_CLASS_NAME,_format(value,options,key));
196214
}
197215

198216
tr=document.createElement("tr");
199217

200-
if(options.showArrayIndex){
218+
if(showArrayIndices){
201219
tr.appendChild(keyNode);
202220
}
203221
tr.appendChild(valNode);
@@ -241,7 +259,7 @@
241259

242260

243261
functionvalidateArrayIndexOption(options){
244-
if(options['showArrayIndex']===undefined){
262+
if(options.showArrayIndex===undefined){
245263
options.showArrayIndex=true;
246264
}else{
247265
// Force to boolean just in case

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp