jQuery Modal close callback - jquery-ui

How can I set a callback function to be ran when a modal dialog is closing, without the click of a button or close (x) icon?

you can also try,
$( ".selector" ).dialog({
beforeClose: function(event, ui) { ... }
});
This event is triggered when a dialog attempts to close. If the beforeClose event handler (callback function) returns false, the close will be prevented.

Why dont you try the event close of jQuery UI dialog?
Code examples
Supply a callback function to handle the close event as an init option.
$( ".selector" ).dialog({
close: function(event, ui) { ... }
});
Bind to the close event by type: dialogclose.
$( ".selector" ).bind( "dialogclose", function(event, ui) {
...
});

Related

Jquery tabs ui 1.10 tabs refresh

I m using jquery tabs .Like to know how to refresh content on tab click .
I m using document ready function with
$(#TABS).TABS()
$(document).ready(function(){
$("#tabs").tabs();
$("#tabs").bind("tabshow",function(event,ui){window.location.href=ui.tab;});});
See the "select event" here
It says:
This event is triggered when clicking a tab.
Code examples
Supply a callback function to handle the select event as an init option.
$( ".selector" ).tabs({
select: function(event, ui) { ... }
});
Bind to the select event by type: tabsselect.
$( ".selector" ).bind( "tabsselect", function(event, ui) {
...
});
in jQuery-UI 1.10, the following should help:
$("#TABS").tabs("load", $("#TABS").tabs("option", "active"));
Edit: More code details:
$(function() {
$("#TABS").tabs();
$("#TABS").on('click','li',function(event,ui) {
$("#TABS").tabs("load", $("#TABS").tabs("option", "active"));
});
});
Here is a link to jsfiddle

jQueryUI - Accordion Scrolling to header freezes when same section opened twice in a row

I'm using the following to control my accordion:
$(function() {
$( "#accordion" ).accordion({
autoHeight: false, collapsible: true, active: false
});
$('#accordion').bind('accordionchange', function (event, ui) {
$(window).scrollTop(ui.newHeader.offset().top);
});
});
It works well unless I open the same section twice. Then, the accordion freezes and I get the following error:
ui.newHeader.offset() is undefined
The accordionchange event appears to be the jQuery event that corresponds to the accordion's activate event; yes, this is a bit confusing but that's what the source tells me:
// change events
(function( $, prototype ) {
//...
} else if ( type === "activate" ) {
ret = _trigger.call( this, "change", event, {
The activate documentation has this to say:
activate( event, ui )
Triggered after a panel has been activated (after animation completes). [...] If the accordion is collapsing, ui.newHeader and ui.newPanel will be empty jQuery objects.
So your ui.newHeader is an empty jQuery object and empty jQuery objects don't have offset()s. A quick length check on ui.newHeader will probably sort you out:
$('#accordion').bind('accordionchange', function(event, ui) {
if(ui.newHeader.length)
$(window).scrollTop(ui.newHeader.offset().top);
});​
Demo: http://jsfiddle.net/ambiguous/e3gUW/

jQuery UI delete confirm call back function

I wang to use jQuery UI to implement a delete confirmation. I want to use a link to trigger the dialog. Here's my code:
delete
<script type="text/javascript">
$(function(){
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
autoOpen: false,
buttons: {
"Okay": function() {
$( this ).dialog( "close" );
return true;
},
Cancel: function() {
$( this ).dialog( "close" );
return false;
}
}
});
$( ".delete" ).click(function() {
$( "#dialog-confirm" ).dialog( "open" );
return false;
});
});
</script>
What I want to do is, when the user click on cancel, it does nothing. But when the user click on okay, then it will continue to go to www.google.com.
However, no matter okay or cancel I click, it remains nothing happens. Any idea?
Even if you do this:
$("a.delete").trigger("click");
You still won't get to google, because after it calls handlers, jQuery triggers an event on the object. It only calls native handlers for click events if the element is not a link.
You could do something like this:
window.location.href = $("a.delete").attr("href");
Or, you could have a hidden link on the page, like this:
delete
Then, on the click of the "Open" button, you could do this:
$("a.hiddenDelete").trigger("click");

how to remove the close button in dialog?

I want to hide the close button in the title bar of the dialog box. I want the user strictly complete the steps in dialog, so restrict the ways of hiding the dialog.
Try this:
$(".ui-dialog-titlebar-close").hide();
You can hide close button on dialog's open event.
Ref : http://jqueryui.com/demos/dialog/#event-open
This event is triggered when dialog is opened.
Code examples
Supply a callback function to handle the open event as an init option.
$( ".selector" ).dialog({
open: function(event, ui) { ... }
});
Bind to the open event by type: dialogopen.
$( ".selector" ).bind( "dialogopen", function(event, ui) {
...
});
Even better, use CSS...
.ui-dialog-titlebar-close {
display:none;
}

Overriding jQuery Dialog method

I am trying to override close method of Jquery Dialog method.
Code :
jQuery.Dialog.close = function() {
alert('my close');
}
But its not working. Please help.
There is an event called beforeClose which would allow you to do what you want, I think. When it fires, you can hide the dialog, then return false, which would prevent the dialog from actually closing.
$( ".selector" ).dialog({
beforeClose: function(event, ui) {
$(this).hide();
return false;
}
});
Reference: http://jqueryui.com/demos/dialog/ under the Events tab below the example
You're setting it up wrong. Check this out to see how to do it correctly.
Ok, so that link doesn't take you where I thought it would. Here's the relevant bit from jqueryui.com.
closeType:dialogclose
This event is triggered when the dialog is closed.
Code examples
Supply a callback function to handle the close event as an init option.
$('.selector').dialog({
close: function(event, ui) { ... }
});
Bind to the close event by type: dialogclose.
$('.selector').bind('dialogclose', function(event, ui) {
...
});

Resources