summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/js/htdocs/elemutil.js
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2011-01-30 22:30:10 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2011-01-30 22:30:10 +0000
commit6afef449a6560d469102ab0298d4cc925d76aa0f (patch)
tree7217fb00927065b2b1b80978cefb6a0488deddfd /sca-cpp/trunk/modules/js/htdocs/elemutil.js
parentdca2f20846323ff20758e76c9c90dae4f1dc325b (diff)
Add composite save function, improve UI a bit and some script cleanup and documentation.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1065409 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules/js/htdocs/elemutil.js')
-rw-r--r--sca-cpp/trunk/modules/js/htdocs/elemutil.js54
1 files changed, 51 insertions, 3 deletions
diff --git a/sca-cpp/trunk/modules/js/htdocs/elemutil.js b/sca-cpp/trunk/modules/js/htdocs/elemutil.js
index be976c3982..f6f8dcd186 100644
--- a/sca-cpp/trunk/modules/js/htdocs/elemutil.js
+++ b/sca-cpp/trunk/modules/js/htdocs/elemutil.js
@@ -203,18 +203,28 @@ function selector(s) {
}
/**
- * Return the value of the attribute with the given name.
+ * Return the attribute with the given name.
*/
-function namedAttributeValue(name, l) {
+function namedAttribute(name, l) {
return memo(l, name, function() {
var f = filter(function(v) { return isAttribute(v) && attributeName(v) == name; }, l);
if (isNil(f))
return null;
- return caddr(car(f));
+ return car(f);
});
}
/**
+ * Return the value of the attribute with the given name.
+ */
+function namedAttributeValue(name, l) {
+ var a = namedAttribute(name, l);
+ if (a == null)
+ return null
+ return attributeValue(a);
+}
+
+/**
* Return child elements with the given name.
*/
function namedElementChildren(name, l) {
@@ -233,3 +243,41 @@ function namedElementChild(name, l) {
return car(f);
}
+/**
+ * Side effect functions. Use with moderation.
+ */
+
+/**
+ * Set the value of the attribute with the given name.
+ */
+function setNamedAttributeValue(name, v, l) {
+ var f = filter(function(v) { return isAttribute(v) && attributeName(v) == name; }, l);
+ if (!isNil(f)) {
+
+ // Un-memoize attribute and change its value
+ unmemo(l, name);
+ car(f)[2] = '' + v;
+ return v;
+ }
+
+ // Insert new attribute
+ insertn$(mklist(attribute, name, '' + v), l, 2);
+ return v;
+}
+
+/**
+ * Set the value of an element.
+ */
+function setElementValue(v, l) {
+ if (elementHasValue(l)) {
+
+ // Change existing element value
+ l[length(l) - 1] = v;
+ return v;
+ }
+
+ // Append element value
+ $append(l, mklist(v));
+ return v;
+}
+