+function ($) {
'use strict';
// AFFIRM CLASS DEFINITION
// =======================
var Affirm = function (element, options) {
this.$element = $(element);
this.settings = {
btnClass: {
cancel: this.$element.data('btn-class-cancel') || Affirm.DEFAULTS.btnClass.cancel,
confirm: this.$element.data('btn-class-confirm') || Affirm.DEFAULTS.btnClass.confirm
},
format: this.$element.data('format') || Affirm.DEFAULTS.text.format,
text: {
cancel: this.$element.data('text-cancel') || Affirm.DEFAULTS.text.cancel,
confirm: this.$element.data('text-confirm') || Affirm.DEFAULTS.text.confirm
},
title: this.$element.data('title') || Affirm.DEFAULTS.text.title
};
this.options = $.extend({}, Affirm.DEFAULTS, this.settings, options);
this.init();
};
if (!$.fn.modal) throw new Error('Affirm requires modal.js');
if (!$.fn.popover) throw new Error('Affirm requires popover.js');
Affirm.VERSION = '1.0.0';
Affirm.DEFAULTS = {
btnClass: {
cancel: 'btn margin-size-right-xs',
confirm: 'btn btn-color-red'
},
format: 'modal',
onCancelCallback: function () {},
onConfirmCallback: function () {},
onDisplayCallback: function () {},
text: {
cancel: 'No, Cancel',
confirm: 'Yes, Confirm'
},
title: 'Are you sure about this?'
};
Affirm.prototype.constructor = Affirm;
Affirm.prototype.init = function () {
var _self = this;
var body = $('body');
this.$element.on('click', function (e) {
e.stopPropagation();
e.preventDefault();
_self.displayFormat();
$.event.trigger('display.bs.affirm');
_self.options.onDisplayCallback();
return false;
});
$('body')
.on('click', '[data-affirm-toggle="cancel"]', function () {
_self.cancelFormat();
$.event.trigger('cancel.bs.affirm');
_self.options.onCancelCallback();
})
.on('click', '[data-affirm-toggle="confirm"]', function () {
_self.confirmFormat();
$.event.trigger('confirm.bs.affirm');
_self.options.onConfirmCallback();
});
};
Affirm.prototype.cancelBtn = function () {
var button = $('')
.addClass(this.options.btnClass.cancel)
.text(this.options.text.cancel);
return button;
};
Affirm.prototype.confirmBtn = function () {
var method = this.$element.attr('data-method');
var target = this.$element.attr('target');
var button = $('')
.addClass(this.options.btnClass.confirm)
.attr('href', this.$element.attr('href'))
.text(this.options.text.confirm);
if (method) button.attr('data-method', method);
if (target) button.attr('target', target);
return button;
};
Affirm.prototype.modalTemplate = function () {
var title = '' + this.options.title + '
';
var header = $('