/*! * 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, //是否自适应尺寸,默认自适应 autohide: false, //是否自自动消失,配合time参数共用 time: 3000, //自动消失时间,单位毫秒 zindex: 99999, //弹出层定位层级 hasmask: false, //是否显示遮罩层 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 = $('