forked from seutje/PimpMyCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
269 lines (234 loc) · 24.6 KB
/
index.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PimpMyJS - Your minified or pretty printed JavaScript</title>
<meta name="description" content="PimpMyJS is a javascript minifier using uglifyjs! You can use it's interface or simply the webservice to minify or get a pretty print of your javascript code" />
<meta name="author" content="Leo Balter" />
<link rel=”canonical” href="http://pimpmyjs.com/" />
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js" defer></script>
<![endif]-->
<!-- Le styles -->
<link href="css/style.min.css?v=125" rel="stylesheet">
<script src="js/compiled.min.js?v=125" async></script>
</head>
<body>
<div class="topbar">
<div class="fill">
<div class="container">
<a class="brand" href="http://pimpmyjs.com">PimpMyJS</a>
<ul class="nav">
<li class="active"><a href="http://pimpmyjs.com">Home</a></li>
<li><a href="https://github.com/leobalter/PimpMyCode" target="_blank">See the code in Github</a></li>
<li class="share">
<g:plusone size="medium"></g:plusone>
</li>
<li class="share">
<a href="https://twitter.com/share" class="twitter-share-button"
data-text="Uglify or Beautify your JavaScript" data-count="horizontal"
data-via="PimpMyJS" data-related="leobalter">Tweet</a>
</li>
</ul>
</div>
</div>
</div>
<div class="container">
<header>
<h1>Uglify or Beautify your JavaScript, it's your choice...</h1>
<p class="desc">It's a code pimper with uglify option! You can use it's interface or simply the webservice to minify or get a pretty print of your javascript code</p>
</header>
<form id="pimpForm" class="form-stacked" action="http://pimpmyjs.com:3000/" novalidate autocomplete="off"
method="POST" target="pimped">
<div class="row">
<textarea name="toPimp" id="code" tabindex="1"></textarea>
<div class="span4">
<div class="alert-message info">
<p>Options</p>
</div>
<div class="clearfix">
<div class="input">
<ul class="inputs-list">
<li>
<label>
<input type="checkbox" value="beautify" name="uglifyopts">
<span>beautify</span>
</label>
<span class="help-block">
Invert the minification process: turns the ugly JS to a <strong>pretty
printed</strong> code. *
</span>
</li>
<li>
<label>
<input type="checkbox" value="lift" name="uglifyopts">
<span>lift-vars</span>
</label>
<span class="help-block">
Merge and move <code>var</code> declarations to the top of the scope
</span>
</li>
<li>
<label>
<input type="checkbox" value="unsafe" name="uglifyopts">
<span>unsafe</span>
</label>
<span class="help-block">
<em>Black Magic Voodoo</em> for better compression
</span>
</li>
<li>
<label>
<input type="checkbox" value="inline" name="uglifyopts">
<span>inline-script</span>
</label>
<span class="help-block">
Escape <code></script></code> to prevent errors in inline scripts
</span>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="row">
<button class="btn danger span16 large" id="pimpit" type="submit">Pimp it!</button>
</div>
<div class="row">
<div id="pimped" class="span16">
<div class="alert-message success">
<a class="close" href="#">×</a>
<p><strong>Pimped!</strong></p>
</div>
<div class="well">
<iframe src="blank.html" name="pimped"></iframe>
</div>
</div>
</div>
</form>
<p class="desc">Checkout the form source to see the webservice's funcionality!</p>
<h2>How does this work?</h2>
<div class="row">
<div class="span4">
<p>You send your Javascript code, ugly or not:</p>
</div>
<div class="span12">
<div class="gist">
<div class="gist-file">
<div class="gist-data gist-syntax">
<div class="gist-highlight"><pre><div class="line"><span class="kd">var</span> <span class="nx">Song</span> <span class="o">=</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">Model</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span></div><div id="LC2" class="line"> <span class="nx">defaults</span><span class="o">:</span> <span class="p">{</span></div><div id="LC3" class="line"> <span class="nx">name</span><span class="o">:</span> <span class="s2">"Not specified"</span><span class="p">,</span></div><div id="LC4" class="line"> <span class="nx">artist</span><span class="o">:</span> <span class="s2">"Not specified"</span></div><div id="LC5" class="line"> <span class="p">},</span></div><div id="LC6" class="line"> <span class="nx">initialize</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span></div><div id="LC7" class="line"> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Music is the answer"</span><span class="p">);</span></div><div id="LC8" class="line"> <span class="p">}</span></div><div id="LC9" class="line"><span class="p">});</span></div><div id="LC10" class="line"><br></div><div id="LC11" class="line"><span class="kd">var</span> <span class="nx">Album</span> <span class="o">=</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">Collection</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span></div><div id="LC12" class="line"> <span class="nx">model</span><span class="o">:</span> <span class="nx">Song</span></div><div id="LC13" class="line"><span class="p">});</span></div><div id="LC14" class="line"><br></div><div id="LC15" class="line"><span class="kd">var</span> <span class="nx">song1</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Song</span><span class="p">({</span> <span class="nx">name</span><span class="o">:</span> <span class="s2">"How Bizarre"</span><span class="p">,</span> <span class="nx">artist</span><span class="o">:</span> <span class="s2">"OMC"</span> <span class="p">});</span></div><div id="LC16" class="line"><span class="kd">var</span> <span class="nx">song2</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Song</span><span class="p">({</span> <span class="nx">name</span><span class="o">:</span> <span class="s2">"Sexual Healing"</span><span class="p">,</span> <span class="nx">artist</span><span class="o">:</span> <span class="s2">"Marvin Gaye"</span> <span class="p">});</span></div><div id="LC17" class="line"><span class="kd">var</span> <span class="nx">song3</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Song</span><span class="p">({</span> <span class="nx">name</span><span class="o">:</span> <span class="s2">"Talk It Over In Bed"</span><span class="p">,</span> <span class="nx">artist</span><span class="o">:</span> <span class="s2">"OMC"</span> <span class="p">});</span></div><div id="LC18" class="line"><br></div><div id="LC19" class="line"><span class="kd">var</span> <span class="nx">myAlbum</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Album</span><span class="p">([</span> <span class="nx">song1</span><span class="p">,</span> <span class="nx">song2</span><span class="p">,</span> <span class="nx">song3</span><span class="p">]);</span></div><div id="LC20" class="line"><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">myAlbum</span><span class="p">.</span><span class="nx">models</span><span class="p">);</span> <span class="c1">// [song1, song2, song3]</span></div></pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="span4">
<p>Then you can uglify it:</p>
</div>
<div class="span12">
<div class="gist">
<div class="gist-file">
<div class="gist-data gist-syntax">
<div class="gist-highlight"><pre><div class="line">var Song=Backbone.Model.extend({defaults:{name:"Not specified",artist:"Not specified"},initialize:function(){console.log("Music is the answer")}}),Album=Backbone.Collection.extend({model:Song}),song1=new Song({name:"How Bizarre",artist:"OMC"}),song2=new Song({name:"Sexual Healing",artist:"Marvin Gaye"}),song3=new Song({name:"Talk It Over In Bed",artist:"OMC"}),myAlbum=new Album([song1,song2,song3]);console.log(myAlbum.models)</div></pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="span4">
<p>Don't know what's written in that ugly js? Try beautifying it!</p>
<p>Yeah, it's not the same original code, but you can read it now, right?</p>
<p>This doesn't bring beauty of Dart of CoffeeScript codes, ever.</p>
</div>
<div class="span12">
<div class="gist">
<div class="gist-file">
<div class="gist-data gist-syntax">
<div class="gist-highlight"><pre><div class="line"><span class="kd">var</span> <span class="nx">Song</span> <span class="o">=</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">Model</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span></div><div id="LC2" class="line"> <span class="nx">defaults</span><span class="o">:</span> <span class="p">{</span></div><div id="LC3" class="line"> <span class="nx">name</span><span class="o">:</span> <span class="s2">"Not specified"</span><span class="p">,</span></div><div id="LC4" class="line"> <span class="nx">artist</span><span class="o">:</span> <span class="s2">"Not specified"</span></div><div id="LC5" class="line"> <span class="p">},</span></div><div id="LC6" class="line"> <span class="nx">initialize</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span></div><div id="LC7" class="line"> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Music is the answer"</span><span class="p">);</span></div><div id="LC8" class="line"> <span class="p">}</span></div><div id="LC9" class="line"><span class="p">}),</span> <span class="nx">Album</span> <span class="o">=</span> <span class="nx">Backbone</span><span class="p">.</span><span class="nx">Collection</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span></div><div id="LC10" class="line"> <span class="nx">model</span><span class="o">:</span> <span class="nx">Song</span></div><div id="LC11" class="line"><span class="p">}),</span> <span class="nx">song1</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Song</span><span class="p">({</span></div><div id="LC12" class="line"> <span class="nx">name</span><span class="o">:</span> <span class="s2">"How Bizarre"</span><span class="p">,</span></div><div id="LC13" class="line"> <span class="nx">artist</span><span class="o">:</span> <span class="s2">"OMC"</span></div><div id="LC14" class="line"><span class="p">}),</span> <span class="nx">song2</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Song</span><span class="p">({</span></div><div id="LC15" class="line"> <span class="nx">name</span><span class="o">:</span> <span class="s2">"Sexual Healing"</span><span class="p">,</span></div><div id="LC16" class="line"> <span class="nx">artist</span><span class="o">:</span> <span class="s2">"Marvin Gaye"</span></div><div id="LC17" class="line"><span class="p">}),</span> <span class="nx">song3</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Song</span><span class="p">({</span></div><div id="LC18" class="line"> <span class="nx">name</span><span class="o">:</span> <span class="s2">"Talk It Over In Bed"</span><span class="p">,</span></div><div id="LC19" class="line"> <span class="nx">artist</span><span class="o">:</span> <span class="s2">"OMC"</span></div><div id="LC20" class="line"><span class="p">}),</span> <span class="nx">myAlbum</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Album</span><span class="p">([</span> <span class="nx">song1</span><span class="p">,</span> <span class="nx">song2</span><span class="p">,</span> <span class="nx">song3</span> <span class="p">]);</span></div><div id="LC21" class="line"><br></div><div id="LC22" class="line"><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">myAlbum</span><span class="p">.</span><span class="nx">models</span><span class="p">);</span></div></pre></div>
</div>
</div>
</div>
</div>
</div>
<h2>What do you mean by unsafe?</h2>
<div class="row">
<div class="span4">
<p>There're some code Uglify can compress but it's possible to break your code, so if you want it on, you
have to
check this option</p>
<p>This will be ignored if you check the beautify option</p>
</div>
<div class="span12">
<div class="gist">
<div class="gist-file">
<div class="gist-data gist-syntax">
<div class="gist-highlight"><pre><div class="line"><span class="nx">obj</span><span class="p">.</span><span class="nx">toString</span><span class="p">()</span> <span class="c1">// => obj+""</span></div><div id="LC2" class="line"><span class="k">new</span> <span class="nb">Array</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span> <span class="c1">// => [1,2,3,4]</span></div><div id="LC3" class="line"><span class="nb">Array</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span> <span class="nx">b</span><span class="p">,</span> <span class="nx">c</span><span class="p">)</span> <span class="c1">// => [a,b,c]</span></div><div id="LC4" class="line"><span class="k">new</span> <span class="nb">Array</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span> <span class="c1">// => Array(5)</span></div><div id="LC5" class="line"><span class="k">new</span> <span class="nb">Array</span><span class="p">(</span><span class="nx">a</span><span class="p">)</span> <span class="c1">// => Array(a)</span></div></pre></div>
</div>
</div>
</div>
</div>
</div>
<h2>Inline Scripts</h2>
<div class="row">
<div class="span4">
<p>You can prevent showing <code></script></code> in your code, turn on this option and Uglify will
escape it!
</p>
</div>
<div class="span12">
<div class="gist">
<div class="gist-file">
<div class="gist-data gist-syntax">
<div class="gist-highlight"><pre><div class="line"><span class="kd">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="s2">"</script>"</span><span class="p">;</span> <span class="c1">// => var a="<\/script>"</span></div></pre></div>
</div>
</div>
</div>
</div>
</div>
<h2>Lift me a var...</h2>
<div class="row">
<div class="span4">
<p>As well said in UglifyJS documentation:</p>
<p>"merge and move <code>var</code> declarations to the top of the scope; discard unused function arguments
or
variables; discard unused (named) inner functions. It also tries to merge assignments following the var
declaration into it.</p>
<p>Note that although it might increase the file size (on jQuery it gains 865 bytes, 243 after gzip) it’s
technically more correct: in certain situations, dead code removal might drop variable declarations,
which would
not happen if the variables are lifted in advance."</p>
</div>
<div class="span12">
<div class="gist">
<div class="gist-file">
<div class="gist-data gist-syntax">
<div class="gist-highlight"><pre><div class="line"><span class="kd">function</span> <span class="nx">f</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span> <span class="nx">b</span><span class="p">,</span> <span class="nx">c</span><span class="p">,</span> <span class="nx">d</span><span class="p">,</span> <span class="nx">e</span><span class="p">)</span> <span class="p">{</span></div><div id="LC2" class="line"> <span class="kd">var</span> <span class="nx">q</span><span class="p">;</span></div><div id="LC3" class="line"> <span class="kd">var</span> <span class="nx">w</span><span class="p">;</span></div><div id="LC4" class="line"> <span class="nx">w</span> <span class="o">=</span> <span class="mi">10</span><span class="p">;</span></div><div id="LC5" class="line"> <span class="nx">q</span> <span class="o">=</span> <span class="mi">20</span><span class="p">;</span></div><div id="LC6" class="line"> <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="mi">10</span><span class="p">;</span> <span class="o">++</span><span class="nx">i</span><span class="p">)</span> <span class="p">{</span></div><div id="LC7" class="line"> <span class="kd">var</span> <span class="nx">boo</span> <span class="o">=</span> <span class="nx">foo</span><span class="p">(</span><span class="nx">a</span><span class="p">);</span></div><div id="LC8" class="line"> <span class="p">}</span></div><div id="LC9" class="line"> <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="mi">1</span><span class="p">;</span> <span class="o">++</span><span class="nx">i</span><span class="p">)</span> <span class="p">{</span></div><div id="LC10" class="line"> <span class="kd">var</span> <span class="nx">boo</span> <span class="o">=</span> <span class="nx">bar</span><span class="p">(</span><span class="nx">c</span><span class="p">);</span></div><div id="LC11" class="line"> <span class="p">}</span></div><div id="LC12" class="line"> <span class="kd">function</span> <span class="nx">foo</span><span class="p">(){</span> <span class="cm">/*...*/</span> <span class="p">}</span></div><div id="LC13" class="line"> <span class="kd">function</span> <span class="nx">bar</span><span class="p">(){</span> <span class="cm">/*...*/</span> <span class="p">}</span></div><div id="LC14" class="line"> <span class="kd">function</span> <span class="nx">baz</span><span class="p">(){</span> <span class="cm">/*...*/</span> <span class="p">}</span></div><div id="LC15" class="line"><span class="p">}</span></div></pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="span4">
<p>Check out the lift vars result (with Beautify):</p>
</div>
<div class="span12">
<div class="gist">
<div class="gist-file">
<div class="gist-data gist-syntax">
<div class="gist-highlight"><pre><div class="line"><span class="kd">function</span> <span class="nx">f</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span> <span class="nx">b</span><span class="p">,</span> <span class="nx">c</span><span class="p">)</span> <span class="p">{</span></div><div id="LC2" class="line"> <span class="kd">var</span> <span class="nx">f</span><span class="p">,</span> <span class="nx">g</span><span class="p">,</span> <span class="nx">h</span><span class="p">,</span> <span class="nx">i</span><span class="p">;</span></div><div id="LC3" class="line"> <span class="kd">function</span> <span class="nx">j</span><span class="p">()</span> <span class="p">{}</span></div><div id="LC4" class="line"> <span class="kd">function</span> <span class="nx">k</span><span class="p">()</span> <span class="p">{}</span></div><div id="LC5" class="line"> <span class="nx">g</span> <span class="o">=</span> <span class="mi">10</span><span class="p">,</span> <span class="nx">f</span> <span class="o">=</span> <span class="mi">20</span><span class="p">;</span></div><div id="LC6" class="line"> <span class="k">for</span> <span class="p">(</span><span class="nx">h</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="nx">h</span> <span class="o"><</span> <span class="mi">10</span><span class="p">;</span> <span class="o">++</span><span class="nx">h</span><span class="p">)</span> <span class="nx">i</span> <span class="o">=</span> <span class="nx">j</span><span class="p">(</span><span class="nx">a</span><span class="p">);</span></div><div id="LC7" class="line"> <span class="k">for</span> <span class="p">(</span><span class="nx">h</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">h</span> <span class="o"><</span> <span class="mi">1</span><span class="p">;</span> <span class="o">++</span><span class="nx">h</span><span class="p">)</span> <span class="nx">i</span> <span class="o">=</span> <span class="nx">k</span><span class="p">(</span><span class="nx">c</span><span class="p">);</span></div><div id="LC8" class="line"><span class="p">}</span></div></pre></div>
</div>
</div>
</div>
</div>
</div>
<footer>
<p>© WTFPL 2011</p>
</footer>
</div>
<!-- /container -->
</body>
</html>