var websitedata = (function(window) { var websitedata = function(data) { return new websitedata.fn.init(data); } var _config_json; var backlist=[]; var s_list; var p_rows; var s_num; //指针 var s_page=0; //数据页面 var p_page=1; var p_maxpage=1; //最大页数 var _isrun=false; //执行状态 var _find_flag; websitedata.fn = websitedata.prototype = { constructor: websitedata, init: function(data) { this.name = data.name; this.flag = data.flag; //数据标识 this.backfun = data.backfun; //回调方法 this.erryfunction= data.errorfun s_num =0; //指针归零 if(!this.flag){ this.configstatus=false; return false; } p_page=data.page?parseint(data.page):1; //当前页 p_rows=data.rows?parseint(data.rows):10; //分页数据 this.getconfig(); }, //查询 指定页数 querypage:function(page){ if(this.flag==null){ alert(prompt["key_param_" + site_config.language]);//未获取关键参数 return false; } if(!_config_json){ alert(prompt["get_config_error_" + site_config.language]);//获取配置错误! } if(page){ p_page=parseint(page); } this.querydata(); var back_data={} //分页数据获取 back_data.page= p_page; back_data.maxpage=p_maxpage; back_data.total=_config_json.total; back_data.list=backlist; if(this.backfun){ this.backfun(back_data); } return backlist; }, //获取数据记录文件 querydata:function(){ backlist=[]; //计算获取那个文件 s_page= math.ceil(((p_page-1)*p_rows+1)/_config_json.rows);//获取页面序号 //默认开始为第一页 if(!s_page||s_page==0){ s_page=1; } s_num=math.abs(((p_page-1)*p_rows)%_config_json.rows); //获取页面下标 var url='json_data/'+this.flag+'@'+s_page+'@data.json'; this.getdata(url,this.loopdata); }, //检索记录所在页码数并{"name":"","value":""} findpage: function(find_json){ _find_flag=find_json; _isrun=true; s_page=0; while(_isrun&&s_page<_config_json.max_page){ s_page++; var url = 'json_data/' + this.flag + '@' + s_page + '@data.json'; this.getdata(url, this.loopdatafind); } return this.querypage(); }, //遍历数据 loopdatafind:function(data){ s_list=data; while(_isrun&&s_num1){ p_page--; $(location).attr('href', getpage(p_page)); } }, //上一页数据 getuppagedata:function(){ var backjson=[]; if(p_page>1){ var tmp_page=p_page; //暂存页码数 backjson=this.querypage(p_page-1); p_page=tmp_page; } return backjson }, //下一页 gotodown:function(){ if(p_page0&&num<=p_maxpage){ p_page = num; $(location).attr('href', getpage(p_page)); //this.querypage(num); } }, gotoend:function(){ p_page= p_maxpage; $(location).attr('href', getpage(p_page)); //this.querypage(); } } websitedata.fn.init.prototype = websitedata.fn; return websitedata; })(); function getpage(num){ var href_data =location.href.split("?page="); return href_data[0]+"?page="+num; } function format(now,mask) { now=now.replace(new regexp(/-/gm) ,"/"); var d = new date(now); var zeroize = function (value, length) { if (!length) length = 2; value = string(value); for (var i = 0, zeros = ''; i < (length - value.length); i++) { zeros += '0'; } return zeros + value; }; return mask.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|m{1,4}|yy(?:yy)?|([hhmstt])\1?|[llz])\b/g, function ($0) { switch ($0) { case 'd': return d.getdate(); case 'dd': return zeroize(d.getdate()); case 'ddd': return ['sun', 'mon', 'tue', 'wed', 'thr', 'fri', 'sat'][d.getday()]; case 'dddd': return ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'][d.getday()]; case 'm': return d.getmonth() + 1; case 'mm': return zeroize(d.getmonth() + 1); case 'mmm': return ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'][d.getmonth()]; case 'mmmm': return ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'][d.getmonth()]; case 'yy': return string(d.getfullyear()).substr(2); case 'yyyy': return d.getfullyear(); case 'h': return d.gethours() % 12 || 12; case 'hh': return zeroize(d.gethours() % 12 || 12); case 'h': return d.gethours(); case 'hh': return zeroize(d.gethours()); case 'm': return d.getminutes(); case 'mm': return zeroize(d.getminutes()); case 's': return d.getseconds(); case 'ss': return zeroize(d.getseconds()); case 'l': return zeroize(d.getmilliseconds(), 3); case 'l': var m = d.getmilliseconds(); if (m > 99) m = math.round(m / 10); return zeroize(m); case 'tt': return d.gethours() < 12 ? 'am' : 'pm'; case 'tt': return d.gethours() < 12 ? 'am' : 'pm'; case 'z': return d.toutcstring().match(/[a-z]+$/); // return quoted strings with the surrounding quotes removed default: return $0.substr(1, $0.length - 2); } }); };