Merged from BRANCHES/DEV/KEVINR:

. NodeInfo panel and Ajax client library
 - Rewrite of Node Info panel
 - Alfresco common DOM methods refactored into namespaced object (YUI/Dojo style) Alfresco.Dom
 - Addition of useful DOM and 'smart' alignment method to common.js
 - OpenSearch now uses additional namespace for it's global method handlers: Alfresco.OpenSearchEngine
 - Temporary icons added for pop-up node info panel
. Additional FreeMarker model API method "cropContent(contentprop, length)" to return the first N bytes of a content stream - auto converted to plain/text from all supported transformation mimetypes
. DownloadContentServlet now handles ContentIOException more gracefully
. AbstractContentReader fixed to handle empty file data when requesting N characters from a content stream

. Yahoo scripts move to PageTag rendering as appropriate
. Refactoring of existing ajax components that output Yahoo scripts

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5253 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2007-03-01 17:24:08 +00:00
parent 2c1fe352a3
commit a4aa830af2
13 changed files with 509 additions and 413 deletions

View File

@@ -51,10 +51,10 @@ function handleErrorDojo(type, errObj)
/**
* Default handler for errors when using the yahoo toolkit
*/
function handleErrorYahoo(msg)
function handleErrorYahoo(e)
{
// TODO: Show a nicer error page, an alert will do for now!
alert(msg);
alert(e.status + " : " + e.statusText);
}
/**
@@ -89,117 +89,173 @@ function getContextPath()
}
/**
* Returns a single child element with the given tag
* name from the given parent. If more than one tag
* exists the first one is returned, if none exist null
* is returned.
* Alfresco Utility libraries
*/
function getElementByTagName(elParent, tagName)
(function()
{
var el = null;
if (elParent != null && tagName != null)
{
var elems = elParent.getElementsByTagName(tagName);
if (elems != null && elems.length > 0)
{
el = elems[0];
}
}
return el;
}
/**
* Returns a single child element with the given tag
* name and namespace from the given parent.
* If more than one tag exists the first one is returned,
* if none exist null is returned.
*/
function getElementByTagNameNS(elParent, nsUri, nsPrefix, tagName)
{
var el = null;
if (elParent != null && tagName != null)
{
var elems = null;
/**
* DOM library
*/
Alfresco.Dom = {
if (elParent.getElementsByTagNameNS)
/**
* Returns a single child element with the given tag
* name from the given parent. If more than one tag
* exists the first one is returned, if none exist null
* is returned.
*/
getElementByTagName: function(elParent, tagName)
{
elems = elParent.getElementsByTagNameNS(nsUri, tagName);
}
else
{
elems = elParent.getElementsByTagName(nsPrefix + ":" + tagName);
}
var el = null;
if (elParent != null && tagName != null)
{
var elems = elParent.getElementsByTagName(tagName);
if (elems != null && elems.length > 0)
{
el = elems[0];
}
}
return el;
},
if (elems != null && elems.length > 0)
/**
* Returns a single child element with the given tag
* name and namespace from the given parent.
* If more than one tag exists the first one is returned,
* if none exist null is returned.
*/
getElementByTagNameNS: function(elParent, nsUri, nsPrefix, tagName)
{
el = elems[0];
var el = null;
if (elParent != null && tagName != null)
{
var elems = null;
if (elParent.getElementsByTagNameNS)
{
elems = elParent.getElementsByTagNameNS(nsUri, tagName);
}
else
{
elems = elParent.getElementsByTagName(nsPrefix + ":" + tagName);
}
if (elems != null && elems.length > 0)
{
el = elems[0];
}
}
return el;
},
/**
* Returns the text of the given DOM element object
*/
getElementText: function(el)
{
var txt = null;
if (el.text != undefined)
{
// get text using IE specific property
txt = el.text;
}
else
{
// use the W3C textContent property
txt = el.textContent;
}
return txt;
},
/**
* Returns the text content of a single child element
* with the given tag name from the given parent.
* If more than one tag exists the text of the first one
* is returned, if none exist null is returned.
*/
getElementTextByTagName: function(elParent, tagName)
{
var txt = null;
var el = this.getElementByTagName(elParent, tagName);
if (el != null)
{
txt = this.getElementText(el);
}
return txt;
},
/**
* Returns the text a single child element with the given tag
* name and namespace from the given parent.
* If more than one tag exists the text of the first one is returned,
* if none exist null is returned.
*/
getElementTextByTagNameNS: function(elParent, nsUri, nsPrefix, tagName)
{
var txt = null;
var el = this.getElementByTagNameNS(elParent, nsUri, nsPrefix, tagName);
if (el != null)
{
txt = this.getElementText(el);
}
return txt;
},
/**
* Aligns an element against the specified element. Automatically adjusts the element above or to
* the left of the destination if the element would cause a scrollbar to appear.
*
* @param el Element to align
* @param destEl Destination element to align against
* @param maxwidth Maximum width of the element (assumed max-width CSS applied)
*/
smartAlignElement: function (el, destEl, maxwidth)
{
// get the position of the element we are aligning against
var pos = YAHOO.util.Dom.getXY(destEl);
// calculate display position for the element
var region = YAHOO.util.Dom.getRegion(el);
//log("DIV popup size: Width:" + (region.right-region.left) + ", Height:" + (region.bottom-region.top));
var elHeight = region.bottom - region.top;
var elWidth = region.right - region.left;
//log("elWidth:" + elWidth + " maxwidth:" + maxwidth);
if (maxwidth != undefined && maxwidth != null)
{
if (elWidth > maxwidth) elWidth = maxwidth;
}
var docWidth = YAHOO.util.Dom.getDocumentWidth();
if (pos[0] + elWidth < docWidth)
{
el.style.left = pos[0];
}
else
{
el.style.left = pos[0] - ((pos[0] + elWidth) - docWidth);
}
//log(" Element Y:" + pos[1] + " doc height:" + YAHOO.util.Dom.getDocumentHeight());
if (pos[1] + 16 + elHeight < YAHOO.util.Dom.getDocumentHeight())
{
el.style.top = pos[1] + 12;
}
else
{
//log(" ***Changing position - will overflow");
el.style.top = pos[1] - elHeight - 4;
}
}
}
return el;
}
/**
* Returns the text of the given DOM element object
*/
function getElementText(el)
{
var txt = null;
if (el.text != undefined)
{
// get text using IE specific property
txt = el.text;
}
else
{
// use the W3C textContent property
txt = el.textContent;
}
return txt;
}
/**
* Returns the text content of a single child element
* with the given tag name from the given parent.
* If more than one tag exists the text of the first one
* is returned, if none exist null is returned.
*/
function getElementTextByTagName(elParent, tagName)
{
var txt = null;
var el = getElementByTagName(elParent, tagName);
if (el != null)
{
txt = getElementText(el);
}
return txt;
}
/**
* Returns the text a single child element with the given tag
* name and namespace from the given parent.
* If more than one tag exists the text of the first one is returned,
* if none exist null is returned.
*/
function getElementTextByTagNameNS(elParent, nsUri, nsPrefix, tagName)
{
var txt = null;
var el = getElementByTagNameNS(elParent, nsUri, nsPrefix, tagName);
if (el != null)
{
txt = getElementText(el);
}
return txt;
}
};
})();
/**
* Logs a message to a debug log window.
@@ -210,7 +266,7 @@ function log(message)
{
if (!log.window_ || log.window_.closed)
{
var win = window.open("", null, "width=400,height=200," +
var win = window.open("", null, "width=600,height=400," +
"scrollbars=yes,resizable=yes,status=no," +
"location=no,menubar=no,toolbar=no");
if (!win) return;
@@ -224,9 +280,4 @@ function log(message)
var logLine = log.window_.document.createElement("div");
logLine.appendChild(log.window_.document.createTextNode(message));
log.window_.document.body.appendChild(logLine);
}
}