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 5ca0973..da032f1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +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/.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/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..d30ba63
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,5 @@
+language: node_js
+node_js:
+ - 0.11
+before_script:
+ - npm install -g grunt-cli bower
diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 0000000..2ff9623
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,43 @@
+
+module.exports = function (grunt) {
+
+// Project configuration
+
+ grunt.initConfig({
+ pkg: '',
+
+ files: {
+ all: ['jquery.serializeObject.js'],
+ tests: ['test/**/*.js']
+ },
+
+ docs: {
+ all: ['README.markdown']
+ },
+
+ uglify: {
+ dist: {
+ 'dist/jquery.serializeObject.min.js': ''
+ }
+ },
+
+ jshint: {
+ options: '',
+ all: ''
+ },
+
+ 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', ['jshint', 'uglify', 'qunit']);
+
+};
\ No newline at end of file
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.
diff --git a/README.markdown b/README.markdown
index 3fcee5d..7407517 100644
--- a/README.markdown
+++ b/README.markdown
@@ -1,9 +1,10 @@
+[](https://travis-ci.org/hongymagic/jQuery.serializeObject)
# What is it?
`$.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?
@@ -13,29 +14,61 @@ 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.3
+
+- Add MIT License
+
+### 2.0.2
+
+- Add support for $.noConflict mode
+
+### 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
+
+## Known issues
+
+- 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).
+
+[](https://bitdeli.com/free "Bitdeli Badge")
diff --git a/bower.json b/bower.json
new file mode 100644
index 0000000..2612443
--- /dev/null
+++ b/bower.json
@@ -0,0 +1,16 @@
+{
+ "name": "jQuery.serializeObject",
+ "version": "2.0.3",
+ "main": "jquery.serializeObject.js",
+ "ignore": [
+ "**/.*",
+ "node_modules",
+ "components"
+ ],
+ "dependencies": {
+ "jquery": "1.9.1"
+ },
+ "devDependencies": {
+ "qunit": "~1.14.0"
+ }
+}
diff --git a/dist/jquery.serializeObject.min.js b/dist/jquery.serializeObject.min.js
new file mode 100644
index 0000000..8aac8a4
--- /dev/null
+++ b/dist/jquery.serializeObject.min.js
@@ -0,0 +1 @@
+$.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
deleted file mode 100644
index 6bf29ec..0000000
--- a/jQuery.serializeObject.js
+++ /dev/null
@@ -1,45 +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),
- mapper = function (element) {
- element.name = $.camelCase(element.name);
- return element;
- },
- 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/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/jquery.serializeObject.js b/jquery.serializeObject.js
new file mode 100644
index 0000000..f6285ac
--- /dev/null
+++ b/jquery.serializeObject.js
@@ -0,0 +1,40 @@
+//
+// Use internal $.serializeArray to get list of form elements which is
+// consistent with $.serialize
+//
+// From version 2.0.0, $.serializeObject will stop converting [name] values
+// to camelCase format. This is *consistent* with other serialize methods:
+//
+// - $.serialize
+// - $.serializeArray
+//
+// If you require camel casing, you can either download version 1.0.4 or map
+// them yourself.
+//
+
+(function($){
+ $.fn.serializeObject = function () {
+ "use strict";
+
+ var result = {};
+ 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) {
+ if ($.isArray(node)) {
+ node.push(element.value);
+ } else {
+ result[element.name] = [node, element.value];
+ }
+ } else {
+ result[element.name] = element.value;
+ }
+ };
+
+ $.each(this.serializeArray(), extend);
+ return result;
+ };
+})(jQuery);
diff --git a/package.json b/package.json
index 87e2df9..b07a0b7 100644
--- a/package.json
+++ b/package.json
@@ -1,39 +1,36 @@
{
- "name": "serializeObject",
- "version": "1.0.0",
- "title": "jQuery.serializeObject()",
- "author": {
- "name": "David G. Hong",
- "url": "https://github.com/hongymagic"
- },
- "licenses": [
- {
- "type": "MIT",
- "url": "MIT-LICENSE.txt"
- },
- {
- "type": "GPLv2",
- "url": "GPL-LICENSE.txt"
- }
- ],
- "dependencies": {
- "jquery": "1"
- },
- "description": "Convert