// 搜索 ;(function($){ $(".searchBox").each(function(i,oE) { var $sForm=$(oE); $sForm.delegate(".enter","click",function(event){ var $ipt=$('.skin',$sForm); if(isNull($ipt.val())){ return $ipt.focus(), prevent_default(event); } }); }); // 模态窗打开 $(".searchBtn").click(function(event) { $(".modal-searchForm").Y_Modal({fn:{ callback:function($this){ $('.skin',$this).focus(); } }}); }); })(jQuery); $.fn.extend({ Y_Modal: function(opt) { var def={triggerBtn:null,autoSetCss:!1,bSingle:!0,bLockScroll:!0,lockall:!0,bKeyboard:!0,duration:300,fn:{before:null,callback:null,afnClose:null,bfnClose:null,fnNo:null,fnYes:null}};opt=$.extend({},def,opt); // function($this,$trigger,$closeBtn){ if(!$(this).length){return !0;} var bActive,$this=this,$contain=$('.contain',$this); $this.addClass('ysqTag-yModal').appendTo($(ysq.wrap)); opt.fn.before && opt.fn.before.call(this, $this, opt.triggerBtn); $('.zhezhao',$this).length||$this.prepend(makeMask()); opt.bKeyboard&&$(document).keydown(function(o){bActive&&27==o.keyCode&&$this[0].fnCloseDown(function(){opt.fn.fnNo && opt.fn.fnNo.call(this, $this, opt.triggerBtn) });}); $this[0].fnCloseDown = function(_FnCallback){ $this.addClass('hideOut'); // $('.skin',$this).length&&$('.skin',$this).blur(); opt.fn.bfnClose && opt.fn.bfnClose.call(this, $this, opt.triggerBtn); setTimeout(function(){ $this.fadeOut(opt.duration, function() { bActive = !1; opt.bLockScroll && unlockScroll(opt.lockall&&$('.zhezhao',$this)); _FnCallback&&_FnCallback(); $this.removeClass('showUp hideOut ysqTag-yModal'); $this[0].trigger = null; opt.autoSetCss&&$contain.removeAttr('style'); opt.fn.afnClose && opt.fn.afnClose.call(this, $this, opt.triggerBtn); }); },300); }; $this[0].fnShowUp = function (_cbk) { bActive=!0; opt.bLockScroll && lockScroll(opt.lockall&&$('.zhezhao',$this)); opt.bSingle&&$this.siblings('.ysqTag-yModal.showUp').length&&$this.siblings('.ysqTag-yModal.showUp')[0].fnCloseDown(); setTimeout(function(){ $this.fadeIn(opt.duration,function(){ _cbk&&_cbk.call(this, $this, opt.triggerBtn); opt.fn.callback && opt.fn.callback.call(this, $this, opt.triggerBtn); fnLazyloadPd($this)&&$.fn.Y_LazyLoad.Init($this,!1); opt.autoSetCss&&setCss(); // 延时绑定 setTimeout(function(){ $this.find('.close').off(TouchEd+'.Y_Modal').on(TouchEd+'.Y_Modal', function(event) { var $btn=$(this); $this[0].fnCloseDown(function(){ opt.fn.fnNo && opt.fn.fnNo.call(this, $this, opt.triggerBtn, $btn); $this.find('.close').off(TouchEd+'.Y_Modal'); }); return prevent_default(event); }); $this.find('.ok').off(TouchEd+'.Y_Modal').on(TouchEd+'.Y_Modal', function() { var $btn=$(this); $this[0].fnCloseDown(function(){ opt.fn.fnYes && opt.fn.fnYes.call(this, $this, opt.triggerBtn, $btn); $this.find('.ok').off(TouchEd+'.Y_Modal'); }); }); },150); }).addClass('showUp'); },300); }; $(document).off('keydown.Y_Modal').on('keydown.Y_Modal', function(event) { if(event.keyCode==27){$this[0].fnCloseDown(function(){opt.fn.fnNo && opt.fn.fnNo.call(this, $this, opt.triggerBtn) });}; }); // $this.click(function(event) { // if(event.target == this){ // $this.find('.close').trigger(TouchEd+'.Y_Modal') // } // }); if (opt.autoSetCss) { w.resize(function() {setCss(); }); function setCss() { if (bActive) { var _th = $contain.outerHeight(), _wh = w.height(); var _css = 1.025*_th>=_wh?{top:(_wh*.05)}:{top:((_wh-_th)/2)}; // console.log() $contain.css(_css); } }; } // sTrigger?$b.delegate(sTrigger,TouchEd,function(g){$this[0].fnShowUp();$this[0].trigger=this;}):$this[0].fnShowUp(); $this[0].fnShowUp(); return this; } })