From 2d83cdeeb67c9604eb7f89d51a310a203a04074e Mon Sep 17 00:00:00 2001 From: Ben Boyle Date: Sat, 29 Mar 2014 00:47:51 +1000 Subject: [PATCH 1/4] define unit tests --- Gruntfile.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 57fde49..a3cc587 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -27,7 +27,7 @@ module.exports = function( grunt ) { }, // code quality tasks qunit: { - files: [ 'test/**/*.html' ] + unit: [ 'test/**/*.html' ] }, jshint: { gruntfile: { @@ -61,11 +61,11 @@ module.exports = function( grunt ) { }, src: { files: '<%= jshint.src.src %>', - tasks: [ 'jshint:src', 'qunit' ] + tasks: [ 'jshint:src', 'qunit:unit' ] }, test: { files: '<%= jshint.test.src %>', - tasks: [ 'jshint:test', 'qunit' ] + tasks: [ 'jshint:test', 'qunit:unit' ] }, } }); From 56b29120aa9018975eec0c36a484d7ebb5913172 Mon Sep 17 00:00:00 2001 From: Ben Boyle Date: Sat, 29 Mar 2014 00:53:11 +1000 Subject: [PATCH 2/4] support jquery 1.4.4 - add jquery 1.4.4 tests - replace .on with .bind/unbind calls in tests --- Gruntfile.js | 31 +++++++++++++++++++++++++++++-- package.json | 3 ++- test/checkValidity.js | 4 ++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index a3cc587..de365cf 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -15,6 +15,14 @@ module.exports = function( grunt ) { clean: { files: [ 'dist' ] }, + connect: { + server: { + options: { + port: 8000, + base: '.' + } + } + }, // production pipeline tasks uglify: { options: { @@ -27,7 +35,25 @@ module.exports = function( grunt ) { }, // code quality tasks qunit: { - unit: [ 'test/**/*.html' ] + unit: [ 'test/**/*.html' ], + // test other jquery versions + jquery: { + options: { + timeout: 12000, + urls: [ + 'http://localhost:8000/test/change.html?jquery=1.4.4', + 'http://localhost:8000/test/checkValidity.html?jquery=1.4.4', + 'http://localhost:8000/test/custom.html?jquery=1.4.4', + 'http://localhost:8000/test/disabled.html?jquery=1.4.4', + 'http://localhost:8000/test/email.html?jquery=1.4.4', + 'http://localhost:8000/test/invalid.html?jquery=1.4.4', + 'http://localhost:8000/test/novalidate.html?jquery=1.4.4', + 'http://localhost:8000/test/pattern.html?jquery=1.4.4', + 'http://localhost:8000/test/required.html?jquery=1.4.4', + 'http://localhost:8000/test/submit.html?jquery=1.4.4', + ] + } + } }, jshint: { gruntfile: { @@ -73,12 +99,13 @@ module.exports = function( grunt ) { // These plugins provide necessary tasks. grunt.loadNpmTasks( 'grunt-contrib-clean' ); grunt.loadNpmTasks( 'grunt-contrib-uglify' ); + grunt.loadNpmTasks( 'grunt-contrib-connect' ); grunt.loadNpmTasks( 'grunt-contrib-qunit' ); grunt.loadNpmTasks( 'grunt-contrib-jshint' ); grunt.loadNpmTasks( 'grunt-contrib-watch' ); // Default task. - grunt.registerTask( 'test', [ 'jshint', 'qunit' ]); + grunt.registerTask( 'test', [ 'jshint', 'connect', 'qunit' ]); grunt.registerTask( 'produce', [ 'clean', 'uglify' ]); grunt.registerTask( 'default', [ 'test', 'produce' ]); diff --git a/package.json b/package.json index fa96a99..71352c0 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,8 @@ "grunt-contrib-watch": "~0.6.1", "grunt-contrib-uglify": "~0.4.0", "grunt-contrib-jshint": "~0.9.2", - "grunt-contrib-qunit": "~0.4.0" + "grunt-contrib-qunit": "~0.4.0", + "grunt-contrib-connect": "~0.7.1" }, "scripts": { "test": "grunt test" diff --git a/test/checkValidity.js b/test/checkValidity.js index 18ebcd7..a99e5c3 100644 --- a/test/checkValidity.js +++ b/test/checkValidity.js @@ -30,7 +30,7 @@ // setup - detect invalid events var invalidDetectedOnFoo = 0; - $( '#foo' ).on( 'invalid.TEST', function() { + $( '#foo' ).bind( 'invalid.TEST', function() { invalidDetectedOnFoo++; strictEqual( invalidDetectedOnFoo, 1, 'invalid event detected on foo' ); }); @@ -42,7 +42,7 @@ strictEqual( $( '#foo' )[ 0 ].checkValidity(), true, 'foo is valid' ); // teardown - $( '#foo' ).on( 'invalid.TEST' ); + $( '#foo' ).unbind( 'invalid.TEST' ); }); From 116f66aebb9850fcc78f4ed7eda3a43f46cf62df Mon Sep 17 00:00:00 2001 From: Ben Boyle Date: Sat, 29 Mar 2014 00:55:31 +1000 Subject: [PATCH 3/4] support jquery 2.1.0 (closes #9) added tests for 2.1.0 --- Gruntfile.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Gruntfile.js b/Gruntfile.js index de365cf..9b8f577 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -51,6 +51,17 @@ module.exports = function( grunt ) { 'http://localhost:8000/test/pattern.html?jquery=1.4.4', 'http://localhost:8000/test/required.html?jquery=1.4.4', 'http://localhost:8000/test/submit.html?jquery=1.4.4', + // latest + 'http://localhost:8000/test/change.html?jquery=2.1.0', + 'http://localhost:8000/test/checkValidity.html?jquery=2.1.0', + 'http://localhost:8000/test/custom.html?jquery=2.1.0', + 'http://localhost:8000/test/disabled.html?jquery=2.1.0', + 'http://localhost:8000/test/email.html?jquery=2.1.0', + 'http://localhost:8000/test/invalid.html?jquery=2.1.0', + 'http://localhost:8000/test/novalidate.html?jquery=2.1.0', + 'http://localhost:8000/test/pattern.html?jquery=2.1.0', + 'http://localhost:8000/test/required.html?jquery=2.1.0', + 'http://localhost:8000/test/submit.html?jquery=2.1.0', ] } } From 52f42310c18376af2ec3de21a1cc515ee4a9791e Mon Sep 17 00:00:00 2001 From: Ben Boyle Date: Sat, 29 Mar 2014 00:57:41 +1000 Subject: [PATCH 4/4] bump version --- bower.json | 2 +- dist/html5.constraintValidationAPI.min.js | 6 +++--- package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bower.json b/bower.json index 2e4ea76..9daeb56 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "html5.constraintValidationAPI", "title": "HTML5 constraintValidationAPI", - "version": "1.0.1", + "version": "1.0.2", "homepage": "https://github.com/bboyle/html5-constraint-validation-API", "authors": [ "Ben Boyle " diff --git a/dist/html5.constraintValidationAPI.min.js b/dist/html5.constraintValidationAPI.min.js index bae2d3b..3ec917f 100644 --- a/dist/html5.constraintValidationAPI.min.js +++ b/dist/html5.constraintValidationAPI.min.js @@ -1,4 +1,4 @@ -/*! HTML5 constraintValidationAPI - v1.0.1 - 2013-08-17 +/*! HTML5 constraintValidationAPI - v1.0.2 - 2014-03-29 * https://github.com/bboyle/html5-constraint-validation-API -* Copyright (c) 2013 Ben Boyle; Licensed MIT */ -"undefined"!==jQuery&&function(t){"use strict";var i=/^[A-Za-z0-9!#$%&'*+\-\/=\?\^_`\{\|\}~\.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)*$/,e="input, select, textarea",a=t(""),n="object"!=typeof a[0].validity,s=function(t,i,e,a,n){return"string"==typeof a&&(e=!!a),{customError:e,typeMismatch:!!t,patternMismatch:!!n,valueMissing:!!i,valid:!(i||e||t||n)}},r=function(e){var a,n,r=t(this),o=!!r.attr("required"),l="email"===this.getAttribute("type")&&!!this.value&&!i.test(this.value);return o&&(o=/^select$/i.test(this.nodeName)?0===this.selectedIndex&&""===this.options[0].value:"radio"===this.type?0===t(this.form.elements[this.name]).filter(":checked").length:"checkbox"===this.type?!this.checked:!this.value),this.getAttribute("pattern")&&(this.value.length>0?(n=RegExp("^(?:"+this.getAttribute("pattern")+")$"),a=!n.test(this.value)):a=!1),this.validity=s(l,o,this.validity.customError||!1,e,a),this.validity.valid?this.validationMessage="":this.validity.customError?"string"==typeof e&&(this.validationMessage=e):this.validationMessage=this.validity.valueMissing?"Please answer this question":this.validity.typeMismatch?"Please type an email address":this.validity.patternMismatch?"Please use the format shown":"Please answer the question correctly",this.disabled||this.validity.valid},o=function(i){var e=i.target;r.call(e),"radio"===e.type&&t(e.form.elements[this.name]).each(function(){this.validity=e.validity,this.validationMessage=e.validationMessage})},l=function(i){var a=t(this),s=!!a.attr("novalidate"),o=!1;return n&&a.find(e).each(function(){o=!r.call(this),s||o&&t(this).triggerHandler("invalid")}),!s&&a.find(e).filter(function(){return!(this.disabled||this.validity.valid)}).length>0?(i.stopImmediatePropagation(),i.preventDefault(),!1):void 0},h=function(){var i=t(e);n&&(i.filter(function(){return"object"!=typeof this.validity}).each(function(){this.validity=s(!1,!1,!1,"",!1),this.validationMessage=""}),i.unbind("change.constraintValidationAPI").bind("change.constraintValidationAPI",o)),"string"!=typeof a[0].validationMessage&&i.filter(function(){return"string"!=typeof this.validationMessage}).each(function(){this.validationMessage=""}),"function"!=typeof a[0].checkValidity&&i.filter(function(){return"function"!=typeof this.checkValidity}).each(function(){var i=this;this.checkValidity=function(){var e=r.call(i);return e||this.form.hasAttribute("novalidate")||t(i).triggerHandler("invalid"),e}}),"function"!=typeof a[0].setCustomValidity&&i.filter(function(){return"function"!=typeof this.setCustomValidity}).each(function(){var t=this;this.setCustomValidity=function(i){r.call(t,i)}}),t("form").unbind("submit.constraintValidationAPI").bind("submit.constraintValidationAPI",l)};h(),t(h),window.initConstraintValidationAPI=h}(jQuery); \ No newline at end of file +* Copyright (c) 2014 Ben Boyle; Licensed MIT */ +"undefined"!==jQuery&&!function(a){"use strict";var b=/^[A-Za-z0-9!#$%&'*+\-\/=\?\^_`\{\|\}~\.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)*$/,c="input, select, textarea",d=a(""),e="object"!=typeof d[0].validity,f=function(a,b,c,d,e){return"string"==typeof d&&(c=!!d),{customError:c,typeMismatch:!!a,patternMismatch:!!e,valueMissing:!!b,valid:!(b||c||a||e)}},g=function(c){var d,e,g=a(this),h=!!g.attr("required"),i="email"===this.getAttribute("type")&&!!this.value&&!b.test(this.value);return h&&(h=/^select$/i.test(this.nodeName)?0===this.selectedIndex&&""===this.options[0].value:"radio"===this.type?0===a(this.form.elements[this.name]).filter(":checked").length:"checkbox"===this.type?!this.checked:!this.value),this.getAttribute("pattern")&&(this.value.length>0?(e=new RegExp("^(?:"+this.getAttribute("pattern")+")$"),d=!e.test(this.value)):d=!1),this.validity=f(i,h,this.validity.customError||!1,c,d),this.validity.valid?this.validationMessage="":this.validity.customError?"string"==typeof c&&(this.validationMessage=c):this.validationMessage=this.validity.valueMissing?"Please answer this question":this.validity.typeMismatch?"Please type an email address":this.validity.patternMismatch?"Please use the format shown":"Please answer the question correctly",this.disabled||this.validity.valid},h=function(b){var c=b.target;g.call(c),"radio"===c.type&&a(c.form.elements[this.name]).each(function(){this.validity=c.validity,this.validationMessage=c.validationMessage})},i=function(b){var d=a(this),f=!!d.attr("novalidate"),h=!1;return e&&d.find(c).each(function(){h=!g.call(this),f||h&&a(this).triggerHandler("invalid")}),!f&&d.find(c).filter(function(){return!(this.disabled||this.validity.valid)}).length>0?(b.stopImmediatePropagation(),b.preventDefault(),!1):void 0},j=function(){var b=a(c);e&&(b.filter(function(){return"object"!=typeof this.validity}).each(function(){this.validity=f(!1,!1,!1,"",!1),this.validationMessage=""}),b.unbind("change.constraintValidationAPI").bind("change.constraintValidationAPI",h)),"string"!=typeof d[0].validationMessage&&b.filter(function(){return"string"!=typeof this.validationMessage}).each(function(){this.validationMessage=""}),"function"!=typeof d[0].checkValidity&&b.filter(function(){return"function"!=typeof this.checkValidity}).each(function(){var b=this;this.checkValidity=function(){var c=g.call(b);return c||this.form.hasAttribute("novalidate")||a(b).triggerHandler("invalid"),c}}),"function"!=typeof d[0].setCustomValidity&&b.filter(function(){return"function"!=typeof this.setCustomValidity}).each(function(){var a=this;this.setCustomValidity=function(b){g.call(a,b)}}),a("form").unbind("submit.constraintValidationAPI").bind("submit.constraintValidationAPI",i)};j(),a(j),window.initConstraintValidationAPI=j}(jQuery); \ No newline at end of file diff --git a/package.json b/package.json index 71352c0..26dbea8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "html5.constraintValidationAPI", "title": "HTML5 constraintValidationAPI", "description": "A polyfill for the HTML5 constraintValidationAPI", - "version": "1.0.1", + "version": "1.0.2", "homepage": "https://github.com/bboyle/html5-constraint-validation-API", "author": { "name": "Ben Boyle",