-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.html
101 lines (91 loc) · 3.71 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<!-- IE has problems if go to github directly, but is happy when we use wrapit instead -->
<script src="http://wrapit.jit.su/?url=https://raw.github.com/omphalos/require-shim/master/require-shim.js" ></script>
<!-- four parts to the query string:
wrapit url: <script src="http://wrapit.jit.su/
file header: ?header= provide('uglify-js/uglify-js', function(require, exports, module){
url to wrap: &url= https://raw.github.com/mishoo/UglifyJS/master/uglify-js.js
file footer: &footer= });"></script>
-->
<!-- reference to uglify-js/lib/consolidator -->
<script src="http://wrapit.jit.su/
?header= provide('uglify-js/lib/consolidator', function(require, exports, module){
&url= https://raw.github.com/mishoo/UglifyJS/master/lib/consolidator.js
&footer= });">
</script>
<!-- reference to uglify-js/lib/parse-js -->
<script src="http://wrapit.jit.su/
?header= provide('uglify-js/lib/parse-js', function(require, exports, module){
&url= https://raw.github.com/mishoo/UglifyJS/master/lib/parse-js.js
&footer= });">
</script>
<!-- reference to uglify-js/lib/process -->
<script src="http://wrapit.jit.su/
?header= provide('uglify-js/lib/process', function(require, exports, module){
&url= https://raw.github.com/mishoo/UglifyJS/master/lib/process.js
&footer= });">
</script>
<!-- reference to uglify-js/lib/squeeze-more -->
<script src="http://wrapit.jit.su/
?header= provide('uglify-js/lib/squeeze-more',function(require, exports, module){
&url= https://raw.github.com/mishoo/UglifyJS/master/lib/squeeze-more.js
&footer= });">
</script>
<!-- include uglify-js/uglify-js -->
<script src="http://wrapit.jit.su/
?header= provide('uglify-js/uglify-js', function(require, exports, module){
&url= https://raw.github.com/mishoo/UglifyJS/master/uglify-js.js
&footer= });">
</script>
<!-- map uglify-js/uglify-js to uglify-js so we can just call require('uglify-js') instead of require('uglify-js/uglify-js') -->
<script type="text/javascript">
provide('uglify-js', function(require, exports, module) {
module.exports = require('uglify-js/uglify-js');
});
</script>
<body>
</body>
<h3>Demo of running a Node.js module (<a href="https://github.com/mishoo/UglifyJS/">uglify-js</a>) from the browser</h3>
<p><strong>Step #1.</strong> Put some javascript here:</p>
<textarea id="in" cols="80" rows="20" style="width:100%;" >
$('input').click(function() {
try {
var js = $('#in').val(); // grab the user's javascript
// this code is adapted from uglify-js's homepage
var uglify = require('uglify-js');
var parser = uglify.parser;
var ast = parser.parse(js);
var pro = uglify.uglify;
ast = pro.ast_mangle(ast);
ast = pro.ast_squeeze(ast);
var finalCode = pro.gen_code(ast);
// give the ugly version to the user
$('#main').html(finalCode);
} catch(err) {
$('#main').html('error: ' + err);
}
});</textarea>
<span><strong>Step #2.</strong></span>
<input type="button" id="btn" value="Click to uglify" />
<p id="main" />
<script type="text/javascript" >
$('input').click(function() {
try {
var uglify = require('uglify-js');
var parser = uglify.parser;
var js = $('#in').val();
var ast = parser.parse(js);
var pro = uglify.uglify;
ast = pro.ast_mangle(ast);
ast = pro.ast_squeeze(ast);
var finalCode = pro.gen_code(ast);
$('#main').html(finalCode);
} catch(err) {
$('#main').html('error: ' + err);
}
});
</script>
</html>