Skip to content

Commit

Permalink
add in class prefix support (kinda)
Browse files Browse the repository at this point in the history
  • Loading branch information
SlexAxton committed Dec 6, 2012
1 parent 9d96517 commit 57808d2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions config-all.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"classPrefix" : "",
"options": [
"setClasses",
"addTest",
Expand Down
10 changes: 8 additions & 2 deletions grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ requirejs.config({
});

var generateInit = requirejs('generate');
console.log(generateInit);

/*global module */
module.exports = function( grunt ) {
'use strict';

var modConfig = JSON.parse(grunt.file.read('config-all.json'));

grunt.initConfig({
pkg: '<json:package.json>',
meta: {
Expand Down Expand Up @@ -147,11 +148,16 @@ module.exports = function( grunt ) {
// Strip define fn
grunt.registerMultiTask('stripdefine', "Strip define call from dist file", function() {
var mod = grunt.file.read( this.file.src[0] ).replace('define("modernizr-init",[], function(){});', '');

// Hack the prefix into place. Anything is way to big for something so small.
if ( modConfig && modConfig.classPrefix ) {
mod = mod.replace("classPrefix : '',", "classPrefix : '" + modConfig.classPrefix.replace(/"/g, '\\"') + "',");
}
grunt.file.write( 'dist/modernizr-build.js', mod );
});

grunt.registerMultiTask('generateinit', "Generate Init file", function() {
grunt.file.write('tmp/modernizr-init.js', generateInit(JSON.parse(grunt.file.read('config-all.json'))));
grunt.file.write('tmp/modernizr-init.js', generateInit(modConfig));
});

// Travis CI task.
Expand Down
5 changes: 5 additions & 0 deletions modular.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<div>
<h1>Config JSON</h1>
<textarea id="config-json">{
"classPrefix" : "",
"options": [
"setClasses",
"addTest",
Expand Down Expand Up @@ -242,6 +243,10 @@ <h3>Minified</h3>
},
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;
Expand Down
4 changes: 2 additions & 2 deletions src/addTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ define(['ModernizrProto', 'Modernizr', 'docElement', 'hasOwnProp'], function( Mo

test = typeof test == 'function' ? test() : test;

if (typeof Modernizr._config.enableClasses !== "undefined" && Modernizr._config.enableClasses) {
docElement.className += ' ' + (test ? '' : 'no-') + feature;
if (Modernizr._config.enableClasses) {
docElement.className += ' ' + (Modernizr._config.classPrefix || '') + (test ? '' : 'no-') + feature;
}
Modernizr[feature] = test;

Expand Down
2 changes: 1 addition & 1 deletion src/setClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ define(['Modernizr', 'docElement', 'classes'], function( Modernizr, docElement,
// Remove "no-js" class from <html> element, if it exists:
theElem.className = theElem.className.replace(/(^|\s)no-js(\s|$)/, '$1$2') +
// Add the new classes to the <html> element.
(Modernizr._config.enableClasses ? ' js ' + classes.join(' ') : '');
(Modernizr._config.enableClasses ? ' js ' + (classes.length ? Modernizr._config.classPrefix || '' : '') + classes.join(' ' + (Modernizr._config.classPrefix || '')) : '');
}

return setClasses;
Expand Down

0 comments on commit 57808d2

Please sign in to comment.