/**
* ===================================================== ========================================================== ======
* ===================================================== ========================================================== ======
*/
/**
* @ Version 1.0
* @ 2009-01-09
* @ Author Lin songbin
*/
/**
* ===================================================== ========================================================== ======
* Initialization
* ===================================================== ========================================================== ======
*/
$ (Document). Ready (function (){
Getchannellist (); // gets the news channel list
Getnewslist (); // get the news list
});
/**
* ===================================================== ========================================================== ======
* Data Retrieval
* ===================================================== ========================================================== ======
*/
// Obtain the news channel list
Function getchannellist (){
$. Ajax ({
URL: "/handler/newshandler/news. ashx? Action = getchannellist & TS = "+ new date (). gettime (),
Type: 'get ',
Datatype: 'json ',
Timeout: 1000,
Error: function (){
// Alert ('error loading XML document ');
},
Success: function (result ){
VaR DATA = (result. Table );
$. Each (data, function (I, n ){
Createchannellist (N );
});
}
});
}
// Retrieve paging data
Function getpagedata (myurl, mydata ){
$. Ajax ({
URL: myurl,
Data: mydata,
Type: "Post ",
Datatype: "JSON ",
Error: function (){
// Alert ('error loading XML document ');
},
Success: function (result ){
('{Newslist'{.html ("");
VaR DATA = (result. Table );
$. Each (data, function (I, n ){
Createnewslist (n); // create a news list
});
VaR totalcount = (result. totalcount [0]. totalcount); // The total number of records
Createpage (totalcount); // create a page
}
});
}
/**
* ===================================================== ========================================================== ======
* Method
* ===================================================== ========================================================== ======
*/
// Obtain the news list
Function getnewslist (){
VaR url = "/handler/newshandler/news. ashx ";
Getpagedata (URL, setparms ());
VaR parm = setparms ();
}
// Set parameters
Function setparms (){
VaR mydata = "Action = getpagedata" +
"& Tablename =" + Page. tablename +
"& Fieldlist =" + Page. fieldlist +
"& Primarykey =" + Page. primarykey +
"& Strwhere =" + Page. strwhere +
"& Strorder =" + Page. strorder +
"& Pagesize =" + Page. pagesize +
"& Pageindex =" + Page. pageindex +
"& TS =" + new date (). gettime ();
Return mydata;
}
/**
* ===================================================== ========================================================== ======
* Function
* ===================================================== ========================================================== ======
*/
// String connection
Function stringbuffer (){
This. _ string = new array;
}
Stringbuffer. Prototype. append = function (STR ){
Return this. _ string. Push (STR );
}
Stringbuffer. Prototype. tostring = function (){
Return this. _ string. Join ("");
}
// String Truncation
Function substring (STR, Len, hasdot ){
VaR newlength = 0;
VaR newstr = "";
VaR chineseregex =/[^ \ x00-\ xFF]/g;
VaR singlechar = "";
VaR strlength = Str. Replace (chineseregex, "**"). length;
For (VAR I = 0; I <strlength; I ++ ){
Singlechar = Str. charat (I). tostring ();
If (singlechar. Match (chineseregex )! = NULL ){
Newlength + = 2;
}
Else {
Newlength ++;
}
If (newlength> Len ){
Break;
}
Newstr + = singlechar;
}
If (hasdot & strlength> Len ){
Newstr + = "...";
}
Return newstr;
}
// Obtain parameters
Function querystring (item ){
VaR svalue = location. Search. Match (New Regexp ("[\? \ &] "+ Item +" = ([^ \ &] *) (\ &?) "," I "))
Return svalue? Svalue [1]: svalue
}
/**
* ===================================================== ========================================================== ======
* Events
* ===================================================== ========================================================== ======
*/
// Click the channel
Function channelclick (channelid ){
Page. strwhere = "channelid =" + channelid;
Getnewslist ();
}
// Click the news
Function newsclick (newsid ){
VaR url = "/news/displaynews.html? Newsid = "+ newsid;
Self. Location = URL;
}
// Click the page
Function pageclick (page_id, JQ ){
Page. pageindex = page_id + 1;
Getnewslist ();
}
/**
* ===================================================== ========================================================== ======
* Operation UI
* ===================================================== ========================================================== ======
*/
// create a news list
function createnewslist (n) {
var li = "
";
Li + = "[";
Li + = "";
Li + = n. channelname;
Li + = "";
Li + = "]";
Li + = "";
Li + = n. title;
Li + = "";
Li + = "";
$ ('# newslist '). append ($ (LI);
}
// Create a news channel list
Function createchannellist (n ){
VaR li = "<li> ";
Li + = "<a href = 'javascript:; 'onclick = 'channelclick (" + N. channelid + ") '; return false'> ";
Li + = n. channelname;
Li + = "</a> ";
Li + = "</LI> ";
$ ('# Channellist'). append ($ (LI ));
}
// Create a page
Function createpage (totalcount ){
$ ("# Pagination"). pagination (totalcount, {items_per_page: page. pagesize, current_page: (page. pageindex-1), callback: pageclick });
}
/**
* ===================================================== ========================================================== ======
* ===================================================== ========================================================== ======
*/
Function page (tablename, fieldlist, primarykey, strwhere, strorder, pagesize, pageindex ){
This. tablename = tablename;
This. fieldlist = fieldlist;
This. primarykey = primarykey;
This. strwhere = strwhere;
This. strorder = strorder;
This. pagesize = pagesize;
This. pageindex = pageindex;
}
VaR page = new page ();
Page. tablename = "ne_news ";
Page. fieldlist = "newsid, channelid, channelname, title ";
Page. primarykey = "newsid ";
Page. strwhere = "";
Page. strorder = "newsid DESC ";
Page. recordercount = 0;
Page. pagesize = 2;
Page. pageindex = 1;
/**
* ===================================================== ========================================================== ======
* ===================================================== ========================================================== ======
*/