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

Commit465f16f

Browse files
committed
add code to allow usage without requirejs
1 parentea3efa7 commit465f16f

File tree

3 files changed

+142
-2
lines changed

3 files changed

+142
-2
lines changed

‎index-no-requirejs.html‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<metacharset='utf-8'>
5+
<title>json.human.js - Json Formatting for Human Beings</title>
6+
<linkrel="stylesheet"media="all"href="css/demo.css"/>
7+
<linkrel="stylesheet"media="all"href="css/json.human.css"/>
8+
<linkrel="stylesheet"media="all"href="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.16.0/codemirror.css"/>
9+
</head>
10+
11+
<body>
12+
<h1>json.human.js: Json Formatting for Human Beings</h1>
13+
14+
<pclass="project-description">Provide JSON and get a DOM node with
15+
a human representation of that JSON.</p>
16+
17+
18+
<h2>Why?</h2>
19+
20+
<p>At<ahref="http://event-fabric.com">Event Fabric</a> we need to display JSON to people from all technical levels without being too technical but also without losing information about the underlying JSON object.</p>
21+
22+
<h2>How?</h2>
23+
24+
<p>you can see<ahref="https://github.com/marianoguerra/json.human.js/blob/master/js/demo.js">js/demo.js</a> in the<ahref="http://github.com/marianoguerra/json.human.js">repo</a> for an example, here is a short one</p>
25+
26+
<pre>
27+
var node = JsonHuman.format(input);
28+
output.appendChild(node);
29+
</pre>
30+
31+
<h2>Try it</h2>
32+
<p>edit the JSON and click<em>Convert</em></p>
33+
34+
<h2>Input: JSON</h2>
35+
36+
<textareaid="input">{
37+
"name": "json.human",
38+
"description": "Convert JSON to human readable HTML",
39+
"author": "Mariano Guerra<mariano@marianoguerra.org>",
40+
"tags": ["DOM", "HTML", "JSON", "Pretty Print"],
41+
"version": "0.1.0",
42+
"main": "json.human.js",
43+
"license" : "MIT",
44+
"dependencies": {
45+
"crel": "1.0.0"
46+
},
47+
"repository": {
48+
"type": "git",
49+
"url": "git://github.com/marianoguerra/json.human.js.git"
50+
},
51+
"bugs": {
52+
"url": "http://github.com/marianoguerra/json.human.js/issues"
53+
},
54+
"contributors": [],
55+
"config": {
56+
"what?": "this object is just to show some extra stuff",
57+
"how?": ["add json.human.js", "add json.human.css", "???", "profit!"],
58+
"customization?": ["customize the css prefix", "change the css file"],
59+
"integer": 42,
60+
"float": 12.3,
61+
"bool": true,
62+
"emptyString": "",
63+
"emptyArray": [],
64+
"emptyObject": {},
65+
"htmlEntities": "<-trailing<em> &</em> and some html "
66+
}
67+
}
68+
</textarea>
69+
70+
<divclass="buttons">
71+
<buttonid="convert">Convert</button>
72+
</div>
73+
74+
<h2>Output: HTML</h2>
75+
76+
<divid="output">
77+
</div>
78+
79+
<h2>Raw HTML</h2>
80+
<textareaid="output-raw"style="width: 100%; height: 20em;">
81+
</textarea>
82+
83+
<h2>License?</h2>
84+
85+
<p><ahref="http://opensource.org/licenses/MIT">MIT</a></p>
86+
87+
<h2>Alternatives</h2>
88+
<ul>
89+
<li><ahref="https://github.com/padolsey/prettyPrint.js">prettyprint.js</a></li>
90+
</ul>
91+
92+
93+
<scriptsrc="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.16.0/codemirror.min.js"></script>
94+
<scriptsrc="lib/crel.js"></script>
95+
<scriptsrc="src/json.human.js"></script>
96+
<scriptsrc="js/demo.no.requirejs.js"></script>
97+
</body>
98+
</html>

‎js/demo.no.requirejs.js‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*global document, JSON, window, alert*/
2+
(function(JsonHuman,crel,CodeMirror){
3+
"use strict";
4+
vartextarea=document.getElementById("input"),
5+
output=document.getElementById("output"),
6+
raw=document.getElementById("output-raw"),
7+
button=document.getElementById("convert"),
8+
editor=CodeMirror.fromTextArea(textarea,{
9+
mode:"application/json",
10+
json:true
11+
});
12+
13+
functionconvert(input,output){
14+
varnode=JsonHuman.format(input);
15+
16+
output.innerHTML="";
17+
output.appendChild(node);
18+
raw.textContent=output.innerHTML;
19+
}
20+
21+
functiondoConvert(){
22+
varjson;
23+
try{
24+
json=JSON.parse(editor.getValue());
25+
}catch(error){
26+
alert("Error parsing json:\n"+error.stack);
27+
return;
28+
}
29+
30+
convert(json,output);
31+
}
32+
33+
button.addEventListener("click",doConvert);
34+
doConvert();
35+
}(window.JsonHuman,window.crel,window.CodeMirror));

‎src/json.human.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
/*globals define*/
2-
define(['crel'],function(crel){
2+
(function(root,factory){
3+
"use strict";
4+
if(typeofdefine==='function'&&define.amd){
5+
define(['crel'],factory);
6+
}else{
7+
root.JsonHuman=factory(root.crel);
8+
}
9+
}(this,function(crel){
310
"use strict";
411
vartoString=Object.prototype.toString,
512
ARRAY=1,
@@ -136,4 +143,4 @@ define(['crel'], function (crel) {
136143
return{
137144
format:format
138145
};
139-
});
146+
}));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp