Skip to content

Commit

Permalink
Making can.param handle nested objects in Dojo; removing reference to…
Browse files Browse the repository at this point in the history
… $ in view
  • Loading branch information
ccummings committed Apr 18, 2012
1 parent d81e9dc commit 77dfa01
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
31 changes: 28 additions & 3 deletions util/dojo/dojo.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,41 @@ 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){
break;
}
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)
Expand Down
2 changes: 1 addition & 1 deletion view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 77dfa01

Please sign in to comment.