From aaffeb998351334a423f833b46066bc8f3a82357 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sun, 12 Dec 2010 18:37:57 +0000 Subject: Refactor some of the Javascript scripts to use a different namespace per script. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1044875 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/js/htdocs/atomutil.js | 91 ++++---- sca-cpp/trunk/modules/js/htdocs/component.js | 81 ++++--- sca-cpp/trunk/modules/js/htdocs/elemutil.js | 20 +- sca-cpp/trunk/modules/js/htdocs/graph.js | 242 ++++++++++----------- sca-cpp/trunk/modules/js/htdocs/scdl.js | 65 +++--- sca-cpp/trunk/modules/js/htdocs/ui.js | 63 +++--- sca-cpp/trunk/modules/oauth/htdocs/index.html | 4 +- sca-cpp/trunk/modules/openid/htdocs/index.html | 4 +- .../store-cluster/htdocs/domains/jane/index.html | 8 +- .../store-cluster/htdocs/domains/joe/index.html | 8 +- sca-cpp/trunk/samples/store-cpp/htdocs/index.html | 8 +- sca-cpp/trunk/samples/store-gae/htdocs/index.html | 8 +- sca-cpp/trunk/samples/store-java/htdocs/index.html | 8 +- .../trunk/samples/store-nosql/htdocs/index.html | 8 +- .../trunk/samples/store-python/htdocs/index.html | 8 +- .../trunk/samples/store-scheme/htdocs/index.html | 8 +- sca-cpp/trunk/samples/store-sql/htdocs/index.html | 8 +- .../store-vhost/htdocs/domains/jane/index.html | 8 +- .../store-vhost/htdocs/domains/joe/index.html | 8 +- 19 files changed, 331 insertions(+), 327 deletions(-) diff --git a/sca-cpp/trunk/modules/js/htdocs/atomutil.js b/sca-cpp/trunk/modules/js/htdocs/atomutil.js index 1c9137b668..3499948083 100644 --- a/sca-cpp/trunk/modules/js/htdocs/atomutil.js +++ b/sca-cpp/trunk/modules/js/htdocs/atomutil.js @@ -20,61 +20,62 @@ /** * ATOM data conversion functions. */ +var atom = new Object(); /** * Convert a list of elements to a list of values representing an ATOM entry. */ -function entryElementsToValues(e) { +atom.entryElementsToValues = function(e) { var lt = filter(selector(mklist(element, "'title")), e); var t = isNil(lt)? '' : elementValue(car(lt)); var li = filter(selector(mklist(element, "'id")), e); var i = isNil(li)? '' : elementValue(car(li)); var lc = filter(selector(mklist(element, "'content")), e); return mklist(t, i, elementValue(car(lc))); -} +}; /** * Convert a list of elements to a list of values representing ATOM entries. */ -function entriesElementsToValues(e) { +atom.entriesElementsToValues = function(e) { if (isNil(e)) return e; - return cons(entryElementsToValues(car(e)), entriesElementsToValues(cdr(e))); -} + return cons(atom.entryElementsToValues(car(e)), atom.entriesElementsToValues(cdr(e))); +}; /** * Convert a list of strings to a list of values representing an ATOM entry. */ -function readATOMEntry(l) { +atom.readATOMEntry = function(l) { var e = readXML(l); if (isNil(e)) return mklist(); - return entryElementsToValues(car(e)); -} + return atom.entryElementsToValues(car(e)); +}; /** * Convert a list of values representy an ATOM entry to a value. */ -function entryValue(e) { +atom.entryValue = function(e) { var v = elementsToValues(mklist(caddr(e))); return cons(car(e), (cadr(e), cdr(car(v)))); -} +}; /** * Return true if a list of strings represents an ATOM feed. */ -function isATOMFeed(l) { +atom.isATOMFeed = function(l) { if (isNil(l)) return false; if (car(l).substring(0, 5) != "'); } @@ -278,16 +271,16 @@ if (supportsVML()) { /** * SVG rendering. */ -if (supportsSVG()) { +if (graph.supportsSVG()) { - var svgns='http://www.w3.org/2000/svg'; + graph.svgns='http://www.w3.org/2000/svg'; /** * Make a shape path. */ - var mkpath = function() { + graph.mkpath = function() { function Path() { - this.BasePath = BasePath; + this.BasePath = graph.BasePath; this.BasePath(); this.move = function(x, y) { @@ -312,69 +305,64 @@ if (supportsSVG()) { } return new Path(); - } + }; /** * Make a title element. */ - var mktitle = function(t) { - var title = document.createElementNS(svgns, 'text'); + graph.mktitle = function(t) { + var title = document.createElementNS(graph.svgns, 'text'); title.setAttribute('text-anchor', 'start'); title.setAttribute('x', 40); title.setAttribute('y', 50); title.appendChild(document.createTextNode(t)); - graph.appendChild(title); + graph.g.appendChild(title); return title; - } + }; /** * Make a component shape. */ - mkcompshape = function(name, color, tsvcs, lsvcs, brefs, rrefs) { - var title = mktitle(name); + graph.mkcompshape = function(name, color, tsvcs, lsvcs, brefs, rrefs) { + var title = graph.mktitle(name); var twidth = title.getBBox().width; - var d = mkcomppath(twidth, tsvcs, lsvcs, brefs, rrefs).str(); + var d = graph.mkcomppath(twidth, tsvcs, lsvcs, brefs, rrefs).str(); - var shape = document.createElementNS(svgns, 'path'); + var shape = document.createElementNS(graph.svgns, 'path'); shape.setAttribute('d', d); shape.setAttribute('fill', color); - var contour = document.createElementNS(svgns, 'path'); + var contour = document.createElementNS(graph.svgns, 'path'); contour.setAttribute('d', d); contour.setAttribute('fill', 'none'); - contour.setAttribute('stroke', gray); + contour.setAttribute('stroke', graph.gray); contour.setAttribute('stroke-width', '4'); contour.setAttribute('stroke-opacity', '0.20'); contour.setAttribute('transform', 'translate(1,1)'); - var g = document.createElementNS(svgns, 'g'); + var g = document.createElementNS(graph.svgns, 'g'); g.appendChild(shape); g.appendChild(contour); g.appendChild(title); return g; - } - - /** - * Drag and drop support. - */ - var dragX; - var dragY; - var dragging = null; + }; /** * Make a graph. */ - mkgraph = function() { + graph.mkgraph = function() { var div = document.createElement('div'); div.id = 'svgdiv'; document.body.appendChild(div); - var svg = document.createElementNS(svgns, 'svg'); + var svg = document.createElementNS(graph.svgns, 'svg'); svg.style.height = '100%'; svg.style.width = '100%'; div.appendChild(svg); + graph.dragging = null; + function draggable(n) { if (n == svg) return null; @@ -388,102 +376,102 @@ if (supportsSVG()) { e.preventDefault(); else e.returnValue= false; - dragging = draggable(e.target); - if (dragging == null) + graph.dragging = draggable(e.target); + if (graph.dragging == null) return false; - dragging.parentNode.appendChild(dragging); + graph.dragging.parentNode.appendChild(graph.dragging); var pos = typeof e.touches != "undefined" ? e.touches[0] : e; - dragX = pos.clientX; - dragY = pos.clientY; + graph.dragX = pos.clientX; + graph.dragY = pos.clientY; return false; }; svg.ontouchstart = svg.onmousedown; svg.onmouseup = function(e) { - if (dragging == null) + if (graph.dragging == null) return false; - dragging = null; + graph.dragging = null; return false; }; svg.ontouchend = svg.onmouseup; svg.onmousemove = function(e) { - if (dragging == null) + if (graph.dragging == null) return false; - var matrix = dragging.getCTM(); + var matrix = graph.dragging.getCTM(); var pos = typeof e.touches != "undefined" ? e.touches[0] : e; - var newX = Number(matrix.e) + (pos.clientX - dragX); - var newY = Number(matrix.f) + (pos.clientY - dragY); - dragX = pos.clientX; - dragY = pos.clientY; - dragging.setAttribute('transform', 'translate(' + newX + ',' + newY + ')'); + var newX = Number(matrix.e) + (pos.clientX - graph.dragX); + var newY = Number(matrix.f) + (pos.clientY - graph.dragY); + graph.dragX = pos.clientX; + graph.dragY = pos.clientY; + graph.dragging.setAttribute('transform', 'translate(' + newX + ',' + newY + ')'); return false; }; svg.ontouchmove = svg.onmousemove; - graph = svg; + graph.g = svg; return svg; - } + }; } /** * Make a reference shape path, positioned to the right of a component shape. */ -function mkrrefpath(path) { +graph.mkrrefpath = function(path) { return path.rline(0,10).rcurve(0,5,-5,0).rcurve(-5,0,0,-5).rcurve(0,-5,-5,0).rcurve(-5,0,0,5).rline(0,20).rcurve(0,5,5,0).rcurve(5,0,0,-5).rcurve(0,-5,5,0).rcurve(5,0,0,5).rline(0,10); -} +}; /** * Make a reference shape path, positioned at the bottom of a component shape. */ -function mkbrefpath(path) { +graph.mkbrefpath = function(path) { return path.rline(-10,0).rcurve(-5,0,0,-5).rcurve(0,-5,5,0).rcurve(5,0,0,-5).rcurve(0,-5,-5,0).rline(-20,0).rcurve(-5,0,0,5).rcurve(0,5,5,0).rcurve(5,0,0,5).rcurve(0,5,-5,0).rline(-10,0); -} +}; /** * Make a service shape path, positioned to the left of a component shape. */ -function mklsvcpath(path) { +graph.mklsvcpath = function(path) { return path.rline(0,-10).rcurve(0,-5,-5,0).rcurve(-5,0,0,5).rcurve(0,5,-5,0).rcurve(-5,0,0,-5).rline(0,-20).rcurve(0,-5,5,0).rcurve(5,0,0,5).rcurve(0,5,5,0).rcurve(5,0,0,-5).rline(0,-10); -} +}; /** * Make a service shape path, positioned at the top of a component shape. */ -function mktsvcpath(path) { +graph.mktsvcpath = function(path) { return path.rline(10,0).rcurve(5,0,0,-5).rcurve(0,-5,-5,0).rcurve(-5,0,0,-5).rcurve(0,-5,5,0).rline(20,0).rcurve(5,0,0,5).rcurve(0,5,-5,0).rcurve(-5,0,0,5).rcurve(0,5,5,0).rline(10,0); -} +}; /** * Make a component shape path. */ -function mkcomppath(twidth, tsvcs, lsvcs, brefs, rrefs) { +graph.mkcomppath = function(twidth, tsvcs, lsvcs, brefs, rrefs) { var height = Math.max(lsvcs, rrefs) * 40 + 60; var width = Math.max(Math.max(tsvcs, brefs) * 40 + 60, twidth + 20); - var path = mkpath().rmove(40,30).rline(20,0); + var path = graph.mkpath().rmove(40,30).rline(20,0); for (var s = 0; s < tsvcs; s++) - path = mktsvcpath(path); + path = graph.mktsvcpath(path); path = path.line(20 + width,path.ypos()).rcurve(10,0,0,10).rline(0,20); for (var r = 0; r < rrefs; r++) - path = mkrrefpath(path); + path = graph.mkrrefpath(path); var boffset = 10 + 30 + (brefs * 40); - path = path.line(path.xpos(),20 + height).rcurve(0,10,-10,0).line(20 + boffset,path.ypos()); + path = path.line(path.xpos(),20 + height).rcurve(0,10,-10,0).line(20 + boffset, path.ypos()); for (var r = 0; r < brefs; r++) - path = mkbrefpath(path); + path = graph.mkbrefpath(path); var loffset = 10 + 30 + (lsvcs * 40); path = path.line(40,path.ypos()).rcurve(-10,0,0,-10).line(path.xpos(), 20 + loffset); for (var s = 0; s < lsvcs; s++) - path = mklsvcpath(path); + path = graph.mklsvcpath(path); path = path.line(30,40).rcurve(0,-10,10,0); return path.end(); -} +}; diff --git a/sca-cpp/trunk/modules/js/htdocs/scdl.js b/sca-cpp/trunk/modules/js/htdocs/scdl.js index 5f3934b060..afdb74ac3b 100644 --- a/sca-cpp/trunk/modules/js/htdocs/scdl.js +++ b/sca-cpp/trunk/modules/js/htdocs/scdl.js @@ -20,28 +20,36 @@ /** * SCDL parsing functions. */ +var scdl = new Object(); /** * Returns a list of components in a composite. */ -function components(l) { +scdl.components = function(l) { var cs = namedElementChildren("'composite", l); if (isNil(cs)) return cs; return namedElementChildren("'component", car(cs)); -} +}; /** * Returns the name of a component, service or reference. */ -function name(l) { +scdl.name = function(l) { return namedAttributeValue("'name", l); -} +}; + +/** + * Returns the color of a component. + */ +scdl.color = function(l) { + return namedAttributeValue("'color", l); +}; /** * Returns the implementation of a component. */ -function implementation(l) { +scdl.implementation = function(l) { function filterImplementation(v) { return isElement(v) && cadr(v).match("implementation.") != null; } @@ -50,58 +58,65 @@ function implementation(l) { if (isNil(n)) return null; return car(n); -} +}; /** * Returns the type of an implementation. */ -function implementationType(l) { +scdl.implementationType = function(l) { return elementName(l).substring(1); -} +}; /** * Returns the URI of a service, reference or implementation. */ -function uri(l) { +scdl.uri = function(l) { return namedAttributeValue("'uri", l); -} +}; + +/** + * Returns the align attribute of a service or reference. + */ +scdl.align = function(l) { + return namedAttributeValue("'align", l); +}; /** * Returns a list of services in a component. */ -function services(l) { +scdl.services = function(l) { return namedElementChildren("'service", l); -} +}; /** * Returns a list of references in a component. */ -function references(l) { +scdl.references = function(l) { return namedElementChildren("'reference", l); -} +}; /** * Returns a list of bindings in a service or reference. */ -function bindings(l) { +scdl.bindings = function(l) { function filterBinding(v) { return isElement(v) && cadr(v).match("binding.") != null; } return filter(filterBinding, l); -} +}; /** * Returns the type of a binding. */ -function bindingType(l) { +scdl.bindingType = function(l) { return elementName(l).substring(1); -} +}; /** * Returns the target of a reference. */ -function target(l) { +scdl.target = function(l) { function bindingsTarget(l) { if (isNil(l)) return null; @@ -114,20 +129,20 @@ function target(l) { var t = namedAttributeValue("'target", l); if (!isNil(t)) return t; - return bindingsTarget(bindings(l)); -} + return bindingsTarget(scdl.bindings(l)); +}; /** * Returns a list of properties in a component. */ -function properties(l) { +scdl.properties = function(l) { return namedElementChildren("'property", l); -} +}; /** * Returns the value of a property. */ -function propertyValue(l) { +scdl.propertyValue = function(l) { return elementValue(l); -} +}; diff --git a/sca-cpp/trunk/modules/js/htdocs/ui.js b/sca-cpp/trunk/modules/js/htdocs/ui.js index 72c6c6b870..fcd61571d1 100644 --- a/sca-cpp/trunk/modules/js/htdocs/ui.js +++ b/sca-cpp/trunk/modules/js/htdocs/ui.js @@ -21,10 +21,12 @@ * UI utility functions. */ +var ui = new Object(); + /** * Build a menu bar. */ -function menu(name, href) { +ui.menu = function(name, href) { function Menu(n, h) { this.name = n; this.href = h; @@ -44,9 +46,9 @@ function menu(name, href) { }; } return new Menu(name, href); -} +}; -function menubar(left, right) { +ui.menubar = function(left, right) { var bar = '' + '
'; for (i in left) @@ -59,8 +61,7 @@ function menubar(left, right) { bar = bar + '
'; return bar; -} - +}; /** * Autocomplete / suggest support for input fields @@ -71,22 +72,22 @@ function menubar(left, right) { * then hook it to an input field as follows: * suggest(document.yourForm.yourInputField, suggestItems); */ -function selectSuggestion(node, value) { +ui.selectSuggestion = function(node, value) { for (;;) { node = node.parentNode; if (node.tagName.toLowerCase() == 'div') break; } node.selectSuggestion(value); -} +}; -function hilightSuggestion(node, over) { +ui.hilightSuggestion = function(node, over) { if (over) node.className = 'suggestHilighted'; node.className = 'suggestItem'; -} +}; -function suggest(input, suggestFunction) { +ui.suggest = function(input, suggestFunction) { input.suggest = suggestFunction; input.selectSuggestion = function(value) { @@ -122,8 +123,8 @@ function suggest(input, suggestFunction) { if (items.length == 0) items += ''; items += ''; + 'onmouseover="ui.hilightSuggestion(this, true)" onmouseout="ui.hilightSuggestion(this, false)" ' + + 'onmousedown="ui.selectSuggestion(this, \'' + values[i] + '\')">' + values[i] + ''; } if (items.length != 0) items += '
' + values[i] + '
'; @@ -162,33 +163,33 @@ function suggest(input, suggestFunction) { input.onblur = function(event) { setTimeout(function() { input.hideSuggestDiv(); }, 50); }; -} +}; /** * Return the content document of a window. */ -function content(win) { +ui.content = function(win) { if (!isNil(win.document)) return win.document; if (!isNil(win.contentDocument)) return win.contentDocument; return null; -} +}; /** * Return a child element of a node with the given id. */ -function elementByID(node, id) { +ui.elementByID = function(node, id) { for (var i in node.childNodes) { var child = node.childNodes[i]; if (child.id == id) return child; - var gchild = elementByID(child, id); + var gchild = ui.elementByID(child, id); if (gchild != null) return gchild; } return null; -} +}; /** * Return the current document, or a child element with the given id. @@ -199,34 +200,34 @@ function $(id) { return widget; return document; } - return elementByID($(document), id); -} + return ui.elementByID($(document), id); +}; /** * Initialize a widget. */ -function onloadwidget() { - if (isNil(window.parent) || isNil(window.parent.widgets)) +ui.onloadwidget = function() { + if (isNil(window.parent) || isNil(window.parent.ui) || isNil(window.parent.ui.widgets)) return true; - var pdoc = content(window.parent); - for (w in window.parent.widgets) { - var ww = elementByID(pdoc, w).contentWindow; + var pdoc = ui.content(window.parent); + for (w in window.parent.ui.widgets) { + var ww = ui.elementByID(pdoc, w).contentWindow; if (ww == window) { - document.widget = elementByID(pdoc, window.parent.widgets[w]); + document.widget = ui.elementByID(pdoc, window.parent.ui.widgets[w]); document.widget.innerHTML = document.body.innerHTML; return true; } } return true; -} +}; /** * Load a widget into an element. */ -var widgets = new Array(); +ui.widgets = new Array(); -function bindwidget(f, el) { - window.widgets[f] = el; +ui.bindwidget = function(f, el) { + window.ui.widgets[f] = el; return f; -} +}; diff --git a/sca-cpp/trunk/modules/oauth/htdocs/index.html b/sca-cpp/trunk/modules/oauth/htdocs/index.html index 9a9d833898..7d26567214 100644 --- a/sca-cpp/trunk/modules/oauth/htdocs/index.html +++ b/sca-cpp/trunk/modules/oauth/htdocs/index.html @@ -21,8 +21,8 @@