diff --git a/Gruntfile.js b/Gruntfile.js index 14252c2..1f9ba54 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -3,23 +3,64 @@ module.exports = function(grunt) { "use strict"; +var banner, + umdStart, + umdMiddle, + umdEnd, + umdStandardDefine, + umdAdditionalDefine, + umdLocalizationDefine; + +banner = "/*!\n" + + " * jQuery Validation Plugin v<%= pkg.version %>\n" + + " *\n" + + " * <%= pkg.homepage %>\n" + + " *\n" + + " * Copyright (c) <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>\n" + + " * Released under the <%= _.pluck(pkg.licenses, 'type').join(', ') %> license\n" + + " */\n"; + +// define UMD wrapper variables + +umdStart = "(function( factory ) {\n" + + "\tif ( typeof define === \"function\" && define.amd ) {\n"; + +umdMiddle = "\t} else {\n" + + "\t\tfactory( jQuery );\n" + + "\t}\n" + + "}(function( $ ) {\n\n"; + +umdEnd = "\n}));"; + +umdStandardDefine = "\t\tdefine( [\"jquery\"], factory );\n"; +umdAdditionalDefine = "\t\tdefine( [\"jquery\", \"./jquery.validate\"], factory );\n"; +umdLocalizationDefine = "\t\tdefine( [\"jquery\", \"../jquery.validate\"], factory );\n"; + grunt.initConfig({ pkg: grunt.file.readJSON("package.json"), concat: { - options: { - banner: "/*!\n" + - " * jQuery Validation Plugin v<%= pkg.version %>\n" + - " *\n" + - " * <%= pkg.homepage %>\n" + - " *\n" + - " * Copyright (c) <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>\n" + - " * Released under the <%= _.pluck(pkg.licenses, 'type').join(', ') %> license\n" + - " */\n" - }, // used to copy to dist folder dist: { + options: { + banner: banner + + umdStart + + umdStandardDefine + + umdMiddle, + footer: umdEnd + }, + files: { + "dist/jquery.validate.js": ["src/core.js", "src/*.js"] + } + }, + extra: { + options: { + banner: banner + + umdStart + + umdAdditionalDefine + + umdMiddle, + footer: umdEnd + }, files: { - "dist/jquery.validate.js": ["src/core.js", "src/*.js"], "dist/additional-methods.js": ["src/additional/additional.js", "src/additional/*.js"] } } @@ -33,11 +74,20 @@ grunt.initConfig({ " * Copyright (c) <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" + " Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */\n" }, - all: { + dist: { files: { - "dist/jquery.validate.min.js": ["dist/jquery.validate.js"], - "dist/additional-methods.min.js": ["dist/additional-methods.js"] + "dist/additional-methods.min.js": ["dist/additional-methods.js"], + "dist/jquery.validate.min.js": ["dist/jquery.validate.js"] } + }, + all: { + files: [{ + expand: true, + cwd: "dist/localization", + src: "**/*.js", + dest: "dist/localization", + ext: ".min.js" + }] } }, compress: { @@ -49,14 +99,14 @@ grunt.initConfig({ pretty: true }, src: [ - "dist/*.js", + "dist/**/*.js", "README.md", "changelog.txt", "Gruntfile.js", "package.json", "demo/**/*.*", "lib/**/*.*", - "src/localization/**/*.*", + "src/**/*.*", "test/**/*.*" ] } @@ -107,6 +157,33 @@ grunt.initConfig({ }, src: "src/**/*.*" } + }, + copy: { + dist: { + options: { + // append UMD wrapper + process: function ( content ) { + return umdStart + umdLocalizationDefine + umdMiddle + content + umdEnd; + } + }, + files: [{ + src: ["src/localization/*"], + dest: "dist/localization", + expand: true, + flatten: true, + filter: "isFile" + }] + } + }, + replace: { + dist: { + src: ["dist/**/*.min.js"], + overwrite: true, + replacements: [{ + from: "./jquery.validate", + to: "./jquery.validate.min" + }] + } } }); @@ -117,9 +194,11 @@ grunt.loadNpmTasks("grunt-contrib-concat"); grunt.loadNpmTasks("grunt-contrib-compress"); grunt.loadNpmTasks("grunt-contrib-watch"); grunt.loadNpmTasks("grunt-jscs-checker"); +grunt.loadNpmTasks("grunt-contrib-copy"); +grunt.loadNpmTasks("grunt-text-replace"); -grunt.registerTask("default", ["concat", "jscs", "jshint", "qunit"]); -grunt.registerTask("release", ["default", "uglify", "compress"]); +grunt.registerTask("default", ["concat", "copy", "jscs", "jshint", "qunit"]); +grunt.registerTask("release", ["default", "uglify", "replace", "compress"]); grunt.registerTask("start", ["concat", "watch"]); }; diff --git a/README.md b/README.md index 02be0d4..4e71318 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,20 @@ Include jQuery and the plugin on a page. Then select a form to validate and call - + ``` +Alternatively include jQuery and the plugin via requirejs in your module. + +```js +define(["jquery", "jquery.validate"], function( $ ) { + $("form").validate(); +}); +``` + For more information on how to setup a rules and customizations, [check the documentation](http://jqueryvalidation.org/documentation/). ## Reporting an Issue diff --git a/demo/index.html b/demo/index.html index 06dc7f3..104b9a8 100644 --- a/demo/index.html +++ b/demo/index.html @@ -217,6 +217,8 @@
  • Displaying Errors within Field Labels
  • +
  • Loading via RequireJS +
  • Real-world examples