09-25-2007 03:29 AM
popupCitation("I Sam. 3:1 (to 1st ;)");
popupCitationWithContext("I Sam. 3:1 (to 1st ;)");
<html dir="ltr">
<head>
<title>Sample use of Book JS library</title>
</head>
<body>
<script src="http://MYSITE/bookservice/csbooks-ui.js" type="text/javascript"></script>
<b>mouse over the citations</b><br/><br/>
<b>with context</b><br/>
<a onmouseover='popupCitationWithContext("LUKE3");' >Luke 3:1</a><br/>
<a onmouseover='popupCitationWithContext("I Sam. 3:1 (to 1st ;)");' >1st Sam. Chapter 3, Line 1 to the first ;</a><br/>
<br/><b>without context</b><br/>
<a onmouseover='popupCitation("LUKE3");' >Luke 3:1</a><br/>
<a onmouseover='popupCitation("I Sam. 3:1 (to 1st ;)");' >1st Sam. Chapter 3, Line 1 to the first ;</a><br/>
</body>
</html>
<script src="http://MYSITE/bookservice/csbooks-ui.js" type="text/javascript"></script>
document.write("<script src='"+mBooksServiceUrl+"/csbooks.js' type='text/javascript'></script>");
document.write("<script src='"+mBooksServiceUrl+"/lib/tips/wz_tooltip.js' type='text/javascript'></script>");
document.write("<script src='"+mBooksServiceUrl+"/lib/tips/tip_centerwindow.js' type='text/javascript'></script>");
document.write("<script src='"+mBooksServiceUrl+"/lib/tips/tip_balloon.js' type='text/javascript'></script>");
<script id="JscriptId3" type="text/javascript" charset="utf-8" src="http://MYSITE/bookservice/citation/nocontextl?reference=I Sam. 3:1 (to 1st ;)&output=json&icallback=handleCitationResponse&callback=popupCitationCallback&noCacheIE=1190706528325">
</script>
popupCitationCallback(handleCitationResponse({"ResultSet":{"Result":[{"book":"","reference":"I Sam. 3:1 (to 1st ;)","content":"
And the child Samuel ministered unto the Lord before Eli. And the word of the Lord was precious in those days;
"}]}}));
/**
* retrieve a given citation and pass the name of call back method which will generate
* the actual UI
* @param pReference book reference to retrieve
*/
function popupCitationWithContext(pReference)
{
retrieveCitationWithContext(pReference, "popupCitationWithContextCallback");
}
/**
* retrieve a given citation
* @param pContent
*/
function popupCitationWithContextCallback(pContent)
{
Tip(pContent, BALLOON, true, ABOVE, true, OFFSETX, -10, WIDTH, 360, TEXTALIGN, 'justify', FADEIN, 600, FADEOUT, 600, PADDING, 30);
}
/**
* retrieve a given citation
* @param pReference book reference to retrieve
* @param pCallback method to callback
*/
function retrieveCitationWithContext(pReference, pCallback)
{
fireRetrieveCitation(pReference, pCallback, true, true);
}
/**
* retrieve a given citation
* @param pReference book reference to retrieve
* @param pCallback method to callback
*/
function retrieveCitation(pReference, pCallback)
{
fireRetrieveCitation(pReference, pCallback, false, false);
}
/**
* Make a call to the underlying book service to get the requested reference
* – for the moment this is only available as HTML
* @pReference book reference to retrieve
* @pCallback function to call back with result
* @param pWithContext with context (surrounding text)
* @param pWithMarks with marks [[[ citation ]]]
*/
function fireRetrieveCitation(pReference, pCallback, pWithContext, pWithMarks)
{
var vServiceUrl = "";
var vQueryString = "";
vJsonRequest = null;
/* determine URL for service */
if(pWithContext==true)
{
vServiceUrl = mInContextReferenceServiceUrl;
}
else
{
vServiceUrl = mNoContextReferenceServiceUrl;
}
/* build query string */
vQueryString = 'reference='+pReference+'&output=json&icallback=handleCitationResponse&callback='+pCallback;
/* create/fire "request" */
vJsonRequest = new JSONscriptRequest(vServiceUrl+'?'+vQueryString);
vJsonRequest.buildScriptTag();
vJsonRequest.addScriptTag();
}
/**
* handles the asynchonous call back from the the underlying book service
* @param pRequest access to the request and response text
* @param pCallback function to call back
*/
function handleCitationResponse(pJsonData)
{
var vResponseText = pJsonData.ResultSet.Result[0].content;
/* TODO I don't agree with using a global – pass the id and remove the element based on the ID */
//vJsonRequest.removeScriptTag();
return vResponseText;
}
/**
* JSONscriptRequest – a simple class for making HTTP requests
* using dynamically generated script tags and JSON
* Author: Jason Levitt
* Date: December 7th, 2005
*/
/**
* Constructor – pass a REST request URL to the constructor
*/
function JSONscriptRequest(pFullUrl)
{
this.fullUrl = pFullUrl; // REST request path
this.noCacheIE = '&noCacheIE=' + (new Date()).getTime(); // Keep IE from caching requests
this.headLoc = document.getElementsByTagName("head").item(0); // Get the DOM location to put the script tag
this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++; // Generate a unique script tag id
}
/**
* Static script ID counter
*/
JSONscriptRequest.scriptCounter = 1;
/**
* buildScriptTag method
*/
JSONscriptRequest.prototype.buildScriptTag = function ()
{
/* Create the script tag */
this.scriptObj = document.createElement("script");
/* Add script object attributes */
this.scriptObj.setAttribute("type", "text/javascript");
this.scriptObj.setAttribute("charset", "utf-8");
this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
this.scriptObj.setAttribute("id", this.scriptId);
}
/**
* removeScriptTag method
*/
JSONscriptRequest.prototype.removeScriptTag = function ()
{
/* Destroy the script tag */
this.headLoc.removeChild(this.scriptObj);
}
/**
* addScriptTag method
*/
JSONscriptRequest.prototype.addScriptTag = function ()
{
/* Create the script tag */
this.headLoc.appendChild(this.scriptObj);
}
09-26-2007 08:40 AM
<html>
</body>
<script>
function showTitle(res)
{
alert(res.feed.title);
}
</script>
<script src="http://localhost:8080/alfresco/service/sample/blog/category/web20.json&alf_callback=showTitle'/>
</body>
</html>
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.