/** * jquery dialog plugin * * depends: * - jquery 1.4.2+ * author: * - lanqy 2015-12-28 * github: * - https://github.com/lanqy/dialog */ (function($) { $.extend($.fn, { dialog: function(options) { return this.each(function() { var dialog = $.data(this, "dialog"); if (!dialog) { dialog = new $.dialog(options, this); $.data(this, "dialog", dialog); } }); } }); $.dialog = function(options, el) { if (arguments.length) { this._init(options, el); } } $.dialog.prototype = { options: { title: 'title', // title showheader:true, // dragable: false, cache: true, // jquery dataļ¼Œdefault true html: '', // html template width: 'auto', // width height: 'auto', // height cannelbtn:true, confirmbtn:true, canneltext: 'cannel', // cannel text confirmtext: 'confirm', // confirm text showfooter: true, onclose: false, // colse callback onopen: false, // open callback onconfirm: false, // confirm callback oncannel: false, // cannel callback getcontent: false // get content callback }, _init: function(options, el) { // init this.options = $.extend(true, {}, this.options, options) this.element = $(el); this._build(this.options.html); this._bindevents(); }, _bindevents: function() { // bind events var self = this; this.element.delegate('.close','click',function(){ self.close(self.options.onclose); }); this.element.delegate('.cannel','click',function(){ self._cannel(self.options.oncannel); }); this.element.delegate('.confirm','click',function(){ self._confirm(self.options.onconfirm); }); $(window).bind("resize", function() { self._center(); self._setlayerwidthheight(); }); if (self.options.dragable) { self._dragable(); } }, _build: function(html) { // build the template for dialog var html; var footer = ''; var header = ''; var cfbtn =''; var clbtn =''; var bodycontent = '
'; if (html) { html = html; } else { if(this.options.confirmbtn){ cfbtn = ''; } if(this.options.cannelbtn){ clbtn = ''; } if (this.options.showfooter) { footer = ''; } if(this.options.showheader){ header = '
\

' + this.options.title + '

\ x\
'; } if(this.options.showfooter){ var h = this.options.height - 80; bodycontent = '
'; }else{ bodycontent = '
'; } html = '
\ '+ header +'\
\ '+ bodycontent +'\
' + footer + '