var zindex=100;
//弹出窗口插件
(function($){
var b=null;
var c=null;
$.fn.window=function(options){
$win=$(window);
var options=$.extend({},$.fn.window.defaults,options);
return this.each(function(){
var _this=this;
if(options.shadow)
b = $("
").hide().appendto('body').show();
if($(_this).find(".dialog-head").length==0){
zindex=zindex+1;
//win标题
var title_name="";
$(_this).attr("title")?title_name=$(_this).attr("title") : title_name=options.title;
var iframestr="";
var str=""
+iframestr+"
"
+$(_this).html()
+"
";
$("body").append($(_this).html(str));
}else{
var title_name="";
$(_this).attr("title")?title_name=$(_this).attr("title") : title_name=options.title;
$(_this).find(".win_title").html(title_name);
}
//关闭win
win_close=function(e){
if(b!=null)b.remove();
var st=$(e).parent().parent().parent();
if(options.cleardata)
st.html("");
st.css("display","none");
}
if(options.closed){
if(options.cleardata)
$(_this).html("");
$(_this).css("display","none");
if(b!=null)b.remove();
}else{
zindex=zindex+1;
$(_this).css("z-index",zindex);
setwincenter();
$(_this).find(".dialog").css("display","block");
$(_this).show();
if(options.move)drag();
}
/*
* 居中显示
*/
function setwincenter(){
var width = $(_this).width(), lt = calposition(width);
$(_this).css({
left: lt[0],
top: lt[1]
});
if(options.top>0){
$(_this).css({
top: options.top
});
}
if(options.left>0){
$(_this).css({
left: options.left
});
}
if(b!=null){
var $h = $("body").height(), $wh = $win.height(),$hh=$("html").height();
$h = math.max($h, $wh);
b.height($h).width($win.width()+$win.scrollleft()) ;
}
}
/*
* 计算window的位置
*/
function calposition(w){
l = $win.scrollleft()+(($win.width() - w) / 2);
if(l<5)l=5;
t = $win.scrolltop() + $win.height() /9;
if(t<80){
t=80;
}
return [l, t];
}
/*
* 拖拽函数drag
*/
function drag(){
$(_this).find('.window-header-move').mousedown(function(e){
var dx, dy, moveout;
c=$(this).parent().parent();
var t =$(this).parent();
t.bind("selectstart", function(){
return false;
});
dx = e.clientx - parseint(c.css("left"));
dy = e.clienty - parseint(c.css("top"));
c.mousemove(move).mouseout(out).css('opacity', 0.8);
t.mouseup(up);
function move(e){
moveout = false;
if (e.clientx - dx < 0) {
l = 0;
}
else
if (e.clientx - dx > $win.width() - c.width()) {
l = $win.width() - c.width();
}
else {
l = e.clientx - dx
}
c.css({
left: l,
top: e.clienty - dy
});
}
function out(e){
moveout = true;
settimeout(function(){
moveout && up(e);
}, 10);
}
function up(e){
c.unbind("mousemove", move).unbind("mouseout", out).css('opacity', 1);
t.unbind("mouseup", up);
}
});
}
});
};
$.fn.window.defaults={
notitle: false,
opacity:0.7,
title:"菜单窗口",
shadow: false,
target:null,
requesttype:null,//iframe,ajax,img
winurl:"img/",
iframewh: {
width: 400,
height: 300
},
top:0,
left:0,
move:true,
cleardata:false,
closed:true
};
})(jquery);
function ontips(obj){
obj.each(function(){
var e=$(this);
var title=e.attr("title");
var trigger=e.attr("data-toggle");
e.attr("title","");
if (trigger=="" || trigger==null){trigger="hover";}
if (trigger=="hover"){
e.mouseover(function(){
$showtips(e,title);
});
}else if(trigger=="click"){
e.click(function(){
$showtips(e,title);
});
}else if(trigger=="show"){
e.ready(function(){
$showtips(e,title);
});
}
});
$showtips=function(e,title){
var trigger=e.attr("data-toggle");
var place=e.attr("data-place");
var width=e.attr("data-width");
var css=e.attr("data-style");
var image=e.attr("data-image");
var content=e.attr("content");
var getid=e.attr("data-target");
var data=e.attr("data-url");
var x=0;
var y=0;
var html="";
var detail="";
if(image!=null){detail=detail+'';}
if(content!=null){detail=detail+''+content+'
';}
if(getid!=null){detail=detail+$(getid).html();}
if(data!=null){detail=detail+$.ajax({url:data,async:false}).responsetext;}
if(title!=null && title!=""){
if(detail!=null && detail!=""){detail=''+title+'
'+detail;}else{detail=''+title+'
';}
}
detail=''+detail+'
';
html=$(detail);
$("body").append( html );
if(width!=null){
html.css("width",width);
}
if(place=="" || place==null){place="top";}
if(place=="left"){
x=e.offset().left - html.outerwidth()-5;
y=e.offset().top - html.outerheight()/2 + e.outerheight()/2;
}else if(place=="top"){
x=e.offset().left - html.outerwidth()/2 + e.outerwidth()/2;
y=e.offset().top - html.outerheight()-5;
}else if(place=="right"){
x=e.offset().left + e.outerwidth()+5;
y=e.offset().top - html.outerheight()/2 + e.outerheight()/2;
}else if(place=="bottom"){
x=e.offset().left - html.outerwidth()/2 + e.outerwidth()/2;
y=e.offset().top + e.outerheight()+5;
}
if (css!=""){html.addclass(css);}
html.css({"left":x+"px","top":y+"px","position":"absolute","z-index":"100000"});
if (trigger=="hover" || trigger=="click" || trigger==null){
e.mouseout(function(){html.remove();e.attr("title",title)});
}
};
}
//图片轮播
function spell_banner(){
$('.banner').each(function(){
var e=$(this);
e.find(".pointer").remove();
var pointer=e.attr("data-pointer");
var interval=e.attr("data-interval");
var style=e.attr("data-style");
var items=e.attr("data-item");
var items_s=e.attr("data-small");
var items_m=e.attr("data-middle");
var items_b=e.attr("data-big");
var num=e.find(".carousel .item").length;
var win=$(window).width();
var i=1;
if(interval==null){interval=5};
if(items==null || items<1){items=1};
if(items_s!=null && win>760){items=items_s};
if(items_m!=null && win>1000){items=items_m};
if(items_b!=null && win>1200){items=items_b};
var itemwidth=math.ceil(e.outerwidth()/items);
var page=math.ceil(num/items);
e.find(".carousel .item").css("width",itemwidth+ "px");
e.find(".carousel").css("width",itemwidth*num + "px");
$showbanner(e,1,items,num);//重新轮播
if(pointer!=0 && page>1){
var point='-
';
for (var j=1;j ';
};
point=point+'
';
var pager=$(point);
if(style!=null){pager.addclass(style);};
e.append(pager);
pager.css("left",e.outerwidth()*0.5 - pager.outerwidth()*0.5+"px");
pager.find("li").click(function(){
$showbanner(e,$(this).val(),items,num);
});
};
});
$showbanner=function(e,i,items,num){
var after=0,leftx=0;
leftx = - math.ceil(e.outerwidth()/items)*(items)*(i-1);
if(i*items > num){after=i*items-num;leftx= - math.ceil(e.outerwidth()/items)*(num-items);};
e.find(".carousel").stop(true, true).animate({"left":leftx+"px"},800);
e.find(".pointer li").removeclass("active");
e.find(".pointer li").eq(i-1).addclass("active");
};
}
$(function(){
//-------------
// icons
//-------------
$('[class^="icon-"],[class*=" icon-"]').each(function () {
var self = $(this);
if (!self.hasclass('icon-xxx')) {
self.addclass('icon-xxx');
}
});
$(".win-homepage").click(function(){
if(document.all){
document.body.style.behavior = 'url(#default#homepage)';
document.body.sethomepage(document.url);
}else{alert("设置首页失败,请手动设置!");}
});
$(".win-favorite").click(function(){
var surl=document.url;
var stitle=document.title;
try {window.external.addfavorite(surl, stitle);}
catch(e){
try{window.sidebar.addpanel(stitle, surl, "");}
catch(e){alert("加入收藏失败,请使用ctrl+d进行添加");}
}
});
$(".win-forward").click(function(){
window.history.forward(1);
});
$(".win-back").click(function(){
window.history.back(-1);
});
$(".win-backtop").click(function(){$('body,html').animate({scrolltop:0},1000);return false;});
$(".win-refresh").click(function(){
window.location.reload();
});
$(".win-print").click(function(){
window.print();
});
$(".win-close").click(function(){
window.close();
});
$('.checkall').click(function(){
var e=$(this);
var name=e.attr("name");
var checkfor=e.attr("checkfor");
var type;
if (checkfor!='' && checkfor!=null && checkfor!=undefined){
type=e.closest('form').find("input[name='"+checkfor+"']");
}else{
type=e.closest('form').find("input[type='checkbox']");
};
if (name=="checkall"){
$(type).each(function(index, element){
element.checked=true;
});
e.attr("name","ok");
}else{
$(type).each(function(index, element){
element.checked=false;
});
e.attr("name","checkall");
}
});
$('.dropdown-toggle').click(function(){
$(this).closest('.button-group, .drop').addclass("open");
});
$(document).bind("click",function(e){
if($(e.target).closest(".button-group.open, .drop.open").length == 0){
$(".button-group, .drop").removeclass("open");
}
});
$checkplaceholder=function(){
var input = document.createelement('input');
return 'placeholder' in input;
};
if(!$checkplaceholder()){
$("textarea[placeholder], input[placeholder]").each(function(index, element){
var content=false;
if($(this).val().length ===0 || $(this).val()==$(this).attr("placeholder")){content=true};
if(content){
$(element).val($(element).attr("placeholder"));
$(element).css("color","rgb(169,169,169)");
$(element).data("pintuerholder",$(element).css("color"));
$(element).focus(function(){$hideplaceholder($(this));});
$(element).blur(function(){$showplaceholder($(this));});
}
})
};
$showplaceholder=function(element){
if( ($(element).val().length ===0 || $(element).val()==$(element).attr("placeholder")) && $(element).attr("type")!="password"){
$(element).val($(element).attr("placeholder"));
$(element).data("pintuerholder",$(element).css("color"));
$(element).css("color","rgb(169,169,169)");
}
};
var $hideplaceholder=function(element){
if($(element).data("pintuerholder")){
$(element).val("");
$(element).css("color", $(element).data("pintuerholder"));
$(element).removedata("pintuerholder");
}
};
$(document).on("blur",'textarea, input, select',function(){
var e = $(this);
if (e.attr("data-validate")) {
e.closest('.field').find(".input-help").remove();
var $checkdata = e.attr("data-validate").split(',');
var $checkvalue = e.val();
var $checkstate = true;
var $checktext = "";
if (e.attr("placeholder") == $checkvalue) {
$checkvalue = "";
}
if ($checkvalue != "" || e.attr("data-validate").indexof("required") >= 0) {
for (var i = 0; i < $checkdata.length; i++) {
var $checktype = $checkdata[i].split(':');
if (!$pintuercheck(e, $checktype[0], $checkvalue)) {
$checkstate = false;
$checktext = $checktext + "" + $checktype[1] + "";
}
}
};
if ($checkstate) {
e.closest('.form-group').removeclass("check-error");
e.parent().find(".input-help").remove();
e.closest('.form-group').addclass("check-success");
}
else {
e.closest('.form-group').removeclass("check-success");
e.closest('.form-group').addclass("check-error");
e.closest('.field').append('');
}
}
});
$pintuercheck=function(element,type,value){
$pintu=value.replace(/(^\s*)|(\s*$)/g, "");
switch(type){
case "required":return /[^(^\s*)|(\s*$)]/.test($pintu);break;
case "chinese":return /^[\u0391-\uffe5]+$/.test($pintu);break;
case "number":return /^\d+$/.test($pintu);break;
case "integer":return /^[-\+]?\d+$/.test($pintu);break;
case "plusinteger":return /^[+]?\d+$/.test($pintu);break;
case "double":return /^[-\+]?\d+(\.\d+)?$/.test($pintu);break;
case "plusdouble":return /^[+]?\d+(\.\d+)?$/.test($pintu);break;
case "english":return /^[a-za-z]+$/.test($pintu);break;
case "username":return /^[a-z]\w{3,}$/i.test($pintu);break;
case "mobile":return /^((\(\d{3}\))|(\d{3}\-))?13[0-9]\d{8}?$|15[89]\d{8}?$|170\d{8}?$|147\d{8}?$/.test($pintu);break;
case "phone":return /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/.test($pintu);break;
case "tel":return /^((\(\d{3}\))|(\d{3}\-))?13[0-9]\d{8}?$|15[89]\d{8}?$|170\d{8}?$|147\d{8}?$/.test($pintu) || /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/.test($pintu);break;
case "email":return /^[^@]+@[^@]+\.[^@]+$/.test($pintu);break;
case "url":return /^http:\/\/[a-za-z0-9]+\.[a-za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/.test($pintu);break;
case "ip":return /^[\d\.]{7,15}$/.test($pintu);break;
case "qq":return /^[1-9]\d{4,10}$/.test($pintu);break;
case "currency":return /^\d+(\.\d+)?$/.test($pintu);break;
case "zip":return /^[1-9]\d{5}$/.test($pintu);break;
case "radio":
var radio=element.closest('form').find('input[name="'+element.attr("name")+'"]:checked').length;
return eval(radio==1);
break;
default:
var $test=type.split('#');
if($test.length>1){
switch($test[0]){
case "compare":
return eval(number($pintu)+$test[1]);
break;
case "regexp":
return new regexp($test[1],"gi").test($pintu);
break;
case "length":
var $length;
if(element.attr("type")=="checkbox"){
$length=element.closest('form').find('input[name="'+element.attr("name")+'"]:checked').length;
}else{
$length=$pintu.replace(/[\u4e00-\u9fa5]/g,"***").length;
}
return eval($length+$test[1]);
break;
case "ajax":
var $getdata;
var $url=$test[1]+$pintu;
$.ajaxsetup({async:false});
$.getjson($url,function(data){
$getdata=data.getdata;
});
if($getdata=="true"){return true;}
break;
case "repeat":
return $pintu==jquery('input[name="'+$test[1]+'"]').eq(0).val();
break;
default:return true;break;
}
break;
}else{
return true;
}
}
};
$('form').submit(function(){
$(this).find('input[data-validate],textarea[data-validate],select[data-validate]').trigger("blur");
$(this).find('input[placeholder],textarea[placeholder]').each(function(){$hideplaceholder($(this));});
var numerror = $(this).find('.check-error').length;
if(numerror){
$(this).find('.check-error').first().find('input[data-validate],textarea[data-validate],select[data-validate]').first().focus().select();
return false;
}
});
$('.form-reset').click(function(){
$(this).closest('form').find(".input-help").remove();
$(this).closest('form').find('.form-submit').removeattr('disabled');
$(this).closest('form').find('.form-group').removeclass("check-error");
$(this).closest('form').find('.form-group').removeclass("check-success");
});
$('.tab .tab-nav li').each(function(){
var e=$(this);
var trigger=e.closest('.tab').attr("data-toggle");
if (trigger=="hover"){
e.mouseover(function(){
$showtabs(e);
});
e.click(function(){
return false;
});
}else{
e.click(function(){
$showtabs(e);
return false;
});
}
});
$showtabs=function(e){
var detail=e.children("a").attr("href");
e.closest('.tab .tab-nav').find("li").removeclass("active");
e.closest('.tab').find(".tab-body .tab-panel").removeclass("active");
e.addclass("active");
$(detail).addclass("active");
};
$('.dialogs').each(function(){
var e=$(this);
var trigger=e.attr("data-toggle");
if (trigger=="hover"){
e.mouseover(function(){
$showdialogs(e);
});
}else if(trigger=="click"){
e.click(function(){
$showdialogs(e);
});
}
});
$showdialogs=function(e){
var trigger=e.attr("data-toggle");
var getid=e.attr("data-target");
var data=e.attr("data-url");
var mask=e.attr("data-mask");
var width=e.attr("data-width");
var detail="";
var masklayout=$('');
if(width==null){width="80%";}
if (mask=="1"){
$("body").append(masklayout);
}
detail='';
if(getid!=null){detail=detail+$(getid).html();}
if(data!=null){detail=detail+$.ajax({url:data,async:false}).responsetext;}
detail=detail+'
';
var win=$(detail);
win.find(".dialog").addclass("open");
$("body").append(win);
var x=parseint($(window).width()-win.outerwidth())/2;
var y=parseint($(window).height()-win.outerheight())/2;
if (y<=10){y="10"}
win.css({"left":x,"top":y});
win.find(".dialog-close,.close").each(function(){
$(this).click(function(){
win.remove();
$('.dialog-mask').remove();
});
});
masklayout.click(function(){
win.remove();
$(this).remove();
});
};
ontips($('.tips'));
$('.alert .close').each(function(){
$(this).click(function(){
$(this).closest('.alert').remove();
});
});
$('.radio label').each(function(){
var e=$(this);
e.click(function(){
e.closest('.radio').find("label").removeclass("active");
e.addclass("active");
});
});
$('.checkbox label').each(function(){
var e=$(this);
e.click(function(){
if(e.find('input').is(':checked')){
e.addclass("active");
}else{
e.removeclass("active");
};
});
});
$('.collapse .panel-head').each(function(){
var e=$(this);
e.click(function(){
var obj=$(e).parent();
if(obj.hasclass("active")){
obj.removeclass("active");
}else{
e.closest('.collapse').find(".panel").removeclass("active");
obj.addclass("active");
}
});
});
$('.icon-navicon').each(function(){
var e=$(this);
var target=e.attr("data-target");
e.click(function(){
$(target).toggleclass("nav-navicon");
});
});
//图片轮播
$('.banner').each(function(){
var e=$(this);
var pointer=e.attr("data-pointer");
var interval=e.attr("data-interval");
var style=e.attr("data-style");
var items=e.attr("data-item");
var items_s=e.attr("data-small");
var items_m=e.attr("data-middle");
var items_b=e.attr("data-big");
var num=e.find(".carousel .item").length;
var win=$(window).width();
var i=1;
if(interval==null){interval=5};
if(items==null || items<1){items=1};
if(items_s!=null && win>760){items=items_s};
if(items_m!=null && win>1000){items=items_m};
if(items_b!=null && win>1200){items=items_b};
var itemwidth=math.ceil(e.outerwidth()/items);
var page=math.ceil(num/items);
e.find(".carousel .item").css("width",itemwidth+ "px");
e.find(".carousel").css("width",itemwidth*num + "px");
var carousel=function(){
i++;
if(i>page){i=1;}
$showbanner(e,i,items,num);
};
var play=setinterval(carousel,interval*600);
e.mouseover(function(){clearinterval(play);});
e.mouseout(function(){play=setinterval(carousel,interval*600);});
if(pointer!=0 && page>1){
var point='-
';
for (var j=1;j ';
};
point=point+'
';
var pager=$(point);
if(style!=null){pager.addclass(style);};
e.append(pager);
pager.css("left",e.outerwidth()*0.5 - pager.outerwidth()*0.5+"px");
pager.find("li").click(function(){
$showbanner(e,$(this).val(),items,num);
});
/*var lefter=$('');
var righter=$('');
if(style!=null){lefter.addclass(style);righter.addclass(style);};
e.append(lefter);
e.append(righter);
lefter.click(function(){
i--;
if(i<1){i=page;}
$showbanner(e,i,items,num);
});
righter.click(function(){
i++;
if(i>page){i=1;}
$showbanner(e,i,items,num);
});*/
};
});
$showbanner=function(e,i,items,num){
var after=0,leftx=0;
leftx = - math.ceil(e.outerwidth()/items)*(items)*(i-1);
if(i*items > num){after=i*items-num;leftx= - math.ceil(e.outerwidth()/items)*(num-items);};
e.find(".carousel").stop(true, true).animate({"left":leftx+"px"},800);
e.find(".pointer li").removeclass("active");
e.find(".pointer li").eq(i-1).addclass("active");
};
$(".spy a").each(function(){
var e=$(this);
var t=e.closest(".spy");
var target=t.attr("data-target");
var top=t.attr("data-offset-spy");
var thistarget="";
var thistop="";
if(top==null){top=0;};
if(target==null){thistarget=$(window);}else{thistarget=$(target);};
thistarget.bind("scroll",function(){
if(target==null){
thistop=$(e.attr("href")).offset().top - $(window).scrolltop() - parseint(top);
}else{
thistop=$(e.attr("href")).offset().top - thistarget.offset().top - parseint(top);
};
if(thistop<0){
t.find('li').removeclass("active");
e.parents('li').addclass("active");
};
});
});
$(".fixed").each(function(){
var e=$(this);
var style=e.attr("data-style");
var top=e.attr("data-offset-fixed");
if(top==null){top=e.offset().top;}else{top=e.offset().top - parseint(top);};
if(style==null){style="fixed-top";};
$(window).bind("scroll",function(){
var thistop=top - $(window).scrolltop();
if(style=="fixed-top" && thistop<0){
e.addclass("fixed-top");
}else{
e.removeclass("fixed-top");
};
var thisbottom=top - $(window).scrolltop()-$(window).height();
if(style=="fixed-bottom" && thisbottom>0){
e.addclass("fixed-bottom");
}else{
e.removeclass("fixed-bottom");
};
});
});
//win8风格
$(".tile-slider").each(function(){
var obj=$(this);
obj.mouseover(function(){
$($(this).find(".tile-content").get(0)).css("display","none");
$($(this).find(".tile-content").get(1)).css("display","block").addclass("overflow");
}).mouseout(function(){
$($(this).find(".tile-content").get(0)).css("display","block");
$($(this).find(".tile-content").get(1)).css("display","none");
});
});
})