// Confirm // Uses AMD or browser globals for jQuery. (function (factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as a module. define('pnotify.confirm', ['jquery', 'pnotify'], factory); } else { // Browser globals factory(jQuery, PNotify); } }(function($, PNotify){ PNotify.prototype.options.confirm = { // Make a confirmation box. confirm: false, // Make a prompt. prompt: false, // Classes to add to the input element of the prompt. prompt_class: "", // The default value of the prompt. prompt_default: "", // Whether the prompt should accept multiple lines of text. prompt_multi_line: false, // Where to align the buttons. (right, center, left, justify) align: "right", // The buttons to display, and their callbacks. buttons: [ { text: "Ok", addClass: "", // Whether to trigger this button when the user hits enter in a single line prompt. promptTrigger: true, click: function(notice, value){ notice.remove(); notice.get().trigger("pnotify.confirm", [notice, value]); } }, { text: "Cancel", addClass: "", click: function(notice){ notice.remove(); notice.get().trigger("pnotify.cancel", notice); } } ] }; PNotify.prototype.modules.confirm = { // The div that contains the buttons. container: null, // The input element of a prompt. prompt: null, init: function(notice, options){ this.container = $('
').css('text-align', options.align).appendTo(notice.container); if (options.confirm || options.prompt) this.makeDialog(notice, options); else this.container.hide(); }, update: function(notice, options){ if (options.confirm) { this.makeDialog(notice, options); this.container.show(); } else { this.container.hide().empty(); } }, afterOpen: function(notice, options){ if (options.prompt) this.prompt.focus(); }, makeDialog: function(notice, options) { var already = false, that = this, btn, elem; this.container.empty(); if (options.prompt) { this.prompt = $('<'+(options.prompt_multi_line ? 'textarea rows="5"' : 'input type="text"')+' style="margin-bottom:5px;clear:both;" />') .addClass(notice.styles.input+' '+options.prompt_class) .val(options.prompt_default) .appendTo(this.container); } for (var i in options.buttons) { btn = options.buttons[i]; if (already) this.container.append(' '); else already = true; elem = $('