$(document).ready(function() {
var $contentModal, retrieveClassFor, storeClassFor;
$contentModal = $('#contentModal');
$contentModal.DEFAULTS;
storeClassFor = function($elem) {
return $elem.data('original-class', $elem.attr('class'));
};
retrieveClassFor = function($elem) {
if (typeof $elem.data('original-class') !== 'undefined') {
return $elem.attr('class', $elem.data('original-class'));
}
};
storeClassFor($contentModal);
$('#contentModal *').each(function(index) {
return storeClassFor($(this));
});
$contentModal.on('hidden.bs.modal', function() {
retrieveClassFor($contentModal);
$('#contentModal *').each(function() {
return retrieveClassFor($(this));
});
$contentModal.find('.modal-content-area').empty();
return $contentModal.data('open', false);
});
return $contentModal.on('show.bs.modal', function() {
return $contentModal.data('open', true);
});
});
this.setupContentModal = function(setupFunc) {
var $contentModal, doSetup, wasOpen;
$contentModal = $('#contentModal');
wasOpen = false;
doSetup = function() {
if (wasOpen) {
$contentModal.off('hidden.bs.modal', doSetup);
}
return setupFunc($contentModal);
};
if ($contentModal.data('open')) {
wasOpen = true;
return $contentModal.on('hidden.bs.modal', doSetup);
} else {
return doSetup();
}
};
this.showContentModal = function(options) {
var $contentModal, showIt, wasOpen;
if (options.force !== false) {
options.force = true;
}
$contentModal = $('#contentModal');
wasOpen = false;
showIt = function() {
var setSection;
if (wasOpen) {
$contentModal.off('hidden.bs.modal', showIt);
}
setSection = function($section, option) {
if (typeof option === 'string') {
return $section.text(option);
} else {
return $section.append(option);
}
};
setSection($('#contentTitle'), options.title);
setSection($('#contentBody'), options.body);
setSection($('#contentFooter'), options.footer);
options.title = null;
options.body = null;
options.footer = null;
$contentModal.modal(options);
if (options.then) {
return options.then($contentModal);
}
};
if ($contentModal.data('open')) {
if (options.force === true) {
wasOpen = true;
$contentModal.on('hidden.bs.modal', showIt);
return $contentModal.modal('hide');
}
} else {
return showIt();
}
};
this.hideContentModal = function() {
return $('#contentModal').modal('hide');
};
this.errorModal = function(body, options) {
if (typeof options !== 'object') {
options = {};
}
options.title || (options.title = 'Error');
options.body || (options.body = body);
options.footer || (options.footer = $(''));
setupContentModal(function($contentModal) {
$contentModal.find('.modal-content').addClass('modal-content-error');
return $contentModal.find('.modal-body').addClass('centered');
});
return showContentModal(options);
};
this.successModal = function(titleOrBody, body, setup) {
var title;
title = body ? titleOrBody : (body = titleOrBody, "Success");
setupContentModal(function($contentModal) {
$contentModal.find('.modal-content').addClass('modal-content-success');
$contentModal.find('.modal-body').addClass('centered');
if (setup) {
return setup($contentModal);
}
});
return showContentModal({
title: title,
body: body,
footer: $("")
});
};
this.confirmModal = function(question, callback) {
var $footer, $modal, $noBtn, $yesBtn;
$modal = $('#contentModal');
$yesBtn = $('Confirm');
$noBtn = $('Cancel');
$footer = $('#contentFooter');
$footer.children().remove();
$footer.append($yesBtn);
$footer.append($noBtn);
$yesBtn.click(function() {
$modal.modal('hide');
if (callback.length === 0) {
return callback();
} else {
return callback(true);
}
});
$noBtn.click(function() {
$modal.modal('hide');
if (callback.length >= 1) {
return callback(false);
}
});
setupContentModal(function($contentModal) {
$contentModal.find('.modal-dialog').addClass('modal-sm');
return $contentModal.find('.modal-body').addClass('centered');
});
return showContentModal({
title: 'Confirm',
body: question,
footer: $footer
});
};