- Avoid code duplication

- Use standard $ prefix for jQuery object
This commit is contained in:
Marc Delisle
2011-04-02 06:22:18 -04:00
parent aa1453d94c
commit 401d211d70
5 changed files with 37 additions and 61 deletions

View File

@@ -91,7 +91,7 @@ $(document).ready(function() {
$("#copy_db_form.ajax").live('submit', function(event) { $("#copy_db_form.ajax").live('submit', function(event) {
event.preventDefault(); event.preventDefault();
var msgbox = PMA_ajaxShowMessage(PMA_messages['strCopyingDatabase']); var $msgbox = PMA_ajaxShowMessage(PMA_messages['strCopyingDatabase']);
var $form = $(this); var $form = $(this);
@@ -120,9 +120,7 @@ $(document).ready(function() {
$('#topmenucontainer').after(data.error); $('#topmenucontainer').after(data.error);
} }
msgbox.clearQueue().fadeOut('medium', function() { PMA_ajaxRemoveMessage($msgbox);
$(this).hide();
});
}) // end $.get }) // end $.get
}) // end copy database }) // end copy database

View File

@@ -138,7 +138,7 @@ $(document).ready(function() {
$("#db_search_form.ajax").live('submit', function(event) { $("#db_search_form.ajax").live('submit', function(event) {
event.preventDefault(); event.preventDefault();
var msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching']); var $msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching']);
// jQuery object to reuse // jQuery object to reuse
$form = $(this); $form = $(this);
@@ -167,10 +167,7 @@ $(document).ready(function() {
$("#sqlqueryresults").html(response['message']); $("#sqlqueryresults").html(response['message']);
} }
msgbox.clearQueue().fadeOut('medium', function() { PMA_ajaxRemoveMessage($msgbox);
$(this).hide();
});
}) })
}) })
}, 'top.frame_content'); // end $(document).ready() }, 'top.frame_content'); // end $(document).ready()

View File

@@ -1260,6 +1260,17 @@ function PMA_ajaxShowMessage(message, timeout) {
return $("#loading"); return $("#loading");
} }
/**
* Removes the message shown for an Ajax operation when it's completed
*/
function PMA_ajaxRemoveMessage($this_msgbox) {
$this_msgbox
.clearQueue()
.fadeOut('medium', function() {
$this_msgbox.hide();
});
}
/** /**
* Hides/shows the "Open in ENUM/SET editor" message, depending on the data type of the column currently selected * Hides/shows the "Open in ENUM/SET editor" message, depending on the data type of the column currently selected
*/ */
@@ -1391,7 +1402,7 @@ $(document).ready(function() {
var button_options_error = {}; var button_options_error = {};
button_options_error[PMA_messages['strOK']] = function() {$(this).dialog('close').remove();} button_options_error[PMA_messages['strOK']] = function() {$(this).dialog('close').remove();}
var msgbox = PMA_ajaxShowMessage(); var $msgbox = PMA_ajaxShowMessage();
if (! $form.find('input:hidden').is('#ajax_request_hidden')) { if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
$form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />'); $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
} }
@@ -1421,9 +1432,7 @@ $(document).ready(function() {
buttons : button_options buttons : button_options
}); // end dialog options }); // end dialog options
} }
msgbox.clearQueue().fadeOut('medium', function() { PMA_ajaxRemoveMessage($msgbox);
$(this).hide();
});
}) // end $.get() }) // end $.get()
// empty table name and number of columns from the minimal form // empty table name and number of columns from the minimal form
@@ -1551,7 +1560,7 @@ $(document).ready(function() {
*/ */
var $form = $("#create_table_form"); var $form = $("#create_table_form");
var msgbox = PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']); var $msgbox = PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
if (! $form.find('input:hidden').is('#ajax_request_hidden')) { if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
$form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />'); $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
} }
@@ -1567,10 +1576,7 @@ $(document).ready(function() {
$("#create_table_div").html(data); $("#create_table_div").html(data);
} }
PMA_verifyTypeOfAllColumns(); PMA_verifyTypeOfAllColumns();
PMA_ajaxRemoveMessage($msgbox);
msgbox.clearQueue().fadeOut('medium', function() {
$(this).hide();
});
}) //end $.post() }) //end $.post()
}) // end create table form (add fields) }) // end create table form (add fields)
@@ -1753,7 +1759,7 @@ $(document).ready(function() {
*/ */
var this_value = $(this).val(); var this_value = $(this).val();
var msgbox = PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']); var $msgbox = PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
$(the_form).append('<input type="hidden" name="ajax_request" value="true" />'); $(the_form).append('<input type="hidden" name="ajax_request" value="true" />');
$.post($(the_form).attr('action'), $(the_form).serialize() + '&change_pw='+ this_value, function(data) { $.post($(the_form).attr('action'), $(the_form).serialize() + '&change_pw='+ this_value, function(data) {
@@ -1762,10 +1768,7 @@ $(document).ready(function() {
$("#change_password_dialog").hide().remove(); $("#change_password_dialog").hide().remove();
$("#edit_user_dialog").dialog("close").remove(); $("#edit_user_dialog").dialog("close").remove();
$('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax'); $('#change_password_anchor.dialog_active').removeClass('dialog_active').addClass('ajax');
PMA_ajaxRemoveMessage($msgbox);
msgbox.clearQueue().fadeOut('medium', function() {
$(this).hide();
});
} }
else { else {
PMA_ajaxShowMessage(data.error); PMA_ajaxShowMessage(data.error);

View File

@@ -163,7 +163,7 @@ $(document).ready(function() {
/** @lends jQuery */ /** @lends jQuery */
event.preventDefault(); event.preventDefault();
var msgbox = PMA_ajaxShowMessage(); var $msgbox = PMA_ajaxShowMessage();
/** /**
* @var button_options Object containing options for jQueryUI dialog buttons * @var button_options Object containing options for jQueryUI dialog buttons
@@ -224,10 +224,7 @@ $(document).ready(function() {
buttons: button_options buttons: button_options
}); //dialog options end }); //dialog options end
displayPasswordGenerateButton(); displayPasswordGenerateButton();
PMA_ajaxRemoveMessage($msgbox);
msgbox.clearQueue().fadeOut('medium', function() {
$(this).hide();
});
}); // end $.get() }); // end $.get()
});//end of Add New User AJAX event handler });//end of Add New User AJAX event handler
@@ -318,7 +315,7 @@ $(document).ready(function() {
/** @lends jQuery */ /** @lends jQuery */
event.preventDefault(); event.preventDefault();
var msgbox = PMA_ajaxShowMessage(); var $msgbox = PMA_ajaxShowMessage();
$(this).parents('tr').addClass('current_row'); $(this).parents('tr').addClass('current_row');
@@ -337,10 +334,7 @@ $(document).ready(function() {
buttons: button_options buttons: button_options
}); //dialog options end }); //dialog options end
displayPasswordGenerateButton(); displayPasswordGenerateButton();
PMA_ajaxRemoveMessage($msgbox);
msgbox.clearQueue().fadeOut('medium', function() {
$(this).hide();
});
}) // end $.get() }) // end $.get()
}) })
@@ -426,7 +420,7 @@ $(document).ready(function() {
/** @lends jQuery */ /** @lends jQuery */
event.preventDefault(); event.preventDefault();
var msgbox = PMA_ajaxShowMessage(); var $msgbox = PMA_ajaxShowMessage();
/** /**
* @var button_options Object containing options for jQueryUI dialog buttons * @var button_options Object containing options for jQueryUI dialog buttons
@@ -441,11 +435,7 @@ $(document).ready(function() {
width : 500, width : 500,
buttons: button_options buttons: button_options
}); });
PMA_ajaxRemoveMessage($msgbox);
msgbox.clearQueue().fadeOut('medium', function() {
$(this).hide();
});
}) //end $.get }) //end $.get
}) //end export privileges }) //end export privileges
@@ -460,7 +450,7 @@ $(document).ready(function() {
$("#initials_table.ajax").find("a").live('click', function(event) { $("#initials_table.ajax").find("a").live('click', function(event) {
event.preventDefault(); event.preventDefault();
var msgbox = PMA_ajaxShowMessage(); var $msgbox = PMA_ajaxShowMessage();
$.get($(this).attr('href'), {'ajax_request' : true}, function(data) { $.get($(this).attr('href'), {'ajax_request' : true}, function(data) {
// This form is not on screen when first entering Privileges // This form is not on screen when first entering Privileges
@@ -471,9 +461,7 @@ $(document).ready(function() {
.after(data).show("medium") .after(data).show("medium")
.siblings("h2").not(":first").remove(); .siblings("h2").not(":first").remove();
msgbox.clearQueue().fadeOut('medium', function() { PMA_ajaxRemoveMessage($msgbox);
$(this).hide();
});
}) // end $.get }) // end $.get
})// end of the paginate users table })// end of the paginate users table

View File

@@ -248,7 +248,7 @@ $(document).ready(function() {
$('.error').remove(); $('.error').remove();
$form = $(this); $form = $(this);
var msgbox = PMA_ajaxShowMessage(); var $msgbox = PMA_ajaxShowMessage();
if (! $form.find('input:hidden').is('#ajax_request_hidden')) { if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
$form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />'); $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
@@ -302,10 +302,8 @@ $(document).ready(function() {
PMA_init_slider(); PMA_init_slider();
} }
} }
PMA_ajaxRemoveMessage($msgbox);
msgbox.clearQueue().fadeOut('medium', function() {
$(this).hide();
});
}) // end $.post() }) // end $.post()
}) // end SQL Query submit }) // end SQL Query submit
@@ -325,7 +323,7 @@ $(document).ready(function() {
/** @lends jQuery */ /** @lends jQuery */
event.preventDefault(); event.preventDefault();
var msgbox = PMA_ajaxShowMessage(); var $msgbox = PMA_ajaxShowMessage();
/** /**
* @var $the_form Object referring to the form element that paginates the results table * @var $the_form Object referring to the form element that paginates the results table
@@ -339,9 +337,7 @@ $(document).ready(function() {
$("#sqlqueryresults").trigger('appendAnchor'); $("#sqlqueryresults").trigger('appendAnchor');
PMA_init_slider(); PMA_init_slider();
msgbox.clearQueue().fadeOut('medium', function() { PMA_ajaxRemoveMessage($msgbox);
$(this).hide();
});
}) // end $.post() }) // end $.post()
})// end Paginate results table })// end Paginate results table
@@ -357,16 +353,13 @@ $(document).ready(function() {
if ($(this).hasClass('ajax')) { if ($(this).hasClass('ajax')) {
event.preventDefault(); event.preventDefault();
var msgbox = PMA_ajaxShowMessage(); var $msgbox = PMA_ajaxShowMessage();
$.post($the_form.attr('action'), $the_form.serialize() + '&ajax_request=true', function(data) { $.post($the_form.attr('action'), $the_form.serialize() + '&ajax_request=true', function(data) {
$("#sqlqueryresults").html(data); $("#sqlqueryresults").html(data);
$("#sqlqueryresults").trigger('appendAnchor'); $("#sqlqueryresults").trigger('appendAnchor');
PMA_init_slider(); PMA_init_slider();
PMA_ajaxRemoveMessage($msgbox);
msgbox.clearQueue().fadeOut('medium', function() {
$(this).hide();
});
}) // end $.post() }) // end $.post()
} else { } else {
$the_form.submit(); $the_form.submit();
@@ -383,7 +376,7 @@ $(document).ready(function() {
$("#table_results.ajax").find("a[title=Sort]").live('click', function(event) { $("#table_results.ajax").find("a[title=Sort]").live('click', function(event) {
event.preventDefault(); event.preventDefault();
var msgbox = PMA_ajaxShowMessage(); var $msgbox = PMA_ajaxShowMessage();
$anchor = $(this); $anchor = $(this);
@@ -391,10 +384,7 @@ $(document).ready(function() {
$("#sqlqueryresults") $("#sqlqueryresults")
.html(data) .html(data)
.trigger('appendAnchor'); .trigger('appendAnchor');
PMA_ajaxRemoveMessage($msgbox);
msgbox.clearQueue().fadeOut('medium', function() {
$(this).hide();
});
}) // end $.get() }) // end $.get()
})//end Sort results table })//end Sort results table