Bug 20168: Update of the OPAC bootstrap template to bootstrap v4
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / en / includes / calendar.inc
blob9830b42377fcb342efbafbd7967b5b46bd5f1549
1 [% USE Koha %]
2 <script>
3         var debug    = "[% debug | html %]";
4         var dformat  = "[% dateformat | html %]";
5         var sentmsg = 0;
6         if (debug > 1) {alert("dateformat: " + dformat + "\ndebug is on (level " + debug + ")");}
8         function Date_from_syspref(dstring) {
9                 var dateX = dstring.split(/[-/.]/);
10                 if (debug > 1 && sentmsg < 1) {sentmsg++; alert("Date_from_syspref(" + dstring + ") splits to:\n" + dateX.join("\n"));}
11                 if (dformat === "iso") {
12                         return new Date(dateX[0], (dateX[1] - 1), dateX[2]);  // YYYY-MM-DD to (YYYY,m(0-11),d)
13                 } else if (dformat === "us") {
14                         return new Date(dateX[2], (dateX[0] - 1), dateX[1]);  // MM/DD/YYYY to (YYYY,m(0-11),d)
15                 } else if (dformat === "metric") {
16                         return new Date(dateX[2], (dateX[1] - 1), dateX[0]);  // DD/MM/YYYY to (YYYY,m(0-11),d)
17                 } else if (dformat === "dmydot") {
18                         return new Date(dateX[2], (dateX[1] - 1), dateX[0]);  // DD.MM.YYYY to (YYYY,m(0-11),d)
19                 } else {
20                         if (debug > 0) {alert("KOHA ERROR - Unrecognized date format: " +dformat);}
21                         return 0;
22                 }
23         }
25         /* Instead of including multiple localization files as you would normally see with
26            jQueryUI we expose the localization strings in the default configuration */
27         jQuery(function($){
28             $.datepicker.regional[''] = {
29                 closeText: _("Done"),
30                 prevText: _("Prev"),
31                 nextText: _("Next"),
32                 currentText: _("Today"),
33                 monthNames: [_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),
34                 _("July"),_("August"),_("September"),_("October"),_("November"),_("December")],
35                 monthNamesShort: [_("Jan"), _("Feb"), _("Mar"), _("Apr"), _("May"), _("Jun"),
36                 _("Jul"), _("Aug"), _("Sep"), _("Oct"), _("Nov"), _("Dec")],
37                 dayNames: [_("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday")],
38                 dayNamesShort: [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat")],
39                 dayNamesMin: [_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa")],
40                 weekHeader: _("Wk"),
41                 dateFormat: '[% IF ( dateformat == "us" ) %]mm/dd/yy[% ELSIF ( dateformat == "metric" ) %]dd/mm/yy[% ELSIF ( dateformat == "dmydot" ) %]dd.mm.yy[% ELSE %]yy-mm-dd[% END %]',
42                 firstDay: [% Koha.Preference('CalendarFirstDayOfWeek') | html %],
43                 isRTL: [% IF ( bidi ) %]true[% ELSE %]false[% END %],
44                 showMonthAfterYear: false,
45                 yearSuffix: ''};
46             $.datepicker.setDefaults($.datepicker.regional['']);
47         });
49         $(document).ready(function(){
51         $.datepicker.setDefaults({
52                 showOn: "both",
53                 changeMonth: true,
54                 changeYear: true,
55                 buttonImage: '[% interface | html %]/lib/famfamfam/calendar.png',
56                 buttonImageOnly: true,
57                 showButtonPanel: true,
58                 showOtherMonths: true,
59                 yearRange: "c-100:c+10"
60             });
62         $("#borrower_dateofbirth").datepicker({
63                 yearRange: "c-100:c"
64             });
66             $( ".datepicker" ).datepicker();
67             // http://jqueryui.com/demos/datepicker/#date-range
68             var dates = $( ".datepickerfrom, .datepickerto" ).datepicker({
69                 changeMonth: true,
70                 numberOfMonths: 1,
71                 onSelect: function( selectedDate ) {
72                     var option = this.id == "from" ? "minDate" : "maxDate",
73                         instance = $( this ).data( "datepicker" );
74                         date = $.datepicker.parseDate(
75                             instance.settings.dateFormat ||
76                             $.datepicker._defaults.dateFormat,
77                             selectedDate, instance.settings );
78                     dates.not( this ).datepicker( "option", option, date );
79                 }
80             });
81         });
83         // jQuery Datepicker - a11y: Map arrow keys
84         var doKeyDown = $.datepicker._doKeyDown
85         $.extend($.datepicker, {
86             _doKeyDown: function(event) {
87                 if (event.which === $.ui.keyCode.LEFT ||
88                     event.which === $.ui.keyCode.RIGHT ||
89                     event.which === $.ui.keyCode.UP ||
90                     event.which === $.ui.keyCode.DOWN) {
91                     event.ctrlKey = true;
92                     doKeyDown(event);
93                 } else {
94                     doKeyDown(event);
95                 }
96             }
97         });
98 </script>