/** * Author: huangzhiyang * Date: 2016/6/30 17:11 * Description: "" */ var Extend = require("COMMON/js/util.extend.js"); var PubSub = require("COMMON/js/util.pubsub.js"); var State = Extend({},PubSub); module.exports = State;
Dialog.prototype = Extend({ init : function(opt){ var that = this; var events = this.events = opt.events; var container = this.container; for(var i in events){ //"click .parent .children" => "click:.parent .children" var _key = i.replace(/(\w*)\s(.*)/,function(str,p1,p2){ return p1+":"+p2; }).split(":"); (function(_key){ var eventType = _key[0]; var selector = _key[1]; var handler = events[i]; container.on(eventType,selector,function(e){ if(typeof handler=="function"){ handler(e); }else if(typeof handler=="string"){ that.prototype[handler](e); } }) })(_key); } setTimeout(function(){ if(opt.drag){ Drag({ trigger : that.header[0], target : that.container[0], onMousedown : function(e){ opt.onDragBefore(e); }, onMousemove : function(e){ opt.onDrag(e); }, onMouseup : function(e){ opt.onDragAfter(e); } }) } },10) this.position(); opt.onReady(); }, position : function(){ var container = this.container; var height = container.height(); var width = container.width(); var WinWH = WinWidthHeight(); var offsetX = this.opt.offsetX; container.css({ left : (WinWH.width-width)/2 + offsetX, top : -height + 10 }).hide(); }, getMask : function(){ var mask = $("#"+this.flag+"mask"); if(mask.length) return mask; mask = $('<div></div>'); mask.attr({ "id" : this.flag + "mask", "class" : this.flag + "mask" }).appendTo($("body")); return mask; }, open : function(opt){ opt = opt || {}; var that = this; var overlay = typeof opt.overlay=="undefined" ? this.opt.overlay : !!opt.overlay; var speed = opt.speed || this.opt.speed; var offsetY = opt.offsetY || this.opt.offsetY; var onBefore = opt.onBefore || this.opt.onOpenBefore; var onAfter = opt.onAfter || this.opt.onOpenAfter; var winH = WinWidthHeight().height; var containerH = this.container.height(); this.position(); this.container.show().css({zIndex:501}); onBefore(); this.container.animate({ top : (winH-containerH)/2 + offsetY },speed,function(){ onAfter(); }) if(overlay) this.getMask().fadeIn(function(){ that.getMask().css("zIndex",500); }); }, close : function(opt){ opt = opt || {}; var container = this.container; var speed = opt.speed || this.opt.speed; var onBefore = opt.onBefore || this.opt.onCloseBefore; var onAfter = opt.onAfter || this.opt.onCloseAfter; var containerH = container.height(); onBefore(); container.animate({ top : -(containerH+10) },speed,function(){ onAfter(); container.hide().css({zIndex:-1}); }) var mask = $("#"+this.flag+"mask"); mask.fadeOut(function(){ mask.css("zIndex",0) }); $("#bindBox .close").off("click"); $("#bindBox .bind").off("click"); }, remove: function( opt ){ this.container.remove(); // this.getMask.remove(); } },PubSub);