Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Making can.param handle nested objects in Dojo; removing reference to…

… $ in view
  • Loading branch information...
commit 77dfa012b2f6baa7dfb0fe84f2d62aeb5b04fc90 1 parent d81e9dc
ccummings authored
Showing with 29 additions and 4 deletions.
  1. +28 −3 util/dojo/dojo.js
  2. +1 −1  view/view.js
View
31 util/dojo/dojo.js
@@ -40,9 +40,6 @@ steal({
}
return dojo.mixin.apply(dojo, arguments)
}
- can.param = function(object){
- return dojo.objectToQuery(object)
- }
can.isEmptyObject = function(object){
var prop;
for(prop in object){
@@ -50,6 +47,34 @@ steal({
}
return prop === undefined;;
}
+
+ // Use a version of param similar to jQuery's param that
+ // handles nested data instead of dojo.objectToQuery which doesn't
+ can.param = function(object){
+ var pairs = [],
+ add = function( key, value ){
+ pairs.push(encodeURIComponent(key) + "=" + encodeURIComponent(value))
+ };
+
+ for(var name in object){
+ can.buildParam(name, object[name], add);
+ }
+ return pairs.join("&").replace(/%20/g, "+");
+ }
+ can.buildParam = function(prefix, obj, add){
+ if(can.isArray(obj)){
+ for(var i = 0, l = obj.length; i < l; ++i){
+ add(prefix + "[]", obj[i])
+ }
+ } else if( dojo.isObject(obj) ){
+ for (var name in obj){
+ can.buildParam(prefix + "[" + name + "]", obj[name], add);
+ }
+ } else {
+ add(prefix, obj);
+ }
+ }
+
// Map function helpers.
can.proxy = function(func, context){
return dojo.hitch(context, func)
View
2  view/view.js
@@ -448,7 +448,7 @@ steal("can/util")
}
//!steal-pluginify-remove-start
- $.extend(can.view, {
+ can.extend(can.view, {
register: function( info ) {
this.types["." + info.suffix] = info;
Please sign in to comment.
Something went wrong with that request. Please try again.