2019-12-20 19:21:55 +08:00

92 lines
3.3 KiB
JavaScript

var CompanyNotice=function(curHeight){
this.noticeJson={};
this.notcieLength=0;
this.maxMayShow=parseInt(curHeight/30);
this.maxShowNumber=3000;
this.mainNoticeBody=$("#main_notice_body");
this.mainNoticeBody.height($(window).height()+"px");
this.loadNotice(); //加载数据
this.initNoticeList();//初始化页面mainnotice.js
this.windowHeight=$(window).height();
this.noticeHeight=16;
this.speed=300; //定时速度
if(this.notcieLength>this.maxMayShow){
this.mainNoticeBody.css("margin-top",$(window).height()+"px");
this.setAutoScroll();
this.autoScrollObject=null;
}
}
CompanyNotice.prototype.loadNotice=function(){
var strMenuJson =RunJavaMethodTrans("com.tenwa.homepage.HomeNotice","getNotices","mianshow="+this.maxShowNumber);
strMenuJson=strMenuJson.replace(/\//g,"");
if(strMenuJson==""){
this.notcieLength=0;
}else{
this.noticeJson=JSON.parse(strMenuJson);
this.notcieLength=this.noticeJson.length;
}
}
CompanyNotice.prototype.initNoticeList=function(){
this.mainNoticeBody.empty();
if(this.notcieLength>0){
var lastIndex=this.maxShowNumber;
if(this.notcieLength<lastIndex){lastIndex=this.notcieLength}
debugger;
for(var i=0;i<lastIndex;i++){
if(this.noticeJson[i].BoardTitle=="更多"){
this.mainNoticeBody.append($("<div class='main_notice_more'>more</div>"));
}else{
var showNotice="<div class='noticecontent'><a onclick=\"";
if(this.noticeJson[i].IsEject=="Y"){
showNotice+="openFile('"+this.noticeJson[i].BoardNo+"','"+this.noticeJson[i].BoardTitle+"');"
}
showNotice+="return false;\" hidefocus href='javascript:void(0)' ><span>"+(i+1)+"、"+this.noticeJson[i].BoardTitle+"</span>";
if(this.noticeJson[i].IsNew=="Y"){
showNotice+="<span class='icon_new'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>"
}
showNotice+="</a></div>"
this.mainNoticeBody.append($(showNotice));
}
}
}
}
CompanyNotice.prototype.initWindowResize=function(){
var tempCompanyNotice=this;
$(window).resize(function() {
tempCompanyNotice.resizeNotice($(window).height());
});
}
CompanyNotice.prototype.resizeNotice=function(curHeight){
this.maxShowNumber=parseInt(curHeight/30);
this.loadNotice(); //加载数据
this.initNoticeList();//初始化页面
//this.initNoticeOnclick();
}
CompanyNotice.prototype.createCallback=function(fn,args){
return function(){
fn.call(window,args);
}
}
CompanyNotice.prototype.setAutoScroll=function(){
this.autoScrollObject=setInterval(this.createCallback(noticeScoll,this),this.speed);
this.mainNoticeBody.mouseover(this.createCallback(removeNotinceScollFuntion,this.autoScrollObject));
this.mainNoticeBody.mouseout(this.createCallback(addNotinceScollFuntion,this))
}
var addNotinceScollFuntion=function(noticeObject){
var autoScrollObject=setInterval(noticeObject.createCallback(noticeScoll,noticeObject),noticeObject.speed);
noticeObject.mainNoticeBody.mouseover(noticeObject.createCallback(removeNotinceScollFuntion,autoScrollObject));
}
var removeNotinceScollFuntion=function(noticeObject){
clearInterval(noticeObject);
}
var noticeScoll=function(noticeObject){
var c=noticeObject.mainNoticeBody.css("margin-top");
c=parseFloat(c.replace("px",""));
c=c-5;
if((c*-1)>(noticeObject.noticeHeight*noticeObject.notcieLength)){
c=noticeObject.windowHeight;
}
noticeObject.mainNoticeBody.css("margin-top",c+"px");
}