From 379313a635d3412e37ee9f07fbc3ad069f5c939e Mon Sep 17 00:00:00 2001 From: hongymagic Date: Fri, 18 Jan 2013 17:09:05 +1100 Subject: [PATCH 01/28] Move package.json to *.jquery.json format --- package.json => jQuery.serializeObject.jquery.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) rename package.json => jQuery.serializeObject.jquery.json (84%) diff --git a/package.json b/jQuery.serializeObject.jquery.json similarity index 84% rename from package.json rename to jQuery.serializeObject.jquery.json index 87e2df9..5a8b87b 100644 --- a/package.json +++ b/jQuery.serializeObject.jquery.json @@ -4,6 +4,7 @@ "title": "jQuery.serializeObject()", "author": { "name": "David G. Hong", + "email": "davidhong.code@gmail.com", "url": "https://github.com/hongymagic" }, "licenses": [ @@ -17,7 +18,7 @@ } ], "dependencies": { - "jquery": "1" + "jquery": ">=1.2" }, "description": "Convert
parameters to JSON (JavaScript Object Notation) format", "keywords": [ @@ -27,6 +28,7 @@ "JSON" ], "homepage": "https://github.com/hongymagic/jQuery.serializeObject", + "bugs": "https://github.com/hongymagic/jQuery.serializeObject/issues", "maintainers": [ { "name": "David G. Hong", From 76368d035c9ff9bee40a070d03ce4a6250cb8d56 Mon Sep 17 00:00:00 2001 From: hongymagic Date: Fri, 18 Jan 2013 18:17:53 +1100 Subject: [PATCH 02/28] Clean up whitespace --- jQuery.serializeObject.jquery.json | 4 ++-- jQuery.serializeObject.js | 37 ++++++++++++++---------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/jQuery.serializeObject.jquery.json b/jQuery.serializeObject.jquery.json index 5a8b87b..73e0176 100644 --- a/jQuery.serializeObject.jquery.json +++ b/jQuery.serializeObject.jquery.json @@ -1,7 +1,7 @@ { "name": "serializeObject", "version": "1.0.0", - "title": "jQuery.serializeObject()", + "title": "jQuery serializeObject", "author": { "name": "David G. Hong", "email": "davidhong.code@gmail.com", @@ -25,7 +25,7 @@ "serializeObject", "serialize", "serialise", - "JSON" + "JSON" ], "homepage": "https://github.com/hongymagic/jQuery.serializeObject", "bugs": "https://github.com/hongymagic/jQuery.serializeObject/issues", diff --git a/jQuery.serializeObject.js b/jQuery.serializeObject.js index 6bf29ec..e86ec52 100644 --- a/jQuery.serializeObject.js +++ b/jQuery.serializeObject.js @@ -1,10 +1,10 @@ // // Use internal $.serializeArray to get list of form elements which is consistent with $.serialize // -// And to avoid names such as +// And to avoid names such as // => object["favorite-color"] // -// We camelcase the name part, so the notation becomes +// We camelcase the name part, so the notation becomes // => object["favoriteColor"] // // Conveniently, this allows period notation to be used. @@ -16,30 +16,27 @@ // => { favoriteColor: 'yellow' } // $.fn.serializeObject = function () { - var - - result = Object.create(null), - mapper = function (element) { - element.name = $.camelCase(element.name); - return element; - }, - extend = function (i, element) { - var node = result[element.name]; + var result = Object.create(null); + var mapper = function (element) { + element.name = $.camelCase(element.name); + return element; + }; + var extend = function (i, element) { + var node = result[element.name]; // If node with same name exists already, need to convert it to an array as it // is a multi-value field (i.e., checkboxes) - if ('undefined' !== typeof node && node !== null) { - result[element.name] = node.push ? node.push(element.value) : [node, element.value]; - } else { - result[element.name] = element.value; - } - }; + if ('undefined' !== typeof node && node !== null) { + result[element.name] = node.push ? node.push(element.value) : [node, element.value]; + } else { + result[element.name] = element.value; + } + }; // For each serialzable element, convert element names to camelCasing and // extend each of them to a JSON object - $.each($.map(this.serializeArray(), mapper), extend); - return result; + $.each($.map(this.serializeArray(), mapper), extend); + return result; }; - From 9f78f06f4d8ab1721808222e455f5e8e999ac8e2 Mon Sep 17 00:00:00 2001 From: hongymagic Date: Fri, 18 Jan 2013 18:21:16 +1100 Subject: [PATCH 03/28] Moved jquery.json file --- ...y.serializeObject.jquery.json => serializeObject.jquery.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename jQuery.serializeObject.jquery.json => serializeObject.jquery.json (97%) diff --git a/jQuery.serializeObject.jquery.json b/serializeObject.jquery.json similarity index 97% rename from jQuery.serializeObject.jquery.json rename to serializeObject.jquery.json index 73e0176..3ecfb36 100644 --- a/jQuery.serializeObject.jquery.json +++ b/serializeObject.jquery.json @@ -1,6 +1,6 @@ { "name": "serializeObject", - "version": "1.0.0", + "version": "1.0.1", "title": "jQuery serializeObject", "author": { "name": "David G. Hong", From 01f48b5874c2500db043f7cf2c319a52f56ec6b3 Mon Sep 17 00:00:00 2001 From: hongymagic Date: Sat, 19 Jan 2013 22:42:48 +1100 Subject: [PATCH 04/28] Remove main script --- jQuery.serializeObject.js | 42 ------------------------------------- serializeObject.jquery.json | 20 +++++++----------- 2 files changed, 7 insertions(+), 55 deletions(-) delete mode 100644 jQuery.serializeObject.js diff --git a/jQuery.serializeObject.js b/jQuery.serializeObject.js deleted file mode 100644 index e86ec52..0000000 --- a/jQuery.serializeObject.js +++ /dev/null @@ -1,42 +0,0 @@ -// -// Use internal $.serializeArray to get list of form elements which is consistent with $.serialize -// -// And to avoid names such as -// => object["favorite-color"] -// -// We camelcase the name part, so the notation becomes -// => object["favoriteColor"] -// -// Conveniently, this allows period notation to be used. -// => object.favoriteColor -// -// This behaviour is similar to $(element).data() -// -// $('
').data() -// => { favoriteColor: 'yellow' } -// -$.fn.serializeObject = function () { - var result = Object.create(null); - var mapper = function (element) { - element.name = $.camelCase(element.name); - return element; - }; - var extend = function (i, element) { - var node = result[element.name]; - -// If node with same name exists already, need to convert it to an array as it -// is a multi-value field (i.e., checkboxes) - - if ('undefined' !== typeof node && node !== null) { - result[element.name] = node.push ? node.push(element.value) : [node, element.value]; - } else { - result[element.name] = element.value; - } - }; - -// For each serialzable element, convert element names to camelCasing and -// extend each of them to a JSON object - - $.each($.map(this.serializeArray(), mapper), extend); - return result; -}; diff --git a/serializeObject.jquery.json b/serializeObject.jquery.json index 3ecfb36..ddac56c 100644 --- a/serializeObject.jquery.json +++ b/serializeObject.jquery.json @@ -1,6 +1,6 @@ { "name": "serializeObject", - "version": "1.0.1", + "version": "1.0.2", "title": "jQuery serializeObject", "author": { "name": "David G. Hong", @@ -11,21 +11,18 @@ { "type": "MIT", "url": "MIT-LICENSE.txt" - }, - { - "type": "GPLv2", - "url": "GPL-LICENSE.txt" } ], "dependencies": { - "jquery": ">=1.2" + "jquery": ">=1.4" }, - "description": "Convert parameters to JSON (JavaScript Object Notation) format", - "keywords": [ + "description": "Convert data to JSON (JavaScript Object Notation) format", + "tags": [ + "form", + "JSON", "serializeObject", "serialize", - "serialise", - "JSON" + "serialise" ], "homepage": "https://github.com/hongymagic/jQuery.serializeObject", "bugs": "https://github.com/hongymagic/jQuery.serializeObject/issues", @@ -34,8 +31,5 @@ "name": "David G. Hong", "url": "https://github.com/hongymagic" } - ], - "files": [ - "jQuery.serializeObject.js" ] } \ No newline at end of file From d5df10d9192908cec681ce032f3ea72eedd4566b Mon Sep 17 00:00:00 2001 From: hongymagic Date: Sat, 19 Jan 2013 22:43:14 +1100 Subject: [PATCH 05/28] Add main script back --- jquery.serializeObject.js | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 jquery.serializeObject.js diff --git a/jquery.serializeObject.js b/jquery.serializeObject.js new file mode 100644 index 0000000..e86ec52 --- /dev/null +++ b/jquery.serializeObject.js @@ -0,0 +1,42 @@ +// +// Use internal $.serializeArray to get list of form elements which is consistent with $.serialize +// +// And to avoid names such as +// => object["favorite-color"] +// +// We camelcase the name part, so the notation becomes +// => object["favoriteColor"] +// +// Conveniently, this allows period notation to be used. +// => object.favoriteColor +// +// This behaviour is similar to $(element).data() +// +// $('
').data() +// => { favoriteColor: 'yellow' } +// +$.fn.serializeObject = function () { + var result = Object.create(null); + var mapper = function (element) { + element.name = $.camelCase(element.name); + return element; + }; + var extend = function (i, element) { + var node = result[element.name]; + +// If node with same name exists already, need to convert it to an array as it +// is a multi-value field (i.e., checkboxes) + + if ('undefined' !== typeof node && node !== null) { + result[element.name] = node.push ? node.push(element.value) : [node, element.value]; + } else { + result[element.name] = element.value; + } + }; + +// For each serialzable element, convert element names to camelCasing and +// extend each of them to a JSON object + + $.each($.map(this.serializeArray(), mapper), extend); + return result; +}; From 77363972141bde0a6314c02a86089b5d34c41af2 Mon Sep 17 00:00:00 2001 From: hongymagic Date: Sat, 19 Jan 2013 22:58:27 +1100 Subject: [PATCH 06/28] Added a more descriptive.. description --- serializeObject.jquery.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/serializeObject.jquery.json b/serializeObject.jquery.json index ddac56c..7484edd 100644 --- a/serializeObject.jquery.json +++ b/serializeObject.jquery.json @@ -1,6 +1,6 @@ { "name": "serializeObject", - "version": "1.0.2", + "version": "1.0.3", "title": "jQuery serializeObject", "author": { "name": "David G. Hong", @@ -16,7 +16,7 @@ "dependencies": { "jquery": ">=1.4" }, - "description": "Convert data to JSON (JavaScript Object Notation) format", + "description": "Convert your form data to into JSON (JavaScript Object Notation) format, so you can manipulate them easily. See Github project page for information. ", "tags": [ "form", "JSON", From 1d936df0ff8df47bc9b3f3cad4a7ceb5440d38ad Mon Sep 17 00:00:00 2001 From: hongymagic Date: Sat, 19 Jan 2013 23:03:36 +1100 Subject: [PATCH 07/28] Remove script injection test --- serializeObject.jquery.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serializeObject.jquery.json b/serializeObject.jquery.json index 7484edd..e938899 100644 --- a/serializeObject.jquery.json +++ b/serializeObject.jquery.json @@ -16,7 +16,7 @@ "dependencies": { "jquery": ">=1.4" }, - "description": "Convert your form data to into JSON (JavaScript Object Notation) format, so you can manipulate them easily. See Github project page for information. ", + "description": "Convert your form data to into JSON (JavaScript Object Notation) format, so you can manipulate them easily. See Github project page for information.", "tags": [ "form", "JSON", From b07477a2ca508a6351a3baae072a9791d2b2cfa4 Mon Sep 17 00:00:00 2001 From: hongymagic Date: Wed, 23 Jan 2013 09:20:28 +1100 Subject: [PATCH 08/28] Fix issue with multi-value form inputs. Closes #2 --- jquery.serializeObject.js | 8 ++++- serializeObject.jquery.json | 2 +- test/serialization-test.js | 35 +++++++++++++------ test/tests.html | 70 ++++++++++++++++++++++--------------- 4 files changed, 74 insertions(+), 41 deletions(-) diff --git a/jquery.serializeObject.js b/jquery.serializeObject.js index e86ec52..7859ade 100644 --- a/jquery.serializeObject.js +++ b/jquery.serializeObject.js @@ -16,6 +16,8 @@ // => { favoriteColor: 'yellow' } // $.fn.serializeObject = function () { + "use strict"; + var result = Object.create(null); var mapper = function (element) { element.name = $.camelCase(element.name); @@ -28,7 +30,11 @@ $.fn.serializeObject = function () { // is a multi-value field (i.e., checkboxes) if ('undefined' !== typeof node && node !== null) { - result[element.name] = node.push ? node.push(element.value) : [node, element.value]; + if ($.isArray(node)) { + node.push(element.value); + } else { + result[element.name] = [node, element.value]; + } } else { result[element.name] = element.value; } diff --git a/serializeObject.jquery.json b/serializeObject.jquery.json index e938899..5f5b1dd 100644 --- a/serializeObject.jquery.json +++ b/serializeObject.jquery.json @@ -1,6 +1,6 @@ { "name": "serializeObject", - "version": "1.0.3", + "version": "1.0.4", "title": "jQuery serializeObject", "author": { "name": "David G. Hong", diff --git a/test/serialization-test.js b/test/serialization-test.js index f677bec..8c61f3a 100644 --- a/test/serialization-test.js +++ b/test/serialization-test.js @@ -2,16 +2,31 @@ module('serialization test'); test('simple form test', function () { - var form = $('form#simple-form'), - data = form.serializeObject(), - expected = { - name: 'John Apple', - age: '21', - email: 'john.apple@apple.com', - password: '', - legalAge: 'yes' - }; + var form = $('form#simple-form'); + var data = form.serializeObject(); + var expected = { + name: 'John Apple', + age: '21', + email: 'john.apple@apple.com', + password: '', + legalAge: 'yes' + }; - deepEqual(data, expected, 'Key/value pairs should be identical'); + deepEqual(data, expected, 'Key/value pairs should be identical'); }); +test('multi value inputs', function () { + var form = $('form#multi-value-form'); + var data = form.serializeObject(); + var expected = { + food: ['Banana', 'Melon'], + drink: [ + 'Water', + 'Milk', + 'Beer', + 'Cocktail' + ] + }; + + deepEqual(data, expected, 'Multiple values should be an array'); +}); diff --git a/test/tests.html b/test/tests.html index 0d6af36..4815cc4 100644 --- a/test/tests.html +++ b/test/tests.html @@ -1,36 +1,48 @@ - - - $.serializeObject tests + + + $.serializeObject tests - - - - - + + + + + - - - -

QUnit Test Suite - Step Addon

-

-
-

-
    + + + +

    QUnit Test Suite - Step Addon

    +

    +
    +

    +
      -
      - - - - - +
      + + + + + - - - -
      - + + + + +
      + + + + + + + + + +
      +
      + From 00e46855a75d166c3051fc0b625c5b25f41df0b0 Mon Sep 17 00:00:00 2001 From: hongymagic Date: Wed, 23 Jan 2013 09:21:01 +1100 Subject: [PATCH 09/28] Add grunt task - JSHint - Run QUnit tests - Create a minified version, not that its big... --- .jshintrc | 67 ++++++++++++++++++++++++++++++ dist/jquery.serializeObject.min.js | 1 + grunt.js | 48 +++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 .jshintrc create mode 100644 dist/jquery.serializeObject.min.js create mode 100644 grunt.js diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..3258d05 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,67 @@ +{ + "bitwise" : true, + "curly" : true, + "eqeqeq" : false, + "forin" : true, + "immed" : true, + "latedef" : true, + "newcap" : true, + "noarg" : true, + "noempty" : true, + "nonew" : true, + "plusplus" : false, + "regexp" : true, + "undef" : true, + "strict" : false, + "trailing" : true, + + "asi" : false, + "boss" : false, + "debug" : false, + "eqnull" : false, + "es5" : false, + "esnext" : false, + "evil" : false, + "expr" : false, + "funcscope" : false, + "globalstrict" : false, + "iterator" : false, + "lastsemic" : false, + "laxbreak" : false, + "laxcomma" : false, + "loopfunc" : false, + "multistr" : false, + "onecase" : false, + "proto" : false, + "regexdash" : false, + "scripturl" : false, + "smarttabs" : false, + "shadow" : false, + "sub" : false, + "supernew" : false, + "validthis" : false, + + "browser" : true, + "couch" : false, + "devel" : true, + "dojo" : false, + "jquery" : true, + "mootools" : false, + "node" : true, + "nonstandard" : false, + "prototypejs" : false, + "rhino" : false, + "wsh" : false, + + "nomen" : false, + "onevar" : false, + "passfail" : false, + "white" : false, + + "maxerr" : 100, + "predef" : [ + "test", + "deepEqual" + ], + "indent" : 4 +} \ No newline at end of file diff --git a/dist/jquery.serializeObject.min.js b/dist/jquery.serializeObject.min.js new file mode 100644 index 0000000..9492def --- /dev/null +++ b/dist/jquery.serializeObject.min.js @@ -0,0 +1 @@ +$.fn.serializeObject=function(){"use strict";var a=Object.create(null),b=function(a){return a.name=$.camelCase(a.name),a},c=function(b,c){var d=a[c.name];"undefined"!=typeof d&&d!==null?$.isArray(d)?d.push(c.value):a[c.name]=[d,c.value]:a[c.name]=c.value};return $.each($.map(this.serializeArray(),b),c),a}; \ No newline at end of file diff --git a/grunt.js b/grunt.js new file mode 100644 index 0000000..4ef473b --- /dev/null +++ b/grunt.js @@ -0,0 +1,48 @@ + +module.exports = function (grunt) { + +// Project configuration + + grunt.initConfig({ + pkg: '', + + files: { + all: ['jquery.serializeObject.js'], + tests: ['test/**/*.js'] + }, + + lint: { + all: ['', ''] + }, + + docs: { + all: ['README.markdown'] + }, + + min: { + dist: { + src: '', + dest: 'dist/jquery.serializeObject.min.js' + } + }, + +// JSHint options +// See: http://www.jshint.com/options/ for list of options and definitions + + jshint: { + options: '' + }, + +// QUnit + + qunit: { + all: ['test/*.html'] + } + + }); + +// Default grunt task + + grunt.registerTask('default', 'lint qunit min'); + +}; \ No newline at end of file From efac2b92bd7d37405549d63b765e04c27da06f3c Mon Sep 17 00:00:00 2001 From: hongymagic Date: Wed, 23 Jan 2013 09:33:32 +1100 Subject: [PATCH 10/28] Update README --- README.markdown | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 3fcee5d..fcb315d 100644 --- a/README.markdown +++ b/README.markdown @@ -3,7 +3,7 @@ `$.serializeObject` is a variant of existing `$.serialize` method which, instead of encoding form elements to string, converts form elements to a valid JSON -object. +object which can be used in your JavaScript application. # Why? @@ -38,4 +38,3 @@ will return: minuteTaker: '', attendees: '' } - From 7789084425b353624fc95487024459f364d11df6 Mon Sep 17 00:00:00 2001 From: hongymagic Date: Wed, 23 Jan 2013 13:38:23 +1100 Subject: [PATCH 11/28] Remove camel casing of keys as suggested by issue #2 This is consistent with other $ methods such as: - $.serializeArray - $.serialize There is no reason why it should follow $.data conventions. Although that isn't hard to achieve. --- README.markdown | 47 +++++++++++++++++++++--------- dist/jquery.serializeObject.min.js | 2 +- jquery.serializeObject.js | 28 +++++++----------- serializeObject.jquery.json | 2 +- test/serialization-test.js | 2 +- 5 files changed, 46 insertions(+), 35 deletions(-) diff --git a/README.markdown b/README.markdown index fcb315d..bb3751b 100644 --- a/README.markdown +++ b/README.markdown @@ -13,28 +13,47 @@ JSON much easier to work with than DOM or string manipulation. # How do I use it? -If you want to see the code and demo first: http://jsfiddle.net/davidhong/gP9bh/ +If you want to see the code and demo first: http://jsfiddle.net/davidhong/PRpJT/ -Simple include the `jQuery.serializeObject.js` along with any `jQuery` instance +Simply include the `jQuery.serializeObject.js` along with any `jQuery` instance and use it like `$.serialize`. If you have a `form` like the following: -
      - - - - ... -
      +
      + + + + + + +
      and wish to convert them to a JSON object: - var minutes = $('form#minutes').serializeObject(); + var minutes = $('form#minutes').serializeObject(); will return: - { - subject: '', - minuteTaker: '', - attendees: '' - } + { + "subject": "", + "minute-taker": "", + "attendees": [ + "David", + "Daniel", + "Darwin" + ] + } + +## Change log + +### 2.0.0 + +*Major version change: Camel casing of names have been removed. Please use +version 1.0.4 if you require camel casing of names.* + +- Remove `$.data` like camelCasing on names + +### 1.0.4 + +- Fix an issue (#2) where arrays longer than 2 resulted in incorrect values diff --git a/dist/jquery.serializeObject.min.js b/dist/jquery.serializeObject.min.js index 9492def..8aac8a4 100644 --- a/dist/jquery.serializeObject.min.js +++ b/dist/jquery.serializeObject.min.js @@ -1 +1 @@ -$.fn.serializeObject=function(){"use strict";var a=Object.create(null),b=function(a){return a.name=$.camelCase(a.name),a},c=function(b,c){var d=a[c.name];"undefined"!=typeof d&&d!==null?$.isArray(d)?d.push(c.value):a[c.name]=[d,c.value]:a[c.name]=c.value};return $.each($.map(this.serializeArray(),b),c),a}; \ No newline at end of file +$.fn.serializeObject=function(){"use strict";var a={},b=function(b,c){var d=a[c.name];"undefined"!=typeof d&&d!==null?$.isArray(d)?d.push(c.value):a[c.name]=[d,c.value]:a[c.name]=c.value};return $.each(this.serializeArray(),b),a}; \ No newline at end of file diff --git a/jquery.serializeObject.js b/jquery.serializeObject.js index 7859ade..1c8dac3 100644 --- a/jquery.serializeObject.js +++ b/jquery.serializeObject.js @@ -1,28 +1,20 @@ // -// Use internal $.serializeArray to get list of form elements which is consistent with $.serialize +// Use internal $.serializeArray to get list of form elements which is +// consistent with $.serialize // -// And to avoid names such as -// => object["favorite-color"] +// From version 2.0.0, $.serializeObject will stop converting [name] values +// to camelCase format. This is *consistent* with other serialize methods: // -// We camelcase the name part, so the notation becomes -// => object["favoriteColor"] +// - $.serialize +// - $.serializeArray // -// Conveniently, this allows period notation to be used. -// => object.favoriteColor -// -// This behaviour is similar to $(element).data() -// -// $('
      ').data() -// => { favoriteColor: 'yellow' } +// If you require camel casing, you can either download version 1.0.4 or map +// them yourself. // $.fn.serializeObject = function () { "use strict"; - var result = Object.create(null); - var mapper = function (element) { - element.name = $.camelCase(element.name); - return element; - }; + var result = {}; var extend = function (i, element) { var node = result[element.name]; @@ -43,6 +35,6 @@ $.fn.serializeObject = function () { // For each serialzable element, convert element names to camelCasing and // extend each of them to a JSON object - $.each($.map(this.serializeArray(), mapper), extend); + $.each(this.serializeArray(), extend); return result; }; diff --git a/serializeObject.jquery.json b/serializeObject.jquery.json index 5f5b1dd..32d4cae 100644 --- a/serializeObject.jquery.json +++ b/serializeObject.jquery.json @@ -1,6 +1,6 @@ { "name": "serializeObject", - "version": "1.0.4", + "version": "2.0.0", "title": "jQuery serializeObject", "author": { "name": "David G. Hong", diff --git a/test/serialization-test.js b/test/serialization-test.js index 8c61f3a..8f43b66 100644 --- a/test/serialization-test.js +++ b/test/serialization-test.js @@ -9,7 +9,7 @@ test('simple form test', function () { age: '21', email: 'john.apple@apple.com', password: '', - legalAge: 'yes' + 'legal-age': 'yes' }; deepEqual(data, expected, 'Key/value pairs should be identical'); From f8873586f33becfafae0f27357413ce62e6f711d Mon Sep 17 00:00:00 2001 From: hongymagic Date: Tue, 16 Apr 2013 12:00:40 +1000 Subject: [PATCH 12/28] Add grunt support --- .gitignore | 1 + grunt.js => Gruntfile.js | 23 +++++++++-------------- package.json | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 14 deletions(-) rename grunt.js => Gruntfile.js (51%) create mode 100644 package.json diff --git a/.gitignore b/.gitignore index 5ca0973..0ca0b3d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store +node_modules/ diff --git a/grunt.js b/Gruntfile.js similarity index 51% rename from grunt.js rename to Gruntfile.js index 4ef473b..2ff9623 100644 --- a/grunt.js +++ b/Gruntfile.js @@ -11,38 +11,33 @@ module.exports = function (grunt) { tests: ['test/**/*.js'] }, - lint: { - all: ['', ''] - }, - docs: { all: ['README.markdown'] }, - min: { + uglify: { dist: { - src: '', - dest: 'dist/jquery.serializeObject.min.js' + 'dist/jquery.serializeObject.min.js': '' } }, -// JSHint options -// See: http://www.jshint.com/options/ for list of options and definitions - jshint: { - options: '' + options: '', + all: '' }, -// QUnit - qunit: { all: ['test/*.html'] } }); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-qunit'); + // Default grunt task - grunt.registerTask('default', 'lint qunit min'); + grunt.registerTask('default', ['jshint', 'uglify', 'qunit']); }; \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..0f7c2b6 --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "name": "jQuery.serializeObject", + "version": "2.0.0", + "description": "A jQuery plugin to turn form data into JSON", + "main": "jquery.serializeObject.js", + "directories": { + "test": "test" + }, + "scripts": { + "test": "grunt test" + }, + "repository": { + "type": "git", + "url": "git://github.com/hongymagic/jQuery.serializeObject.git" + }, + "keywords": [ + "jquery", + "serialize", + "object", + "json", + "serializeJSON", + "serializeObject" + ], + "author": "David G. Hong", + "license": "MIT", + "gitHead": "7789084425b353624fc95487024459f364d11df6", + "readmeFilename": "README.markdown", + "devDependencies": { + "grunt": "~0.4.1", + "grunt-contrib-uglify": "~0.2.0", + "grunt-contrib-jshint": "~0.4.3", + "grunt-contrib-qunit": "~0.2.1" + } +} From a5306cb053443ad0fe4bd80eba068a2b5fdc98b7 Mon Sep 17 00:00:00 2001 From: hongymagic Date: Tue, 16 Apr 2013 12:00:45 +1000 Subject: [PATCH 13/28] 2.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0f7c2b6..10187c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jQuery.serializeObject", - "version": "2.0.0", + "version": "2.0.1", "description": "A jQuery plugin to turn form data into JSON", "main": "jquery.serializeObject.js", "directories": { From 583120bd9822be88a0a7ff9d4769f68f4e833d4b Mon Sep 17 00:00:00 2001 From: hongymagic Date: Tue, 16 Apr 2013 12:01:47 +1000 Subject: [PATCH 14/28] Bump jquery.json to 2.0.1 --- serializeObject.jquery.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serializeObject.jquery.json b/serializeObject.jquery.json index 32d4cae..6712623 100644 --- a/serializeObject.jquery.json +++ b/serializeObject.jquery.json @@ -1,6 +1,6 @@ { "name": "serializeObject", - "version": "2.0.0", + "version": "2.0.1", "title": "jQuery serializeObject", "author": { "name": "David G. Hong", From e51c377d135dabe4b6a0fb41d030e833ed15c2c8 Mon Sep 17 00:00:00 2001 From: Sathvik Ponangi Date: Mon, 22 Apr 2013 16:42:03 +0530 Subject: [PATCH 15/28] Support for jQuery.noConflict. Closes #3 --- jquery.serializeObject.js | 42 ++++++++++++++++++------------------- package.json | 2 +- serializeObject.jquery.json | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/jquery.serializeObject.js b/jquery.serializeObject.js index 1c8dac3..f6285ac 100644 --- a/jquery.serializeObject.js +++ b/jquery.serializeObject.js @@ -11,30 +11,30 @@ // If you require camel casing, you can either download version 1.0.4 or map // them yourself. // -$.fn.serializeObject = function () { - "use strict"; - var result = {}; - var extend = function (i, element) { - var node = result[element.name]; +(function($){ + $.fn.serializeObject = function () { + "use strict"; -// If node with same name exists already, need to convert it to an array as it -// is a multi-value field (i.e., checkboxes) + var result = {}; + var extend = function (i, element) { + var node = result[element.name]; - if ('undefined' !== typeof node && node !== null) { - if ($.isArray(node)) { - node.push(element.value); + // If node with same name exists already, need to convert it to an array as it + // is a multi-value field (i.e., checkboxes) + + if ('undefined' !== typeof node && node !== null) { + if ($.isArray(node)) { + node.push(element.value); + } else { + result[element.name] = [node, element.value]; + } } else { - result[element.name] = [node, element.value]; + result[element.name] = element.value; } - } else { - result[element.name] = element.value; - } - }; + }; -// For each serialzable element, convert element names to camelCasing and -// extend each of them to a JSON object - - $.each(this.serializeArray(), extend); - return result; -}; + $.each(this.serializeArray(), extend); + return result; + }; +})(jQuery); diff --git a/package.json b/package.json index 10187c1..8017c7c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jQuery.serializeObject", - "version": "2.0.1", + "version": "2.0.2", "description": "A jQuery plugin to turn form data into JSON", "main": "jquery.serializeObject.js", "directories": { diff --git a/serializeObject.jquery.json b/serializeObject.jquery.json index 6712623..4f2d75c 100644 --- a/serializeObject.jquery.json +++ b/serializeObject.jquery.json @@ -1,6 +1,6 @@ { "name": "serializeObject", - "version": "2.0.1", + "version": "2.0.2", "title": "jQuery serializeObject", "author": { "name": "David G. Hong", From 03002347bcec724268156157ee878c081ea27354 Mon Sep 17 00:00:00 2001 From: hongymagic Date: Mon, 22 Apr 2013 21:46:29 +1000 Subject: [PATCH 16/28] Add travis.yml integration --- .travis.yml | 5 +++++ README.markdown | 1 + 2 files changed, 6 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8fa1c38 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: node_js +node_js: + - 0.8 + - 0.9 + - 0.10 diff --git a/README.markdown b/README.markdown index bb3751b..f061967 100644 --- a/README.markdown +++ b/README.markdown @@ -1,3 +1,4 @@ +[![Build Status](https://travis-ci.org/hongymagic/jQuery.serializeObject.png)](https://travis-ci.org/hongymagic/jQuery.serializeObject) # What is it? From 7ceecbc170429360c6099af7626c1386c1b86d83 Mon Sep 17 00:00:00 2001 From: hongymagic Date: Mon, 22 Apr 2013 21:54:41 +1000 Subject: [PATCH 17/28] Update 2.0.2 changelog --- README.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.markdown b/README.markdown index f061967..669ecc7 100644 --- a/README.markdown +++ b/README.markdown @@ -48,6 +48,10 @@ will return: ## Change log +### 2.0.2 + +- Add support for $.noConflict mode + ### 2.0.0 *Major version change: Camel casing of names have been removed. Please use From b18a3e9fd432002a5d1629b545f854991f102da8 Mon Sep 17 00:00:00 2001 From: hongymagic Date: Mon, 22 Apr 2013 21:58:51 +1000 Subject: [PATCH 18/28] Add before script to .travis.yml --- .travis.yml | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8fa1c38..f61a724 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,5 @@ node_js: - 0.8 - 0.9 - 0.10 +before_script: + - npm install -g grunt-cli diff --git a/package.json b/package.json index 8017c7c..10b7498 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "test" }, "scripts": { - "test": "grunt test" + "test": "grunt" }, "repository": { "type": "git", From d1731128d45d74b6ca2f6e216d3f883bc94823b3 Mon Sep 17 00:00:00 2001 From: hongymagic Date: Wed, 22 May 2013 10:14:03 +1000 Subject: [PATCH 19/28] Add pretest step to update submodules --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 10b7498..8bc01a8 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "test": "test" }, "scripts": { + "pretest": "git submodule update --init", "test": "grunt" }, "repository": { From 88cfe216c518e1e742f127140e2ea2a81c9508be Mon Sep 17 00:00:00 2001 From: hongymagic Date: Fri, 24 May 2013 23:49:51 +1000 Subject: [PATCH 20/28] Add pretask to build jquery --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8bc01a8..ddb0768 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "test" }, "scripts": { - "pretest": "git submodule update --init", + "pretest": "git submodule update --init --recursive && git submodule foreach --recursive git pull origin master && cd tools/jquery && npm install && grunt", "test": "grunt" }, "repository": { From 9dc0d3a74260baa64dd57d30baed69b67058e621 Mon Sep 17 00:00:00 2001 From: hongymagic Date: Sun, 26 May 2013 13:45:19 +1000 Subject: [PATCH 21/28] Add bower package definition --- bower.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 bower.json diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..f855dd3 --- /dev/null +++ b/bower.json @@ -0,0 +1,10 @@ +{ + "name": "jQuery.serializeObject", + "version": "2.0.2", + "main": "jQuery.serializeObject.js", + "ignore": [ + "**/.*", + "node_modules", + "components" + ] +} \ No newline at end of file From 85a8e72785140fbf97c1066ade2231982ff6b298 Mon Sep 17 00:00:00 2001 From: David Hong Date: Wed, 2 Oct 2013 07:11:29 -0700 Subject: [PATCH 22/28] Add LICENSE file via addalicense.com --- LICENSE.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..f4b72d7 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013 David Hong + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From 642ada9998ae73b7232ddaec1e12c4cfa92f0a4a Mon Sep 17 00:00:00 2001 From: hongymagic Date: Thu, 3 Oct 2013 00:34:39 +1000 Subject: [PATCH 23/28] Update README to include new changes --- README.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.markdown b/README.markdown index 669ecc7..8cdf7f8 100644 --- a/README.markdown +++ b/README.markdown @@ -48,6 +48,10 @@ will return: ## Change log +### 2.0.3 + +- Add MIT License + ### 2.0.2 - Add support for $.noConflict mode From 5c5957f0895ed283f3373065e46a86490e1b966c Mon Sep 17 00:00:00 2001 From: hongymagic Date: Thu, 3 Oct 2013 00:36:24 +1000 Subject: [PATCH 24/28] 2.0.3 --- bower.json | 2 +- package.json | 2 +- serializeObject.jquery.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index f855dd3..5121008 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jQuery.serializeObject", - "version": "2.0.2", + "version": "2.0.3", "main": "jQuery.serializeObject.js", "ignore": [ "**/.*", diff --git a/package.json b/package.json index ddb0768..bb16761 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jQuery.serializeObject", - "version": "2.0.2", + "version": "2.0.3", "description": "A jQuery plugin to turn form data into JSON", "main": "jquery.serializeObject.js", "directories": { diff --git a/serializeObject.jquery.json b/serializeObject.jquery.json index 4f2d75c..bbc4022 100644 --- a/serializeObject.jquery.json +++ b/serializeObject.jquery.json @@ -1,6 +1,6 @@ { "name": "serializeObject", - "version": "2.0.2", + "version": "2.0.3", "title": "jQuery serializeObject", "author": { "name": "David G. Hong", From 4e2d79f77a81e36fdbb373af21e2fa8aafbf45a3 Mon Sep 17 00:00:00 2001 From: Bitdeli Chef Date: Fri, 13 Dec 2013 00:46:47 +0000 Subject: [PATCH 25/28] Add a Bitdeli badge to README --- README.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.markdown b/README.markdown index 8cdf7f8..d69768a 100644 --- a/README.markdown +++ b/README.markdown @@ -66,3 +66,7 @@ version 1.0.4 if you require camel casing of names.* ### 1.0.4 - Fix an issue (#2) where arrays longer than 2 resulted in incorrect values + + +[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/hongymagic/jquery.serializeobject/trend.png)](https://bitdeli.com/free "Bitdeli Badge") + From 2576a083c1c8b88be645b8081e9eaae023d3fe1d Mon Sep 17 00:00:00 2001 From: hongymagic Date: Thu, 15 May 2014 10:47:05 +1000 Subject: [PATCH 26/28] Replace git submodules and use bower dependencies instead - Fix #10 (thanks @piacentini) --- .bowerrc | 3 +++ .gitignore | 1 + .gitmodules | 6 ------ .travis.yml | 6 ++---- bower.json | 12 +++++++++--- package.json | 2 +- test/tests.html | 8 ++++---- tools/jquery | 1 - tools/qunit | 1 - 9 files changed, 20 insertions(+), 20 deletions(-) create mode 100644 .bowerrc delete mode 160000 tools/jquery delete mode 160000 tools/qunit diff --git a/.bowerrc b/.bowerrc new file mode 100644 index 0000000..ffede22 --- /dev/null +++ b/.bowerrc @@ -0,0 +1,3 @@ +{ + "directory": "components" +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0ca0b3d..da032f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store node_modules/ +components/ diff --git a/.gitmodules b/.gitmodules index 79ddfb5..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +0,0 @@ -[submodule "tools/qunit"] - path = tools/qunit - url = https://github.com/jquery/qunit.git -[submodule "tools/jquery"] - path = tools/jquery - url = https://github.com/jquery/jquery.git diff --git a/.travis.yml b/.travis.yml index f61a724..d30ba63 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: node_js node_js: - - 0.8 - - 0.9 - - 0.10 + - 0.11 before_script: - - npm install -g grunt-cli + - npm install -g grunt-cli bower diff --git a/bower.json b/bower.json index 5121008..2612443 100644 --- a/bower.json +++ b/bower.json @@ -1,10 +1,16 @@ { "name": "jQuery.serializeObject", "version": "2.0.3", - "main": "jQuery.serializeObject.js", + "main": "jquery.serializeObject.js", "ignore": [ "**/.*", "node_modules", "components" - ] -} \ No newline at end of file + ], + "dependencies": { + "jquery": "1.9.1" + }, + "devDependencies": { + "qunit": "~1.14.0" + } +} diff --git a/package.json b/package.json index bb16761..2e3b0a0 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "test" }, "scripts": { - "pretest": "git submodule update --init --recursive && git submodule foreach --recursive git pull origin master && cd tools/jquery && npm install && grunt", + "pretest": "bower install", "test": "grunt" }, "repository": { diff --git a/test/tests.html b/test/tests.html index 4815cc4..efc21ff 100644 --- a/test/tests.html +++ b/test/tests.html @@ -4,10 +4,10 @@ $.serializeObject tests - - - - + + + + diff --git a/tools/jquery b/tools/jquery deleted file mode 160000 index d511613..0000000 --- a/tools/jquery +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d511613d748a92af04a3f07943f34f9baadc4153 diff --git a/tools/qunit b/tools/qunit deleted file mode 160000 index c319c35..0000000 --- a/tools/qunit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c319c356cb4942a16ea62e5b9020044e7d97c1b9 From 8a037f1890085f8c7553e8e654f7d243f8bd2bcd Mon Sep 17 00:00:00 2001 From: David Hong Date: Thu, 26 Nov 2015 14:08:58 +1100 Subject: [PATCH 27/28] docs: add known issues section in readme --- README.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index d69768a..7407517 100644 --- a/README.markdown +++ b/README.markdown @@ -67,6 +67,8 @@ version 1.0.4 if you require camel casing of names.* - Fix an issue (#2) where arrays longer than 2 resulted in incorrect values +## Known issues -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/hongymagic/jquery.serializeobject/trend.png)](https://bitdeli.com/free "Bitdeli Badge") +- In rare cases, this won't work with old checkbox/hidden hack. See [this issue for more details](https://github.com/hongymagic/jQuery.serializeObject/issues/9). +[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/hongymagic/jquery.serializeobject/trend.png)](https://bitdeli.com/free "Bitdeli Badge") From bf9502f8d7bb6ab2ee4500550b6b0bbbd14fd19b Mon Sep 17 00:00:00 2001 From: Erik van Velzen Date: Wed, 14 Jun 2017 19:21:39 +0200 Subject: [PATCH 28/28] Add a typescript definition for the library --- jquery.serializeObject.d.ts | 4 ++++ package.json | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 jquery.serializeObject.d.ts diff --git a/jquery.serializeObject.d.ts b/jquery.serializeObject.d.ts new file mode 100644 index 0000000..3aea456 --- /dev/null +++ b/jquery.serializeObject.d.ts @@ -0,0 +1,4 @@ + +interface JQuery { + serializeObject(): { [index: string]: string|string[] } +} diff --git a/package.json b/package.json index 2e3b0a0..b07a0b7 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "name": "jQuery.serializeObject", - "version": "2.0.3", + "version": "2.0.4", "description": "A jQuery plugin to turn form data into JSON", "main": "jquery.serializeObject.js", + "types": "jquery.serializeObject.d.ts", "directories": { "test": "test" },