Bug 2093: (follow-up) Add OPAC dashboard for logged-in users
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / 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.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 /* Plugin to allow sorting numerically on data stored in a span's title attribute
59  *
60  * Ex: <td><span title="[% total %]">Total: [% total %]</span></td>
61  *
62  * In DataTables config:
63  *     "aoColumns": [
64  *        { "sType": "title-numeric" }
65  *     ]
66  * http://legacy.datatables.net/plug-ins/sorting#hidden_title
67  */
68 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
69     "title-numeric-pre": function ( a ) {
70         console.log(a);
71         var x = a.match(/title="*(-?[0-9\.]+)/)[1];
72         return parseFloat( x );
73     },
74
75     "title-numeric-asc": function ( a, b ) {
76         return ((a < b) ? -1 : ((a > b) ? 1 : 0));
77     },
78
79     "title-numeric-desc": function ( a, b ) {
80         return ((a < b) ? 1 : ((a > b) ? -1 : 0));
81     }
82 } );
83
84 (function() {
85
86     /* Plugin to allow text sorting to ignore articles
87      *
88      * In DataTables config:
89      *     "aoColumns": [
90      *        { "sType": "anti-the" },
91      *      ]
92      * Based on the plugin found here:
93      * http://datatables.net/plug-ins/sorting#anti_the
94      * Modified to exclude HTML tags from sorting
95      * Extended to accept a string of space-separated articles
96      * from a configuration file (in English, "a," "an," and "the")
97      */
98
99     if(CONFIG_EXCLUDE_ARTICLES_FROM_SORT){
100         var articles = CONFIG_EXCLUDE_ARTICLES_FROM_SORT.split(" ");
101         var rpattern = "";
102         for(i=0;i<articles.length;i++){
103             rpattern += "^" + articles[i] + " ";
104             if(i < articles.length - 1){ rpattern += "|"; }
105         }
106         var re = new RegExp(rpattern, "i");
107     }
108
109     jQuery.extend( jQuery.fn.dataTableExt.oSort, {
110         "anti-the-pre": function ( a ) {
111             var x = String(a).replace( /<[\s\S]*?>/g, "" );
112             var y = x.trim();
113             var z = y.replace(re, "").toLowerCase();
114             return z;
115         },
116
117         "anti-the-asc": function ( a, b ) {
118             return ((a < b) ? -1 : ((a > b) ? 1 : 0));
119         },
120
121         "anti-the-desc": function ( a, b ) {
122             return ((a < b) ? 1 : ((a > b) ? -1 : 0));
123         }
124     });
125
126 }());