-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjquery-serialize-object-v5.js.html
More file actions
executable file
·139 lines (116 loc) · 3.7 KB
/
Copy pathjquery-serialize-object-v5.js.html
File metadata and controls
executable file
·139 lines (116 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: jquery-serialize-object-v5.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: jquery-serialize-object-v5.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* @file jQuery extension to help serializing forms
*
* @author Gerkin
* @copyright 2016
* @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
* @package iThoughts-toolbox
*
*/
'use strict';
(( ithoughts ) => {
/*jslint plusplus: true*/
/*globals iThoughts*/
var $ = ithoughts.$;
/**
* Send a form through ajax
* @method external:"jQuery".fn.serializeObject
* @returns {object} Associative object representing the form
*/
$.fn.extend({
serializeObject() {
var json = {};
$.map( $( this ).serializeArray(), formvalue => {
var nestingIndex = formvalue.name.indexOf( '[' ),
nestingsCount,
jsonLocal,
nestings,
i,
fvn = formvalue.value || '';
if ( nestingIndex > -1 ) {
jsonLocal = json;
nestings = formvalue.name.replace( /\]/gi, '' ).split( '[' );
for ( i = 0, nestingsCount = nestings.length; i < nestingsCount; i++ ) {
if ( i === nestingsCount - 1 ) {
if ( nestings[i] !== '' ) {
if ( jsonLocal[nestings[i]]) {
if ( 'string' === typeof jsonLocal[nestings[i]]) {
jsonLocal[nestings[i]] = [ jsonLocal[nestings[i]] ];
}
jsonLocal[nestings[i]].push( fvn );
} else {
jsonLocal[nestings[i]] = fvn;
}
} else {
jsonLocal.push( fvn );
}
} else {
jsonLocal = jsonLocal[nestings[i]] = jsonLocal[nestings[i]] || ( '' === nestings[i + 1] ? [] : {});
}
}
} else if ( json[formvalue.name] !== undefined ) {
if ( !json[formvalue.name].push ) {
json[formvalue.name] = [ json[formvalue.name] ];
}
json[formvalue.name].push( fvn );
} else {
json[formvalue.name] = fvn;
}
});
return json;
},
serializeInputsObject( forceValue ) {
var value = {};
this.each(( index, element ) => {
var valueThis = {},
valuePtr = valueThis,
name = element.name,
nestings = name.replace( /\]/gi, '' ).split( '[' ),
i = 0,
nestingsCount = nestings.length;
for ( i; i < nestingsCount; i++ ) {
if ( i === nestingsCount - 1 ) {
valuePtr[nestings[i]] = typeof forceValue !== 'undefined' ? forceValue : this.value;
} else {
valuePtr = ( valuePtr[nestings[i]] = {});
}
}
$.extend( value, valueThis );
});
return value;
},
});
})( iThoughts.v5 );
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="iThoughts.html">iThoughts</a></li><li><a href="iThoughts.v5.html">v5</a></li></ul><h3>Global</h3><ul><li><a href="global.html#_go">_go</a></li><li><a href="global.html#_off">_off</a></li><li><a href="global.html#_on">_on</a></li><li><a href="global.html#isNA">isNA</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Wed Jul 05 2017 15:21:22 GMT+0200 (CEST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>