From 5a8cade5b6a99fcb3f50fc966886580adf564a62 Mon Sep 17 00:00:00 2001 From: ntziolis <nikolas@tziolis.de> Date: Tue, 4 Jan 2011 22:28:18 +0100 Subject: [PATCH 1/2] Added support for additional element types (one way support, for non input fields) Retrieving the field to update based on the nodeName (tag name) --- jquery.datalink.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/jquery.datalink.js b/jquery.datalink.js index 7a1c586..0bc5b29 100644 --- a/jquery.datalink.js +++ b/jquery.datalink.js @@ -15,9 +15,47 @@ var oldcleandata = $.cleanData, html: "html", text: "text" }; + +function getField(target) { + switch (target.nodeName.toLowerCase()) { + case "input": + case "select": + case "textarea": + return fnSetters.val; + + case "h1": + case "h2": + case "h3": + case "h4": + case "h5": + case "h6": + case "h7": + case "li": + case "p": + case "span": + return fnSetters.text; + + // links actually have multiple value fields + // like text and the link location + // it might be a good idea to be able to bind to specific propertys + // rather than just one binding per element + // also for getting/setting the href the jquery 'attr' method would have to be used, + // which would require additionl changes + case "a": + return fnSetters.text; + + default: + return fnSetters.html; + } +} function setValue(target, field, value) { if ( target.nodeType ) { + // if this point was reached the supplied field would always be 'val' + // which only works with input elements + // therefore we have to figure out which setter method to use + field = getField(target); + var setter = fnSetters[ field ] || "attr"; $(target)[setter](value); } else { From 4e47432092459fc0656f42aee752fa714f751654 Mon Sep 17 00:00:00 2001 From: ntziolis <nikolas@tziolis.de> Date: Tue, 4 Jan 2011 22:36:50 +0100 Subject: [PATCH 2/2] added support for additional tags --- jquery.datalink.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jquery.datalink.js b/jquery.datalink.js index 0bc5b29..25eecf4 100644 --- a/jquery.datalink.js +++ b/jquery.datalink.js @@ -32,7 +32,11 @@ function getField(target) { case "h7": case "li": case "p": + case "blockquote": + case "address": case "span": + case "div": + case "pre": return fnSetters.text; // links actually have multiple value fields