/* * 图片切换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 = '
'; $("body").append(string); $("#imagedatacontainer").addclass('ontop'); } else { string = '
'; $("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 = $('