//滚动切换 slideshow = function(slideshowid, recordcount, imagewidth, imageheight, imagelazyloading, verticalscroll, speed, manualswitch, switchbykey, autoscaling) { this.slideshowid = slideshowid; this.recordcount = recordcount; this.imagewidth = imagewidth; this.imageheight = imageheight; this.imagelazyloading = imagelazyloading; imagelazyloading=false; // this.verticalscroll = verticalscroll; this.speed = speed; this.manualswitch = manualswitch; this.needscaling = autoscaling && !imagelazyloading; this.scrollindex = 0; //当前记录 this.pageelement = document.getelementbyid("slideshow_" + this.slideshowid); this.contentdiv = domutils.getelement(this.pageelement, 'div', 'contentdiv'); this.recordstable = domutils.getelement(this.pageelement, "table", "records"); //获取控制栏 this.controlbar = domutils.getelement(this.pageelement, null, "controlbar"); //获取控制栏边距 this.controlbarleft = this.controlbar.style.left; this.controlbartop = this.controlbar.style.top; this.controlbarright = this.controlbar.style.right; this.controlbarbottom = this.controlbar.style.bottom; //获取控制栏记录容器 var selectedrecord = domutils.getelement(this.controlbar, null, "selectedrecord_0"); if(selectedrecord) { this.controlbarrecordscontainer = selectedrecord.parentnode.parentnode; //获取尺寸 this.controlbarrecordscontainersize = cssutils.getstyle(this.controlbarrecordscontainer.style.csstext, this.verticalscroll ? "height" : "width") || "100%"; //获取overflow样式 this.controlbarrecordscontaineroverflow = cssutils.getelementcomputedstyle(this.controlbarrecordscontainer, this.verticalscroll ? "overflow-y" : "overflow-x"); } this.appendslideshowlist(); //添加到列表 var slideshow = this; if(!this.needscaling) { //不需要自动调整尺寸 this._resizecontrolbar(); //重置控制栏大小 } else { this._scaling(); eventutils.addevent(window, 'resize', function() { slideshow._scaling(); }); eventutils.addevent(window, 'load', function() { slideshow._scaling(true); }); } //创建滚动条 this.scroller = new scroller(this.contentdiv, !this.verticalscroll, this.verticalscroll, false, false, false, true); this.scroller.onafterscroll = function(x, y, isleft, isright, istop, isbottom, touchend) { var index = slideshow.scrollindex; if(slideshow.verticalscroll) { if(math.abs(y) > slideshow.imageheight/5) { //超过1/5 index += y<0 ? -1 : 1; } } else { if(math.abs(x) > slideshow.imagewidth/5) { //超过1/5 index += x<0 ? -1 : 1; } } slideshow._slide(index==-1 ? slideshow.recordcount-1 : (index==slideshow.recordcount ? 0 : index)); }; if(switchbykey) { //方向键翻阅 eventutils.addevent(document, "keydown", function(event) { if(event.keycode==37) { slideshow.slidetonextimage(slideshowid, false); } else if(event.keycode==39) { slideshow.slidetonextimage(slideshowid, true); } }); } this.startautoswitch(); //启动切换 }; slideshow.prototype._resizecontrolbar = function() { //重置控制栏大小 try { if(this.pageelement.parentnode.offsetwidth==0) { if(this.resizecontrolbartimer) { return; } var slideshow = this; this.resizecontrolbartimer = window.setinterval(function() { slideshow._resizecontrolbar(); }, 30); return; } if(this.resizecontrolbartimer) { window.clearinterval(this.resizecontrolbartimer); this.resizecontrolbartimer = null; } var imgs = this.controlbar.getelementsbytagname('img'); if(!imgs[0] || !imgs[0].src || imgs[0].src.indexof('_breviary_')==-1) { //控制栏中没有缩略图 return; } //获取区域宽度或高度 var areasize; if(!this.verticalscroll) { //水平滚动 areasize = this.imagewidth ? this.imagewidth : (this.pageelement.rows.length==1 ? this.getminimagesize().width : number(this.contentdiv.parentnode.width.replace('px', ''))); if(isnan(areasize) || areasize<=0) { return; } this.controlbarrecordscontainer.style.width = ''; areasize -= this.controlbar.offsetwidth - this.controlbarrecordscontainer.offsetwidth; if(this.controlbarleft.indexof('px')!=-1) { areasize -= number(this.controlbarleft.replace('px', '')); } if(this.controlbarright.indexof('px')!=-1) { areasize -= number(this.controlbarright.replace('px', '')); } } else { //垂直方向滚动 areasize = this.imageheight>0 ? this.imageheight : this.getminimagesize().height; if(areasize<=0) { return; } this.controlbarrecordscontainer.style.height = ''; areasize -= this.controlbar.offsetheight - this.controlbarrecordscontainer.offsetheight; if(this.controlbartop.indexof('px')!=-1) { areasize -= number(this.controlbartop.replace('px', '')); } if(this.controlbarbottom.indexof('px')!=-1) { areasize -= number(this.controlbarbottom.replace('px', '')); } } var size = this.controlbarrecordscontainersize; if(size.indexof('%')!=-1) { size = areasize * number(size.replace(/%/, '')) / 100; } else { size = number(size.replace(/px/, '')); } if(this.controlbarrecordscontaineroverflow=='hidden' || this.controlbarrecordscontaineroverflow=='auto') { //允许滚动 eval('this.controlbarrecordscontainer.style.' + (this.verticalscroll ? 'height' : 'width') + '= size + "px";'); return; } if(this.controlbarrecordscontainer.style.display=='none') { return; } var distance = (this.verticalscroll ? this.controlbarrecordscontainer.offsetheight : this.controlbarrecordscontainer.offsetwidth) - size; if(!this.controlbarresized && distance<=0) { return; } this.controlbarresized = true; distance = math.round(distance/this.recordcount); for(var i=0; i0 && (size.width==0 || width0 && (size.height==0 || height100 ? 10 : 5; step = step / loop; var count = 0; var timer = window.setinterval(function() { if((++count)= this.controlbarrecordscontainer.scrollheight; } else { isscrollbegin = this.controlbarrecordscontainer.scrollleft==0; isscrollend = this.controlbarrecordscontainer.scrollleft + this.controlbarrecordscontainer.offsetwidth >= this.controlbarrecordscontainer.scrollwidth; } var previouspagebutton = domutils.getelement(this.controlbar, null, 'previouspagebutton'); if(previouspagebutton) { if(isscrollbegin) { cssutils.setgray(previouspagebutton); } else { cssutils.removegray(previouspagebutton); } } var nextpagebutton = domutils.getelement(this.controlbar, null, 'nextpagebutton'); if(nextpagebutton) { if(isscrollend) { cssutils.setgray(nextpagebutton); } else { cssutils.removegray(nextpagebutton); } } }; slideshow.prototype.startautoswitch = function() { //启动自动切换 if(!this.manualswitch) { //不是手动切换 var slideshow = this; this.scrolltimerid = window.setinterval(function() { slideshow._slide(slideshow.scrollindex < slideshow.recordcount-1 ? slideshow.scrollindex + 1 : 0); }, this.speed); //定时切换 } }; slideshow.prototype.stopautoswitch = function() { //停止自动切换 if(this.scrolltimerid) { window.clearinterval(this.scrolltimerid); } }; slideshow.prototype.appendslideshowlist = function() { //添加到列表 for(var i=0; i<(window.slideshowlist ? window.slideshowlist.length : 0); i++) { if(window.slideshowlist[i].id==this.slideshowid) { window.slideshowlist[i].slideshow = this; return; } } if(!window.slideshowlist) { window.slideshowlist = []; } window.slideshowlist[window.slideshowlist.length] = {id:this.slideshowid, slideshow:this}; }; slideshow._getslideshow = function(slideshowid) { //获取slideshow对象 for(var i=0; i<(window.slideshowlist ? window.slideshowlist.length : 0); i++) { if(window.slideshowlist[i].id==slideshowid) { return window.slideshowlist[i].slideshow; } } }; slideshow.slide = function(slideshowid, index) { //切换记录 var slideshow = slideshow._getslideshow(slideshowid); if(slideshow) { slideshow._slide(index); } }; slideshow.openlink = function(slideshowid, index) { //打开链接 var slideshow = slideshow._getslideshow(slideshowid); if(slideshow) { slideshow.openlink(index); } }; slideshow.shownextpreviousbutton = function(slideshowid, show, src, event) { //显示或者隐藏“上一图片”“下一图片”按钮 var slideshow = slideshow._getslideshow(slideshowid); if(!slideshow) { return; } var showpreviousimagebutton = show, shownextimagebutton = show; if(show) { var pos = domutils.getabsoluteposition(src, null, true); showpreviousimagebutton = event.clientx < pos.left + src.offsetwidth / 2; shownextimagebutton = !showpreviousimagebutton; } var previousimagebutton = domutils.getelement(slideshow.pageelement, 'div', 'previousimagebutton'); if(previousimagebutton) { previousimagebutton.style.visibility = showpreviousimagebutton ? 'visible' : 'hidden'; } var nextimagebutton = domutils.getelement(slideshow.pageelement, 'div', 'nextimagebutton'); if(nextimagebutton) { nextimagebutton.style.visibility = shownextimagebutton ? 'visible' : 'hidden'; } }; slideshow.onclickimage = function(slideshowid, imageclickaction, src, event) { //点击图片 var slideshow = slideshow._getslideshow(slideshowid); if(slideshow.controlbar && slideshow.controlbar.contains(event.srcelement)) { return; } if(imageclickaction=="nextimage") { slideshow.slidetonextimage(slideshowid, true); } else { var pos = domutils.getabsoluteposition(src, null, true); slideshow.slidetonextimage(slideshowid, (event.clientx ? event.clientx : event.x) >= pos.left + src.offsetwidth / 2); } }; slideshow.slidetonextimage = function(slideshowid, next) { //切换上一图片或者下一图片 var slideshow = slideshow._getslideshow(slideshowid); if(!slideshow) { return; } if(next && slideshow.scrollindex < slideshow.recordcount-1) { slideshow._slide(slideshow.scrollindex + 1); } else if(!next && slideshow.scrollindex > 0) { slideshow._slide(slideshow.scrollindex - 1); } }; slideshow.gotopage = function(slideshowid, next) { //翻页 var slideshow = slideshow._getslideshow(slideshowid); if(!slideshow) { return; } if(slideshow.verticalscroll) { slideshow.controlbarrecordscontainer.scrolltop += (next ? 1 : -1) * slideshow.controlbarrecordscontainer.offsetheight; } else { slideshow.controlbarrecordscontainer.scrollleft += (next ? 1 : -1) * slideshow.controlbarrecordscontainer.offsetwidth; } slideshow.controlbarrecordscontainer.style.overflow = "auto"; slideshow.controlbarrecordscontainer.style.overflow = "hidden"; slideshow._setpagingbuttonstate(); }; //滚动图片:头尾衔接 joinscrollmarquee = function(marqueeelenent, marqueecontentelement, scrollamount, speed) { this.marqueeelenent = marqueeelenent; this.marqueecontentelement = marqueecontentelement; this.scrollamount = scrollamount; this.speed = speed; var joinscrollmarquee = this; //添加事件处理 marqueeelenent.onmouseover = function() { window.cleartimeout(joinscrollmarquee.marqueetimer); }; marqueeelenent.onmouseout = function() { joinscrollmarquee.scroll(); } this.scroll(); }; //滚动 joinscrollmarquee.prototype.scroll = function() { if(this.marqueeelenent.scrollleft >= this.marqueecontentelement.offsetwidth/2) { this.marqueeelenent.scrollleft -= this.marqueecontentelement.offsetwidth/2; } else { this.marqueeelenent.scrollleft += this.scrollamount; } var joinscrollmarquee = this; window.cleartimeout(this.marqueetimer); this.marqueetimer = window.settimeout(function() { joinscrollmarquee.scroll(); }, this.speed); }; //记录日历 recordcalendar = function(title, startdate, dataurl, terminaltype) { this.title = title; this.startdate = startdate; this.dataurl = dataurl; this.terminaltype = terminaltype; this.istouchmode = terminaltype && terminaltype!='' && terminaltype!='computer'; this.id = ("" + math.random()).substring(2); if(!window.recordcalendars) { window.recordcalendars = []; } window.recordcalendars['recordcalendar_' + this.id] = this; document.write('
'); this.calendarcontainer = document.getelementbyid('recordcalendar_' + this.id); this._readcalendardata(); }; recordcalendar.prototype._readcalendardata = function() { //创建记录日历 var recordcalendar = this; scriptutils.appendjsfile(document, this.dataurl + '&recordcalendar.id=' + this.id + '&recordcalendar.startdate=' + this.startdate.format('yyyy-m-d') + '&seq=' + math.random(), 'scriptrecordcalendar', function() { var calendarrecords = window.recordcalendars['recordcalendar_' + recordcalendar.id].calendarrecords; if(!recordcalendar.dateview) { recordcalendar._create(calendarrecords); } else { recordcalendar._processcalendardata(calendarrecords); } }, 'utf-8'); }; recordcalendar.prototype._create = function(calendarrecords) { //创建日历视图 var recordcalendar = this; this.dateview = new dateview(this.startdate, this.terminaltype, true); this.dateview.onload = function() { recordcalendar._processcalendardata(calendarrecords); }; this.dateview.onmonthchanged = function() { recordcalendar._hidecalendardata(); recordcalendar.startdate = new date(recordcalendar.dateview.year + '/' + recordcalendar.dateview.month + '/1'); recordcalendar._readcalendardata(); }; if(this.istouchmode) { this.dateview.onclick = function(srcelement) { recordcalendar._showcalendardata(srcelement); }; } else { this.dateview.onmouseover = function(srcelement) { recordcalendar._showcalendardata(srcelement); }; } this.dateview.create(this.calendarcontainer); }; recordcalendar.prototype._processcalendardata = function(calendarrecords) { //处理日历数据 var rows = this.dateview.daytable.rows; for(var i = 1; i < rows.length; i++) { for(var j = 0; j < rows[i].cells.length; j++) { var html = this.calendarrecords['day_' + rows[i].cells[j].innerhtml]; this.dateview.setselected(rows[i].cells[j], html ? true : false); } } }; recordcalendar.prototype._showcalendardata = function(srcelement) { //显示日历数据 var html = this.calendarrecords['day_' + srcelement.innerhtml]; this._hidecalendardata(); if(!html) { return; } this.picker = new formfield.picker(this.title, '' + html + '', srcelement, -1, -1, false, true, true, true, this.terminaltype); this.picker.show(); this._startuptimerforhidecalendardata(); var recordcalendar = this; this.picker.pickerbody.onmousemove = function() { recordcalendar._startuptimerforhidecalendardata(); }; }; recordcalendar.prototype._hidecalendardata = function() { //隐藏日历数据 if(!this.istouchmode && this.picker) { this.picker.destory(); this.picker = null; } }; recordcalendar.prototype._startuptimerforhidecalendardata = function() { //启动隐藏隐藏日历数据定时器 if(this.istouchmode) { return; } if(this.calendartimer) { window.cleartimeout(this.calendartimer); } var recordcalendar = this; this.calendartimer = window.settimeout(function() { recordcalendar._hidecalendardata(); }, 5000); };