Portal Theme JavaScript Utility Library
The utility library contains helpful tools for enhancing portal functionality using
Javascript in your portal theme pages.
harp-sdk.js
adds the HARPPortal
object to the global
scope. This object has the following interface:
interface HARPPortal { // Returns the Titania Delivery Version String getVersion(); // Returns the Titania Delivery build identifier String getBuildId(); // Returns the url to the given path String getPortalUrl(String path); /** * Returns the url to the Titania Delivery endpoint * that handles data transfer of assemblies, * comments, and helpful votes. Valid values are * 'assemblies', 'comments', and 'feedback'. */ String getPortalRpcUrl(String path); // AJAX interface to userData. UserDataStorage userData; // AJAX interface to siteData SiteDataStorage siteData; /** * Deletes the assembly indicated by assemblyKey * redirectTo is an optional parameter that takes a * path relative to the Portal root that the user will * be redirected to. */ void deleteAssembly(assemblyKey, redirectTo); }
These functions can be called anywhere JavaScript is legal on a page. For instance:
<script>alert(HARPPortal.getPortalUrl("search"));</script>
Add this library to any page by putting the following code snippet into the
<head>
of the page:
<#assign c=JspTaglibs['http://java.sun.com/jsp/jstl/core']/> <script type="text/javascript" src="<@c.url value="/resources/scripts/harp-sdk.js"/>"></script>
Note: HARP is an internal legacy name for Titania Delivery. As such, some of the APIs referenced
in
this documentation still use the name HARP in place of Titania Delivery.
UserData and SiteData in Javascript
The HARPPortal object has userData and siteData properties that can be used to manage persistent data without reloading the whole page. The interfaces to these objects is the same as the DataStorage and SiteData Freemarker objects, with the exception that all methods return jQuery Promises instead of values.
HARPPortal.userData.put('foo', 'bar').then(function() { console.log('Stored foo'); return HARPPortal.userData.get('foo'); }).then(function(s) { console.log('Got foo: ' + s); return HARPPortal.userData.delete('foo'); }).then(function() { console.log('Deleted foo'); return HARPPortal.userData.push('testList', 1); }).then(function() { console.log('Pushed 1'); return HARPPortal.userData.push('testList', {foo: 'bar'}); }).then(function() { console.log('Pushed object.'); return HARPPortal.userData.getList('testList'); }).then(function(arr) { console.log('Got test list.'); console.log(arr); return HARPPortal.userData.delete('testList'); }).then(function() { console.log('testList deleted'); }).fail(function(e) { alert('Failed'); console.log(e); });