source: extensions/GrumPluginClasses/js/pagesNavigator.min.js @ 12201

Last change on this file since 12201 was 8961, checked in by grum, 14 years ago

release 3.4.0
fix bug:1984, bug:2109
js file are minified, remove packed files

  • Property svn:executable set to *
File size: 5.0 KB
Line 
1/* file: pageNavigator.js - v1.0.0 | minified on 2011/01/27 with http://jscompress.com/ */
2function pagesNavigator(container)
3{var itemsId={first:'iNavFirst',last:'iNavLast',previous:'iNavPrevious',next:'iNavNext',pageNumber:'iNavPage',morePrevious:'iNavPrevMore',moreNext:'iNavNextMore',container:container,},pages={num:0,current:1,},options={numberItem:0,itemPerPage:25,defaultPage:0,displayNumPage:7,displayFirst:true,displayLast:true,displayPrevious:true,displayNext:true,hideMode:'1,<',textFirst:'<<',textLast:'>>',textPrevious:'<',textNext:'>',textMore:'...',onPageChange:null,classActive:'',classInactive:'',classDisabled:'',};this.doAction=function(fct)
4{switch(fct)
5{case'setOptions':if(arguments.length==2)
6{setOptions(arguments[1]);}
7break;}};var calcNumPages=function(numItems,numPerPage)
8{return(Math.ceil(numItems/numPerPage));};var setOptions=function(optionsToSet)
9{if(typeof optionsToSet=='object')
10{options=jQuery.extend(options,optionsToSet);if(options.numberItem<=0)options.numberItem=0;if(options.itemPerPage<=0)options.itemPerPage=25;if(options.displayNumPage<=2)options.displayNumPage=8;pages.num=calcNumPages(options.numberItem,options.itemPerPage);if(options.defaultPage>0&&options.defaultPage<=pages.num)pages.current=options.defaultPage;build();}};var build=function()
11{re=/1/;if((re.exec(options.hideMode)==null)==false&&pages.num==1)
12{$('#'+itemsId.container).html('');return('');}
13var content="<ul id='"+container+"PageNavigator'>";styleLI=" list-style:none;float:left; ";re=/</;if((re.exec(options.hideMode)==null)==false&&pages.num<=options.displayNumPage)
14{hideFPNL='display:none;';}
15else
16{hideFPNL='';}
17pnClass="class='cPnInactive "+options.classInactive+"'";if(options.displayFirst)content+="<li style='"+styleLI+hideFPNL+"' id='"+itemsId.first+"' "+pnClass+">"+options.textFirst+"</li>";if(options.displayPrevious)content+="<li style='"+styleLI+hideFPNL+"' id='"+itemsId.previous+"' "+pnClass+">"+options.textPrevious+"</li>";content+="<li style='"+styleLI+"display:none;' id='"+itemsId.morePrevious+"' class='cPnDisabled "+options.classDisabled+"'>"+options.textMore+"</li>";for(i=1;i<=pages.num;i++)
18{content+="<li style='"+styleLI+"display:none;' id='"+itemsId.pageNumber+i+"' "+pnClass+">"+i+"</li>";}
19content+="<li style='"+styleLI+";display:none;' id='"+itemsId.moreNext+"' class='cPnDisabled "+options.classDisabled+"'>"+options.textMore+"</li>";if(options.displayNext)content+="<li style='"+styleLI+hideFPNL+"' id='"+itemsId.next+"' "+pnClass+">"+options.textNext+"</li>";if(options.displayLast)content+="<li style='"+styleLI+hideFPNL+"' id='"+itemsId.last+"' "+pnClass+">"+options.textLast+"</li>";content+="</ul>";$('#'+itemsId.container).css('visibility','hidden').html(content);$('.cPnInactive').bind('click',onChangePage);displayNav();$('#'+itemsId.container).css('visibility','visible');};var displayNav=function()
20{prev=Math.ceil((options.displayNumPage-1)/2);if(pages.current-prev<=0)
21{prev=pages.current-1;}
22next=options.displayNumPage-1-prev;if(pages.current+next>=pages.num)
23{prev+=(pages.current+next-pages.num);next=pages.num-pages.current;}
24prev=pages.current-prev;next=pages.current+next;if(prev>1)
25{$('#'+itemsId.morePrevious).css('display','block');}
26else
27{$('#'+itemsId.morePrevious).css('display','none');}
28if(next<pages.num)
29{$('#'+itemsId.moreNext).css('display','block');}
30else
31{$('#'+itemsId.moreNext).css('display','none');}
32$('#'+itemsId.container+' ul li').each(function()
33{id=-1;if(!(this.id==itemsId.first||this.id==itemsId.previous||this.id==itemsId.next||this.id==itemsId.last||this.id==itemsId.morePrevious||this.id==itemsId.moreNext))
34{re=/[0-9]*$/i;id=re.exec(this.id)[0];if(id>=prev&&id<=next)
35{$(this).css('display','block');}
36else
37{$(this).css('display','none');}
38if(id==pages.current)
39{$(this).addClass('cPnActive '+options.classActive).removeClass('cPnInactive '+options.classInactive);}
40else
41{$(this).addClass('cPnInactive '+options.classInactive).removeClass('cPnActive '+options.classActive);}}
42if(((this.id==itemsId.first||this.id==itemsId.previous)&&pages.current==1)||((this.id==itemsId.last||this.id==itemsId.next)&&pages.current==pages.num)||(this.id==itemsId.morePrevious||this.id==itemsId.moreNext))
43{$(this).addClass('cPnDisabled '+options.classDisabled).removeClass('cPnInactive '+options.classInactive);}
44else
45{$(this).addClass('cPnInactive '+options.classInactive).removeClass('cPnDisabled '+options.classDisabled);}});};var onChangePage=function(event)
46{if(event.target.id==itemsId.first)
47{pages.current=1;}
48else if(event.target.id==itemsId.previous)
49{pages.current--;}
50else if(event.target.id==itemsId.next)
51{pages.current++;}
52else if(event.target.id==itemsId.last)
53{pages.current=pages.num;}
54else
55{re=/[0-9]*$/i;page=re.exec(event.target.id)[0];if(page==pages.current)return(false);pages.current=eval(page);}
56if(pages.current<=0)pages.current=1;if(pages.current>=pages.num)pages.current=pages.num;displayNav();if(options.onPageChange!=null&&jQuery.isFunction(options.onPageChange))options.onPageChange(pages.current);};if(arguments.length==2)
57{setOptions(arguments[1]);}}
Note: See TracBrowser for help on using the repository browser.