Hi,
My jQuery pretty much sucks so I'm having this problem where I need to bind
to the Show event before actually showing the Modal.
This all happen inside a plugin, and I figured it might be better showing
the whole thing:
(function ($) {
$.fn.extend({
selectServiceProviders: function (options, callback) {
var defaults = {
url: '', // must be set to url to
action returning service providers selection form
currentSelection: '' // currently selected items
};
options = $.extend(defaults, options);
return this.each(function () {
var url = options["url"];
$('#modalContent', this).load(url);
// Bind to Show Event : See if we have a current selection
and if so check off checkboxes accordingly
$(this).bind('show', function () {
var currentSelection = options["currentSelection"];
if (currentSelection != '') {
$('[name=chkProviders]:checkbox').each(function () {
if (jQuery.inArray($(this).attr("id"),
currentSelection) > -1) {
$(this).attr("checked", "checked");
}
});
}
});
// Bind to Hide Event : Call the callback function when we
close
$(this).bind('hidden', function () {
if (typeof callback == 'function') {
var selectedIds = new Array();
var selectedNames = new Array();
$('input[name=chkProviders]:checked').each(function
() {
selectedIds.push($(this).attr('id'));
selectedNames.push($(this).attr('value'));
});
callback.call(this, selectedIds, selectedNames);
}
});
*// PROBLEM: this should fire AFTER binding, but it does
not (unless i have a breakpoint)*
$(this).modal('show');
});
}
});
})(jQuery);