Changing cursor to wait while request is in progress

Switching cursor to ‘wait’ and back to ‘default’ is tricky since some elements such as link, input or button have a different default style. Setting it back to ‘auto’ does not work in Firefox, but to an empty string works. Here’s how you would do it with dojo:

require(['dojo/_base/connect', 'dojo/query'], function(connect, query) {
	// change cursor on first ajax request
	connect.subscribe("/dojo/io/start", function() {
		query('*').style('cursor', 'wait'); // also when mouse is over buttons or inputs
	// change cursor back on last ajax request
	connect.subscribe("/dojo/io/stop", function() {
		window.setTimeout(function() { // seems to fix FF not always setting cursor back to auto on some elements
			query('*').style('cursor', ''); // in FF auto would set default cursor, use '' instead
		}, 50);

Leave a comment

Your email address will not be published. Required fields are marked *