From e4fbed487a07af86a68e4f62ce0ce5f4dc827850 Mon Sep 17 00:00:00 2001 From: Olivier PEREZ Date: Thu, 2 Apr 2015 17:05:24 +0200 Subject: [PATCH] Fix: date picker that doesn't appear when clicking on calendar icon --- js/app/framadatepicker.js | 29 +++++++++++++++++++++-------- js/core.js | 22 ---------------------- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/js/app/framadatepicker.js b/js/app/framadatepicker.js index 72b5aa6..20ebca0 100644 --- a/js/app/framadatepicker.js +++ b/js/app/framadatepicker.js @@ -15,7 +15,7 @@ * Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaƫl DROZ * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) */ -$(document).ready(function() { +$(document).ready(function () { var init_datepicker = function () { $('.input-group.date').datepicker({ format: "dd/mm/yyyy", @@ -25,16 +25,19 @@ $(document).ready(function() { language: lang, todayHighlight: true, beforeShowDay: function (date) { - var $selected_days = []; + // Retrieve selected dates from text fields + var selected_days = []; $('#selected-days').find('input[id^="day"]').each(function () { if ($(this).val() != '') { - $selected_days.push($(this).val()); + selected_days.push($(this).val()); } }); - for (var i = 0; i < $selected_days.length; i++) { - var $selected_date = $selected_days[i].split('/'); - if (date.getFullYear() == $selected_date[2] && (date.getMonth() + 1) == $selected_date[1] && date.getDate() == $selected_date[0]) { + // Disable selected dates in DatePicker + for (var i = 0; i < selected_days.length; i++) { + var selected_date = selected_days[i].split('/'); + + if (date.getFullYear() == selected_date[2] && (date.getMonth() + 1) == selected_date[1] && date.getDate() == selected_date[0]) { return { classes: 'disabled selected' }; @@ -44,16 +47,26 @@ $(document).ready(function() { }); }; + $(document).on('click', '.input-group.date .input-group-addon', function () { + // Re-init datepicker config before displaying + init_datepicker(); + $(this).parent().datepicker('show'); + + // Trick to refresh calendar + $('.datepicker-days .prev').trigger('click'); + $('.datepicker-days .next').trigger('click'); + }); + // Complete the date fields when use partialy fill it (eg: 15/01 could become 15/01/2016) - var leftPad = function(text, pad) { + var leftPad = function (text, pad) { return text ? pad.substring(0, pad.length - text.length) + text : text; }; $(document).on('change', '.input-group.date input', function () { // Complete field if needed var val = $(this).val(); - var capture = /([0-9]+)(?:\/([0-9]+))?/.exec(val); + var capture = /^([0-9]+)(?:\/([0-9]+))?$/.exec(val); if (capture) { var inputDay = leftPad(capture[1], "00"); // 5->05, 15->15 diff --git a/js/core.js b/js/core.js index 4667c90..3687d49 100644 --- a/js/core.js +++ b/js/core.js @@ -2,28 +2,6 @@ $(document).ready(function() { window.lang = $('html').attr('lang'); - var datepickerfocus = false; // a11y : datepicker not display on focus until there is one click on the button - - $(document).on('click','.input-group.date .input-group-addon', function() { - datepickerfocus = true; - // Re-init datepicker config before displaying - $(this).parent().datepicker(init_datepicker()); - $(this).parent().datepicker('show'); - - // Trick to refresh calendar - $('.datepicker-days .prev').trigger('click'); - $('.datepicker-days .next').trigger('click'); - // .active must be clicable in order to unfill the form - $('.datepicker-days .active').removeClass('disabled'); - }); - - $(document).on('focus','.input-group.date input', function() { - if(datepickerfocus) { - $(this).parent('.input-group.date').datepicker(init_datepicker()); - $(this).parent('.input-group.date').datepicker('show'); - } - }); - /** * adminstuds.php **/