Skip to content
This repository was archived by the owner on Jan 16, 2020. It is now read-only.

Commit eadd120

Browse files
author
InfinitiesLoop
committed
Added update option
1 parent c6c8f01 commit eadd120

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

jQuery.datalink.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,22 @@ $.linkLive = function( settings, context ) {
247247
// the contents, not the array itself
248248
source = $.isArray( source ) ? [ source ] : source;
249249
target = $.isArray( target ) ? [ target ] : target;
250-
convert = $.convertFn[ convert ] || convert;
251-
252-
var handler = function(ev) {
253-
var source = ev.target;
250+
251+
var handler = function(ev, forceSource) {
252+
var source = ev ? ev.target : forceSource;
254253
var attr = sourceAttr;
255254
if ( !attr ) {
256255
// val for inputs, text for everything else
257-
var nodeName = source.nodeName;
258-
attr = formElems.test( nodeName ) ? "val" : "text";
256+
if ( source.nodeType ) {
257+
var nodeName = source.nodeName;
258+
attr = formElems.test( nodeName ) ? "val" : "text";
259+
}
259260
}
260261
var _source = $(source),
261-
newValue = ev ? ev.newValue : getValue( _source, attr );
262-
if ( convert ) {
263-
newValue = convert( newValue, settings );
262+
newValue = ev ? ev.newValue : getValue( _source, attr ),
263+
cv = convert ? ($.convertFn[ convert ] || convert) : null;
264+
if ( cv ) {
265+
newValue = cv( newValue, settings );
264266
}
265267
if ( typeof newValue !== "undefined" ) {
266268
setValue( _source, $(target, context), targetAttr, newValue );
@@ -278,6 +280,13 @@ $.linkLive = function( settings, context ) {
278280
context: context,
279281
handler: handler
280282
});
283+
284+
if ( settings.update ) {
285+
$(source).each(function() {
286+
handler(null, this);
287+
});
288+
289+
}
281290
}
282291

283292
$.unlinkLive = function( settings, context ) {

0 commit comments

Comments
 (0)