Permalink
Browse files

Added jQuery.params

  • Loading branch information...
trabianmatt committed Jan 28, 2013
1 parent 33e2efd commit 47994065998efd189c16785888589a2f46b20ad0
Showing with 128 additions and 0 deletions.
  1. +1 −0 package.json
  2. +2 −0 src/tb/lib/ti/extend.coffee
  3. +125 −0 vendor/jquery.param.js
View
@@ -65,6 +65,7 @@
"vendor/underscore.js",
"vendor/backbone.js",
"vendor/jquery.deferred.js",
+ "vendor/jquery.param.js",
"backbone.stickit:backbone.stickit.js",
"vendor/jade.js"
],
@@ -23,6 +23,8 @@ module.exports = (ti) ->
$.Deferred = jQuery.Deferred
$.Callbacks = jQuery.Callbacks
+ $.param = jQuery.param
+
ajax = require('./ajax') $
events = require('./events') $
manipulation = require('./manipulation') $
View
@@ -0,0 +1,125 @@
+// Copyright 2013 jQuery Foundation and other contributors
+// http://jquery.com/
+
+// 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.
+
+(function() {
+
+var r20 = /%20/g,
+ rbracket = /\[\]$/,
+ rCRLF = /\r?\n/g,
+ rsubmitterTypes = /^(?:submit|button|image|reset)$/i,
+ rsubmittable = /^(?:input|select|textarea|keygen)/i;
+
+// jQuery.fn.extend({
+// serialize: function() {
+// return jQuery.param( this.serializeArray() );
+// },
+// serializeArray: function() {
+// return this.map(function(){
+// // Can add propHook for "elements" to filter or add form elements
+// var elements = jQuery.prop( this, "elements" );
+// return elements ? jQuery.makeArray( elements ) : this;
+// })
+// .filter(function(){
+// var type = this.type;
+// // Use .is(":disabled") so that fieldset[disabled] works
+// return this.name && !jQuery( this ).is( ":disabled" ) &&
+// rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
+// ( this.checked || !manipulation_rcheckableType.test( type ) );
+// })
+// .map(function( i, elem ){
+// var val = jQuery( this ).val();
+
+// return val == null ?
+// null :
+// jQuery.isArray( val ) ?
+// jQuery.map( val, function( val ){
+// return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
+// }) :
+// { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
+// }).get();
+// }
+// });
+
+//Serialize an array of form elements or a set of
+//key/values into a query string
+jQuery.param = function( a, traditional ) {
+ var prefix,
+ s = [],
+ add = function( key, value ) {
+ // If value is a function, invoke it and return its value
+ value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
+ s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
+ };
+
+ // Set traditional to true for jQuery <= 1.3.2 behavior.
+ if ( traditional === undefined ) {
+ traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
+ }
+
+ // If an array was passed in, assume that it is an array of form elements.
+ if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
+ // Serialize the form elements
+ jQuery.each( a, function() {
+ add( this.name, this.value );
+ });
+
+ } else {
+ // If traditional, encode the "old" way (the way 1.3.2 or older
+ // did it), otherwise encode params recursively.
+ for ( prefix in a ) {
+ buildParams( prefix, a[ prefix ], traditional, add );
+ }
+ }
+
+ // Return the resulting serialization
+ return s.join( "&" ).replace( r20, "+" );
+};
+
+function buildParams( prefix, obj, traditional, add ) {
+ var name;
+
+ if ( jQuery.isArray( obj ) ) {
+ // Serialize array item.
+ jQuery.each( obj, function( i, v ) {
+ if ( traditional || rbracket.test( prefix ) ) {
+ // Treat each array item as a scalar.
+ add( prefix, v );
+
+ } else {
+ // Item is non-scalar (array or object), encode its numeric index.
+ buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
+ }
+ });
+
+ } else if ( !traditional && jQuery.type( obj ) === "object" ) {
+ // Serialize object item.
+ for ( name in obj ) {
+ buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
+ }
+
+ } else {
+ // Serialize scalar item.
+ add( prefix, obj );
+ }
+}
+
+}).call(this);

0 comments on commit 4799406

Please sign in to comment.