app/assets/javascripts/jqr-helpers.js in jqr-helpers-1.0.43 vs app/assets/javascripts/jqr-helpers.js in jqr-helpers-1.0.44
- old
+ new
@@ -21,31 +21,31 @@
$('#ujs-dialog-throbber').remove();
$(element).removeAttr('disabled');
}
var ujsDialogElement = null; // the element that opened the dialog
- var ujsLastDialog = null; // last opened dialog
var ujsSubmitElement = null; // the element that submitted a form
// called from dialog button value
function ujsSubmitDialogForm() {
$('.ui-dialog:visible form').first().submit();
}
// called from dialog button value
+ // uses $.proxy to set the "this" context
function ujsDialogClose() {
- if (!ujsLastDialog) return;
- if (ujsLastDialog.data('remote-dialog')) {
- ujsLastDialog.dialog('destroy').remove();
+ var dialog = $(this).closest('.ui-dialog-content');
+ if (dialog.length == 0) dialog = $(this).find('.ui-dialog-content');
+ if (dialog.data('remote-dialog')) {
+ dialog.dialog('destroy').remove();
}
else {
- ujsLastDialog.dialog('destroy').addClass('ujs-dialog-hidden');
+ dialog.dialog('destroy').addClass('ujs-dialog-hidden');
}
}
function ujsDialogOpen() {
- ujsLastDialog = $(this);
$(this).css('maxHeight', ($(window).height() * 0.8) + 'px');
if ($(this).parent().height() > $(window).height()) {
$(this).height($(window).height() * 0.8);
$(this).css('overflow-y', 'auto');
}
@@ -100,14 +100,15 @@
}
else if (element.click == 'submit') {
dialogOptions.buttons[index].click = ujsSubmitDialogForm;
}
else if (element == 'close') {
- dialogOptions.buttons[index] = ujsDialogClose;
+ dialogOptions.buttons[index] = $.proxy(ujsDialogClose, dialogElement);
}
else if (element.click == 'close') {
- dialogOptions.buttons[index].click = ujsDialogClose;
+ dialogOptions.buttons[index].click =
+ $.proxy(ujsDialogClose, dialogElement);
}
else {
dialogOptions.buttons[index] = eval(element);
}
});
@@ -144,11 +145,11 @@
event.stopPropagation();
return false;
}
function ujsDialogCloseClick() {
- ujsDialogClose();
+ ujsDialogClose.call(this);
return false;
}
function ujsSubmitClick(event) {
ujsSubmitElement = event.target;
@@ -229,11 +230,11 @@
// element that opened it for update/append/delete callbacks.
if ($('.ui-dialog:visible').length) {
if (element.data('use-dialog-opener'))
targetElement = ujsDialogElement;
if (element.data('close-dialog'))
- ujsDialogClose();
+ ujsDialogClose.call(element);
}
if (element.data('refresh')) {
window.location.reload();
return;
}
@@ -254,10 +255,13 @@
else container = targetElement.parents(container);
}
switch (element.data('result-method')) {
case 'update':
- target = $(data).replaceAll(target);
+ // sometimes this adds text nodes
+ target = $(data).replaceAll(target).filter(function() {
+ return this.nodeType == 1;
+ });
target.trigger('jqr.load');
break;
case 'append':
if (empty && target.children().length == 0) {
$('#' + empty).hide();