Skip to content

Instantly share code, notes, and snippets.

@holisticnetworking
Last active March 15, 2017 16:33
Show Gist options
  • Save holisticnetworking/2a9652eb9cc161a5254177893e81f2d9 to your computer and use it in GitHub Desktop.
Save holisticnetworking/2a9652eb9cc161a5254177893e81f2d9 to your computer and use it in GitHub Desktop.
Generic function for opening a dialog with a spinner
/*
* Generic function for opening a dialog box
* @var str url: the URL for the content that will be loaded into the dialog
* @var obj data: a data object to pass to the URL
* @var obj options: the Dialog "options" object
* @var func complete: a callable function to be performed when the content loads into the dialog
*/
jQuery.fn.openDialog = function( url, data, options, complete ) {
var popup = $( "#popup" );
var content = $( "#popup-content" );
var spinner = $( "#spinner" );
spinner.show();
content
.hide()
.load( url, data, function() {
spinner.hide();
content.show();
// Run any callback functions, if present.
if( typeof complete === 'function' ) {
complete();
}
} );
// Load our dialog options, if present:
if( options != null && typeof options === 'object' ) {
popup.dialog( 'option', options );
}
popup.dialog( 'open' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment