From 6837ddf68f13a1633ea868ab55d71389ca5bc175 Mon Sep 17 00:00:00 2001 From: Horus3 Date: Fri, 27 Feb 2015 04:02:15 +0100 Subject: Version 0.2. Sends E-Mails now. Also sticky post on index page to quickly inform people. Concatenated all CSS and JavaScript files. --- static/js/jquery.confirm.js | 145 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 static/js/jquery.confirm.js (limited to 'static/js/jquery.confirm.js') diff --git a/static/js/jquery.confirm.js b/static/js/jquery.confirm.js new file mode 100644 index 0000000..ec1ac92 --- /dev/null +++ b/static/js/jquery.confirm.js @@ -0,0 +1,145 @@ +/*! + * jquery.confirm + * + * @version 2.3.1 + * + * @author My C-Labs + * @author Matthieu Napoli + * @author Russel Vela + * @author Marcus Schwarz + * + * @license MIT + * @url http://myclabs.github.io/jquery.confirm/ + */ +(function ($) { + + /** + * Confirm a link or a button + * @param [options] {{title, text, confirm, cancel, confirmButton, cancelButton, post, confirmButtonClass}} + */ + $.fn.confirm = function (options) { + if (typeof options === 'undefined') { + options = {}; + } + + this.click(function (e) { + e.preventDefault(); + + var newOptions = $.extend({ + button: $(this) + }, options); + + $.confirm(newOptions, e); + }); + + return this; + }; + + /** + * Show a confirmation dialog + * @param [options] {{title, text, confirm, cancel, confirmButton, cancelButton, post, confirmButtonClass}} + * @param [e] {Event} + */ + $.confirm = function (options, e) { + // Do nothing when active confirm modal. + if ($('.confirmation-modal').length > 0) + return; + + // Parse options defined with "data-" attributes + var dataOptions = {}; + if (options.button) { + var dataOptionsMapping = { + 'title': 'title', + 'text': 'text', + 'confirm-button': 'confirmButton', + 'cancel-button': 'cancelButton', + 'confirm-button-class': 'confirmButtonClass', + 'cancel-button-class': 'cancelButtonClass' + }; + $.each(dataOptionsMapping, function(attributeName, optionName) { + var value = options.button.data(attributeName); + if (value) { + dataOptions[optionName] = value; + } + }); + } + + // Default options + var settings = $.extend({}, $.confirm.options, { + confirm: function () { + var url = e && (('string' === typeof e && e) || (e.currentTarget && e.currentTarget.attributes['href'].value)); + if (url) { + if (options.post) { + var form = $('
'); + $("body").append(form); + form.submit(); + } else { + window.location = url; + } + } + }, + cancel: function (o) { + }, + button: null + }, dataOptions, options); + + // Modal + var modalHeader = ''; + if (settings.title !== '') { + modalHeader = + ''; + } + var modalHTML = + ''; + + var modal = $(modalHTML); + + modal.on('shown.bs.modal', function () { + modal.find(".btn-primary:first").focus(); + }); + modal.on('hidden.bs.modal', function () { + modal.remove(); + }); + modal.find(".confirm").click(function () { + settings.confirm(settings.button); + }); + modal.find(".cancel").click(function () { + settings.cancel(settings.button); + }); + + // Show the modal + $("body").append(modal); + modal.modal('show'); + }; + + /** + * Globally definable rules + */ + $.confirm.options = { + text: "Are you sure?", + title: "", + confirmButton: "Yes", + cancelButton: "Cancel", + post: false, + confirmButtonClass: "btn-primary", + cancelButtonClass: "btn-default" + } +})(jQuery); -- cgit v1.2.3