1
|
(function($) {
|
2
|
$(function () {
|
3
|
try {
|
4
|
// in case of the #date-selector element doesn't exist
|
5
|
var value = $('#date-selector').attr('value');
|
6
|
var week = value.substring(value.indexOf('(') + 1, value.length - 1);
|
7
|
var format = "DD d MM yy (" + week + ")";
|
8
|
} catch(err) {
|
9
|
var format = "DD d MM yy";
|
10
|
};
|
11
|
$('#date-selector').datepicker({
|
12
|
dateFormat: format,
|
13
|
showWeek: true,
|
14
|
onClose: function(dateText, inst) {
|
15
|
}
|
16
|
});
|
17
|
$('#date-selector').on('change', function () {
|
18
|
var date = $(this).datepicker('getDate');
|
19
|
var year = date.getFullYear();
|
20
|
var month = date.getMonth() + 1;
|
21
|
var first_jan = new Date(year, 0, 1);
|
22
|
var dayOfYear = ((date - first_jan + 1) / 86400000);
|
23
|
var week = Math.ceil(dayOfYear/7);
|
24
|
var day = date.getDate();
|
25
|
var current_date = $(this).attr('value');
|
26
|
current_date = current_date.replace(/\([0-9]{2}\)/, '(' + week + ')');
|
27
|
$(this).attr('value', current_date);
|
28
|
var url_tpl = $(this).data('url');
|
29
|
var new_date = year + '-' + month + '-' + day;
|
30
|
var url = url_tpl.replace(/[0-9]{4}-[0-9]{2}-[0-9]{2}/, new_date);
|
31
|
window.location.href = url;
|
32
|
});
|
33
|
});
|
34
|
})(window.jQuery)
|