In this article I will describe how to implement and use the jQuery NProgress nano scrollbar plugin
The demonstration database can be downloaded from the link above or from here
Since Youtube.com added their nano scroll bar at the top of the page there have been a flurry of different jQuery plugins which mimic the nano progress bar at the top of the screen.
The silly thing is that the progress bar itself does nothing useful.
- It does not
- Indicate any meaningful progress on the download of the AJAX or page
- Give any indication of the likelyhood of page download completion
- It does
- Give the user a false sense of something happening on the page
- Provide a nice User Experience for very little overhead and effort on the part of the developer
Using NProgress you can very quickly and easily add this capability to your website for only a very small overhead to the size of your application.
Adding NProgress to your XPages
- Go to the NProgress site and download the file from the github site linked on the page
- Drag and drop the contents of the zip file into your WebContents folder
- Create a sample page with the following
The reason we add this to our XPage in the manner above is because nprogress uses AMD as a possible loader (to integrate with require.js) and because of that Dojo 1.8 (on an R9 server) breaks it.
On my demo page I have loaded a viewPanel with 1300 documents in it – I cannot show you more because I do not want a large database on my host’s site but rest assured if you run this up to a 5000 row viewPanel the effect is better because the refresh is slower.
On the demo I have included the main example from the NProgress site and you can see that there are a number of methods for starting and manipulating the progress bar. I use start because it very nicely randomly increments itself to give that illusion of progress.
On the XPage I have a button which refreshes the view Panel – and in the client script as the button is pushed I start the NProgress. In the onComplete of the refresh I end NProgress and really it is as simple as that
<xp:button value="Reload viewPanel" id="button1" styleClass="clickMe btn btn-warning"> <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="viewwrapper" onComplete="NProgress.done()"> <xp:this.script><![CDATA[ NProgress.start() ]]></xp:this.script> </xp:eventHandler> </xp:button>
I would suggest that if you are able to integrate with Tony McGuckin’s excellent XSnippet for intercepting dojo io events you could create an automated NProgress bar should you so chose.
As web developers we have used spinners in our application for quite a number of years – this is a new twist on that concept and seems to be getting very good reviews from users. Consider integrating it into your applications.