window.showBSModal = function self(options) { var options = $.extend({ title : '', body : '', remote : false, backdrop : 'static', size : false, onShow : false, onHide : false, actions : false }, options); self.onShow = typeof options.onShow == 'function' ? options.onShow : function () {}; self.onHide = typeof options.onHide == 'function' ? options.onHide : function () {}; if (self.$modal == undefined) { self.$modal = $('').appendTo('body'); self.$modal.on('shown.bs.modal', function (e) { self.onShow.call(this, e); }); self.$modal.on('hidden.bs.modal', function (e) { self.onHide.call(this, e); }); } var modalClass = { small : "modal-sm", large : "modal-lg" }; self.$modal.data('bs.modal', false); self.$modal.find('.modal-dialog').removeClass().addClass('modal-dialog ' + (modalClass[options.size] || '')); self.$modal.find('.modal-content').html(''.replace('${title}', options.title).replace('${body}', options.body)); var footer = self.$modal.find('.modal-footer'); if (Object.prototype.toString.call(options.actions) == "[object Array]") { for (var i = 0, l = options.actions.length; i < l; i++) { options.actions[i].onClick = typeof options.actions[i].onClick == 'function' ? options.actions[i].onClick : function () {}; $('').appendTo(footer).on('click', options.actions[i].onClick); } } else { $('').appendTo(footer); } self.$modal.modal(options); }