/* ========================================================================
* SaRibe: eModal.js v1.1.03
* http://saribe.github.io/eModal
* ========================================================================
* Copyright Samuel Ribeiro.
* Licensed under.
* ======================================================================== */
; (function (define) {
define(['jquery'], function ($) {
///
/// @params allowed elements:
/// buttons {array}: An array of objects to configure buttons to modal footer; only able if message == string
/// css {object}: css objext try apply into message body; only able if message == string
/// loading {bool}: set loading progress as message.
/// message {string|object}: The body message string or the html element. eg: $(selector);
/// size {string}: sm || lg -> define the modal size.
/// subtitle {string}: The header subtitle string. This apper in a smaller text.
/// title {string}: The header title string.
/// useBin {bool}: set message as recycable.
///
/// Modal options parameters os string body message.
/// The string header title or a flag to set default params.
/// The modal element.
//The modal element UX and events.
var defaultSettings = {
allowContentRecycle: true,
size: '',
loadingHtml: '
Loading...
100% Complete
',
title: 'Attention'
};
var $modal;
var bin = 'recycle-bin';
var div = '
';
var footerId = 'eModalFooter';
var hide = 'hide.bs.modal';
var lastParams = {};
var modalBody = 'modal-body';
var options = {};
var recModalContent = 'rec-modal-content';
var size = { sm: 'sm', lg: 'lg' };
var shown = 'shown.bs.modal';
var tmpModalContent = 'tmp-modal-content';
var catchCallback;
var thenPool = [];
var linq = {
element: $modal,
'catch': fail,
then: then
};
return {
ajax: ajax,
alert: alert,
close: close,
confirm: confirm,
emptyBin: emptyBin,
iframe: iframe,
prompt: prompt,
setEModalOptions: setEModalOptions,
setModalOptions: setModalOptions,
size: size,
version: '1.1.03'
};
//#region Private Logic
function build(message) {
$modal.find('.modal-content')
.append(message);
$modal.modal(options);
return linq;
}
function isFunction(instance) {
return typeof instance === 'function';
}
function getModalInstance() {
///
/// Return a new modal object if is the first request or the already created model.
///
/// The model instance.
if (!$modal) {
//add recycle bin container to document
if (!document.getElementById(bin)) {
$('body').append($(div).prop('id', bin).hide());
}
$modal = createModalElement();
linq.element = $modal;
}
return $modal;
function createModalElement() {
///
///
return $('
'
+ '
'
+ '
'
+ '
'
+ '
'
+ '
'
+ '
')
.on('hidden.bs.modal', recycleModal)
.on('click', 'button.x', function (ev) {
var btn = $(ev.currentTarget);
if (btn.prop('type') !== 'submit')
return $modal.modal('hide');
try {
if (btn.closest('form')[0].checkValidity())
return close();
} catch (e) {
return close();
}
return $modal;
});
}
}
function getFooter(buttons) {
///
///
if (buttons === false) { return ''; }
var messageFotter = $(div).addClass('modal-footer').prop('id', footerId);
if (buttons) {
for (var i = 0, k = buttons.length; i < k; i++) {
var btnOp = buttons[i];
var btn = $('