/*! * dialogBox 0.0.1 * by Liuyuchao * Copyright 2015.3 * Date: Wed Mar 25 2015 */ (function($,window,document){ var pluginName = 'dialogBox', defaults = { width: null, //弹出层宽度 height: null, //弹出层高度 autoSize: true, //是否自适应尺寸,默认自适应 autofadeOut: false, //是否自自动消失,配合time参数共用 time: 3000, //自动消失时间,单位毫秒 zIndex:9999999, //弹出层定位层级 hasMask: true, //是否显示遮罩层 hasClose: false, //是否显示关闭按钮 hasBtn: false, //是否显示操作按钮,如取消,确定 confirmValue: null, //确定按钮文字内容 confirm: function(){}, //点击确定后回调函数 cancelValue: null, //取消按钮文字内容 cancel: function(){}, //点击取消后回调函数,默认关闭弹出框 effect: '', //动画效果:fade(默认),newspaper,fall,scaled,flip-horizontal,flip-vertical,sign, type: 'normal', //对话框类型:normal(普通对话框),correct(正确/操作成功对话框),error(错误/警告对话框) title: '', //标题内容,如果不设置,则连同关闭按钮(不论设置显示与否)都不显示标题 content: '' //正文内容,可以为纯字符串,html标签字符串,以及URL地址,当content为URL地址时,将内嵌目标页面的iframe。 }; function DialogBox(element,options){ this.element = element; this.settings = $.extend({}, defaults, options); this.init(); } DialogBox.prototype = { //初始化弹出框 init: function(){ var that = this, element = this.element; that.render(element); that.setStyle(); that.show(); that.trigger(element); }, //创建弹出框 create: function(element){ var that = this, $this = $(element), title = that.settings.title, hasBtn = that.settings.hasBtn, hasMask = that.settings.hasMask, hasClose = that.settings.hasClose, confirmValue = that.settings.confirmValue, cancelValue = that.settings.cancelValue, dialogHTML = []; if(!title){ dialogHTML[0] = '
'; }else{ if(!hasClose){ dialogHTML[0] = '

'+ title + '

'; }else{ dialogHTML[0] = '

'+ title + '

×
'; } } if(!hasBtn){ dialogHTML[1] = '
'; }else{ if(confirmValue && cancelValue){ dialogHTML[1] = '
' + cancelValue + '' + confirmValue + '
'; }else if(cancelValue){ dialogHTML[1] = '
' + cancelValue + '
'; }else if(confirmValue){ dialogHTML[1] = '
' + confirmValue + '
'; }else{ dialogHTML[1] = '
取消确定
'; } } if(!hasMask){ dialogHTML[2] = ''; }else{ dialogHTML[2] = '
'; } return dialogHTML; }, //渲染弹出框 render: function(element){ var that = this, $this = $(element), dialogHTML = that.create($this), $content = that.parseContent(); $this.replaceWith(dialogHTML[0] + dialogHTML[1]); if(typeof($content) === 'object'){ $content.appendTo('.dialog-box-content'); }else{ $('.dialog-box-content').append($content); } $('body').append(dialogHTML[2]); }, //解析并处理弹出框内容 parseContent: function(){ var that = this, content = that.settings.content, width = that.settings.width, height = that.settings.height, type = that.settings.type, $iframe = $('