Bug 9916 - Use DataTables in the OPAC
[koha.git] / koha-tmpl / opac-tmpl / ccsr / 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     // "aaSorting": [$(" - select row position of th -")],
27     "sDom": 't',
28     "bPaginate": false,
29     // "fnHeaderCallback": function() {
30     //     return $('th.sorting.nosort,th.sorting_desc.nosort,th.sorting_asc.nosort').removeClass("sorting sorting_desc sorting_asc").unbind("click");
31     // }
32 };
33
34 /* Plugin to allow sorting on data stored in a span's title attribute
35  *
36  * Ex: <td><span title="[% ISO_date %]">[% formatted_date %]</span></td>
37  *
38  * In DataTables config:
39  *     "aoColumns": [
40  *        { "sType": "title-string" },
41  *      ]
42  * http://datatables.net/plug-ins/sorting#hidden_title_string
43  */
44 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
45     "title-string-pre": function ( a ) {
46         return a.match(/title="(.*?)"/)[1].toLowerCase();
47     },
48
49     "title-string-asc": function ( a, b ) {
50         return ((a < b) ? -1 : ((a > b) ? 1 : 0));
51     },
52
53     "title-string-desc": function ( a, b ) {
54         return ((a < b) ? 1 : ((a > b) ? -1 : 0));
55     }
56 } );
57
58 (function() {
59
60     /* Plugin to allow text sorting to ignore articles
61      *
62      * In DataTables config:
63      *     "aoColumns": [
64      *        { "sType": "anti-the" },
65      *      ]
66      * Based on the plugin found here:
67      * http://datatables.net/plug-ins/sorting#anti_the
68      * Modified to exclude HTML tags from sorting
69      * Extended to accept a string of space-separated articles
70      * from a configuration file (in English, "a," "an," and "the")
71      */
72
73     if(CONFIG_EXCLUDE_ARTICLES_FROM_SORT){
74         var articles = CONFIG_EXCLUDE_ARTICLES_FROM_SORT.split(" ");
75         var rpattern = "";
76         for(i=0;i<articles.length;i++){
77             rpattern += "^" + articles[i] + " ";
78             if(i < articles.length - 1){ rpattern += "|"; }
79         }
80         var re = new RegExp(rpattern, "i");
81     }
82
83     jQuery.extend( jQuery.fn.dataTableExt.oSort, {
84         "anti-the-pre": function ( a ) {
85             var x = String(a).replace( /<[\s\S]*?>/g, "" );
86             var y = x.trim();
87             var z = y.replace(re, "").toLowerCase();
88             return z;
89         },
90
91         "anti-the-asc": function ( a, b ) {
92             return ((a < b) ? -1 : ((a > b) ? 1 : 0));
93         },
94
95         "anti-the-desc": function ( a, b ) {
96             return ((a < b) ? 1 : ((a > b) ? -1 : 0));
97         }
98     });
99
100 }());