forked from Modernizr/Modernizr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
modular.html
336 lines (316 loc) · 9.36 KB
/
modular.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<!doctype html>
<html class="no-js" lang=en>
<head>
<title>Modular Modernizr Demo Page</title>
<style>
textarea {
width: 100%;
height: 20em;
}
</style>
</head>
<body>
<div>
<h1>Config JSON</h1>
<textarea id="config-json">{
"classPrefix" : "",
"options": [
"setClasses",
"addTest",
"html5printshiv",
"load",
"testProp",
"fnBind"
],
"feature-detects": [
"test/a/download",
"test/audio/audiodata",
"test/audio/webaudio",
"test/battery/lowbattery",
"test/canvas/todataurl",
"test/css/animations",
"test/css/backgroundposition-shorthand",
"test/css/backgroundposition-xy",
"test/css/backgroundrepeat",
"test/css/backgroundsize",
"test/css/backgroundsizecover",
"test/css/borderimage",
"test/css/borderradius",
"test/css/boxshadow",
"test/css/boxsizing",
"test/css/calc",
"test/css/columns",
"test/css/cubicbezierrange",
"test/css/displayrunin",
"test/css/displaytable",
"test/css/filters",
"test/css/flexbox",
"test/css/flexboxlegacy",
"test/css/fontface",
"test/css/generatedcontent",
"test/css/gradients",
"test/css/hsla",
"test/css/hyphens",
"test/css/lastchild",
"test/css/mask",
"test/css/mediaqueries",
"test/css/multiplebgs",
"test/css/objectfit",
"test/css/opacity",
"test/css/overflow-scrolling",
"test/css/pointerevents",
"test/css/positionsticky",
"test/css/reflections",
"test/css/regions",
"test/css/remunit",
"test/css/resize",
"test/css/rgba",
"test/css/scrollbars",
"test/css/subpixelfont",
"test/css/supports",
"test/css/textshadow",
"test/css/transforms",
"test/css/transforms3d",
"test/css/transitions",
"test/css/userselect",
"test/css/vhunit",
"test/css/vmaxunit",
"test/css/vminunit",
"test/css/vwunit",
"test/css/wrapflow",
"test/dom/classlist",
"test/dom/createElement-attrs",
"test/dom/dataset",
"test/dom/microdata",
"test/elem/datalist",
"test/elem/details",
"test/elem/output",
"test/elem/progress-meter",
"test/elem/ruby",
"test/elem/time",
"test/elem/track",
"test/es5/strictmode",
"test/event/deviceorientation-motion",
"test/file/api",
"test/file/filesystem",
"test/forms/fileinput",
"test/forms/formattribute",
"test/forms/inputnumber-l10n",
"test/forms/placeholder",
"test/forms/speechinput",
"test/forms/validation",
"test/iframe/sandbox",
"test/iframe/seamless",
"test/iframe/srcdoc",
"test/img/apng",
"test/img/webp-lossless",
"test/img/webp",
"test/network/connection",
"test/network/eventsource",
"test/network/xhr2",
"test/script/async",
"test/script/defer",
"test/storage/localstorage",
"test/storage/sessionstorage",
"test/storage/websqldatabase",
"test/style/scoped",
"test/svg/clippaths",
"test/svg/filters",
"test/svg/inline",
"test/svg/smil",
"test/url/data-uri",
"test/webgl/extensions",
"test/websockets/binary",
"test/window/framed",
"test/workers/blobworkers",
"test/workers/dataworkers",
"test/workers/webworkers",
"test/webrtc/getusermedia",
"test/webrtc/peerconnection",
"test/applicationcache",
"test/audio",
"test/battery",
"test/blob",
"test/canvas",
"test/canvastext",
"test/contenteditable",
"test/contentsecuritypolicy",
"test/contextmenu",
"test/cookies",
"test/cors",
"test/custom-protocol-handler",
"test/dart",
"test/dataview-api",
"test/draganddrop",
"test/emoji",
"test/exif-orientation",
"test/fullscreen-api",
"test/gamepad",
"test/hashchange",
"test/history",
"test/ie8compat",
"test/indexedDB",
"test/input",
"test/inputtypes",
"test/json",
"test/lists-reversed",
"test/mathml",
"test/notification",
"test/pagevisibility-api",
"test/performance",
"test/pointerevents",
"test/pointerlock-api",
"test/postmessage",
"test/quota-management-api",
"test/requestanimationframe",
"test/svg",
"test/touchevents",
"test/unicode",
"test/userdata",
"test/vibration",
"test/video",
"test/web-intents",
"test/webgl",
"test/websockets"
]
}</textarea>
</div>
<button id="build">If you build it</button>
<div>
<h1>Modernizr Output</h1>
<h3>Development</h3>
<textarea id="buildoutput"></textarea>
<br />
<h3>Minified</h3>
<textarea id="buildoutputmin"></textarea>
</div>
<script src="r.js"></script>
<script src="node_modules/underscore/underscore-min.js"></script>
<script>
var buildButton = document.getElementById('build');
var configArea = document.getElementById('config-json');
var license = '/*!\n' +
' * Modernizr v3.0.0pre\n' +
' * modernizr.com\n' +
' *\n' +
' * Copyright (c) Faruk Ates, Paul Irish, Alex Sexton\n' +
' * MIT License\n' +
'*/\n' +
' \n' +
'/*\n' +
' * Modernizr tests which native CSS3 and HTML5 features are available in the\n' +
' * current UA and makes the results available to you in two ways: as properties on\n' +
' * a global `Modernizr` object, and as classes on the `<html>` element. This\n' +
' * information allows you to progressively enhance your pages with a granular level\n' +
' * of control over the experience.\n' +
' *\n' +
' * Modernizr has an optional (*not included*) conditional resource loader called\n' +
' * `Modernizr.load()`, based on [Yepnope.js](http://yepnopejs.com). You can get a\n' +
' * build that includes `Modernizr.load()`, as well as choosing which feature tests\n' +
' * to include on the [Download page](http://www.modernizr.com/download/).\n' +
' *\n' +
' *\n' +
' * Authors Faruk Ates, Paul Irish, Alex Sexton\n' +
' * Contributors Ryan Seddon, Ben Alman\n' +
' */';
// avoid some config
define('underscore', function () { return _; });
// Handle a build
buildButton.onclick = function () {
var config = configArea.value;
try {
config = JSON.parse(config);
}
catch(e) {
alert('Bad config, yo');
return;
}
require(['src/generate'], function( generate ) {
var modInit = generate(config);
requirejs.optimize({
"baseUrl" : "src/",
"optimize" : "none",
"optimizeCss" : "none",
"paths" : {
"test" : "../../feature-detects",
},
"include" : ["modernizr-init"],
rawText: {
"modernizr-init" : modInit
},
wrap: {
start: license + "\n;(function(window, document, undefined){",
end: "})(this, document);"
},
onBuildWrite: function (id, path, contents) {
if ((/define\(.*?\{/).test(contents)) {
//Remove AMD ceremony for use without require.js or almond.js
contents = contents.replace(/define\(.*?\{/, '');
contents = contents.replace(/\}\);\s*?$/,'');
if ( !contents.match(/Modernizr\.addTest\(/) && !contents.match(/Modernizr\.addAsyncTest\(/) ) {
//remove last return statement and trailing })
contents = contents.replace(/return.*[^return]*$/,'');
}
}
else if ((/require\([^\{]*?\{/).test(contents)) {
contents = contents.replace(/require[^\{]+\{/, '');
contents = contents.replace(/\}\);\s*$/,'');
}
return contents;
},
out : function (output) {
output = output.replace('define("modernizr-init", function(){});', '');
// Hack the prefix into place. Anything is way to big for something so small.
if ( config && config.classPrefix ) {
output = output.replace("classPrefix : '',", "classPrefix : '" + config.classPrefix.replace(/"/g, '\\"') + "',");
}
var outBox = document.getElementById('buildoutput');
var outBoxMin = document.getElementById('buildoutputmin');
outBox.innerHTML = output;
require({context: 'build'}, ['uglifyjs2'], function (u2){
var UglifyJS = u2.UglifyJS;
outBoxMin.innerHTML = '/*! Modernizr 3.0.0pre (Custom Build) | MIT */\n' + minify(UglifyJS, output, {});
});
// add in old hack for now, just so i don't forget
//outBoxMin.innerHTML = uglify( output, ['--extra', '--unsafe'] ).replace( "return a.history&&history.pushState", "return !!(a.history&&history.pushState)" );
}
}, function (buildText) {
console.log({ buildOutput: buildText });
});
});
};
function minify( UglifyJS, code, options) {
options = UglifyJS.defaults(options, {
outSourceMap : null,
sourceRoot : null,
inSourceMap : null,
fromString : false,
warnings : false
});
if (typeof files == "string") {
files = [ files ];
}
// 1. parse
var toplevel = UglifyJS.parse(code, {
filename: 'modernizr-custombuild.min.js',
toplevel: toplevel
});
// 2. compress
toplevel.figure_out_scope();
var sq = UglifyJS.Compressor({
warnings: options.warnings,
hoist_vars: true
});
toplevel = toplevel.transform(sq);
// 3. mangle
toplevel.figure_out_scope();
toplevel.compute_char_frequency();
toplevel.mangle_names({except: ['Modernizr']});
// 4. output
var stream = UglifyJS.OutputStream({});
toplevel.print(stream);
return stream.toString();
}
</script>
</body>
</html>