Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add a close button to jquery model ( BlockUI)

I used the following which works correctly but I need to have a close button rather than closing automatically how to do that? (I am using jQuery BlockUI http://www.malsup.com/jquery/block/#demos)

 $(document).ready(function() { 
     $('#app').click(function() { 
         $.blockUI({ 
             theme:     true, 
             title:    'Welcome to your page', 
             message:  '<p>Please have a look..</p>', 
             timeout:   2000 
        }); 
    });    
}); 
like image 406
Eme Emertana Avatar asked Sep 21 '12 12:09

Eme Emertana


1 Answers

I don't know if you are still interested in this, but I was looking for it and could not find it, so I had to create my own solution. You have to update the plugin though (jquery.blockUI.js), and go to this line:

if ( opts.title ) {
    s +=  '<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(opts.title || '&nbsp;')+'</div>';

and replace it with this one:

if ( opts.title ) {
    s += '<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"><span id="ui-id-1" class="ui-dialog-title">' +(opts.title || '&nbsp;')+ '</span><button id="btnCloseBlockUI" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close" role="button" aria-disabled="false" title="close"><span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span><span class="ui-button-text">close</span></button></div>';

This will add a button to the title bar. To add a button click handler:

//Unblocks the UI when clicking the close button
$("button#btnCloseBlockUI.ui-button").click(function () {
    $.unblockUI();
});

You can be more fancy and add an extra option, something like showCloseButtonUI and display it only when it's set to true.

like image 174
Hanlet Escaño Avatar answered Sep 25 '22 01:09

Hanlet Escaño