Skip to content

Commit

Permalink
connected front end to api of modulizr. seems to work...
Browse files Browse the repository at this point in the history
  • Loading branch information
SlexAxton committed Nov 22, 2010
1 parent 90eb824 commit 08c5bf5
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 21 deletions.
2 changes: 2 additions & 0 deletions modernizr.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ window.Modernizr = (function(window,document,undefined){
set_css( '' );
modElem = f = null;

//>>BEGIN IEPP
// Enable HTML 5 elements for styling in IE.
// fyi: jscript version does not reflect trident version
// therefore ie9 in ie7 mode will still have a jScript v.9
Expand Down Expand Up @@ -959,6 +960,7 @@ window.Modernizr = (function(window,document,undefined){
);
})(window, document);
}
//>>END IEPP

// Assign private properties to the return object with prefix
ret._enableHTML5 = enableHTML5;
Expand Down
25 changes: 15 additions & 10 deletions modulizr/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
<h1>Modernizr Modular Build Tool</h1>

<h3>Choose the features you want to test for:</h3>

<ul id="tests" class="features">
<li id="fontface"><input type="checkbox" value="fontface" /> @font-face</li>
<li id="fontface"><input type="checkbox" value="fontface" /> @font-face</li>
<li id="flexbox"><input type="checkbox" value="flexbox" /> FlexBox CSS Model</li>
<li id="webgl"><input type="checkbox" value="webgl" /> WebGL</li>
<li id="touch"><input type="checkbox" value="touch" /> Touch Events</li>
<li id="postmessage"><input type="checkbox" value="postmessage" /> PostMessage</li>
<li id="textshadow"><input type="checkbox" value="textshadow" /> text-shadow</li>
<li id="inlinesvg"><input type="checkbox" value="inlinesvg" /> Inline SVG</li>
<li id="canvas"><input type="checkbox" value="canvas" /> Canvas</li>
<li id="canvastext"><input type="checkbox" value="canvastext" /> Canvas Text</li>
<li id="audio"><input type="checkbox" value="audio" /> HTML5 Audio</li>
Expand Down Expand Up @@ -38,23 +45,20 @@ <h3>Choose the features you want to test for:</h3>
<li id="svgclippaths"><input type="checkbox" value="svgclippaths" /> SVG Clipping</li>
<li id="draganddrop"><input type="checkbox" value="draganddrop" /> Drag and Drop</li>
<li id="hashchange"><input type="checkbox" value="hashchange" /> hashchange</li>
<li id="crosswindowmessaging"><input type="checkbox" value="crosswindowmessaging" /> X-window Messaging</li>
<li id="historymanagement"><input type="checkbox" value="historymanagement" /> History Management</li>
<li id="history"><input type="checkbox" value="history" /> History</li>
<li id="applicationcache"><input type="checkbox" value="applicationcache" /> applicationCache</li>
<li id="websockets"><input type="checkbox" value="websockets" /> Web Sockets</li>
<li id="webworkers"><input type="checkbox" value="webworkers" /> Web Workers</li>
<li id="webWorkers"><input type="checkbox" value="webWorkers" /> Web Workers</li>
<li id="websockets"><input type="checkbox" value="websockets" /> Web Sockets</li>
<li id="websqldatabase"><input type="checkbox" value="websqldatabase" /> Web SQL Database</li>
<li id="indexeddb"><input type="checkbox" value="indexeddb" /> IndexedDB</li>
<li id="indexedDB"><input type="checkbox" value="indexedDB" /> IndexedDB</li>
<li id="inputtypes"><input type="checkbox" value="inputtypes" /> Input Types</li>
<li id="input"><input type="checkbox" value="input" /> Input Attributes</li>
</ul>

<h3>Choose the enhancements you want to run:</h3>
<ul id="enhancements" class="features">
<li id="shim"><input type="checkbox" value="shim" /> HTML5 Shim</li>
<li id="shim"><input type="checkbox" value="addtest" /> Add Your Own Tests (via addTest())</li>
<li id="shim"><input type="checkbox" value="htmlclasses" /> Add &lt;html&gt; Classes (e.g. class="no-csstransitions")</li>
<li id="shim"><input type="checkbox" value="removenojs" /> Remove the 'no-js' class from the 'html' element</li>
<li id="iepp"><input type="checkbox" value="iepp" /> IEPP/HTML5 Shim</li>
<!--li id="shim"><input type="checkbox" value="htmlclasses" /> Add &lt;html&gt; Classes (e.g. class="no-csstransitions")</li-->
</ul>
<input type="button" id="generate" value="Generate Custom Modernizr Build" />
<div id="buildArea">
Expand All @@ -73,6 +77,7 @@ <h3>Choose the enhancements you want to run:</h3>
<script src="js/downloadify.min.js"></script>
<script>
jQuery(function($){
$(':checkbox').attr('checked', true);
$('#generate').click(function(){
// Get all the tests and enhancements
var tests = $('.features input:checked').map(function(){
Expand Down
83 changes: 72 additions & 11 deletions modulizr/js/modulizr.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,41 @@
ize: function(source, tests){
// Variables for string manipulation and saving
var js_notests,
js_noret,
js_nostr,
parsed,
i, j,
i, j, l,
strings = [],
retStack = [],
testStack = [],
sid = '_' + ( + new Date()),
multilinespaceExp = new RegExp(/\s{4}\n/g);


// Handle the out of the ordinary stuff first
source = this._handleSpecialCases(source, tests);

// Remove comments so we don't have false parsing positives
source = this._removeComments(source);

// Mark the tests
js_notests = source.replace(/tests\['(.*)'\]/g, function($0, $1) {
testStack[testStack.length] = {"code":$0, "name": $1};
return 'TEST__'+$1+'__'
return 'TEST__'+$1+'__';
});

js_noret = js_notests.replace(/ret\['(.*)'\]/g, function($0, $1) {
retStack[retStack.length] = {"code":$0, "name":$1};
return 'TRET__'+$1+'__';
});

// remove string literals
js_nostr = js_notestsstr.replace(/("|')((?:\\\1|.)+?)\1/g, function($0) {
js_nostr = js_noret.replace(/("|')((?:\\\1|.)+?)\1/g, function($0) {
strings[strings.length] = $0;
return 'STR__'+(strings.length-1)+'__';
});


js_nostr = this._pullOutTests(js_nostr, ['flexbox', 'touch', 'geolocation']);

parsed = js_nostr;
// actually take out the code, etc
parsed = this._pullOutTests(js_nostr, tests);

for (j = 0; j < strings.length; j++) {
// put the strings back where they belong!
Expand All @@ -57,6 +66,13 @@
});
}

for (l = 0; l < retStack.length; l++) {
// put the strings back where they belong!
parsed = parsed.replace(RegExp("TRET__"+retStack[l].name+"__", 'g'), function($0) {
return retStack[l].code;
});
}

// put the test array declarations back where they go
for (i = 0; i < testStack.length; i++) {
parsed = parsed.replace(RegExp("TEST__"+testStack[i].name+"__", 'g'), function($0) {
Expand All @@ -74,6 +90,35 @@

},

_handleSpecialCases: function(source, wanted) {
// Functions to run if they are NOT wanted
var specialCases = {
// This function removes the IE print protector
iepp: function(source) {
source = source.replace(new RegExp("\/\/>>BEGIN IEPP[\\s|\\S]*\/\/>>END IEPP", "ig"), "");
return source;
}
},
// Speedier lookups
wantedHash = (function(){
var hash = {}, k;
for(k = 0; k < wanted.length; k++) {
hash[wanted[k]] = true;
}
return hash;
})();

for (var name in specialCases) {
if (specialCases.hasOwnProperty(name)) {
// If we DONT want any of the special cases, run them
if (!wantedHash[name]) {
source = specialCases[name](source);
}
}
}
return source;
},

_pullOutTests: function(source, wanted) {
var sub, i, j, start, end, name,
sub2, bracketStack, tests = {},
Expand All @@ -84,7 +129,7 @@
for (i = 0; i < source.length; i++) {
sub = source.substr(i, 6);
// If we find a test identifier
if (sub === "TEST__") {
if (sub === "TEST__" || sub === "TRET__") {
// Save the beginning here
start = i;

Expand All @@ -110,7 +155,7 @@
i += 8;

// Look for the opening '{' character
while (source.substr(i, 1) !== '{') {
while (source.charAt(i) !== '{') {
i++;
}

Expand All @@ -120,7 +165,7 @@

// Find an even amount of {} pairs
while(bracketStack) {
sub2 = source.substr(i,1);
sub2 = source.charAt(i);
if (sub2 === '{') {
bracketStack++;
}
Expand All @@ -129,6 +174,22 @@
}
i++;
}

// Watch out for IFFEs
if (source.substr(i,2) === ")(") {
i += 2;
parenStack = 1;
while (parenStack) {
if (source.charAt(i) === ')') {
parenStack--;
}
else if (source.charAt(i) === '(') {
parenStack++;
}
i++;
}
}

// Add the semicolon
end = i+1;

Expand Down

0 comments on commit 08c5bf5

Please sign in to comment.