/
uglifui.js
84 lines (72 loc) · 2.08 KB
/
uglifui.js
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
/**
* UglifUI
* by Alex Sexton - AlexSexton@gmail.com
*
* A web interface to UglifyJS
*
* All the UglifyJS Code plus the modifications made to it
* in order to make UglifUI work are subject to the license
* that UglifyJS is released under (currently BSD)
*
* The rest of the code (more or less this file) is WTFPL
* so go crazy.
*
* I pronounce it "UG-LIH-FEW-EYE" ["JAY-ESS"] - but I don't
* care how you say it.
*/
(function ( global, doc, $, uglify, undef ) {
// Create our app object
var uglifui = {
init: function () {
var self = this;
// Dom ready
$(function () {
self.setElements();
self.hookEvents();
});
},
elements : {},
setElements : function () {
// Main code text area
this.elements.ta_code = $('#code');
// The form element
this.elements.frm_uglify = $('#ugForm');
// List of flags
this.elements.ul_flags = $('#flagList');
},
getCode : function () {
return this.elements.ta_code.val();
},
getFlags : function () {
var flags = [],
linelen = $('#max-line-len'),
lineval = global.parseInt( $('#linelen').val(), 10 );
// Loop through and add the correct flags
this.elements.ul_flags.find(':checked:not(#max-line-len)').each(function ( key, elem ) {
flags.push( '--' + elem.id );
});
// Special case for line len (with a sane minimum)
if ( linelen.is( ':checked' ) && lineval > 3 ) {
flags.push( '--max-line-len' );
flags.push( lineval + "" );
}
return flags;
},
submit : function () {
var code = this.getCode(),
flags = this.getFlags();
this.elements.ta_code.val( uglify( code, flags ) );
},
hookEvents : function () {
var self = this;
// Hook up the submit event
this.elements.frm_uglify.submit(function ( e ) {
e.preventDefault();
self.submit();
return false;
});
}
};
// Start it up
uglifui.init();
})( this, this.document, this.jQuery, this.uglify );