0
|
1 /*
|
|
2 * Variable: oPagination
|
|
3 * Purpose:
|
|
4 * Scope: jQuery.fn.dataTableExt
|
|
5 */
|
|
6 $.extend( DataTable.ext.oPagination, {
|
|
7 /*
|
|
8 * Variable: two_button
|
|
9 * Purpose: Standard two button (forward/back) pagination
|
|
10 * Scope: jQuery.fn.dataTableExt.oPagination
|
|
11 */
|
|
12 "two_button": {
|
|
13 /*
|
|
14 * Function: oPagination.two_button.fnInit
|
|
15 * Purpose: Initialise dom elements required for pagination with forward/back buttons only
|
|
16 * Returns: -
|
|
17 * Inputs: object:oSettings - dataTables settings object
|
|
18 * node:nPaging - the DIV which contains this pagination control
|
|
19 * function:fnCallbackDraw - draw function which must be called on update
|
|
20 */
|
|
21 "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
|
|
22 {
|
|
23 var oLang = oSettings.oLanguage.oPaginate;
|
|
24 var oClasses = oSettings.oClasses;
|
|
25 var fnClickHandler = function ( e ) {
|
|
26 if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
|
|
27 {
|
|
28 fnCallbackDraw( oSettings );
|
|
29 }
|
|
30 };
|
|
31
|
|
32 var sAppend = (!oSettings.bJUI) ?
|
|
33 '<a class="'+oSettings.oClasses.sPagePrevDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button">'+oLang.sPrevious+'</a>'+
|
|
34 '<a class="'+oSettings.oClasses.sPageNextDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button">'+oLang.sNext+'</a>'
|
|
35 :
|
|
36 '<a class="'+oSettings.oClasses.sPagePrevDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button"><span class="'+oSettings.oClasses.sPageJUIPrev+'"></span></a>'+
|
|
37 '<a class="'+oSettings.oClasses.sPageNextDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button"><span class="'+oSettings.oClasses.sPageJUINext+'"></span></a>';
|
|
38 $(nPaging).append( sAppend );
|
|
39
|
|
40 var els = $('a', nPaging);
|
|
41 var nPrevious = els[0],
|
|
42 nNext = els[1];
|
|
43
|
|
44 oSettings.oApi._fnBindAction( nPrevious, {action: "previous"}, fnClickHandler );
|
|
45 oSettings.oApi._fnBindAction( nNext, {action: "next"}, fnClickHandler );
|
|
46
|
|
47 /* ID the first elements only */
|
|
48 if ( !oSettings.aanFeatures.p )
|
|
49 {
|
|
50 nPaging.id = oSettings.sTableId+'_paginate';
|
|
51 nPrevious.id = oSettings.sTableId+'_previous';
|
|
52 nNext.id = oSettings.sTableId+'_next';
|
|
53
|
|
54 nPrevious.setAttribute('aria-controls', oSettings.sTableId);
|
|
55 nNext.setAttribute('aria-controls', oSettings.sTableId);
|
|
56 }
|
|
57 },
|
|
58
|
|
59 /*
|
|
60 * Function: oPagination.two_button.fnUpdate
|
|
61 * Purpose: Update the two button pagination at the end of the draw
|
|
62 * Returns: -
|
|
63 * Inputs: object:oSettings - dataTables settings object
|
|
64 * function:fnCallbackDraw - draw function to call on page change
|
|
65 */
|
|
66 "fnUpdate": function ( oSettings, fnCallbackDraw )
|
|
67 {
|
|
68 if ( !oSettings.aanFeatures.p )
|
|
69 {
|
|
70 return;
|
|
71 }
|
|
72
|
|
73 var oClasses = oSettings.oClasses;
|
|
74 var an = oSettings.aanFeatures.p;
|
|
75 var nNode;
|
|
76
|
|
77 /* Loop over each instance of the pager */
|
|
78 for ( var i=0, iLen=an.length ; i<iLen ; i++ )
|
|
79 {
|
|
80 nNode = an[i].firstChild;
|
|
81 if ( nNode )
|
|
82 {
|
|
83 /* Previous page */
|
|
84 nNode.className = ( oSettings._iDisplayStart === 0 ) ?
|
|
85 oClasses.sPagePrevDisabled : oClasses.sPagePrevEnabled;
|
|
86
|
|
87 /* Next page */
|
|
88 nNode = nNode.nextSibling;
|
|
89 nNode.className = ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() ) ?
|
|
90 oClasses.sPageNextDisabled : oClasses.sPageNextEnabled;
|
|
91 }
|
|
92 }
|
|
93 }
|
|
94 },
|
|
95
|
|
96
|
|
97 /*
|
|
98 * Variable: iFullNumbersShowPages
|
|
99 * Purpose: Change the number of pages which can be seen
|
|
100 * Scope: jQuery.fn.dataTableExt.oPagination
|
|
101 */
|
|
102 "iFullNumbersShowPages": 5,
|
|
103
|
|
104 /*
|
|
105 * Variable: full_numbers
|
|
106 * Purpose: Full numbers pagination
|
|
107 * Scope: jQuery.fn.dataTableExt.oPagination
|
|
108 */
|
|
109 "full_numbers": {
|
|
110 /*
|
|
111 * Function: oPagination.full_numbers.fnInit
|
|
112 * Purpose: Initialise dom elements required for pagination with a list of the pages
|
|
113 * Returns: -
|
|
114 * Inputs: object:oSettings - dataTables settings object
|
|
115 * node:nPaging - the DIV which contains this pagination control
|
|
116 * function:fnCallbackDraw - draw function which must be called on update
|
|
117 */
|
|
118 "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
|
|
119 {
|
|
120 var oLang = oSettings.oLanguage.oPaginate;
|
|
121 var oClasses = oSettings.oClasses;
|
|
122 var fnClickHandler = function ( e ) {
|
|
123 if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
|
|
124 {
|
|
125 fnCallbackDraw( oSettings );
|
|
126 }
|
|
127 };
|
|
128
|
|
129 $(nPaging).append(
|
|
130 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageFirst+'">'+oLang.sFirst+'</a>'+
|
|
131 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPagePrevious+'">'+oLang.sPrevious+'</a>'+
|
|
132 '<span></span>'+
|
|
133 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageNext+'">'+oLang.sNext+'</a>'+
|
|
134 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageLast+'">'+oLang.sLast+'</a>'
|
|
135 );
|
|
136 var els = $('a', nPaging);
|
|
137 var nFirst = els[0],
|
|
138 nPrev = els[1],
|
|
139 nNext = els[2],
|
|
140 nLast = els[3];
|
|
141
|
|
142 oSettings.oApi._fnBindAction( nFirst, {action: "first"}, fnClickHandler );
|
|
143 oSettings.oApi._fnBindAction( nPrev, {action: "previous"}, fnClickHandler );
|
|
144 oSettings.oApi._fnBindAction( nNext, {action: "next"}, fnClickHandler );
|
|
145 oSettings.oApi._fnBindAction( nLast, {action: "last"}, fnClickHandler );
|
|
146
|
|
147 /* ID the first elements only */
|
|
148 if ( !oSettings.aanFeatures.p )
|
|
149 {
|
|
150 nPaging.id = oSettings.sTableId+'_paginate';
|
|
151 nFirst.id =oSettings.sTableId+'_first';
|
|
152 nPrev.id =oSettings.sTableId+'_previous';
|
|
153 nNext.id =oSettings.sTableId+'_next';
|
|
154 nLast.id =oSettings.sTableId+'_last';
|
|
155 }
|
|
156 },
|
|
157
|
|
158 /*
|
|
159 * Function: oPagination.full_numbers.fnUpdate
|
|
160 * Purpose: Update the list of page buttons shows
|
|
161 * Returns: -
|
|
162 * Inputs: object:oSettings - dataTables settings object
|
|
163 * function:fnCallbackDraw - draw function to call on page change
|
|
164 */
|
|
165 "fnUpdate": function ( oSettings, fnCallbackDraw )
|
|
166 {
|
|
167 if ( !oSettings.aanFeatures.p )
|
|
168 {
|
|
169 return;
|
|
170 }
|
|
171
|
|
172 var iPageCount = DataTable.ext.oPagination.iFullNumbersShowPages;
|
|
173 var iPageCountHalf = Math.floor(iPageCount / 2);
|
|
174 var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength);
|
|
175 var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
|
|
176 var sList = "";
|
|
177 var iStartButton, iEndButton, i, iLen;
|
|
178 var oClasses = oSettings.oClasses;
|
|
179 var anButtons, anStatic, nPaginateList, nNode;
|
|
180 var an = oSettings.aanFeatures.p;
|
|
181 var fnBind = function (j) {
|
|
182 oSettings.oApi._fnBindAction( this, {"page": j+iStartButton-1}, function(e) {
|
|
183 /* Use the information in the element to jump to the required page */
|
|
184 oSettings.oApi._fnPageChange( oSettings, e.data.page );
|
|
185 fnCallbackDraw( oSettings );
|
|
186 e.preventDefault();
|
|
187 } );
|
|
188 };
|
|
189
|
|
190 /* Pages calculation */
|
|
191 if ( oSettings._iDisplayLength === -1 )
|
|
192 {
|
|
193 iStartButton = 1;
|
|
194 iEndButton = 1;
|
|
195 iCurrentPage = 1;
|
|
196 }
|
|
197 else if (iPages < iPageCount)
|
|
198 {
|
|
199 iStartButton = 1;
|
|
200 iEndButton = iPages;
|
|
201 }
|
|
202 else if (iCurrentPage <= iPageCountHalf)
|
|
203 {
|
|
204 iStartButton = 1;
|
|
205 iEndButton = iPageCount;
|
|
206 }
|
|
207 else if (iCurrentPage >= (iPages - iPageCountHalf))
|
|
208 {
|
|
209 iStartButton = iPages - iPageCount + 1;
|
|
210 iEndButton = iPages;
|
|
211 }
|
|
212 else
|
|
213 {
|
|
214 iStartButton = iCurrentPage - Math.ceil(iPageCount / 2) + 1;
|
|
215 iEndButton = iStartButton + iPageCount - 1;
|
|
216 }
|
|
217
|
|
218
|
|
219 /* Build the dynamic list */
|
|
220 for ( i=iStartButton ; i<=iEndButton ; i++ )
|
|
221 {
|
|
222 sList += (iCurrentPage !== i) ?
|
|
223 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+'">'+oSettings.fnFormatNumber(i)+'</a>' :
|
|
224 '<a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButtonActive+'">'+oSettings.fnFormatNumber(i)+'</a>';
|
|
225 }
|
|
226
|
|
227 /* Loop over each instance of the pager */
|
|
228 for ( i=0, iLen=an.length ; i<iLen ; i++ )
|
|
229 {
|
|
230 nNode = an[i];
|
|
231 if ( !nNode.hasChildNodes() )
|
|
232 {
|
|
233 continue;
|
|
234 }
|
|
235
|
|
236 /* Build up the dynamic list first - html and listeners */
|
|
237 $('span:eq(0)', nNode)
|
|
238 .html( sList )
|
|
239 .children('a').each( fnBind );
|
|
240
|
|
241 /* Update the permanent button's classes */
|
|
242 anButtons = nNode.getElementsByTagName('a');
|
|
243 anStatic = [
|
|
244 anButtons[0], anButtons[1],
|
|
245 anButtons[anButtons.length-2], anButtons[anButtons.length-1]
|
|
246 ];
|
|
247
|
|
248 $(anStatic).removeClass( oClasses.sPageButton+" "+oClasses.sPageButtonActive+" "+oClasses.sPageButtonStaticDisabled );
|
|
249 $([anStatic[0], anStatic[1]]).addClass(
|
|
250 (iCurrentPage==1) ?
|
|
251 oClasses.sPageButtonStaticDisabled :
|
|
252 oClasses.sPageButton
|
|
253 );
|
|
254 $([anStatic[2], anStatic[3]]).addClass(
|
|
255 (iPages===0 || iCurrentPage===iPages || oSettings._iDisplayLength===-1) ?
|
|
256 oClasses.sPageButtonStaticDisabled :
|
|
257 oClasses.sPageButton
|
|
258 );
|
|
259 }
|
|
260 }
|
|
261 }
|
|
262 } );
|