+function ($) {
'use strict';
// AFFIRM CLASS DEFINITION
// =======================
var Affirm = function (element, options) {
this.$element = $(element);
this.settings = {
title: this.$element.data('title'),
offset: this.$element.data('offset'),
removeClass: this.$element.data('remove-class')
};
this.options = $.extend({}, Affirm.DEFAULTS, options);
this.init();
};
if (!$.fn.modal) throw new Error('Affirm requires modal.js');
Affirm.VERSION = '1.0.0';
Affirm.DEFAULTS = {
btnClass: {
cancel: 'btn margin-size-right-xs',
confirm: 'btn btn-color-red'
},
modalClass: 'modal fade',
modalId: 'bsAffirmModal',
format: 'modal',
text: {
cancel: 'No, Cancel',
confirm: 'Yes, Confirm'
},
title: 'Are you 100% sure about this?'
};
Affirm.prototype.constructor = Affirm;
Affirm.prototype.init = function () {
var _self = this;
var body = $('body');
var modalId = '#' + this.options.modalId;
this.$element.click(function () {
$(modalId).remove();
body.append(_self.modalTemplate());
$(modalId).modal('show');
return false;
});
body.on('click', '[data-affirm-toggle="confirm"]', function () {
$(modalId).modal('hide');
});
};
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 = $('