Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# jQuery Data Link plugin plugin v1.0.0pre.
# jQuery Data Link plugin v1.0.0pre.

_Note: This plugin is currently in beta form and may change significantly before version 1.0 is released. See tagged versions for stable Beta releases. Requires jquery version 1.4.2._

Expand Down
21 changes: 16 additions & 5 deletions jquery.datalink.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,18 @@ $.extend({

$this.triggerHandler( eventNameSetField + parts[1] + "!", args );
if ( value !== undefined ) {
target[ field ] = value;
var props = field.split(/[\[]/g),
target_path = target,
last_prop = props.pop().replace(']', ''),
current_prop;

for (var i = 0, props_len = props.length; i < props_len; i++) {
current_prop = props[i].replace(']', '');
if (!target_path[current_prop]) target_path[current_prop] = {};
target_path = target_path[current_prop];
}
target_path[last_prop] = value;
// target[ field ] = value;
}
$this.triggerHandler( eventNameChangeField + parts[1] + "!", args );
}
Expand All @@ -100,7 +111,7 @@ function getMapping(ev, changed, newvalue, map) {
} else {
name = (target.name || target.id);
}

if ( !map ) {
mappedName = name;
} else {
Expand Down Expand Up @@ -128,7 +139,7 @@ $.extend($.fn, {
return self;
}
function matchByName(name) {
var selector = "[name=" + name + "], [id=" + name +"]";
var selector = "[name='" + name + "'], [id='" + name +"']";
// include elements in this set that match as well a child matches
return self.filter(selector).add(self.find(selector));
}
Expand Down Expand Up @@ -173,7 +184,7 @@ $.extend($.fn, {
}
});
}

};
if ( mapping ) {
$.each(mapping, function(n, v) {
Expand Down Expand Up @@ -226,7 +237,7 @@ $.extend($.fn, {
this.each(function() {
var self = $(this),
links = getLinks( this ).s;
for (var i = links.length-1; i >= 0; i--) {
for (var i = links.length-1; i >= 0; i--) {
var link = links[ i ];
if ( link.target === target ) {
// unbind the handlers
Expand Down