Anonymous avatar Anonymous committed 9eacd9a

update to latest jquery.datalink.js

Comments (0)

Files changed (1)

js/jquery_datalink/resources/jquery.datalink.js

 /*!
- * jQuery Data Link Plugin
+ * jQuery Data Link plugin 1.0.0pre
  * http://github.com/jquery/jquery-datalink
  *
  * Copyright Software Freedom Conservancy, Inc.
  * Dual licensed under the MIT or GPL Version 2 licenses.
  * http://jquery.org/license
  */
-(function($){
+(function( $, undefined ){
 
 var oldcleandata = $.cleanData,
 	links = [],
 		val: "val",
 		html: "html",
 		text: "text"
-	};
-
-function setValue(target, field, value) {
-	if ( target.nodeType ) {
-		var setter = fnSetters[ field ] || "attr";
-		$(target)[setter](value);
-	} else {
-		$(target).data( field, value );
-	}
-}
+	},
+	eventNameSetField = "setField",
+	eventNameChangeField = "changeField";
 
 function getLinks(obj) {
 	var data = $.data( obj ),
 }
 
 function bind(obj, wrapped, handler) {
-	wrapped.bind( obj.nodeType ? "change" : "changeData", handler );
+	wrapped.bind( obj.nodeType ? "change" : eventNameChangeField, handler );
 }
 function unbind(obj, wrapped, handler) {
-	wrapped.unbind( obj.nodeType ? "change" : "changeData", handler );
+	wrapped.unbind( obj.nodeType ? "change" : eventNameChangeField, handler );
 }
 
 $.extend({
 		"!": function(value) {
 			return !value;
 		}
+	},
+	setField: function(target, field, value) {
+		if ( target.nodeType ) {
+			var setter = fnSetters[ field ] || "attr";
+			$(target)[setter](value);
+		} else {
+			var parts = field.split(".");
+			parts[1] = parts[1] ? "." + parts[1] : "";
+
+				var $this = $( target ),
+					args = [ parts[0], value ];
+
+			$this.triggerHandler( eventNameSetField + parts[1] + "!", args );
+			if ( value !== undefined ) {
+				target[ field ] = value;
+			}
+			$this.triggerHandler( eventNameChangeField + parts[1] + "!", args );
+		}
 	}
 });
 
-function getMapping(ev, changed, newvalue, map, source, target) {
+function getMapping(ev, changed, newvalue, map) {
 	var target = ev.target,
-		isSetData = ev.type === "changeData",
+		isSetData = ev.type === eventNameChangeField,
 		mappedName,
-		convert;
+		convert,
 		name;
 	if ( isSetData ) {
 		name = changed;
 						value = convert( value, ev.target, target );
 					}
 					if ( value !== undefined ) {
-						setValue( target, name, value );
+						$.setField( target, name, value );
 					}
 				}
 			},
 							newvalue = convert( newvalue, target, this );
 						}
 						if ( newvalue !== undefined ) {
-							setValue( this, "val", newvalue );
+							$.setField( this, "val", newvalue );
 						}
 					});
 				}
 				}
 			}
 		});
+	},
+	setField: function(field, value) {
+		return this.each(function() {
+			$.setField( this, field, value );
+		});
 	}
 });
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.