JavaScript
Article

jQuery ICEpush Integration

By Sam Deering

Integration of jQuery

The jquery.icepush.js provides an extension library for the clients of jQuery of Java Web applications.

Page Inclusion and Initialization

1.       You need to include the icepush.jar in your Java web application.

2.       ICEpush javascript code must be declared inside the head tag of any HTML page that requires push in your application.

3.       jQuery library and the ICEpush jQuery plugin must be decalred after the ICEpush javascript.


jQuery ICEpush Plugin API


Global Functions

$.push.listenToGroup (groupName, callback);

The function above will add client page to a push group, register the callback provided listener with the ICEpush bridge. The listener of callback will be triggered when a push notification occurs for the group specified.

Arguments

groupName: ICEpush group names that are being joined.

Callback: This is the listener function that will be called an event notifies the joined group.

Example

Suppose that the client registers itself with an ICE group named ‘time’, and an anonymous callback listener function is provided. The group ‘time’ does not have to be declared on client’s server and will be created by the ICEpush bridge when registration happens. If any of the notifications for the group ‘time’ occur, the function will be called by ICEpush bridge, and the function that will  do the calling to the server with the $.fn.load(url) jQuery function and update and element with the id of ‘timeElem’ on the page. These push events is possible to trigger on the client through a call to ice.push.notify(groupName); or from the server with the help of Java API.

$.push.listenToGroup("time", function(){
$("#timeElem").load('./time');
});

$.push.stopListingToGroup(groupName, callback);

This particular function will remove the client page from a joined group, unregistering it from the group.

Arguments

groupName: ICEpush group Name.

callback: This is the listener that previously registered. If not present, all of the callback listeners from ICEpush group will be removed.

Example

When the button was clicked, it will remove the client page from the ‘time’ group and will remove all of the callbacks registered for that group as well.

[/cc]

Suppose you had multiple different callback functions that are registered to the time group, we could selectively remove individual functions this way:

Member Functions

$.fn.loadPushUpdates(groupName,url)

This will register the client page with an ICEPush group,  and call the url provided automatically when an ICEpush event occurs for the registered group. When push event occurs, HTTP GET request will be made for the url provided and the HTML response will be loaded into all elements selected from the jQuery object.

Arguments

groupName: ICEpush group name that are joined.

url: This is the url that will be called on a push event of the group.

Example

The starting jQuery selector code is $(‘div.time’) which selects the two divs on top of the script. The .loadPushUpdates(‘time’,’./time’); registers the client page with the ICEpush group ‘time’. When an ICEpush notification occurs for the group ‘time’, the url ‘./time’ will be called with an HTTP GET request, and the response resulted will be placed inside both div elements that are selected.

$.fn.appendPushUpdates(groupName,url)

The function above will register the client page using ICEPush group, and will call the url provided automatically when an ICEpush event occurs for the group registered. Again, when a push event occurs, a HTTP GET request will be made for the url provided, and the HTML response will be appended in all of the selected elements from the jQuery object.

Arguments

groupName: ICEpush group name that are joined.

url: Url that will be called on a push event for the group.

Example

This is exactly the same as $(‘div.time’) .loadPushUpdates(“time”,”.time”); in the above example, though content will be appended into the elements selected.  In this kind of situation, each div’s name would be still even after any update, hence any content appended into the elements from previous updates would also remain.

Time Stamps

2nd Group of Time Stamps

No Reader comments

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in JavaScript, once a week, for free.