You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

324 lines
8.1 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//全局函数公共类
//需要JQurey.1.4.4以上支持
//BY SHW 2011.3.1
function Code(e){
var _this=this;
var nowDom=$(e);
//缩略图
this.sPic=function(w,h){
for(var i=0;i<nowDom.length;i++){
var thisDom=$(nowDom[i]);
var nowW=parseInt(thisDom.css("width"));
var nowH=parseInt(thisDom.css("height"));
var isOver=(nowW/nowH)-(w/h);
var nw=w-2;
var nh=h-2;
if(isOver>=0){
thisDom.css("width",w+"px");
}else{
thisDom.css("height",nh+"px");
nowW=parseInt(thisDom.css("width"));
nowH=parseInt(thisDom.css("height"));
var mLeft=(nw-nowW)/2;
var mTop=(nh-nowH)/2;
thisDom.css({margin:mTop+"px "+mLeft+"px "+mTop+"px "+mLeft+"px"});
var thisBox=$("<div><\/div>");
thisDom.clone().prependTo(thisBox);
thisBox.css({width:nw+"px",height:nh+"px",border:"1px solid #DDD"});
thisDom.after(thisBox);
thisDom.remove();
}
}
}
//选项卡(点击切换)
this.tabs=function(title,box,on,isClick){
var nowTit=nowDom.find(title);
var nowOn=0;
var onClass=on.replace(".","");
$(title).each(function(i){
if($(this).hasClass(onClass)){
nowOn=i;
}
});
if(nowOn=="undefined"){
var nowOn=nowDom.find(title+on).index();//ie6失效
}
var nowBox=nowDom.find(box);
nowBox.hide();
nowBox.eq(nowOn).show();
if(isClick){
nowTit.click(function(){
nowTit.removeClass(onClass);
$(this).addClass(onClass);
$(title).each(function(i){
if($(this).hasClass(onClass)){
nowOn=i;
}
});
if(nowOn=="undefined"){
nowOn=$(this).index();//ie6失效
}
nowBox.hide();
nowBox.eq(nowOn).show();
});
}else{
nowTit.hover(function(){
nowTit.removeClass(onClass);
$(this).addClass(onClass);
$(title).each(function(i){
if($(this).hasClass(onClass)){
nowOn=i;
}
});
nowBox.hide();
nowBox.eq(nowOn).show();
});
}
}
//切换效果(鼠标切换)
this.tabMouse=function(title,box,on,t,canBack,nowIndex){
var nowTit=nowDom.find(title);
var nowOn=0;
var onClass=on.replace(".","");
$(title).each(function(i){
if($(this).hasClass(onClass)){
nowOn=i;
}
});
if(nowOn=="undefined"){
var nowOn=nowDom.find(title+on).index();//ie6失效
}
var nowBox=nowDom.find(box);
if(t==null)var t=99999999;
if(canBack){
nowEq=nowOn;
if(nowOn<=0){nowEq=0}
}
nowBox.hide();
if(nowIndex>0){nowBox.eq(nowIndex-1).show();
}else{
nowBox.eq(nowOn).show();}
var setTimeBack;
var setTimeOn=setInterval(function(){
nowShow=nowDom.find(title+on).index();
nowShow++;
if(nowShow>=nowTit.length)nowShow=0;
nowTit.removeClass(onClass);
nowTit.eq(nowShow).addClass(onClass);
nowBox.hide();
nowBox.eq(nowShow).show();
},t);
nowDom.hover(function(){
nowTit.mouseover(function(){
clearInterval(setTimeOn);
clearInterval(setTimeBack);
var nowClass="";
var nowClass=$(this).attr("class");
alert(nowClass);
var isFirst=nowClass.indexOf("first");
//var nowClick=$(this).index();
nowTit.removeClass(onClass);
if(isFirst==-1){$(this).addClass(onClass);}
$(title).each(function(i){
if($(this).hasClass(onClass)){
nowOn=i;
}
});
if(nowOn=="undefined"){
nowOn=$(this).index();//ie6失效
}
nowBox.hide();
nowBox.eq(nowOn).show();
});
},function(){
var nowClass=nowTit.eq(nowEq).attr("class");
var isFirst=nowClass.indexOf("first");
if(canBack){
setTimeBack=setTimeout(function(){
nowTit.removeClass(onClass);
if(isFirst!=0)nowTit.eq(nowEq).addClass(onClass);
nowBox.eq(nowEq).show();
},1500);
}
setTimeOn=setInterval(function(){
nowShow=nowDom.find(title+on).index();
nowShow++;
if(nowShow>=nowTit.length)nowShow=0;
nowTit.removeClass(onClass);
nowTit.eq(nowShow).addClass(onClass);
nowBox.hide();
nowBox.eq(nowShow).show();
},t);
});
}
//tips
this.tips=function(){
var x = 10;
var y = 18;
nowDom.hover(function(e){
this.myTitle = this.title;
this.title = "";
var tooltip = "<div class='tooltip'>"+ this.myTitle +"</div>";
$("body").append(tooltip);
$(".tooltip").css({"position":"absolute","top":(e.pageY+y)+"px","left":(e.pageX+x)+"px"}).show("fast");
},function(){
this.title = this.myTitle;
$(".tooltip").remove();
});
}
//无间滚动
this.domScroll=function(times){
var scrollTimer;
if(times==null)var times=1500;
nowDom.hover(function(){
clearInterval(scrollTimer);
},function(){
scrollTimer = setInterval(function(){
scrollNews(nowDom);
}, times );
}).trigger("mouseleave");
}
function scrollNews(obj){
var $self = obj.find("ul:first");
var lineHeight = $self.find("li:first").height(); //获取行高
$self.animate({ "marginTop" : -lineHeight +"px" }, 600 , function(){
$self.css({marginTop:0}).find("li:first").appendTo($self); //appendTo能直接移动元素
})
}
//模块展开和关闭(默认为隐藏状态)
this.showAndHide=function(Box){
nowDom.toggle(function(){
$(Box).show();
},function(){$(Box).hide();});
}
//模块关闭和展开(默认为展示状态)
this.hideAndShow=function(Box){
nowDom.toggle(function(){
$(Box).hide();
},function(){$(Box).show();});
}
//hoverClass防止IE6伪类处理失败
this.hoverClass=function(className){
nowDom.hover(function(){$(this).addClass(className);},function(){$(this).removeClass(className);});
}
//隔行样式交替
this.evenReplace=function(className){
$(e+":even").addClass(className);
}
//表单验证
this.formRed=function(type){
var theStr=nowDom.val();
switch(type){
case "email":
var xre=/^[a-zA-Z0-9_-_\.]+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/ig;
var nStr=theStr.match(xre);
if(nStr!=null){
return true;
}else{return false;}
break;
case "tel":
var xre=/^([0-9]|[\-])+$/ig;
var nStr=theStr.match(xre);
if(nStr!=null && theStr.length>=5){
return true;
}else{return false;}
break;
case "num":
var xre=/[0-9]+$/ig;
var nStr=theStr.match(xre);
if(nStr!=null){
return true;
}else{return false;}
break;
default:
if(theStr!=null){
return true;
}else{return false;}
}
}
//动态加载广告
this.loadAds=function(pic,url,target){
var nowPic="<img src='"+pic+"'/>";
var theTarget="";
if(target!=null) theTarget="target='"+target+"'";
if(url!=null) var nowPic="<a href='"+url+"' "+theTarget+" >"+nowPic+"</a>";
nowDom.append(nowPic);
}
//遮照层
this.overBox=function(str){
var bottomDom=$("<div></div>");
var overDom=$("<div><p id='closeOverBox'>Close X</p></div>");
$("body").append(bottomDom);
$("body").append(overDom);
bottomDom.css({width:"100%",height:"100%",display:"block",opacity:"0.7","z-index":"999"});
$("#closeOverBox").click(function(){
bottomDom.remove();
overDom.remove();
});
}
//队列
this.orderCode=function(orderFun){
nowDom.queue('orderList',orderFun);
nowDom.dequeue('orderList');
}
}
Cht=function(e){
var str=e;
return new Code(e);
}
var doOrder=function(e){$(e).dequeue('orderList');}
/*其他公用*/
document.write ('<script language="javascript" type="text/javascript" src="/js/jquery.boxy.js"></script>');
var allDialogs = [];
var seq = 0;
var bottomclose = '<div class="boxy_bottom"><a onclick="Boxy.get(this).hide(); return false" class="close">CLOSE X</a></div>';
function iframe(url,w,h){
return '<iframe id="Dialog-iframe" frameborder="0" src="'+url+'" style="width: '+w+'px; height: '+h+'px;"></iframe>';
}
function CreateBoxy(tit,cnt,options){
options = $.extend({title: tit}, options || {});
var dialog = new Boxy(cnt, options);
allDialogs.push(dialog);
return false;
}
function ShowIFrame(title,url,w,h,closeplace){
var options;
var cnt = iframe(url,w,h);
if(closeplace=='top'){
options = {fixed: false,modal: true}
}
else if(closeplace=='bottom'){
options = {fixed: false,modal: true,closeable: false}
cnt = cnt + bottomclose;
}
else{
options = {fixed: false,modal: true,closeable: false}
}
return CreateBoxy(title,cnt,options);
}
//打开发送邮件窗口
function ShowSendMail(){
return ShowIFrame('','/forms/sendmail.aspx',610,510,'bottom');
}