diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-01-30 22:30:10 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-01-30 22:30:10 +0000 |
commit | 6afef449a6560d469102ab0298d4cc925d76aa0f (patch) | |
tree | 7217fb00927065b2b1b80978cefb6a0488deddfd /sca-cpp/trunk/modules/js | |
parent | dca2f20846323ff20758e76c9c90dae4f1dc325b (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')
-rw-r--r-- | sca-cpp/trunk/modules/js/htdocs/atomutil.js | 2 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/js/htdocs/component.js | 4 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/js/htdocs/elemutil.js | 54 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/js/htdocs/scdl.js | 2 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/js/htdocs/ui.css | 8 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/js/htdocs/ui.js | 4 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/js/htdocs/util.js | 118 |
7 files changed, 179 insertions, 13 deletions
diff --git a/sca-cpp/trunk/modules/js/htdocs/atomutil.js b/sca-cpp/trunk/modules/js/htdocs/atomutil.js index 24a47980f7..21aa16e0fc 100644 --- a/sca-cpp/trunk/modules/js/htdocs/atomutil.js +++ b/sca-cpp/trunk/modules/js/htdocs/atomutil.js @@ -20,7 +20,7 @@ /** * ATOM data conversion functions. */ -var atom = new Object(); +var atom = {}; /** * Convert a list of elements to a list of values representing an ATOM entry. diff --git a/sca-cpp/trunk/modules/js/htdocs/component.js b/sca-cpp/trunk/modules/js/htdocs/component.js index 9907e955c9..835cc148c2 100644 --- a/sca-cpp/trunk/modules/js/htdocs/component.js +++ b/sca-cpp/trunk/modules/js/htdocs/component.js @@ -34,7 +34,7 @@ /** * Escape a character. */ -var JSONClient = new Object(); +var JSONClient = {}; JSONClient.escapeJSONChar = function(c) { if(c == "\"" || c == "\\") return "\\" + c; @@ -450,7 +450,7 @@ if (typeof DOMParser == "undefined") { * Public API. */ -var sca = new Object(); +var sca = {}; /** * Return a component. 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; +} + diff --git a/sca-cpp/trunk/modules/js/htdocs/scdl.js b/sca-cpp/trunk/modules/js/htdocs/scdl.js index df661a29ba..73d07b4a1c 100644 --- a/sca-cpp/trunk/modules/js/htdocs/scdl.js +++ b/sca-cpp/trunk/modules/js/htdocs/scdl.js @@ -20,7 +20,7 @@ /** * SCDL parsing functions. */ -var scdl = new Object(); +var scdl = {}; /** * Returns a composite element. diff --git a/sca-cpp/trunk/modules/js/htdocs/ui.css b/sca-cpp/trunk/modules/js/htdocs/ui.css index f3f4507e27..5b441b735d 100644 --- a/sca-cpp/trunk/modules/js/htdocs/ui.css +++ b/sca-cpp/trunk/modules/js/htdocs/ui.css @@ -28,10 +28,10 @@ font-family: arial,sans-serif; font-style: normal; font-variant: normal; font-si } th { -font-weight: bold; background-color: #e5ecf9; color: #598edd; +font-weight: bold; background-color: #96d333; color: #000000; text-align: left; padding-left: 2px; padding-right: 8px; padding-top: 2px; padding-bottom: 4px; vertical-align: text-top; border-top: 1px; border-bottom: 1px; border-left: 0px; border-right: 0px; -border-style: solid; border-top-color: #a2bae7; border-bottom-color: #d1d3d4; +border-style: solid; border-top-color: #96d333; border-bottom-color: #96d333; } td { @@ -52,11 +52,11 @@ vertical-align: middle; } a:link { -color: blue; +color: #96d333; } a:visited { -color: blue; +color: #96d333; } h1 { diff --git a/sca-cpp/trunk/modules/js/htdocs/ui.js b/sca-cpp/trunk/modules/js/htdocs/ui.js index 483aef6f9f..31cdaed7c6 100644 --- a/sca-cpp/trunk/modules/js/htdocs/ui.js +++ b/sca-cpp/trunk/modules/js/htdocs/ui.js @@ -21,7 +21,7 @@ * UI utility functions. */ -var ui = new Object(); +var ui = {}; /** * Return true if the current browser is Internet Explorer. @@ -266,7 +266,7 @@ ui.installwidget = function() { /** * Convert a CSS position to a numeric position. */ -ui.posn = function(p) { +ui.csspos = function(p) { if (p == '') return 0; return Number(p.substr(0, p.length - 2)); diff --git a/sca-cpp/trunk/modules/js/htdocs/util.js b/sca-cpp/trunk/modules/js/htdocs/util.js index 155836b4e9..873874c7be 100644 --- a/sca-cpp/trunk/modules/js/htdocs/util.js +++ b/sca-cpp/trunk/modules/js/htdocs/util.js @@ -218,3 +218,121 @@ function memo(obj, key, f) { return obj[key] = f(); } +/** + * Un-memoize a value. + */ +function unmemo(obj, key) { + obj[key] = null; + return true; +} + +/** + * Functions with side effects. Use with moderation. + */ + +/** + * Set the car of a list. + */ +function setcar(l, v) { + l[0] = v; + return l; +} + +/** + * Set the cadr of a list. + */ +function setcadr(l, v) { + l[1] = v; + return l; +} + +/** + * Set the caddr of a list. + */ +function setcaddr(l, v) { + l[2] = v; + return l; +} + +/** + * Append the elements of a list to a list. + */ +function setappend(a, b) { + if (isNil(b)) + return a; + a.push(car(b)); + return setappend(a, cdr(b)); +} + +/** + * Set the cdr of a list. + */ +function setcdr(a, b) { + a.length = 1; + return setappend(a, b); +} + +/** + * Set the contents of a list. + */ +function setlist(a, b) { + a.length = 0; + return setappend(a, b); +} + +/** + * Insert a value at a given position in a list. + */ +function insertn$(v, n, l) { + function upshift(i) { + if (i == n) + return true; + l[i] = l[i - 1]; + return upshift(i - 1); + } + + upshift(length(l)); + l[n] = v; + return l; +} + +/** + * Insert a value at the beginning of a list. + */ +function insert$(v, l) { + return insertn$(v, 0, l); +} + +/** + * Append a list at the end of a list. + */ +function append$(a, b) { + if (isNil(b)) + return a; + a.push(car(b)); + return append$(a, cdr(b)); +} + +/** + * Delete a value from a list. + */ +function delete$(v, l) { + function dnshift(i, max) { + if (i >= max) + return true; + l[i] = l[i + 1]; + return dnshift(i + 1, max); + } + + dnshift(n, length(l) - 1); + l.pop(); + return l; +} + +/** + * Delete a value at the beginning of a list. + */ +function delete$(l) { + return deleten$(l, 0); +} + |