Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
102 lines (91 sloc) 3.71 KB
<!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>