Bug 12899: Row grouping in checkouts table is alphabetical and depends on translation
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / js / datatables.js
1 // These default options are for translation but can be used
2 // for any other datatables settings
3 // MSG_DT_* variables comes from datatables-strings.inc
4 // To use it, write:
5 //  $("#table_id").dataTable($.extend(true, {}, dataTableDefaults, {
6 //      // other settings
7 //  } ) );
8 var dataTablesDefaults = {
9     "oLanguage": {
10         "oPaginate": {
11             "sFirst"    : window.MSG_DT_FIRST || "First",
12             "sLast"     : window.MSG_DT_LAST || "Last",
13             "sNext"     : window.MSG_DT_NEXT || "Next",
14             "sPrevious" : window.MSG_DT_PREVIOUS || "Previous"
15         },
16         "sEmptyTable"       : window.MSG_DT_EMPTY_TABLE || "No data available in table",
17         "sInfo"             : window.MSG_DT_INFO || "Showing _START_ to _END_ of _TOTAL_ entries",
18         "sInfoEmpty"        : window.MSG_DT_INFO_EMPTY || "No entries to show",
19         "sInfoFiltered"     : window.MSG_DT_INFO_FILTERED || "(filtered from _MAX_ total entries)",
20         "sLengthMenu"       : window.MSG_DT_LENGTH_MENU || "Show _MENU_ entries",
21         "sLoadingRecords"   : window.MSG_DT_LOADING_RECORDS || "Loading...",
22         "sProcessing"       : window.MSG_DT_PROCESSING || "Processing...",
23         "sSearch"           : window.MSG_DT_SEARCH || "Search:",
24         "sZeroRecords"      : window.MSG_DT_ZERO_RECORDS || "No matching records found"
25     },
26     "sDom": 'C<"top pager"ilpf>tr<"bottom pager"ip>',
27     "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, window.MSG_DT_ALL || "All"]],
28     "iDisplayLength": 20
29 };
30
31
32 // Return an array of string containing the values of a particular column
33 $.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) {
34     // check that we have a column id
35     if ( typeof iColumn == "undefined" ) return new Array();
36     // by default we only wany unique data
37     if ( typeof bUnique == "undefined" ) bUnique = true;
38     // by default we do want to only look at filtered data
39     if ( typeof bFiltered == "undefined" ) bFiltered = true;
40     // by default we do not wany to include empty values
41     if ( typeof bIgnoreEmpty == "undefined" ) bIgnoreEmpty = true;
42     // list of rows which we're going to loop through
43     var aiRows;
44     // use only filtered rows
45     if (bFiltered == true) aiRows = oSettings.aiDisplay;
46     // use all rows
47     else aiRows = oSettings.aiDisplayMaster; // all row numbers
48
49     // set up data array
50     var asResultData = new Array();
51     for (var i=0,c=aiRows.length; i<c; i++) {
52         iRow = aiRows[i];
53         var aData = this.fnGetData(iRow);
54         var sValue = aData[iColumn];
55         // ignore empty values?
56         if (bIgnoreEmpty == true && sValue.length == 0) continue;
57         // ignore unique values?
58         else if (bUnique == true && jQuery.inArray(sValue, asResultData) > -1) continue;
59         // else push the value onto the result data array
60         else asResultData.push(sValue);
61     }
62     return asResultData;
63 }
64
65 // List of unbind keys (Ctrl, Alt, Direction keys, etc.)
66 // These keys must not launch filtering
67 var blacklist_keys = new Array(0, 16, 17, 18, 37, 38, 39, 40);
68
69 // Set a filtering delay for global search field
70 jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
71     /*
72      * Inputs:      object:oSettings - dataTables settings object - automatically given
73      *              integer:iDelay - delay in milliseconds
74      * Usage:       $('#example').dataTable().fnSetFilteringDelay(250);
75      * Author:      Zygimantas Berziunas (www.zygimantas.com) and Allan Jardine
76      * License:     GPL v2 or BSD 3 point style
77      * Contact:     zygimantas.berziunas /AT\ hotmail.com
78      */
79     var
80         _that = this,
81         iDelay = (typeof iDelay == 'undefined') ? 250 : iDelay;
82
83     this.each( function ( i ) {
84         $.fn.dataTableExt.iApiIndex = i;
85         var
86             $this = this,
87             oTimerId = null,
88             sPreviousSearch = null,
89             anControl = $( 'input', _that.fnSettings().aanFeatures.f );
90
91         anControl.unbind( 'keyup.DT' ).bind( 'keyup.DT', function(event) {
92             var $$this = $this;
93             if (blacklist_keys.indexOf(event.keyCode) != -1) {
94                 return this;
95             }else if ( event.keyCode == '13' ) {
96                 $.fn.dataTableExt.iApiIndex = i;
97                 _that.fnFilter( $(this).val() );
98             } else {
99                 if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
100                     window.clearTimeout(oTimerId);
101                     sPreviousSearch = anControl.val();
102                     oTimerId = window.setTimeout(function() {
103                         $.fn.dataTableExt.iApiIndex = i;
104                         _that.fnFilter( anControl.val() );
105                     }, iDelay);
106                 }
107             }
108         });
109
110         return this;
111     } );
112     return this;
113 }
114
115 // Add a filtering delay on general search and on all input (with a class 'filter')
116 jQuery.fn.dataTableExt.oApi.fnAddFilters = function ( oSettings, sClass, iDelay ) {
117     var table = this;
118     this.fnSetFilteringDelay(iDelay);
119     var filterTimerId = null;
120     $(table).find("input."+sClass).keyup(function(event) {
121       if (blacklist_keys.indexOf(event.keyCode) != -1) {
122         return this;
123       }else if ( event.keyCode == '13' ) {
124         table.fnFilter( $(this).val(), $(this).attr('data-column_num') );
125       } else {
126         window.clearTimeout(filterTimerId);
127         var input = this;
128         filterTimerId = window.setTimeout(function() {
129           table.fnFilter($(input).val(), $(input).attr('data-column_num'));
130         }, iDelay);
131       }
132     });
133 }
134
135 // Useful if you want to filter on dates with 2 inputs (start date and end date)
136 // You have to include calendar.inc to use it
137 function dt_add_rangedate_filter(begindate_id, enddate_id, dateCol) {
138     $.fn.dataTableExt.afnFiltering.push(
139         function( oSettings, aData, iDataIndex ) {
140
141             var beginDate = Date_from_syspref($("#"+begindate_id).val()).getTime();
142             var endDate   = Date_from_syspref($("#"+enddate_id).val()).getTime();
143
144             var data = Date_from_syspref(aData[dateCol]).getTime();
145
146             if ( !parseInt(beginDate) && ! parseInt(endDate) ) {
147                 return true;
148             }
149             else if ( beginDate <= data && !parseInt(endDate) ) {
150                 return true;
151             }
152             else if ( data <= endDate && !parseInt(beginDate) ) {
153                 return true;
154             }
155             else if ( beginDate <= data && data <= endDate) {
156                 return true;
157             }
158             return false;
159         }
160     );
161 }
162
163 // Sorting on html contains
164 // <a href="foo.pl">bar</a> sort on 'bar'
165 function dt_overwrite_html_sorting_localeCompare() {
166     jQuery.fn.dataTableExt.oSort['html-asc']  = function(a,b) {
167         a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
168         b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
169         if (typeof(a.localeCompare == "function")) {
170            return a.localeCompare(b);
171         } else {
172            return (a > b) ? 1 : ((a < b) ? -1 : 0);
173         }
174     };
175
176     jQuery.fn.dataTableExt.oSort['html-desc'] = function(a,b) {
177         a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
178         b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
179         if(typeof(b.localeCompare == "function")) {
180             return b.localeCompare(a);
181         } else {
182             return (b > a) ? 1 : ((b < a) ? -1 : 0);
183         }
184     };
185
186     jQuery.fn.dataTableExt.oSort['num-html-asc']  = function(a,b) {
187         var x = a.replace( /<.*?>/g, "" );
188         var y = b.replace( /<.*?>/g, "" );
189         x = parseFloat( x );
190         y = parseFloat( y );
191         return ((x < y) ? -1 : ((x > y) ?  1 : 0));
192     };
193
194     jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
195         var x = a.replace( /<.*?>/g, "" );
196         var y = b.replace( /<.*?>/g, "" );
197         x = parseFloat( x );
198         y = parseFloat( y );
199         return ((x < y) ?  1 : ((x > y) ? -1 : 0));
200     };
201 }
202
203 // Sorting on string without accentued characters
204 function dt_overwrite_string_sorting_localeCompare() {
205     jQuery.fn.dataTableExt.oSort['string-asc']  = function(a,b) {
206         a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
207         b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
208         if (typeof(a.localeCompare == "function")) {
209            return a.localeCompare(b);
210         } else {
211            return (a > b) ? 1 : ((a < b) ? -1 : 0);
212         }
213     };
214
215     jQuery.fn.dataTableExt.oSort['string-desc'] = function(a,b) {
216         a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
217         b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
218         if(typeof(b.localeCompare == "function")) {
219             return b.localeCompare(a);
220         } else {
221             return (b > a) ? 1 : ((b < a) ? -1 : 0);
222         }
223     };
224 }
225
226 // Replace a node with a html and js contain.
227 function replace_html( original_node, type ) {
228     switch ( $(original_node).attr('data-type') ) {
229         case "range_dates":
230             var id = $(original_node).attr("data-id");
231             var format = $(original_node).attr("data-format");
232             replace_html_date( original_node, id, format );
233             break;
234         default:
235             alert(_("This node can't be replaced"));
236     }
237 }
238
239 // Replace a node with a "From [date] To [date]" element
240 // Used on tfoot > td
241 function replace_html_date( original_node, id, format ) {
242     var node = $('<span style="white-space:nowrap">' + _("From") + '<input type="text" id="' + id + 'from" readonly="readonly" placeholder=\'' + _("Pick date") + '\' size="7" /><a title="' + _("Delete this filter") + '" style="cursor:pointer" onclick=\'$("#' + id + 'from").val("").change();\' >&times;</a></span><br/><span style="white-space:nowrap">' + _("To") + '<input type="text" id="' + id + 'to" readonly="readonly" placeholder=\'' + _("Pick date") + '\' size="7" /><a title="' + _("Delete this filter") + '" style="cursor:pointer" onclick=\'$("#' + id + 'to").val("").change();\' >&times;</a></span>');
243     $(original_node).replaceWith(node);
244     var script = document.createElement( 'script' );
245     script.type = 'text/javascript';
246     var script_content = "Calendar.setup({";
247     script_content += "    inputField: \"" + id + "from\",";
248     script_content += "    ifFormat: \"" + format + "\",";
249     script_content += "    button: \"" + id + "from\",";
250     script_content += "    onClose: function(){ $(\"#" + id + "from\").change(); this.hide();}";
251     script_content += "  });";
252     script_content += "  Calendar.setup({";
253     script_content += "    inputField: \"" + id + "to\",";
254     script_content += "    ifFormat: \"" + format + "\",";
255     script_content += "    button: \"" + id + "to\",";
256     script_content += "    onClose: function(){ $(\"#" + id + "to\").change(); this.hide();}";
257     script_content += "  });";
258     script.text = script_content;
259     $(original_node).append( script );
260 }
261
262 $.fn.dataTableExt.oPagination.four_button = {
263     /*
264      * Function: oPagination.four_button.fnInit
265      * Purpose:  Initalise dom elements required for pagination with a list of the pages
266      * Returns:  -
267      * Inputs:   object:oSettings - dataTables settings object
268      *           node:nPaging - the DIV which contains this pagination control
269      *           function:fnCallbackDraw - draw function which must be called on update
270      */
271     "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
272     {
273         nFirst = document.createElement( 'span' );
274         nPrevious = document.createElement( 'span' );
275         nNext = document.createElement( 'span' );
276         nLast = document.createElement( 'span' );
277
278         nFirst.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sFirst ) );
279         nPrevious.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sPrevious ) );
280         nNext.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sNext ) );
281         nLast.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sLast ) );
282
283         nFirst.className = "paginate_button first";
284         nPrevious.className = "paginate_button previous";
285         nNext.className="paginate_button next";
286         nLast.className = "paginate_button last";
287
288         nPaging.appendChild( nFirst );
289         nPaging.appendChild( nPrevious );
290         nPaging.appendChild( nNext );
291         nPaging.appendChild( nLast );
292
293         $(nFirst).click( function () {
294             oSettings.oApi._fnPageChange( oSettings, "first" );
295             fnCallbackDraw( oSettings );
296         } );
297
298         $(nPrevious).click( function() {
299             oSettings.oApi._fnPageChange( oSettings, "previous" );
300             fnCallbackDraw( oSettings );
301         } );
302
303         $(nNext).click( function() {
304             oSettings.oApi._fnPageChange( oSettings, "next" );
305             fnCallbackDraw( oSettings );
306         } );
307
308         $(nLast).click( function() {
309             oSettings.oApi._fnPageChange( oSettings, "last" );
310             fnCallbackDraw( oSettings );
311         } );
312
313         /* Disallow text selection */
314         $(nFirst).bind( 'selectstart', function () { return false; } );
315         $(nPrevious).bind( 'selectstart', function () { return false; } );
316         $(nNext).bind( 'selectstart', function () { return false; } );
317         $(nLast).bind( 'selectstart', function () { return false; } );
318     },
319
320     /*
321      * Function: oPagination.four_button.fnUpdate
322      * Purpose:  Update the list of page buttons shows
323      * Returns:  -
324      * Inputs:   object:oSettings - dataTables settings object
325      *           function:fnCallbackDraw - draw function which must be called on update
326      */
327     "fnUpdate": function ( oSettings, fnCallbackDraw )
328     {
329         if ( !oSettings.aanFeatures.p )
330         {
331             return;
332         }
333
334         /* Loop over each instance of the pager */
335         var an = oSettings.aanFeatures.p;
336         for ( var i=0, iLen=an.length ; i<iLen ; i++ )
337         {
338             var buttons = an[i].getElementsByTagName('span');
339             if ( oSettings._iDisplayStart === 0 )
340             {
341                 buttons[0].className = "paginate_disabled_previous";
342                 buttons[1].className = "paginate_disabled_previous";
343             }
344             else
345             {
346                 buttons[0].className = "paginate_enabled_previous";
347                 buttons[1].className = "paginate_enabled_previous";
348             }
349
350             if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() )
351             {
352                 buttons[2].className = "paginate_disabled_next";
353                 buttons[3].className = "paginate_disabled_next";
354             }
355             else
356             {
357                 buttons[2].className = "paginate_enabled_next";
358                 buttons[3].className = "paginate_enabled_next";
359             }
360         }
361     }
362 };
363
364 $.fn.dataTableExt.oSort['num-html-asc']  = function(a,b) {
365     var x = a.replace( /<.*?>/g, "" );
366     var y = b.replace( /<.*?>/g, "" );
367     x = parseFloat( x );
368     y = parseFloat( y );
369     return ((x < y) ? -1 : ((x > y) ?  1 : 0));
370 };
371
372 $.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
373     var x = a.replace( /<.*?>/g, "" );
374     var y = b.replace( /<.*?>/g, "" );
375     x = parseFloat( x );
376     y = parseFloat( y );
377     return ((x < y) ?  1 : ((x > y) ? -1 : 0));
378 };
379
380 (function() {
381
382 /*
383  * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
384  * Author: Jim Palmer (based on chunking idea from Dave Koelle)
385  * Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo
386  * See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js
387  */
388 function naturalSort (a, b) {
389     var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
390         sre = /(^[ ]*|[ ]*$)/g,
391         dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
392         hre = /^0x[0-9a-f]+$/i,
393         ore = /^0/,
394         // convert all to strings and trim()
395         x = a.toString().replace(sre, '') || '',
396         y = b.toString().replace(sre, '') || '',
397         // chunk/tokenize
398         xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
399         yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
400         // numeric, hex or date detection
401         xD = parseInt(x.match(hre), 10) || (xN.length != 1 && x.match(dre) && Date.parse(x)),
402         yD = parseInt(y.match(hre), 10) || xD && y.match(dre) && Date.parse(y) || null;
403     // first try and sort Hex codes or Dates
404     if (yD)
405         if ( xD < yD ) return -1;
406         else if ( xD > yD )  return 1;
407     // natural sorting through split numeric strings and default strings
408     for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
409         // find floats not starting with '0', string or 0 if not defined (Clint Priest)
410         var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
411         var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
412         // handle numeric vs string comparison - number < string - (Kyle Adams)
413         if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1;
414         // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
415         else if (typeof oFxNcL !== typeof oFyNcL) {
416             oFxNcL += '';
417             oFyNcL += '';
418         }
419         if (oFxNcL < oFyNcL) return -1;
420         if (oFxNcL > oFyNcL) return 1;
421     }
422     return 0;
423 }
424
425 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
426     "natural-asc": function ( a, b ) {
427         return naturalSort(a,b);
428     },
429
430     "natural-desc": function ( a, b ) {
431         return naturalSort(a,b) * -1;
432     }
433 } );
434
435 }());
436
437 /* Plugin to allow sorting on data stored in a span's title attribute
438  *
439  * Ex: <td><span title="[% ISO_date %]">[% formatted_date %]</span></td>
440  *
441  * In DataTables config:
442  *     "aoColumns": [
443  *        { "sType": "title-string" },
444  *      ]
445  * http://datatables.net/plug-ins/sorting#hidden_title_string
446  */
447 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
448     "title-string-pre": function ( a ) {
449         return a.match(/title="(.*?)"/)[1].toLowerCase();
450     },
451
452     "title-string-asc": function ( a, b ) {
453         return ((a < b) ? -1 : ((a > b) ? 1 : 0));
454     },
455
456     "title-string-desc": function ( a, b ) {
457         return ((a < b) ? 1 : ((a > b) ? -1 : 0));
458     }
459 } );
460
461 /* Plugin to allow sorting on numeric data stored in a span's title attribute
462  *
463  * Ex: <td><span title="[% decimal_number_that_JS_parseFloat_accepts %]">
464  *              [% formatted currency %]
465  *     </span></td>
466  *
467  * In DataTables config:
468  *     "aoColumns": [
469  *        { "sType": "title-numeric" },
470  *      ]
471  * http://datatables.net/plug-ins/sorting#hidden_title
472  */
473 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
474     "title-numeric-pre": function ( a ) {
475         var x = a.match(/title="*(-?[0-9\.]+)/)[1];
476         return parseFloat( x );
477     },
478
479     "title-numeric-asc": function ( a, b ) {
480         return ((a < b) ? -1 : ((a > b) ? 1 : 0));
481     },
482
483     "title-numeric-desc": function ( a, b ) {
484         return ((a < b) ? 1 : ((a > b) ? -1 : 0));
485     }
486 } );
487
488 (function() {
489
490     /* Plugin to allow text sorting to ignore articles
491      *
492      * In DataTables config:
493      *     "aoColumns": [
494      *        { "sType": "anti-the" },
495      *      ]
496      * Based on the plugin found here:
497      * http://datatables.net/plug-ins/sorting#anti_the
498      * Modified to exclude HTML tags from sorting
499      * Extended to accept a string of space-separated articles
500      * from a configuration file (in English, "a," "an," and "the")
501      */
502
503     if(CONFIG_EXCLUDE_ARTICLES_FROM_SORT){
504         var articles = CONFIG_EXCLUDE_ARTICLES_FROM_SORT.split(" ");
505         var rpattern = "";
506         for(i=0;i<articles.length;i++){
507             rpattern += "^" + articles[i] + " ";
508             if(i < articles.length - 1){ rpattern += "|"; }
509         }
510         var re = new RegExp(rpattern, "i");
511     }
512
513     jQuery.extend( jQuery.fn.dataTableExt.oSort, {
514         "anti-the-pre": function ( a ) {
515             var x = String(a).replace( /<[\s\S]*?>/g, "" );
516             var y = x.trim();
517             var z = y.replace(re, "").toLowerCase();
518             return z;
519         },
520
521         "anti-the-asc": function ( a, b ) {
522             return ((a < b) ? -1 : ((a > b) ? 1 : 0));
523         },
524
525         "anti-the-desc": function ( a, b ) {
526             return ((a < b) ? 1 : ((a > b) ? -1 : 0));
527         }
528     });
529
530 }());
531
532 // Remove string between NSB NSB characters
533 $.fn.dataTableExt.oSort['nsb-nse-asc'] = function(a,b) {
534     var pattern = new RegExp("\x88.*\x89");
535     a = a.replace(pattern, "");
536     b = b.replace(pattern, "");
537     return (a > b) ? 1 : ((a < b) ? -1 : 0);
538 }
539 $.fn.dataTableExt.oSort['nsb-nse-desc'] = function(a,b) {
540     var pattern = new RegExp("\x88.*\x89");
541     a = a.replace(pattern, "");
542     b = b.replace(pattern, "");
543     return (b > a) ? 1 : ((b < a) ? -1 : 0);
544 }
545
546 /* Define two custom functions (asc and desc) for basket callnumber sorting */
547 jQuery.fn.dataTableExt.oSort['callnumbers-asc']  = function(x,y) {
548         var x_array = x.split("<div>");
549         var y_array = y.split("<div>");
550
551         /* Pop the first elements, they are empty strings */
552         x_array.shift();
553         y_array.shift();
554
555         x_array = jQuery.map( x_array, function( a ) {
556             return parse_callnumber( a );
557         });
558         y_array = jQuery.map( y_array, function( a ) {
559             return parse_callnumber( a );
560         });
561
562         x_array.sort();
563         y_array.sort();
564
565         x = x_array.shift();
566         y = y_array.shift();
567
568         if ( !x ) { x = ""; }
569         if ( !y ) { y = ""; }
570
571         return ((x < y) ? -1 : ((x > y) ?  1 : 0));
572 };
573
574 jQuery.fn.dataTableExt.oSort['callnumbers-desc'] = function(x,y) {
575         var x_array = x.split("<div>");
576         var y_array = y.split("<div>");
577
578         /* Pop the first elements, they are empty strings */
579         x_array.shift();
580         y_array.shift();
581
582         x_array = jQuery.map( x_array, function( a ) {
583             return parse_callnumber( a );
584         });
585         y_array = jQuery.map( y_array, function( a ) {
586             return parse_callnumber( a );
587         });
588
589         x_array.sort();
590         y_array.sort();
591
592         x = x_array.pop();
593         y = y_array.pop();
594
595         if ( !x ) { x = ""; }
596         if ( !y ) { y = ""; }
597
598         return ((x < y) ?  1 : ((x > y) ? -1 : 0));
599 };
600
601 function parse_callnumber ( html ) {
602     var array = html.split('<span class="callnumber">');
603     if ( array[1] ) {
604         array = array[1].split('</span>');
605         return array[0];
606     } else {
607         return "";
608     }
609 }