UNPKG

yqb

Version:

Static Package Manager

102 lines (89 loc) 3.13 kB
/** * 弹窗类 * author: <%= author %> * version: <%= version %> * website: http://www.431103.com */ !(function(root, factory) { if (typeof define === 'function' && define.amd) { define(['jquery'], function($) { return factory(root, $); }); } else if (typeof exports === 'object') { factory(root, require('jquery')); } else { factory(root, root.jQuery || root.Zepto); } })(this, function(global, $) { 'use strict'; var defaults = { content: '请稍等...', title: '提示', okText:'确认', cancelText:'取消' } var Dialog = function(options) { this.settings = $.extend({}, defaults, options); this.init(); }; Dialog.prototype = { init: function() { this.create(); }, create: function() { var $body = $(document.body); var templates = '<div class="paf-dialog show">' + '<div class="paf-dialog-cnt">' + '<div class="paf-dialog-bd">' + '<div>' + '<h4>'+this.settings.title+'</h4>' + '<div>'+this.settings.content+'</div>' + '</div>' + '</div>' + '<div class="paf-dialog-ft paf-btn-group">' + '</div>' + '</div>' + '</div>' ; this.dialogDom=$(templates).prependTo('body'); this.ok(); // 设置cancel按钮 if(this.settings.cancel instanceof Function) { this.cancel(); } }, ok:function(){ var self = this; var footer = this.dialogDom.find('.paf-dialog-ft'); $('<button>', { text : self.settings.okText, type:'button', click : function() { if(self.settings.ok instanceof Function) { self.settings.ok(); } self.close(); } }).prependTo(footer); }, cancel:function(){ var self = this; var footer = this.dialogDom.find('.paf-dialog-ft'); $('<button>', { text : self.settings.cancelText, click : function() { if(self.settings.cancel instanceof Function) { self.settings.cancel(); } self.close(); } }).prependTo(footer); }, close: function() { this.dialogDom.remove(); }, }; var dialog = function(options) { new Dialog(options); } window.dialog = $.dialog = dialog; });