/*
* 图片切换api
* */
(function($) {
$.smallslider=function(elm, options){
// this 为当前的smallslider对象,为了区别,使用 _this 替换
var _this = this;
_this.elm = elm ; // elm 为当前的 dom对象 ,即使用class="smallslider" 的那个div对象。
_this.$elm = $(elm); // $elm 为elm对象的jquery形式
_this.opts=$.extend({},$.smallslider.defaults, options);
_this.slidertimer= null ;
// 初始化对象
_this.init = function()
{
_this.$ul = _this.$elm.find('>ul') ; // 为子元素ul
_this.$lis = _this.$elm.find('li') ; // 为所有ul下子元素li 数组
_this.$ims = _this.$elm.find('img') ; // 为所有li下子元素img 数组
_this.itemnums = _this.$lis.length ;
_this.width = _this.$elm.width();
_this.height = _this.$elm.height();
_this.current = 0 ; // 当前的index索引
if(_this.itemnums > 1)
{
if(_this.opts.switcheffect=='ease')
{
_this.$ul.css({
position:'absolute',
left:0,
top: 0
});
if(_this.opts.switchpath=='left')
{
var width = _this.itemnums * _this.width;
_this.$lis.css({
'float' : 'left'
});
_this.$ul.css({
'width' : width
});
}
else if(_this.opts.switchpath=='up')
{
var height = _this.itemnums * _this.height;
_this.$ul.css({
'height' : height
});
}
}
else if(_this.opts.switcheffect=='fadeout')
{
_this.$ul.css({
position:'relative'
});
_this.$lis.css({
position:'absolute',
zindex:1
}).eq(0).css({
zindex:2
});
}
if(_this.opts.showbuttons)
{
_this.createbuttons(); // 创建按钮。
}
if(_this.opts.showtext)
{
_this.createtext(); // 创建文字显示。
}
if(_this.opts.autostart)
{
_this.startslider(1);
}
if(_this.opts.onimagestop)
{
_this.onimage();
}
}
};
_this.createbuttons = function()
{
var buttons='';
for(var i=1; i <= _this.itemnums ; i++ ){
buttons += ''+i+'';
}
buttons ='
' + buttons + '
';
var left=0,right=0,top =0,bottom=0;
var style_btns={};
switch(_this.opts.buttonposition){
case 'lefttop':
left = _this.opts.buttonoffsetx;
top = _this.opts.buttonoffsety;
style_btns={left: left + 'px' , top: top+'px'};
break;
case 'righttop':
right = _this.opts.buttonoffsetx;
top = _this.opts.buttonoffsety;
style_btns={right: right + 'px' , top: top+'px'};
break;
case 'rightbottom':
right = _this.opts.buttonoffsetx;
bottom = _this.opts.buttonoffsety;
style_btns={right: right + 'px' ,bottom: bottom+'px'};
break;
case 'leftbottom':
left = _this.opts.buttonoffsetx;
bottom = _this.opts.buttonoffsety;
style_btns={left: left + 'px' ,bottom: bottom+'px'};
break;
}
$(buttons).css(style_btns).appendto(_this.$elm);
_this.$btns = _this.$elm.find('span');
_this.$elm.find('span:not(:first)').css({marginleft: _this.opts.buttonspace+'px'});
_this.$btns.removeclass('current-btn');
_this.$btns.eq(0).addclass('current-btn');
if(_this.opts.switchmode=='click'){
_this.$btns.click(function(){
var ix = _this.$btns.index($(this));
_this.slideto(ix); // 表示需要切换到哪一张
});
}else if(_this.opts.switchmode=='hover'){
_this.$btns.hover(function(){
var ix = _this.$btns.index($(this));
_this.slideto(ix);
});
}
};
// 创建标题标签
_this.createtext = function(){
var style_tex={};
switch(_this.opts.buttonposition){
case 'lefttop':
style_tex={left:0, top:0,textalign:'right'};
_this.textposition = 'top';
break;
case 'righttop':
style_tex={left:0, top:0,textalign:'left'};
_this.textposition = 'top';
break;
case 'rightbottom':
style_tex={left:0,bottom:0,textalign:'left'};
_this.textposition = 'bottom';
break;
case 'leftbottom':
style_tex={left:0,bottom:0,textalign:'right'};
_this.textposition = 'bottom';
break;
}
if(_this.opts.textposition){
switch(_this.opts.textposition)
{
case 'top':
style_tex.left = 0 ; style_tex.top = 0;
break;
case 'bottom':
style_tex.left = 0 ; style_tex.bottom=0 ;
break;
}
_this.textposition = _this.opts.textposition ;
}
if(_this.opts.textalign)
{
style_tex.textalign =_this.opts.textalign;
}
$('').css(style_tex).css({
opacity:0.39
}).appendto(_this.$elm);
var tex0= _this.$ims.eq(0).attr('alt');
if(_this.opts.textlink){
tex0 = ''+ tex0+'';
}
$('').css(style_tex).html(tex0).appendto(_this.$elm);
_this.$h3 = _this.$elm.find('h3');
_this.$lay = _this.$elm.find('div.smallslider-lay');
_this.$tex = _this.$elm.find('.smallslider-tex');
};
_this.onimage =function(){
_this.$ims.hover(function(){
_this.stopslider();
}, function(){
_this.slideto(_this.current+1);
});
};
_this.slideto = function (index){
_this.stopslider(); // 先清掉以前的settimeout;
if(index > _this.itemnums -1) index = 0;
if(index < 0 ) index = _this.itemnums -1 ;
// 切换表示当前元素
_this.$lis.removeclass('current-li').eq(index).addclass('current-li');
if(_this.opts.showbuttons)
{
_this.$btns.removeclass('current-btn');
_this.$btns.eq(index).addclass('current-btn');
}
_this.slidetext(index);
var chattr = '';
var ic = 0;
switch(_this.opts.switchpath)
{
case 'left':
chattr = 'left';
ic =_this.width ;
break;
case 'up':
default :
chattr = 'top';
ic = _this.height ;
break;
}
var icx = -1 * index * ic; // top或left 变化量
var switchease = _this.opts.switchease ;
switch( _this.opts.switcheffect){
case 'fadeout':
_this.$lis.stop(true,false);
_this.$lis.css({zindex:1,opacity:1}).hide();
_this.$lis.eq(_this.current).css({zindex:3}).show();
_this.$lis.eq(index).css({zindex:2}).show();
if(_this.current != index)
{
_this.$lis.eq(_this.current).fadeout(_this.opts.switchtime,function(){
_this.$lis.css({zindex:1});
_this.$lis.eq(index).css({zindex:3,opacity:1}).show();
});
}
break;
case 'ease':
_this.$ul.stop(true,false);
if(chattr=='top')
_this.$ul.animate({top : icx}, {duration: _this.opts.switchtime, easing: switchease, complete: function(){
}
});
else if(chattr=='left')
_this.$ul.animate({left : icx}, {duration: _this.opts.switchtime, easing: switchease ,complete:function(){
}});
break;
case 'none':
default :
_this.$lis.eq(_this.current).hide();
_this.$lis.eq(index).show();
break;
}
_this.current = index ;
_this.startslider(index+1);
};
// 切换文字
_this.slidetext = function(index)
{
if(_this.opts.showtext)
{
var tex = _this.$ims.eq(index).attr('alt');
if(_this.opts.textlink){
tex = ''+ tex+'';
}
_this.$h3.html(tex);
if(_this.opts.textswitch>0){
var t_path = _this.$h3.height();
var t_ani1 ={}, t_ani2 ={};
if(_this.textposition=='top'){
t_ani1 = {top : -1*t_path};
t_ani2 = {top : 0};
}
else if(_this.textposition=='bottom'){
t_ani1 = {bottom : -1*t_path};
t_ani2 = {bottom : 0};
}
if(_this.opts.textswitch==1) {
_this.$h3.stop(true, false).animate(t_ani1, {duration: 200, easing: 'easeoutquad'}).animate(t_ani2, {duration: 200, easing: 'easeoutquad'});
}else if(_this.opts.textswitch==2){
_this.$tex.stop(true, false).animate(t_ani1, {duration: 200, easing: 'easeoutquad'}).animate(t_ani2, {duration: 200, easing: 'easeoutquad'});
//_this.$lay.animate(t_ani1, {duration: 200, easing: 'easeoutquad'}).animate(t_ani2, {duration: 200, easing: 'easeoutquad'});
}
}
}
};
// 开始切换
_this.startslider = function(index){
// 由第几个序号开始 初始为1
var st =settimeout(function(){
_this.slideto(index);
},_this.opts.time);
_this.slidertimer = st ;
};
// 停止切换
_this.stopslider = function(){
//if(_this.opts.switcheffect=='fadeout') _this.$lis.stop();
// else if(_this.opts.switcheffect=='ease') _this.$ul.stop();
if(_this.slidertimer) {
cleartimeout(_this.slidertimer);
}
_this.slidertimer = null;
};
_this.init();
};
$.smallslider.defaults={
time:3000, // 切换时间间隔,单位毫秒,1秒=1000毫秒
autostart:true, // 是否自动开始播放
onimagestop : false , // 鼠标放在图片上时,是否停止播放
switchmode:'hover', // 图片切换的方式,click为单击切换,hover为鼠标移动到按钮上时切换
switcheffect:'fadeout', // 切换特效,fadeout, ease, none,
switchpath: 'left' , // 切换的方向,可选值为:up , left ,即向上,向左
switchease : 'easeoutquart' , // 可选值列表如下
switchtime: 600, // 切换时间,单位毫秒,1秒=1000毫秒
buttonposition: 'rightbottom', // 按钮位置表示,共有四个值:lefttop,leftbottom, righttop, rightbottom
buttonoffsetx:10, // 水平方向上的按钮偏移位置,指向中心部移动多少,这里是数值,不加px
buttonoffsety:4, // 竖直方向上的按钮偏移位置,指向中心部移动多少,这里是数值,不加px
buttonspace:4, // 按钮之间的间隔 单位为像素,但不要加px
showtext: true, // 是否显示标题,如果不显示,则只显示按钮
showbuttons : true, // 是否显示按钮,默认显示
textlink : true, // 是否给显示的标题加上链接,如果为false,则,只显示标题,标题不可单击,链接的地址自动和当前播放到的图片地址一致
textswitch : 0 , // 标题是否运动显示,如果为0则不动,1 标题动,2 标题和背景一起动。
textposition: '', // 标题栏的位置,默认为空,即和按钮的位置一致,取值 top , bottom
textalign: '' // 如果留空,则会默认和按钮位置的相反方向排列,取值:left, center, right
};
$.fn.smallslider = function(options){
// 遍历由$.smallslider类创建生成的smallslider对象。
return this.each(function(i){
(new $.smallslider(this, options));
});
};
})(jquery);
$.smallslider.switcheases = ["easeinquad", "easeoutquad", "easeinoutquad", "easeincubic", "easeoutcubic",
"easeinoutcubic", "easeinquart", "easeoutquart", "easeinoutquart", "easeinquint", "easeoutquint", "easeinoutquint",
"easeinsine", "easeoutsine", "easeinoutsine", "easeinexpo", "easeoutexpo", "easeinoutexpo", "easeincirc", "easeoutcirc", "easeinoutcirc", "easeinelastic",
"easeoutelastic", "easeinoutelastic", "easeinback", "easeoutback", "easeinoutback",
"easeinbounce", "easeoutbounce", "easeinoutbounce"];
// t: current time, b: beginning value, c: change in value, d: duration
jquery.easing['jswing'] = jquery.easing['swing'];
jquery.extend( jquery.easing,
{
def: 'easeoutquad',
swing: function (x, t, b, c, d) {
//alert(jquery.easing.default);
return jquery.easing[jquery.easing.def](x, t, b, c, d);
},
easeinquad: function (x, t, b, c, d) {
return c*(t/=d)*t + b;
},
easeoutquad: function (x, t, b, c, d) {
return -c *(t/=d)*(t-2) + b;
},
easeinoutquad: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t + b;
return -c/2 * ((--t)*(t-2) - 1) + b;
},
easeincubic: function (x, t, b, c, d) {
return c*(t/=d)*t*t + b;
},
easeoutcubic: function (x, t, b, c, d) {
return c*((t=t/d-1)*t*t + 1) + b;
},
easeinoutcubic: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t + b;
return c/2*((t-=2)*t*t + 2) + b;
},
easeinquart: function (x, t, b, c, d) {
return c*(t/=d)*t*t*t + b;
},
easeoutquart: function (x, t, b, c, d) {
return -c * ((t=t/d-1)*t*t*t - 1) + b;
},
easeinoutquart: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
return -c/2 * ((t-=2)*t*t*t - 2) + b;
},
easeinquint: function (x, t, b, c, d) {
return c*(t/=d)*t*t*t*t + b;
},
easeoutquint: function (x, t, b, c, d) {
return c*((t=t/d-1)*t*t*t*t + 1) + b;
},
easeinoutquint: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
return c/2*((t-=2)*t*t*t*t + 2) + b;
},
easeinsine: function (x, t, b, c, d) {
return -c * math.cos(t/d * (math.pi/2)) + c + b;
},
easeoutsine: function (x, t, b, c, d) {
return c * math.sin(t/d * (math.pi/2)) + b;
},
easeinoutsine: function (x, t, b, c, d) {
return -c/2 * (math.cos(math.pi*t/d) - 1) + b;
},
easeinexpo: function (x, t, b, c, d) {
return (t==0) ? b : c * math.pow(2, 10 * (t/d - 1)) + b;
},
easeoutexpo: function (x, t, b, c, d) {
return (t==d) ? b+c : c * (-math.pow(2, -10 * t/d) + 1) + b;
},
easeinoutexpo: function (x, t, b, c, d) {
if (t==0) return b;
if (t==d) return b+c;
if ((t/=d/2) < 1) return c/2 * math.pow(2, 10 * (t - 1)) + b;
return c/2 * (-math.pow(2, -10 * --t) + 2) + b;
},
easeincirc: function (x, t, b, c, d) {
return -c * (math.sqrt(1 - (t/=d)*t) - 1) + b;
},
easeoutcirc: function (x, t, b, c, d) {
return c * math.sqrt(1 - (t=t/d-1)*t) + b;
},
easeinoutcirc: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return -c/2 * (math.sqrt(1 - t*t) - 1) + b;
return c/2 * (math.sqrt(1 - (t-=2)*t) + 1) + b;
},
easeinelastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b;if ((t/=d)==1) return b+c;if (!p) p=d*.3;
if (a < math.abs(c)) {a=c;s=p/4;}
else s = p/(2*math.pi) * math.asin (c/a);
return -(a*math.pow(2,10*(t-=1)) * math.sin( (t*d-s)*(2*math.pi)/p )) + b;
},
easeoutelastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b;if ((t/=d)==1) return b+c;if (!p) p=d*.3;
if (a < math.abs(c)) {a=c;s=p/4;}
else s = p/(2*math.pi) * math.asin (c/a);
return a*math.pow(2,-10*t) * math.sin( (t*d-s)*(2*math.pi)/p ) + c + b;
},
easeinoutelastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b;if ((t/=d/2)==2) return b+c;if (!p) p=d*(.3*1.5);
if (a < math.abs(c)) {a=c;s=p/4;}
else s = p/(2*math.pi) * math.asin (c/a);
if (t < 1) return -.5*(a*math.pow(2,10*(t-=1)) * math.sin( (t*d-s)*(2*math.pi)/p )) + b;
return a*math.pow(2,-10*(t-=1)) * math.sin( (t*d-s)*(2*math.pi)/p )*.5 + c + b;
},
easeinback: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c*(t/=d)*t*((s+1)*t - s) + b;
},
easeoutback: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
},
easeinoutback: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
},
easeinbounce: function (x, t, b, c, d) {
return c - jquery.easing.easeoutbounce (x, d-t, 0, c, d) + b;
},
easeoutbounce: function (x, t, b, c, d) {
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
}
},
easeinoutbounce: function (x, t, b, c, d) {
if (t < d/2) return jquery.easing.easeinbounce (x, t*2, 0, c, d) * .5 + b;
return jquery.easing.easeoutbounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
}
});
/*
* 图片放大
* */
(function($){
var opts;
$.fn.lightbox = function(options){
// build main options
opts = $.extend({}, $.fn.lightbox.defaults, options);
// initalize the lightbox
$.fn.lightbox.initialize();
return this.each(function(){
$(this).click(function(){
$(this).lightbox.start(this);
return false;
});
});
};
// lightbox functions
$.fn.lightbox.initialize = function(){
$('#overlay').remove();
$('#lightbox').remove();
opts.inprogress = false;
var outerimage = '';
var imagedata = '
'
if (opts.displayhelp)
imagedata += '
' + opts.strings.help + '';
imagedata += '
';
var string;
if (opts.navbarontop) {
string = '' + imagedata + outerimage + '
';
$("body").append(string);
$("#imagedatacontainer").addclass('ontop');
} else {
string = '' + outerimage + imagedata + '
';
$("body").append(string);
}
$("#overlay").click(function(){ $.fn.lightbox.end(); }).hide();
$("#lightbox").click(function(){ $.fn.lightbox.end();}).hide();
$("#loadinglink").click(function(){ $.fn.lightbox.end(); return false;});
$("#bottomnavclose").click(function(){ $.fn.lightbox.end(); return false; });
$('#outerimagecontainer').width(opts.widthcurrent).height(opts.heightcurrent);
$('#imagedatacontainer').width(opts.widthcurrent);
};
$.fn.lightbox.getpagesize = function(){
var xscroll, yscroll;
if (window.innerheight && window.scrollmaxy) {
xscroll = window.innerwidth + window.scrollmaxx;
yscroll = window.innerheight + window.scrollmaxy;
} else if (document.body.scrollheight > document.body.offsetheight){ // all but explorer mac
xscroll = document.body.scrollwidth;
yscroll = document.body.scrollheight;
} else { // explorer mac...would also work in explorer 6 strict, mozilla and safari
xscroll = document.body.offsetwidth;
yscroll = document.body.offsetheight;
}
var windowwidth, windowheight;
if (self.innerheight) { // all except explorer
if(document.documentelement.clientwidth){
windowwidth = document.documentelement.clientwidth;
} else {
windowwidth = self.innerwidth;
}
windowheight = self.innerheight;
} else if (document.documentelement && document.documentelement.clientheight) { // explorer 6 strict mode
windowwidth = document.documentelement.clientwidth;
windowheight = document.documentelement.clientheight;
} else if (document.body) { // other explorers
windowwidth = document.body.clientwidth;
windowheight = document.body.clientheight;
}
// for small pages with total height less then height of the viewport
if(yscroll < windowheight){
pageheight = windowheight;
} else {
pageheight = yscroll;
}
// for small pages with total width less then width of the viewport
if(xscroll < windowwidth){
pagewidth = xscroll;
} else {
pagewidth = windowwidth;
}
var arraypagesize = new array(pagewidth,pageheight,windowwidth,windowheight);
return arraypagesize;
};
$.fn.lightbox.getpagescroll = function(){
var xscroll, yscroll;
if (self.pageyoffset) {
yscroll = self.pageyoffset;
xscroll = self.pagexoffset;
} else if (document.documentelement && document.documentelement.scrolltop){ // explorer 6 strict
yscroll = document.documentelement.scrolltop;
xscroll = document.documentelement.scrollleft;
} else if (document.body) {// all other explorers
yscroll = document.body.scrolltop;
xscroll = document.body.scrollleft;
}
var arraypagescroll = new array(xscroll,yscroll);
return arraypagescroll;
};
$.fn.lightbox.pause = function(ms){
var date = new date();
var curdate = null;
do{curdate = new date();}
while( curdate - date < ms);
};
$.fn.lightbox.start = function(imagelink){
$("select, embed, object").hide();
var arraypagesize = $.fn.lightbox.getpagesize();
$("#overlay").hide().css({width: '100%', height: arraypagesize[1]+'px', opacity : opts.overlayopacity}).fadein();
opts.imagearray = [];
imagenum = 0;
var anchors = document.getelementsbytagname( imagelink.tagname);
// if image is not part of a set..
if(!imagelink.rel || (imagelink.rel == '')){
// add single image to lightbox.imagearray
opts.imagearray.push(new array(imagelink.href, opts.displaytitle ? imagelink.title : ''));
} else {
// if image is part of a set..
$("a").each(function(){
if(this.href && (this.rel == imagelink.rel)){
opts.imagearray.push(new array(this.href, opts.displaytitle ? this.title : ''));
}
})
for(i = 0; i < opts.imagearray.length; i++){
for(j = opts.imagearray.length-1; j>i; j--){
if(opts.imagearray[i][0] == opts.imagearray[j][0]){
opts.imagearray.splice(j,1);
}
}
}
while(opts.imagearray[imagenum][0] != imagelink.href) { imagenum++;}
}
// calculate top and left offset for the lightbox
var arraypagescroll = $.fn.lightbox.getpagescroll();
var lightboxtop = arraypagescroll[1] + (arraypagesize[3] / 10);
var lightboxleft = arraypagescroll[0];
$('#lightbox').css({top: lightboxtop+'px', left: lightboxleft+'px'}).show();
if (!opts.slidenavbar)
$('#imagedata').hide();
$.fn.lightbox.changeimage(imagenum);
};
$.fn.lightbox.changeimage = function(imagenum){
if(opts.inprogress == false){
opts.inprogress = true;
opts.activeimage = imagenum; // update global var
// hide elements during transition
$('#loading').show();
$('#lightboximage').hide();
$('#hovernav').hide();
$('#prevlink').hide();
$('#nextlink').hide();
if (opts.slidenavbar) { // delay preloading image until navbar will slide up
// $('#imagedatacontainer').slideup(opts.navbarslidespeed, $.fn.dochangeimage);
$('#imagedatacontainer').hide();
$('#imagedata').hide();
$.fn.dochangeimage();
} else {
$.fn.dochangeimage();
}
}
};
$.fn.dochangeimage = function(){
imgpreloader = new image();
// once image is preloaded, resize image container
imgpreloader.onload=function(){
var newwidth = imgpreloader.width;
var newheight = imgpreloader.height;
if (opts.fittoscreen) {
var arraypagesize = $.fn.lightbox.getpagesize();
var ratio;
var initialpagewidth = arraypagesize[2] - 2 * opts.bordersize;
var initialpageheight = arraypagesize[3] - 200;
if (imgpreloader.height > initialpageheight)
{
newwidth = parseint((initialpageheight/imgpreloader.height) * imgpreloader.width);
newheight = initialpageheight;
}
else if (imgpreloader.width > initialpagewidth)
{
newheight = parseint((initialpagewidth/imgpreloader.width) * imgpreloader.height);
newwidth = initialpagewidth;
}
}
$('#lightboximage').attr('src', opts.imagearray[opts.activeimage][0])
.width(newwidth).height(newheight);
$.fn.lightbox.resizeimagecontainer(newwidth, newheight);
}
imgpreloader.src = opts.imagearray[opts.activeimage][0];
}
$.fn.lightbox.end = function(){
$.fn.lightbox.disablekeyboardnav();
$('#lightbox').hide();
$('#overlay').fadeout();
$('select, object, embed').show();
};
$.fn.lightbox.preloadneighborimages = function(){
if((opts.imagearray.length - 1) > opts.activeimage){
preloadnextimage = new image();
preloadnextimage.src = opts.imagearray[opts.activeimage + 1][0];
}
if(opts.activeimage > 0){
preloadprevimage = new image();
preloadprevimage.src = opts.imagearray[opts.activeimage - 1][0];
}
};
$.fn.lightbox.keyboardaction = function(e){
if (e == null) { // ie
var keycode = event.keycode;
var escapekey = 27;
} else { // mozilla
var keycode = e.keycode;
var escapekey = e.dom_vk_escape;
}
var key = string.fromcharcode(keycode).tolowercase();
if((key == 'x') || (key == 'o') || (key == 'c') || (keycode == escapekey)){ // close lightbox
$.fn.lightbox.end();
} else if((key == 'p') || (keycode == 37)){ // display previous image
if(opts.activeimage != 0){
$.fn.lightbox.disablekeyboardnav();
$.fn.lightbox.changeimage(opts.activeimage - 1);
}
} else if((key == 'n') || (keycode == 39)){ // display next image
if(opts.activeimage != (opts.imagearray.length - 1)){
$.fn.lightbox.disablekeyboardnav();
$.fn.lightbox.changeimage(opts.activeimage + 1);
}
}
};
$.fn.lightbox.resizeimagecontainer = function(imgwidth, imgheight){
// get current width and height
opts.widthcurrent = document.getelementbyid('outerimagecontainer').offsetwidth;
opts.heightcurrent = document.getelementbyid('outerimagecontainer').offsetheight;
// get new width and height
var widthnew = (imgwidth + (opts.bordersize * 2));
var heightnew = (imgheight + (opts.bordersize * 2));
// scalars based on change from old to new
opts.xscale = ( widthnew / opts.widthcurrent) * 100;
opts.yscale = ( heightnew / opts.heightcurrent) * 100;
// calculate size difference between new and old image, and resize if necessary
wdiff = opts.widthcurrent - widthnew;
hdiff = opts.heightcurrent - heightnew;
$('#imagedatacontainer').animate({width: widthnew},opts.resizespeed,'linear');
$('#outerimagecontainer').animate({width: widthnew},opts.resizespeed,'linear',function(){
$('#outerimagecontainer').animate({height: heightnew},opts.resizespeed,'linear',function(){
$.fn.lightbox.showimage();
});
});
// if new and old image are same size and no scaling transition is necessary,
// do a quick pause to prevent image flicker.
if((hdiff == 0) && (wdiff == 0)){
if (jquery.browser.msie){ $.fn.lightbox.pause(250); } else { $.fn.lightbox.pause(100);}
}
$('#prevlink').height(imgheight);
$('#nextlink').height(imgheight);
};
$.fn.lightbox.showimage = function(){
$('#loading').hide();
$('#lightboximage').fadein("fast");
$.fn.lightbox.updatedetails();
$.fn.lightbox.preloadneighborimages();
opts.inprogress = false;
};
$.fn.lightbox.updatedetails = function(){
if(opts.imagearray[opts.activeimage][1]){
$('#caption').html(opts.imagearray[opts.activeimage][1]).show();
}
// if image is part of set display 'image x of x'
if(opts.imagearray.length > 1){
var nav_html;
nav_html = opts.strings.image + (opts.activeimage + 1) + opts.strings.of + opts.imagearray.length;
// display previous / next text links
if ((opts.activeimage) > 0) {
nav_html = '' + opts.strings.prevlinktext + "" + nav_html;
}
if ((opts.activeimage + 1) < opts.imagearray.length) {
nav_html += '' + opts.strings.nextlinktext + "";
}
$('#numberdisplay').html(nav_html).show();
}
if (opts.slidenavbar) {
$("#imagedata").slidedown(opts.navbarslidespeed);
} else {
$("#imagedata").show();
}
var arraypagesize = $.fn.lightbox.getpagesize();
$('#overlay').height(arraypagesize[1]);
$.fn.lightbox.updatenav();
};
$.fn.lightbox.updatenav = function(){
$('#hovernav').show();
// if not first image in set, display prev image button
if(opts.activeimage != 0){
$('#prevlink,#prevlinktext').show().click(function(){
$.fn.lightbox.changeimage(opts.activeimage - 1); return false;
});
}
// if not last image in set, display next image button
if(opts.activeimage != (opts.imagearray.length - 1)){
$('#nextlink,#nextlinktext').show().click(function(){
$.fn.lightbox.changeimage(opts.activeimage +1); return false;
});
}
$.fn.lightbox.enablekeyboardnav();
};
$.fn.lightbox.enablekeyboardnav = function(){
document.onkeydown = $.fn.lightbox.keyboardaction;
};
$.fn.lightbox.disablekeyboardnav = function(){
document.onkeydown = '';
};
$.fn.lightbox.defaults = {
fileloadingimage : 'static/image/lightbox/loading.gif',
filebottomnavcloseimage : 'static/image/lightbox/closelabel.gif',
overlayopacity : 0.8,
bordersize : 10,
imagearray : new array,
activeimage : null,
inprogress : false,
resizespeed : 350,
widthcurrent: 250,
heightcurrent: 250,
xscale : 1,
yscale : 1,
displaytitle: true,
navbarontop: false,
slidenavbar: false, // slide nav bar up/down between image resizing transitions
navbarslidespeed: 350,
displayhelp: false,
strings : {
help: ' \u2190 / p - previous image\u00a0\u00a0\u00a0\u00a0\u2192 / n - next image\u00a0\u00a0\u00a0\u00a0esc / x - close image gallery',
prevlinktitle: 'previous image',
nextlinktitle: 'next image',
prevlinktext: '« previous',
nextlinktext: 'next »',
closetitle: 'close image gallery',
image: 'image ',
of: 'of '
},
fittoscreen: false // resize images if they are bigger than window
};
})(jquery);
/*
* ajax提交
* */
(function($) {
$.fn.ajaxsubmit = function(options) {
if (!this.length) {
log('ajaxsubmit: skipping submit process - no element selected');
return this;
}
if (typeof options == 'function')
options = { success: options };
options = $.extend({
url: this.attr('action') || window.location.tostring(),
type: this.attr('method') || 'get'
}, options || {});
var veto = {};
this.trigger('form-pre-serialize', [this, options, veto]);
if (veto.veto) {
log('ajaxsubmit: submit vetoed via form-pre-serialize trigger');
return this;
}
if (options.beforeserialize && options.beforeserialize(this, options) === false) {
log('ajaxsubmit: submit aborted via beforeserialize callback');
return this;
}
var a = this.formtoarray(options.semantic);
if (options.data) {
options.extradata = options.data;
for (var n in options.data) {
if(options.data[n] instanceof array) {
for (var k in options.data[n])
a.push( { name: n, value: options.data[n][k] } )
}
else
a.push( { name: n, value: options.data[n] } );
}
}
if (options.beforesubmit && options.beforesubmit(a, this, options) === false) {
log('ajaxsubmit: submit aborted via beforesubmit callback');
return this;
}
this.trigger('form-submit-validate', [a, this, options, veto]);
if (veto.veto) {
log('ajaxsubmit: submit vetoed via form-submit-validate trigger');
return this;
}
var q = $.param(a);
if (options.type.touppercase() == 'get') {
options.url += (options.url.indexof('?') >= 0 ? '&' : '?') + q;
options.data = null; // data is null for 'get'
}
else
options.data = q; // data is the query string for 'post'
var $form = this, callbacks = [];
if (options.resetform) callbacks.push(function() { $form.resetform(); });
if (options.clearform) callbacks.push(function() { $form.clearform(); });
if (!options.datatype && options.target) {
var oldsuccess = options.success || function(){};
callbacks.push(function(data) {
$(options.target).html(data).each(oldsuccess, arguments);
});
}
else if (options.success)
callbacks.push(options.success);
options.success = function(data, status) {
for (var i=0, max=callbacks.length; i < max; i++)
callbacks[i].apply(options, [data, status, $form]);
};
var files = $('input:file', this).fieldvalue();
var found = false;
for (var j=0; j < files.length; j++)
if (files[j])
found = true;
if (options.iframe || found) {
if ($.browser.safari && options.closekeepalive)
$.get(options.closekeepalive, fileupload);
else
fileupload();
}
else
$.ajax(options);
this.trigger('form-submit-notify', [this, options]);
return this;
function fileupload() {
var form = $form[0];
if ($(':input[name=submit]', form).length) {
alert('error: form elements must not be named "submit".');
return;
}
var opts = $.extend({}, $.ajaxsettings, options);
var s = jquery.extend(true, {}, $.extend(true, {}, $.ajaxsettings), opts);
var id = 'jqformio' + (new date().gettime());
var $io = $('');
var io = $io[0];
if ($.browser.msie || $.browser.opera)
io.src = 'javascript:false;document.write("");';
$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
var xhr = { // mock object
aborted: 0,
responsetext: null,
responsexml: null,
status: 0,
statustext: 'n/a',
getallresponseheaders: function() {},
getresponseheader: function() {},
setrequestheader: function() {},
abort: function() {
this.aborted = 1;
$io.attr('src','about:blank'); // abort op in progress
}
};
var g = opts.global;
if (g && ! $.active++) $.event.trigger("ajaxstart");
if (g) $.event.trigger("ajaxsend", [xhr, opts]);
if (s.beforesend && s.beforesend(xhr, s) === false) {
s.global && jquery.active--;
return;
}
if (xhr.aborted)
return;
var cbinvoked = 0;
var timedout = 0;
var sub = form.clk;
if (sub) {
var n = sub.name;
if (n && !sub.disabled) {
options.extradata = options.extradata || {};
options.extradata[n] = sub.value;
if (sub.type == "image") {
options.extradata[name+'.x'] = form.clk_x;
options.extradata[name+'.y'] = form.clk_y;
}
}
}
settimeout(function() {
var t = $form.attr('target'), a = $form.attr('action');
$form.attr({
target: id,
method: 'post',
action: opts.url
});
if (! options.skipencodingoverride) {
$form.attr({
encoding: 'multipart/form-data',
enctype: 'multipart/form-data'
});
}
if (opts.timeout)
settimeout(function() { timedout = true; cb(); }, opts.timeout);
var extrainputs = [];
try {
if (options.extradata)
for (var n in options.extradata)
extrainputs.push(
$('')
.appendto(form)[0]);
$io.appendto('body');
io.attachevent ? io.attachevent('onload', cb) : io.addeventlistener('load', cb, false);
form.submit();
}
finally {
$form.attr('action', a);
t ? $form.attr('target', t) : $form.removeattr('target');
$(extrainputs).remove();
}
}, 10);
function cb() {
if (cbinvoked++) return;
io.detachevent ? io.detachevent('onload', cb) : io.removeeventlistener('load', cb, false);
var operahack = 0;
var ok = true;
try {
if (timedout) throw 'timeout';
var data, doc;
doc = io.contentwindow ? io.contentwindow.document : io.contentdocument ? io.contentdocument : io.document;
if (doc.body == null && !operahack && $.browser.opera) {
operahack = 1;
cbinvoked--;
settimeout(cb, 100);
return;
}
xhr.responsetext = doc.body ? doc.body.innerhtml : null;
xhr.responsexml = doc.xmldocument ? doc.xmldocument : doc;
xhr.getresponseheader = function(header){
var headers = {'content-type': opts.datatype};
return headers[header];
};
if (opts.datatype == 'json' || opts.datatype == 'script') {
var ta = doc.getelementsbytagname('textarea')[0];
xhr.responsetext = ta ? ta.value : xhr.responsetext;
}
else if (opts.datatype == 'xml' && !xhr.responsexml && xhr.responsetext != null) {
xhr.responsexml = toxml(xhr.responsetext);
}
data = $.httpdata(xhr, opts.datatype);
}
catch(e){
ok = false;
$.handleerror(opts, xhr, 'error', e);
}
if (ok) {
opts.success(data, 'success');
if (g) $.event.trigger("ajaxsuccess", [xhr, opts]);
}
if (g) $.event.trigger("ajaxcomplete", [xhr, opts]);
if (g && ! --$.active) $.event.trigger("ajaxstop");
if (opts.complete) opts.complete(xhr, ok ? 'success' : 'error');
settimeout(function() {
$io.remove();
xhr.responsexml = null;
}, 100);
};
function toxml(s, doc) {
if (window.activexobject) {
doc = new activexobject('microsoft.xmldom');
doc.async = 'false';
doc.loadxml(s);
}
else
doc = (new domparser()).parsefromstring(s, 'text/xml');
return (doc && doc.documentelement && doc.documentelement.tagname != 'parsererror') ? doc : null;
};
};
};
$.fn.ajaxform = function(options) {
return this.ajaxformunbind().bind('submit.form-plugin',function() {
$(this).ajaxsubmit(options);
return false;
}).each(function() {
// store options in hash
$(":submit,input:image", this).bind('click.form-plugin',function(e) {
var form = this.form;
form.clk = this;
if (this.type == 'image') {
if (e.offsetx != undefined) {
form.clk_x = e.offsetx;
form.clk_y = e.offsety;
} else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
var offset = $(this).offset();
form.clk_x = e.pagex - offset.left;
form.clk_y = e.pagey - offset.top;
} else {
form.clk_x = e.pagex - this.offsetleft;
form.clk_y = e.pagey - this.offsettop;
}
}
// clear form vars
settimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 10);
});
});
};
// ajaxformunbind unbinds the event handlers that were bound by ajaxform
$.fn.ajaxformunbind = function() {
this.unbind('submit.form-plugin');
return this.each(function() {
$(":submit,input:image", this).unbind('click.form-plugin');
});
};
$.fn.formtoarray = function(semantic) {
var a = [];
if (this.length == 0) return a;
var form = this[0];
var els = semantic ? form.getelementsbytagname('*') : form.elements;
if (!els) return a;
for(var i=0, max=els.length; i < max; i++) {
var el = els[i];
var n = el.name;
if (!n) continue;
if (semantic && form.clk && el.type == "image") {
// handle image inputs on the fly when semantic == true
if(!el.disabled && form.clk == el)
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
continue;
}
var v = $.fieldvalue(el, true);
if (v && v.constructor == array) {
for(var j=0, jmax=v.length; j < jmax; j++)
a.push({name: n, value: v[j]});
}
else if (v !== null && typeof v != 'undefined')
a.push({name: n, value: v});
}
if (!semantic && form.clk) {
// input type=='image' are not found in elements array! handle them here
var inputs = form.getelementsbytagname("input");
for(var i=0, max=inputs.length; i < max; i++) {
var input = inputs[i];
var n = input.name;
if(n && !input.disabled && input.type == "image" && form.clk == input)
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
}
}
return a;
};
$.fn.formserialize = function(semantic) {
//hand off to jquery.param for proper encoding
return $.param(this.formtoarray(semantic));
};
$.fn.fieldserialize = function(successful) {
var a = [];
this.each(function() {
var n = this.name;
if (!n) return;
var v = $.fieldvalue(this, successful);
if (v && v.constructor == array) {
for (var i=0,max=v.length; i < max; i++)
a.push({name: n, value: v[i]});
}
else if (v !== null && typeof v != 'undefined')
a.push({name: this.name, value: v});
});
//hand off to jquery.param for proper encoding
return $.param(a);
};
$.fn.fieldvalue = function(successful) {
for (var val=[], i=0, max=this.length; i < max; i++) {
var el = this[i];
var v = $.fieldvalue(el, successful);
if (v === null || typeof v == 'undefined' || (v.constructor == array && !v.length))
continue;
v.constructor == array ? $.merge(val, v) : val.push(v);
}
return val;
};
$.fieldvalue = function(el, successful) {
var n = el.name, t = el.type, tag = el.tagname.tolowercase();
if (typeof successful == 'undefined') successful = true;
if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
(t == 'checkbox' || t == 'radio') && !el.checked ||
(t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
tag == 'select' && el.selectedindex == -1))
return null;
if (tag == 'select') {
var index = el.selectedindex;
if (index < 0) return null;
var a = [], ops = el.options;
var one = (t == 'select-one');
var max = (one ? index+1 : ops.length);
for(var i=(one ? index : 0); i < max; i++) {
var op = ops[i];
if (op.selected) {
// extra pain for ie...
var v = $.browser.msie && !(op.attributes['value'].specified) ? op.text : op.value;
if (one) return v;
a.push(v);
}
}
return a;
}
return el.value;
};
$.fn.clearform = function() {
return this.each(function() {
$('input,select,textarea', this).clearfields();
});
};
$.fn.clearfields = $.fn.clearinputs = function() {
return this.each(function() {
var t = this.type, tag = this.tagname.tolowercase();
if (t == 'text' || t == 'password' || tag == 'textarea')
this.value = '';
else if (t == 'checkbox' || t == 'radio')
this.checked = false;
else if (tag == 'select')
this.selectedindex = -1;
});
};
$.fn.resetform = function() {
return this.each(function() {
// guard against an input with the name of 'reset'
// note that ie reports the reset function as an 'object'
if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodetype))
this.reset();
});
};
$.fn.enable = function(b) {
if (b == undefined) b = true;
return this.each(function() {
this.disabled = !b
});
};
$.fn.selected = function(select) {
if (select == undefined) select = true;
return this.each(function() {
var t = this.type;
if (t == 'checkbox' || t == 'radio')
this.checked = select;
else if (this.tagname.tolowercase() == 'option') {
var $sel = $(this).parent('select');
if (select && $sel[0] && $sel[0].type == 'select-one') {
// deselect all other options
$sel.find('option').selected(false);
}
this.selected = select;
}
});
};
function log() {
if ($.fn.ajaxsubmit.debug && window.console && window.console.log)
window.console.log('[jquery.form] ' + array.prototype.join.call(arguments,''));
};
})(jquery);
/*
* 导航下拉菜单api
* */
var ddsmoothmenu={
transition: {overtime:200, outtime:200}, //duration of slide in/ out animation, in milliseconds
//下拉菜单阴影
shadow: {enable:false, offsetx:0, offsety:0},
detectwebkit: navigator.useragent.tolowercase().indexof("applewebkit")!=-1, //detect webkit browsers (safari, chrome etc)
detectie6: document.all && !window.xmlhttprequest,
getajaxmenu:function($, setting){ //function to fetch external page containing the panel divs
var $menucontainer=$('#'+setting.contentsource[0]) //reference empty div on page that will hold menu
$menucontainer.html("loading menu...")
$.ajax({
url: setting.contentsource[1], //path to external menu file
async: true,
error:function(ajaxrequest){
$menucontainer.html('error fetching content. server response: '+ajaxrequest.responsetext)
},
success:function(content){
$menucontainer.html(content)
ddsmoothmenu.buildmenu($, setting)
}
})
},
buildmenu:function($, setting){
var smoothmenu=ddsmoothmenu
var $mainmenu=$("#"+setting.mainmenuid+">ul") //reference main menu ul
$mainmenu.parent().get(0).classname=setting.classname || "ddsmoothmenu"
var $headers=$mainmenu.find("ul").parent()
$headers.hover(
function(e){
$(this).children('a:eq(0)').addclass('selected')
},
function(e){
$(this).children('a:eq(0)').removeclass('selected')
}
)
$headers.each(function(i){ //loop through each li header
var $curobj=$(this).css({zindex: 100-i}) //reference current li header
var $subul=$(this).find('ul:eq(0)').css({display:'block'})
this._dimensions={w:this.offsetwidth, h:this.offsetheight, subulw:$subul.outerwidth(), subulh:$subul.outerheight()}
this.istopheader=$curobj.parents("ul").length==1? true : false //is top level header?
$subul.css({top:this.istopheader && setting.orientation!='v'? this._dimensions.h+"px" : 0})
// $curobj.children("a:eq(0)").css(this.istopheader? {paddingright: smoothmenu.arrowimages.down[2]} : {}).append( //add arrow images
// ''
// )
if (smoothmenu.shadow.enable){
this._shadowoffset={x:(this.istopheader?$subul.offset().left+smoothmenu.shadow.offsetx : this._dimensions.w), y:(this.istopheader? $subul.offset().top+smoothmenu.shadow.offsety : $curobj.position().top)} //store this shadow's offsets
if (this.istopheader)
$parentshadow=$(document.body)
else{
var $parentli=$curobj.parents("li:eq(0)")
$parentshadow=$parentli.get(0).$shadow
}
this.$shadow=$('').prependto($parentshadow).css({left:this._shadowoffset.x+'px', top:this._shadowoffset.y+'px'}) //insert shadow div and set it to parent node for the next shadow div
}
$curobj.hover(
function(e){
var $targetul=$(this).children("ul:eq(0)")
this._offsets={left:$(this).offset().left, top:$(this).offset().top}
var menuleft=this.istopheader && setting.orientation!='v'? 0 : this._dimensions.w
menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader && setting.orientation!='v'? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft //calculate this sub menu's offsets from its parent
if ($targetul.queue().length<=1){ //if 1 or less queued animations
$targetul.css({left:menuleft+"px", width:this._dimensions.subulw+'px'}).animate({height:'show',opacity:'show'}, ddsmoothmenu.transition.overtime)
if (smoothmenu.shadow.enable){
var shadowleft=this.istopheader? $targetul.offset().left+ddsmoothmenu.shadow.offsetx : menuleft
var shadowtop=this.istopheader?$targetul.offset().top+smoothmenu.shadow.offsety : this._shadowoffset.y
if (!this.istopheader && ddsmoothmenu.detectwebkit){ //in webkit browsers, restore shadow's opacity to full
this.$shadow.css({opacity:1})
}
this.$shadow.css({overflow:'', width:this._dimensions.subulw+'px', left:shadowleft+'px', top:shadowtop+'px'}).animate({height:this._dimensions.subulh+'px'}, ddsmoothmenu.transition.overtime)
}
}
},
function(e){
var $targetul=$(this).children("ul:eq(0)")
$targetul.animate({height:'hide', opacity:'hide'}, ddsmoothmenu.transition.outtime)
if (smoothmenu.shadow.enable){
if (ddsmoothmenu.detectwebkit){ //in webkit browsers, set first child shadow's opacity to 0, as "overflow:hidden" doesn't work in them
this.$shadow.children('div:eq(0)').css({opacity:0})
}
this.$shadow.css({overflow:'hidden'}).animate({height:0}, ddsmoothmenu.transition.outtime)
}
}
) //end hover
}) //end $headers.each()
$mainmenu.find("ul").css({display:'none', visibility:'visible'})
},
init:function(setting){
if (typeof setting.customtheme=="object" && setting.customtheme.length==2){ //override default menu colors (default/hover) with custom set?
var mainmenuid='#'+setting.mainmenuid
var mainselector=(setting.orientation=="v")? mainmenuid : mainmenuid+', '+mainmenuid
document.write('')
}
this.shadow.enable=(document.all && !window.xmlhttprequest)? false : this.shadow.enable //in ie6, always disable shadow
jquery(document).ready(function($){ //ajax menu?
if (typeof setting.contentsource=="object"){ //if external ajax menu
ddsmoothmenu.getajaxmenu($, setting)
}
else{ //else if markup menu
ddsmoothmenu.buildmenu($, setting)
}
})
}
} //end ddsmoothmenu variable