/* ========================================================================
* SaRibe: eModal.js v1.2.67
* http://saribe.github.io/eModal
* ========================================================================
* Copyright Samuel Ribeiro.
* Licensed under MIT.
* ======================================================================== */
/**
* Easy Modal for bootstrap, is a simple way to create modal dialogs using javascript.
* @params allowed elements:
* buttons {array}: An array of objects to configure buttons to modal footer; only able if message == string
* css {object}: CSS object try apply into message body; only able if message == string
* data {object}: Used for iframe with post data parameters
* loading {boolean}: Set loading progress as message.
* message {string|object}: The body message string or the HTML element. e.g.: $(selector);
* size {string}: sm || lg || xl -> define the modal size.
* subtitle {string}: The header subtitle string. This appear in a smaller text.
* title {string}: The header title string.
* useBin {boolean}: Set message as recyclable.
*
* Modal options parameters of string body message.
* The string header title or a flag to set default parameters.
* { then, element }.
*/
;
(function (define) {
define(['jquery'], function ($, root) {
var $modal;
var BIN = 'recycle-bin';
var DIV = '
';
var EMPTY = '';
var EVENT_CLICK = 'click';
var EVENT_HIDE = 'hide';
var EVENT_SHOW = 'shown.bs.modal';
var EVENT_SUBMIT = 'submit';
var FOOTER_ID = 'eFooter';
var HIDE = EVENT_HIDE + '.bs.modal';
var INPUT = 'input';
var KEY_DANGER = 'danger';
var LABEL = {
OK: 'Cancel',
True: 'False',
Yes: 'No'
};
var lastParams = {};
var MODAL_BODY = 'modal-body';
var MODAL_DIALOG = '.modal-dialog';
var options = {};
var REC_MODAL_CONTENT = 'modal-rec';
var SIZE = {
sm: 'sm',
lg: 'lg',
xl: 'xl'
};
var TMP_MODAL_CONTENT = 'modal-tmp';
var defaultSettings = {
allowContentRecycle: true,
confirmLabel: Object.keys(LABEL)[0],
labels: LABEL,
loadingHtml: '
Loading...
',
size: EMPTY,
title: 'Attention',
autofocus: false
};
root = root || {};
root.addLabel = addLabel;
root.ajax = ajax;
root.alert = alert;
root.close = close;
root.confirm = confirm;
root.emptyBin = emptyBin;
root.iframe = iframe;
root.prompt = prompt;
root.setId = setId;
root.setEModalOptions = setEModalOptions;
root.setModalOptions = setModalOptions;
root.size = SIZE;
root.version = '1.2.67';
return root;
//#region /////////////////////////* Private Logic */////////////////////////
/**
* Find modal body and append message to it.
* @param {String | DOM} message
*/
function _build(message) {
$modal
.modal(options)
.find('.modal-content')
.append(message);
}
/**
* Will find what Promises approach the developer is using.
* Will use Promises A+ if Q.js is present, otherwise will use Promises A from jQuery.
* @returns {Promise}
*/
function _createDeferred() {
var defer;
// try native promise
//if (Promise) defer = Promise.defer();
var q;
try {
q = require('Q');
} // Load option Q by require if exist
catch (e) {
q = window.Q;
}
if (q) { // try Q
defer = q.defer();
} else { // Use jQuery :(
defer = $.Deferred();
defer.promise = defer.promise();
}
defer.promise.element = _getModalInstance(true).find(MODAL_DIALOG);
return defer;
}
/**
* Will create modal DOM footer with all buttons.
* @param {Array} buttons - all custom buttons, if none, will generate defaults
* @returns {$DOM} footer DOM element
*/
function _getFooter(buttons) {
if (buttons === false) {
return EMPTY;
}
var messageFotter = $(DIV).addClass('modal-footer').prop('id', FOOTER_ID);
if (buttons) {
for (var i = 0, k = buttons.length; i < k; i++) {
var btnOp = buttons[i];
var btn = $('