(function(window,$,undefined){ window.popup = { numbers : 0, index : 1000, domname : ['','alert','confirm','prompt','layer','iframe','loading','taps'] } var fun = function(j_){ var that = this, jd = { addtarget : $('body'), type : 1, cname : "", shade :{yes : 1, bgcolor : '#000000', opacity : 0.5, animate : {type : 1 , target : 0.6}, close : false}, area : {w : 'auto', h : 'auto'}, offset : {fix : 1, t : 'auto',r : 'auto', b : 'auto', l : 'auto'}, zindex :{yes:0,val:1000}, animate : {type : 1, target : 1}, autoclose : {yes : 0, time : 0}, move : {yes : 1, handle : '.evpopuphead'}, head : {yes : 1, text : 'ϵͳ��ʾ'}, opbut : {yes : 1, close : 1, min : 0, max : 0}, con : { text : [1,"��ʾ��ϣ"], img : [1,"wran"], src : 'http://www.ev123.net', html : "

����html����

" }, but : { yes : 0, button : {} }, bfun : function(){} }; //�ж��������ĭ��ֵ switch(j_.type){ case 1 : jd.but.yes = 1; jd.but.button = { but_1 : {text:"ȷ��" ,fun : function(){}} } break; case 2 : jd.but.yes = 1; jd.but.button = { but_1 : {text:"ȷ��" ,fun : function(){}}, but_2 : {text:"ȡ��" ,fun : function(){}} } break; case 3 : jd.but.yes = 1; jd.but.button = { but_1 : {text:"ȷ��" ,fun : function(){}}, but_2 : {text:"ȡ��" ,fun : function(){}} } break; case 4 : break; case 5 : break; case 6 : jd.head.yes = 0; jd.opbut.yes = 0; jd.con.img[0] = 1; jd.con.img[1] = "loading"; break; case 7 : jd.head.yes = 0; jd.opbut.yes = 0; break; } that.j = $.extend(true,{},jd,j_); popup.numbers++; that.numbers = popup.numbers; if(that.j.zindex.yes){ that.index = that.j.zindex.val }else{ that.index = popup.index; } that.createdom(); }; //fun���캯��ԭ�� fun.pt = fun.prototype; //�õ����ڵŀ�ߣ�dom�ŀ�ߣ�elemnet�ŀ�� fun.pt.winattr = function(o){ this.winw = $(window).width(); this.winh = $(window).height(); this.domw = $(document).width(); this.domh = $(document).height(); this.domst = $(document).scrolltop(); this.domsl = $(document).scrollleft(); this.popupw = o.width(); this.popuph = o.height(); }; //���dom������ fun.pt.createdom = function(){ var that = this, j = that.j, evshade = $('
'), evpopup = $('
'), evremovepopup = $(''), evhidepopup = $(''), evshowpopup = $(''), evpopupopbut = $('
'), evpopuphead =$('

'+ j.head.text +'

'), evpopupbody = $('
'), evpopupcon = $('
'), evpopupbut = $('
'); //���õ���������ֵ���ʽ���������� evshade.data("dataindex",that.numbers).addclass("evshade"+popup.domname[j.type]).css({"z-index":++that.index,"background-color":j.shade.bgcolor,"opacity":j.shade.opacity}); evpopup.data("dataindex",that.numbers).addclass( "evpopup"+ popup.domname[j.type] +" "+ j.cname).css({"z-index":++that.index}); //�����ص�Ԫ����ӵ������������رյ����� evremovepopup.data("dataindex",that.numbers).on("click",function(){ that.closeanimate(evshade,j.shade.animate); that.closeanimate(evpopup,j.animate); }).appendto(evpopup); //�����ص�Ԫ����ӵ��������������ص����� evhidepopup.data("dataindex",that.numbers).on("click",function(){ that.popuphide(evshade); that.popuphide(evpopup); }).appendto(evpopup); //�����ص�Ԫ����ӵ�������������ʾ������ evshowpopup.data("dataindex",that.numbers).on("click",function(){ that.popupshow(evshade); that.popupshow(evpopup); }).appendto(evpopup); popup.index+=2; //�жϰ�ť��ʾ��� if(j.opbut.yes){ //��ӹرհ�ť if(j.opbut.close){ var opbutclose = $(''); opbutclose.attr({"title":"�ر�"}).data("dataindex",that.numbers).on({ mouseenter : function(){$(this).addclass("evopbutclosehover")}, mouseleave : function(){$(this).removeclass("evopbutclosehover")}, click : function(){ evremovepopup.trigger("click"); } }).appendto(evpopupopbut); } //�����с����ť if(j.opbut.min){ var opbutmin = $(''); opbutmin.attr({"title":"��с��"}).data("dataindex",that.numbers).on({ mouseenter : function(){$(this).addclass("evopbutminhover")}, mouseleave : function(){$(this).removeclass("evopbutminhover")}, click : function(){ } }).appendto(evpopupopbut); } //�����󻯰�ť if(j.opbut.max){ var opbutmin = $(''), opbutmaxmin = $(''); opbutmin.attr({"title":"���"}).data("dataindex",that.numbers).on({ mouseenter : function(){$(this).addclass("evopbutmanhover")}, mouseleave : function(){$(this).removeclass("evopbutmanhover")}, click : function(){ } }).appendto(evpopupopbut); opbutmaxmin.attr({"title":"��ԭ"}).data("dataindex",that.numbers).on({ mouseenter : function(){$(this).addclass("evopbutmanminhover")}, mouseleave : function(){$(this).removeclass("evopbutmanminhover")}, click : function(){ } }).appendto(evpopupopbut); } evpopupopbut.appendto(evpopup); } //���ݲ�ͬ���ͣ��ж��������� switch(j.type){ case 1 : var span = j.con.text[0] == 1 ? ''+j.con.text[1]+'' : "", img = j.con.img[0] == 1 ? '' : ""; evpopupcon.append(img,span); break; case 2 : var span = j.con.text[0] == 1 ? ''+j.con.text[1]+'' : "", img = j.con.img[0] == 1 ? '' : ""; evpopupcon.append(img,span); break; case 3 : var inpute = $('
'); if(j.con.text[0] == 1){ inpute.find("input").attr("placeholder",j.con.text[1]); } evpopupcon.append(inpute); break; case 4 : var layerhtml = typeof(j.con.html) == 'object' ? j.con.html.html() : j.con.html; evpopupcon.append(layerhtml); break; case 5 : var iframe = $(''); iframe.css({"height":"auto"}).appendto(evpopupcon); break; case 6 : var loadingimg = $('
'), img = $(''); evpopupcon.append(loadingimg.append(img)); break; case 7 : var tops = $('

'+ j.con.text[1] +'

'); evpopupcon.append(tops); break; } //������ݵ������� evpopupbody.find(".evpopupbodycc").append(evpopupcon); //��ӵ�����ť if(j.but.yes){ if(j.type == 1 || j.type == 2 || j.type == 3){ var butlength = 0,butwidth = 0,x = "",cname=""; //���ݴ���i�ť����ѭ����ӱ�ť for(x in j.but.button){ butlength++; cname = j.but.button[x]["cname"] || ""; var popupbut = $(''+ j.but.button[x]['text'] +''); popupbut.data("data-name",x).appendto(evpopupbut.children(".evpopupbut")); } //����ť���ÿ�� evpopupbut.find(".popupbut").each(function(){ $(this).width(100/butlength+"%"); }); //����ť���¼� evpopupbut.on({ click : function(){ var dataname = $(this).data('data-name'); if(typeof(j.but.button[dataname]['fun'])==='function'){ j.but.button[dataname]['fun'](); } evremovepopup.trigger("click"); } },".popupbut"); } evpopupbut.appendto(evpopup); } //�жϵ������� j.head.yes ? evpopuphead.prependto(evpopup) : "";//����������ӱ��� evpopup.append(evpopupbody).appendto(j.addtarget);//�ѵ�������ӵ�ҳ���� that.popupcountwh(evpopup); //���ú������㵯������ that.winattr(evpopup); //��ⴰ�ں�dom�ŀ�ߡ� //���� if(j.shade.yes){ evshade.appendto(j.addtarget);//�ж�������� that.shadecountwh(evshade);//�������ֵŀ�� that.openanimate(evshade,j.shade.animate);//���ֶ��� //�ж��ƿ��������ӵ���¼� j.shade.close ? evshade.on("click",function(){ that.closeanimate(evshade,j.shade.animate); that.closeanimate(evpopup,j.animate); }) : ""; } that.popupoffset(evpopup); that.openanimate(evpopup,j.animate); //�զ��ر� if(j.autoclose.yes){ settimeout(function(){ evremovepopup.trigger("click"); },j.autoclose.time*1000); //that.autoclose(evpopup); } if(j.move.yes){ that.popupmove(evpopup); } }; //�������߼��� fun.pt.popupcountwh = function(evpopup){ var that = this, j = that.j, hh = 0, buth = 0, ch = 0, lh= 0, evpopupbodycc = evpopup.find(".evpopupbodycc"); if(j.head.yes){ hh = evpopup.find(".evpopuphead").height(); var padt = hh - evpopup.children("div.evpopupbody").children('div.evpopupbodyt').height(); evpopupbodycc.css({"padding-top":padt+"px"}); ch -=hh; } if(j.but.yes){ buth = evpopup.find(".evpopupbutarea").height(); evpopupbodycc.css({"padding-bottom":buth+"px"}); ch = ch-buth; } if(j.area.w != "auto"){ evpopup.css({"width":j.area.w+"px"}); } if(j.area.h != "auto"){ evpopup.css({"height":j.area.h+"px"}); ch = j.area.h - evpopup.children("div.evpopupbody").children('div.evpopupbodyt').height() - evpopup.children("div.evpopupbody").children('.evpopupbodyb').height()+ch; }else{ ch = evpopup.height()-evpopup.children("div.evpopupbody").children('div.evpopupbodyt').height() - evpopup.children("div.evpopupbody").children('.evpopupbodyb').height()+ch; } evpopupbodycc.css({"height":ch+"px"}); if(j.type == 5){ if(j.area.w == 'auto' && j.area.h == 'auto'){ var loadingwait = $('
'), loadh = evpopupbodycc.outerheight(), iframes = evpopupbodycc.find("iframe"); loadingwait.css({"height":loadh + "px"}).appendto(evpopupbodycc); iframes.load(function(){ loadingwait.remove(); iframes[0].contentwindow.iframenumber = that.numbers; var iw = iframes.contents().width(), ih = iframes.contents().height(); evpopupbodycc.children("div.eviframecon").css({"width":iw+"px","height":ih+"px"}); iframes.css({"width":iw+"px","height":ih+"px"}); var iew = evpopup.find(".evpopupbodyc").outerwidth(); evpopup.css({"width":iew+"px"}); that.winattr(evpopup); that.popupoffset(evpopup); }); }else{ var iw = evpopup.children(".evpopupbody").find("div.eviframecon").width(), ih = evpopup.children(".evpopupbody").find("div.eviframecon").height(), loadingwait = $('
'), loadh = evpopupbodycc.outerheight(), iframes = evpopupbodycc.find("iframe"); loadingwait.css({"height":loadh + "px","width":"100%"}).appendto(evpopupbodycc); iframes.css({"width":iw+"px","height":ih+"px","top":"10px"}); iframes.load(function(){ iframes[0].contentwindow.iframenumber = that.numbers; loadingwait.remove(); }); } }else{ if ( $.browser.msie){ if( $.browser.version == 7 || $.browser.version == 6){ var iew = evpopup.find(".evpopupbodyc").outerwidth(); evpopup.css({"width":(iew+10)+"px"}); } } } if(j.type == 6){ if(j.area.w == 'auto' && j.area.h == 'auto'){ var img = evpopupbodycc.find("img"); img.load(function(){ var iw = img.width(), ih = img.width(); evpopupbodycc.children("div.evloadingcon").css({"width":iw+"px","height":ih+"px"}); that.winattr(evpopup); that.popupoffset(evpopup); }) } } }; //���ֵŀ�߼��� fun.pt.shadecountwh = function(evshade){ var that = this, j = that.j; if(j.offset.fix){ evshade.css({"position":"fixed","left":"0px","top":"0px","width":that.winw+"px","height":that.winh+"pc"}); }else{ evshade.css({"position":"absolute","left":"0px","top":"0px","width":that.winw+"px","height":that.domh+"px"}); } } fun.pt.popupoffset = function(evpopup){ var that = this, j = that.j, t = 0, l = 0; if(j.offset.fix){ evpopup.css({"position":"fixed"}); if(j.offset.t == "auto"){ t = (that.winh - that.popuph)/2; }else{ t = j.offset.t; } }else{ if(j.offset.t == "auto"){ t = that.domst + (that.winh - that.popuph)/2; }else{ t = that.domst+j.offset.t; } } if(j.offset.l!="auto"){ l = j.offset.l; }else{ l = (that.winw - that.popupw)/2; } if(t<0){t=0;} evpopup.css({"left":l+"px","top":t+"px"}); }; fun.pt.openanimate = function(o,an){//�򿪶���ч�� switch (an.type){ case 0 : break; case 1 : o.css({"opacity":0}); o.animate({"opacity":an.target},300); break; case 2 : var objh = o.height(); o.css({"margin-top":-objh+"px","opacity":0}); o.animate({margintop:0,opacity:1},300); break; case 3 : var objw = o.width(); o.css({"margin-left":objw+"px","opacity":0}); o.animate({marginleft:0,opacity:1},300); break; case 4 : var objh = o.height(); o.css({"margin-top":objh+"px","opacity":0}); o.animate({margintop:0,opacity:1},300); break; case 5 : var objw = o.width(); o.css({"margin-left":-objw+"px","opacity":0}); o.animate({marginleft:0,opacity:1},300); break; } }; fun.pt.closeanimate = function(o,an){//�رն���ч�� switch (an.type){ case 0 : o.remove(); break; case 1 : o.animate({"opacity":0},300,function(){ o.remove(); }); break; case 2 : var objh = o.height(); o.animate({margintop:-objh,opacity:0},300,function(){ o.remove(); }); break; case 3 : var objw = o.width(); o.animate({marginleft:objw,opacity:0},300,function(){ o.remove(); }); break; case 4 : var objh = o.height(); o.animate({margintop:objh,opacity:0},300,function(){ o.remove(); }); break; case 5 : var objw = o.width(); o.animate({marginleft:-objw,opacity:0},300,function(){ o.remove(); }); break; } }; //�����϶��¼� fun.pt.popupmove = function(evpopup){ var that = this, j = that.j; evpopup.find(j.move.handle).on({ mousedown : function(ev){ that.winattr(evpopup); var ev = ev || window.event, objw = evpopup.width(), objh = evpopup.height(), objl = evpopup.offset().left, objt = evpopup.offset().top, zindex = evpopup.css("z-index")*1+1, startx = ev.pagex, starty = ev.pagey, clickw = startx - objl, clickh = starty - objt, movex = 0, movey = 0, endl = 0, endt = 0, movepx = 0, moveobj = $('
'); moveobj.css({"width":objw+"px","height":objh+"px","left":objl+"px","top":objt+"px","z-index":zindex}).children("div").css({"height":(objh-2)+"px"}); $(document).on({ mousemove : function(ev){ var ev = ev || window.event; movepx = math.abs(ev.pagex - startx); if(movepx > 1){ if(moveobj.data("data-have") != 1){ moveobj.appendto(j.addtarget); moveobj.data("data-have",1); } $(document).find("body").css({"cursor":"move"}); endl = movex = ev.pagex - clickw; endt = movey = ev.pagey - clickh; if(movex < 0){ movex = 0; endl = 0; }else if(movex > (that.winw - objw)){ movex = that.winw - objw; endl = that.winw - objw; } if(j.offset.fix){ endt = ev.pagey - clickh - that.domst; if(movey < that.domst){ movey = that.domst; endt = 0; }else if(movey > (that.domst + that.winh - objh)){ movey = that.domst + that.winh - objh; endt = movey - that.domst; } }else{ if(movey < 0){ movey = 0; endt = 0; }else if(movey > that.domh - objh){ movey = that.domh - objh; endt = that.domh - objh; } } moveobj.css({"left" : movex + "px","top" : movey + "px"}); } return false; }, mouseup : function(){ if(movepx>1){ moveobj.remove(); $(this).off("mousemove mouseup"); evpopup.css({"left" : endl+"px","top" : endt+"px"}); $(document).find("body").css({"cursor":"default"}); } $(this).off("mousemove mouseup"); } }) return false; } }) }; //����popup���� fun.pt.popuphide = function(o){ o.css({display:"none"}); /*o.animate({opacity:0},300,function(){ $(this).css({display:"none"}); });*/ }; fun.pt.popupshow = function(o){ o.css({display:"block"}); }; $.popup = function(j){ var o = new fun(j); return o.numbers; }; $.popupclose = function(numbers){ $('body').children("div.evpopup").each(function(){ if($(this).data("dataindex") ==numbers){ $(this).children("small.rmovepopup").trigger("click"); } }) }; $.popuphide = function(numbers){ $('body').children("div.evpopup").each(function(){ if($(this).data("dataindex") == numbers){ $(this).children("small.hidepopup").trigger("click"); } }) }; $.popupshow = function(numbers){ $('body').children("div.evpopup").each(function(){ if($(this).data("dataindex") == numbers){ $(this).children("small.showpopup").trigger("click"); } }) }; })(window,jquery,undefined);