From 78a489b53f4a4e1ea56ca768881605db1ca1d406 Mon Sep 17 00:00:00 2001 From: Jonas Lergell Date: Sat, 20 Feb 2016 16:45:04 +0100 Subject: [PATCH] Remove highlighting for calendar day when switching months in the datetimepicker --- .../static_src/wagtailadmin/js/page-editor.js | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/wagtail/wagtailadmin/static_src/wagtailadmin/js/page-editor.js b/wagtail/wagtailadmin/static_src/wagtailadmin/js/page-editor.js index 7f93bc80a9..3edbc542aa 100644 --- a/wagtail/wagtailadmin/static_src/wagtailadmin/js/page-editor.js +++ b/wagtail/wagtailadmin/static_src/wagtailadmin/js/page-editor.js @@ -71,23 +71,43 @@ function insertRichTextDeleteControl(elem) { }); } +// Compare two date objects. Ignore minutes and seconds. +function dateEqual(x, y) { + return x.getDate() === y.getDate() && + x.getMonth() === y.getMonth() && + x.getYear() === y.getYear() +} + +/* +Remove the xdsoft_current css class from markup unless the selected date is currently in view. +Keep the normal behaviour if the home button is clicked. + */ +function hideCurrent(current, input) { + var selected = new Date(input[0].value); + if (!dateEqual(selected, current)) { + $(this).find('.xdsoft_datepicker .xdsoft_current:not(.xdsoft_today)').removeClass('xdsoft_current'); + } +} + function initDateChooser(id, opts) { if (window.dateTimePickerTranslations) { $('#' + id).datetimepicker($.extend({ closeOnDateSelect: true, timepicker: false, - scrollInput:false, + scrollInput: false, format: 'Y-m-d', i18n: { lang: window.dateTimePickerTranslations }, - lang: 'lang' + lang: 'lang', + onGenerate: hideCurrent }, opts || {})); } else { $('#' + id).datetimepicker($.extend({ timepicker: false, - scrollInput:false, - format: 'Y-m-d' + scrollInput: false, + format: 'Y-m-d', + onGenerate: hideCurrent }, opts || {})); } } @@ -97,7 +117,7 @@ function initTimeChooser(id) { $('#' + id).datetimepicker({ closeOnDateSelect: true, datepicker: false, - scrollInput:false, + scrollInput: false, format: 'H:i', i18n: { lang: window.dateTimePickerTranslations @@ -117,15 +137,17 @@ function initDateTimeChooser(id, opts) { $('#' + id).datetimepicker($.extend({ closeOnDateSelect: true, format: 'Y-m-d H:i', - scrollInput:false, + scrollInput: false, i18n: { lang: window.dateTimePickerTranslations }, - language: 'lang' + language: 'lang', + onGenerate: hideCurrent }, opts || {})); } else { $('#' + id).datetimepicker($.extend({ - format: 'Y-m-d H:i' + format: 'Y-m-d H:i', + onGenerate: hideCurrent }, opts || {})); } }