From aad964276215f53dd566c3ee6a67cb8867b22b8a Mon Sep 17 00:00:00 2001 From: Steve Greatrex Date: Thu, 3 Oct 2013 20:03:05 +0100 Subject: [PATCH] first steps to a better build: new gruntfile and jshint working+passing --- .gitignore | 2 + .jshintrc | 18 + Lib/knockout-latest.debug.js | 7249 +++++++++++++++-------------- Scripts/_references.js | 1 + Src/knockout.validation.js | 30 +- Tests/{ => Qunit}/jquery-1.7.1.js | 0 Tests/test-runner.htm | 2 +- Tests/validation-tests.js | 38 +- Tests/validation-ui-tests.js | 72 +- grunt.js | 59 - gruntfile.js | 65 + package.json | 32 + 12 files changed, 3859 insertions(+), 3709 deletions(-) create mode 100644 .jshintrc create mode 100644 Scripts/_references.js rename Tests/{ => Qunit}/jquery-1.7.1.js (100%) delete mode 100644 grunt.js create mode 100644 gruntfile.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index 0dd9a511..21f654f8 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ *.iws target *.ncrunchsolution +node_modules +*.webinfo \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 00000000..541883b6 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,18 @@ +{ + "curly": true, + "eqeqeq": true, + "immed": true, + "latedef": true, + "newcap": true, + "noarg": true, + "sub": true, + "undef": true, + "boss": true, + "eqnull": true, + "browser": true, + "smarttabs": true, + "globals": { + "jQuery": false, + "ko": true + } +} \ No newline at end of file diff --git a/Lib/knockout-latest.debug.js b/Lib/knockout-latest.debug.js index b65eb054..9fe33c8f 100644 --- a/Lib/knockout-latest.debug.js +++ b/Lib/knockout-latest.debug.js @@ -1,3580 +1,3679 @@ -// Knockout JavaScript library v2.2.0 +// Knockout JavaScript library v2.3.0 // (c) Steven Sanderson - http://knockoutjs.com/ // License: MIT (http://www.opensource.org/licenses/mit-license.php) (function () { - var DEBUG = true; - (function (window, document, navigator, jQuery, undefined) { - !function (factory) { - // Support three module loading scenarios - if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') { - // [1] CommonJS/Node.js - var target = module['exports'] || exports; // module.exports is for Node.js - factory(target); - } else if (typeof define === 'function' && define['amd']) { - // [2] AMD anonymous module - define(['exports'], factory); - } else { - // [3] No module loader (plain "); - }; - - if (jQueryTmplVersion > 0) { - jQuery['tmpl']['tag']['ko_code'] = { - open: "__.push($1 || '');" - }; - jQuery['tmpl']['tag']['ko_with'] = { - open: "with($1) {", - close: "} " - }; - } - }; - - ko.jqueryTmplTemplateEngine.prototype = new ko.templateEngine(); - - // Use this one by default *only if jquery.tmpl is referenced* - var jqueryTmplTemplateEngineInstance = new ko.jqueryTmplTemplateEngine(); - if (jqueryTmplTemplateEngineInstance.jQueryTmplVersion > 0) - ko.setTemplateEngine(jqueryTmplTemplateEngineInstance); - - ko.exportSymbol('jqueryTmplTemplateEngine', ko.jqueryTmplTemplateEngine); - })(); - }); - })(window, document, navigator, window["jQuery"]); + var DEBUG = true; + (function (undefined) { + // (0, eval)('this') is a robust way of getting a reference to the global object + // For details, see http://stackoverflow.com/questions/14119988/return-this-0-evalthis/14120023#14120023 + var window = this || (0, eval)('this'), + document = window['document'], + navigator = window['navigator'], + jQuery = window["jQuery"], + JSON = window["JSON"]; + (function (factory) { + // Support three module loading scenarios + if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') { + // [1] CommonJS/Node.js + var target = module['exports'] || exports; // module.exports is for Node.js + factory(target); + } else if (typeof define === 'function' && define['amd']) { + // [2] AMD anonymous module + define(['exports'], factory); + } else { + // [3] No module loader (plain - + diff --git a/Tests/validation-tests.js b/Tests/validation-tests.js index 1c859736..df6524f5 100644 --- a/Tests/validation-tests.js +++ b/Tests/validation-tests.js @@ -1,6 +1,14 @@ -/// -/// -/// +/*global + module:false, + equal:false, + notEqual:false, + strictEqual:false, + test:false, + ok:false, + asyncTest:false, + start: false, + stop: false +*/ //#region Required Validation @@ -82,7 +90,7 @@ test('Object is Valid and isValid returns True', function () { }); test('Object is Valid and isValid returns True (with min: 0)', function () { - testObj = ko.observable('') + var testObj = ko.observable('') .extend({ min: 0 }); testObj("0"); @@ -822,7 +830,7 @@ test('Issue #78 - Falsy Params', function () { //#endregion //#region Manual Validation -module("Manual Validation") +module("Manual Validation"); test("setError sets isValid and error message", function () { var testObj = ko.observable(); testObj.extend({ validatable: true }); @@ -845,7 +853,7 @@ test("clearError clears manually-specified error", function () { testObj.setError("oh no!"); //fail the validation - ok(!testObj.isValid()) + ok(!testObj.isValid()); //clear the validation testObj.clearError(); @@ -957,7 +965,7 @@ test('Error Grouping works', function () { var errors = ko.validation.group(vm); - equals(errors().length, 2, 'Grouping correctly finds 2 invalid properties'); + equal(errors().length, 2, 'Grouping correctly finds 2 invalid properties'); }); test('Nested Grouping works - Observable', function () { @@ -975,7 +983,7 @@ test('Nested Grouping works - Observable', function () { var errors = ko.validation.group(vm, { deep: true, observable: true }); - equals(errors().length, 3, 'Grouping correctly finds 3 invalid properties'); + equal(errors().length, 3, 'Grouping correctly finds 3 invalid properties'); }); test('Nested Grouping works - Not Observable', function () { @@ -993,7 +1001,7 @@ test('Nested Grouping works - Not Observable', function () { var errors = ko.validation.group(vm, { deep: true, observable: false }); - equals(errors().length, 3, 'Grouping correctly finds 3 invalid properties'); + equal(errors().length, 3, 'Grouping correctly finds 3 invalid properties'); }); test('Issue #31 - Recursively Show All Messages', function () { @@ -1022,7 +1030,7 @@ test('Issue #31 - Recursively Show All Messages', function () { ok(vm.two.one.isModified(), "Level 2 is modified"); ok(vm.three.two.one.isModified(), "Level 3 is modified"); - equals(errors().length, 3, 'Grouping correctly finds 3 invalid properties'); + equal(errors().length, 3, 'Grouping correctly finds 3 invalid properties'); }); test('Issue #31 - Recursively Show All Messages - using computed', function () { @@ -1051,7 +1059,7 @@ test('Issue #31 - Recursively Show All Messages - using computed', function () { ok(vm.two.one.isModified(), "Level 2 is modified"); ok(vm.three.two.one.isModified(), "Level 3 is modified"); - equals(errors().length, 3, 'Grouping correctly finds 3 invalid properties'); + equal(errors().length, 3, 'Grouping correctly finds 3 invalid properties'); }); test('Issue #37 - Toggle ShowAllMessages', function () { @@ -1080,7 +1088,7 @@ test('Issue #37 - Toggle ShowAllMessages', function () { ok(vm.two.one.isModified(), "Level 2 is modified"); ok(vm.three.two.one.isModified(), "Level 3 is modified"); - equals(errors().length, 3, 'Grouping correctly finds 3 invalid properties'); + equal(errors().length, 3, 'Grouping correctly finds 3 invalid properties'); // now shut them off errors.showAllMessages(false); @@ -1105,7 +1113,7 @@ test('Grouping options does not overwrite global configuration options', functio var errors = ko.validation.group(vm); - equals(errors().length, 1, 'Grouping finds one invalid object because deep option was not specified.'); + equal(errors().length, 1, 'Grouping finds one invalid object because deep option was not specified.'); }); test("Issue #235 - formatMessage should unwrap observable parameters", function () { @@ -1153,10 +1161,10 @@ test('Changing the value of observable used in onlyIf condition triggers validat required: { onlyIf: person.isMarried } }); person.isMarried(false); - ok(person.spouseName.isValid(), 'Unmarried person is valid without spouse name') + ok(person.spouseName.isValid(), 'Unmarried person is valid without spouse name'); person.isMarried(true); - equal(person.spouseName.isValid(), false, 'Married person is not valid without spouse name') + equal(person.spouseName.isValid(), false, 'Married person is not valid without spouse name'); }); //#endregion diff --git a/Tests/validation-ui-tests.js b/Tests/validation-ui-tests.js index 7272f7d1..75db9126 100644 --- a/Tests/validation-ui-tests.js +++ b/Tests/validation-ui-tests.js @@ -1,7 +1,15 @@ -/// -/// -/// -/// +/*global + module:false, + equal:false, + notEqual:false, + strictEqual:false, + test:false, + ok:false, + asyncTest:false, + start: false, + stop: false, + $: false +*/ module('UI Tests', { setup: function () { @@ -121,7 +129,7 @@ test('Showing Errors As Titles Works', function () { var isValid = vm.firstName.isValid(); ok(!isValid, 'First Name is NOT Valid'); - console.log($testInput) + var msg = $testInput.attr('title'); equal(msg, 'This field is required.', msg); @@ -157,44 +165,44 @@ test('Original titles are restored', function () { $testInput.val("a"); //set it $testInput.change(); //trigger change event - var msg = $testInput.attr('title'); + msg = $testInput.attr('title'); equal(msg, 'my-orig-title', msg); }); test("Original titles are restored to blank", function () { - addTestHtml(''); + addTestHtml(''); - var vm = { - firstName: ko.observable('').extend({ required: true }) - }; + var vm = { + firstName: ko.observable('').extend({ required: true }) + }; - // make sure the options are ok. - ko.validation.init({ - errorsAsTitleOnModified: true, - decorateElement: true - }, true); + // make sure the options are ok. + ko.validation.init({ + errorsAsTitleOnModified: true, + decorateElement: true + }, true); - applyTestBindings(vm); + applyTestBindings(vm); - var $testInput = $('#myTestInput'); + var $testInput = $('#myTestInput'); - $testInput.val("a"); //set it - $testInput.change(); //trigger change event + $testInput.val("a"); //set it + $testInput.change(); //trigger change event - $testInput.val(""); //set it - $testInput.change(); //trigger change event + $testInput.val(""); //set it + $testInput.change(); //trigger change event - ok(!vm.firstName.isValid(), 'First Name is NOT Valid'); + ok(!vm.firstName.isValid(), 'First Name is NOT Valid'); - //now make the name valid - vm.firstName("valid name"); - ok(vm.firstName.isValid(), "Should now be valid"); + //now make the name valid + vm.firstName("valid name"); + ok(vm.firstName.isValid(), "Should now be valid"); - //and check that the title was reset to blank - var updatedTitle = $testInput.attr("title") - ok(!updatedTitle, "Title should have been reset to blank"); -}) + //and check that the title was reset to blank + var updatedTitle = $testInput.attr("title"); + ok(!updatedTitle, "Title should have been reset to blank"); +}); test('Original titles are restored with multiple validators, too', function () { @@ -226,13 +234,13 @@ test('Original titles are restored with multiple validators, too', function () { $testInput.val("a"); //set it $testInput.change(); //trigger change event - var msg = $testInput.attr('title'); + msg = $testInput.attr('title'); equal(msg, 'Please enter at least 2 characters.', msg); $testInput.val("aa"); //set it $testInput.change(); //trigger change event - var msg = $testInput.attr('title'); + msg = $testInput.attr('title'); equal(msg, 'my-orig-title', msg); }); @@ -265,7 +273,7 @@ test('Showing Errors As Titles is disabled sucessfully', function () { var isValid = vm.firstName.isValid(); ok(!isValid, 'First Name is NOT Valid'); - console.log($testInput) + var msg = $testInput.attr('title'); notEqual(msg, 'This field is required.', msg); diff --git a/grunt.js b/grunt.js deleted file mode 100644 index e194f3d6..00000000 --- a/grunt.js +++ /dev/null @@ -1,59 +0,0 @@ -/*global module:false*/ -module.exports = function (grunt) { - - // Project configuration. - grunt.initConfig({ - meta: { - version: '1.0.2', - banner: '/*\n' + - '===============================================================================\n' + - ' Author: Eric M. Barnard - @ericmbarnard \n' + - ' License: MIT (http://opensource.org/licenses/mit-license.php) \n' + - ' \n' + - ' Description: Validation Library for KnockoutJS \n' + - '===============================================================================\n' + - '*/' - }, - lint: { - files: ['grunt.js', 'src/knockout.validation.js'] - }, - qunit: { - files: ['Tests/test-runner.htm'] - }, - concat: { - dist: { - src: ['', ''], - dest: 'Dist/knockout.validation.js' - } - }, - min: { - dist: { - src: ['', ''], - dest: 'dist/knockout.validation.min.js' - } - }, - jshint: { - options: { - curly: true, - eqeqeq: true, - immed: true, - latedef: true, - newcap: true, - noarg: true, - sub: true, - undef: true, - boss: true, - eqnull: true, - browser: true - }, - globals: { - jQuery: false - } - }, - uglify: {} - }); - - // Default task. - grunt.registerTask('default', 'lint qunit concat min'); - -}; diff --git a/gruntfile.js b/gruntfile.js new file mode 100644 index 00000000..f32a7b4b --- /dev/null +++ b/gruntfile.js @@ -0,0 +1,65 @@ +/*global module:false*/ +module.exports = function (grunt) { + + // Project configuration. + grunt.initConfig({ + pkg: grunt.file.readJSON("package.json"), + meta: { + banner: "/*\n" + + "===============================================================================\n" + + " Author: Eric M. Barnard - @ericmbarnard \n" + + " License: MIT (http://opensource.org/licenses/mit-license.php) \n" + + " \n" + + " Description: Validation Library for KnockoutJS \n" + + "===============================================================================\n" + + "*/" + }, + concat: { + options: { + separator: ";", + banner: "<%= meta.banner %>" + }, + dist: { + src: [ + "<%= meta.banner %>", + "src/<%= pkg.name %>.js", + ], + dest: "dist/<%= pkg.name %>.js" + } + }, + uglify: { + options: { + banner: "<%= meta.banner %>" + }, + dist: { + files: { + "dist/<%= pkg.name %>.min.js": ["<%= concat.dist.dest %>"] + } + } + }, + qunit: { + files: ["Tests/test-runner.htm"] + }, + jshint: { + files: ["src/**/*.js", "Tests/*.js"], + options: grunt.file.readJSON(".jshintrc"), + }, + watch: { + clear: { + files: ["src/**/*.js", "Tests/*.js"], + tasks: ["clear", "test"] + } + } + }); + + grunt.loadNpmTasks("grunt-contrib-uglify"); + grunt.loadNpmTasks("grunt-contrib-jshint"); + grunt.loadNpmTasks("grunt-contrib-qunit"); + grunt.loadNpmTasks("grunt-contrib-concat"); + grunt.loadNpmTasks("grunt-contrib-watch"); + grunt.loadNpmTasks("grunt-clear"); + + // Default task. + grunt.registerTask("default", ["qunit", "jshint", "concat", "uglify"]); + grunt.registerTask("test", ["qunit", "jshint"]); +}; diff --git a/package.json b/package.json new file mode 100644 index 00000000..79452ac7 --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "knockout.validation", + "version": "2.0.0-Pre", + "description": "A KnockoutJS Plugin for model and property validation", + "main": "gruntfile.js", + "dependencies": { + "grunt": "~0.4.1", + "grunt-cli": "~0.1.9" + }, + "devDependencies": { + "grunt": "~0.4.1", + "grunt-cli": "~0.1.9", + "grunt-contrib-jshint": "~0.6.0", + "grunt-contrib-uglify": "~0.2.2", + "grunt-contrib-concat": "~0.3.0", + "grunt-contrib-qunit": "~0.2.2", + "grunt-contrib-watch": "~0.5.3", + "grunt-clear": "~0.2.1" + }, + "scripts": { + "test": "grunt test --verbose" + }, + "repository": { + "type": "git", + "url": "https://github.com/Knockout-Contrib/Knockout-Validation.git" + }, + "author": "@ericmbarnard", + "license": "MIT", + "bugs": { + "url": "https://github.com/Knockout-Contrib/Knockout-Validation/issues" + } +}