From b3521926478a340dad98d077c3d1afa6e959da50 Mon Sep 17 00:00:00 2001 From: FramaJosephK Date: Thu, 26 Feb 2015 17:06:09 +0100 Subject: [PATCH] =?UTF-8?q?Le=20datepicker=20m=C3=A9morise=20la=20derni?= =?UTF-8?q?=C3=A8re=20date=20s=C3=A9lectionn=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/core.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/js/core.js b/js/core.js index 87b2914..329885f 100644 --- a/js/core.js +++ b/js/core.js @@ -1,6 +1,6 @@ $(document).ready(function() { var lang = $('html').attr('lang'); - + // Datepicker var framadatepicker = function() { $('.input-group.date').datepicker({ @@ -32,13 +32,25 @@ $(document).ready(function() { var datepickerfocus = false; // a11y : datepicker not display on focus until there is one click on the button - + var lastDate = new Date(); + $(document).on('click','.input-group.date .input-group-addon', function() { datepickerfocus = true; // Re-init datepicker config before displaying $(this).parent().datepicker(framadatepicker()); $(this).parent().datepicker('show'); - + + // Trick to keep the last datepicker view + if ($(this).parent().find('input').val() == '') { + $('.input-group.date input').each(function(){ + if($(this).val()!='') { + lastDate = $(this).val(); + } + }); + $(this).parent().datepicker('setDate', lastDate); + $(this).parent().datepicker('setDate', ''); + } + // Trick to refresh calendar $('.datepicker-days .prev').trigger('click'); $('.datepicker-days .next').trigger('click'); @@ -48,8 +60,9 @@ $(document).ready(function() { $(document).on('focus','.input-group.date input', function() { if(datepickerfocus) { - $(this).parent('.input-group.date').datepicker(framadatepicker()); - $(this).parent('.input-group.date').datepicker('show'); + // unfocus and click instead (because we are not in a11y mode anymore) + $(this).blur(); + $(this).parent().find('.input-group-addon').trigger('click'); } }); /**