From: tjhunt Date: Mon, 16 Mar 2009 03:42:14 +0000 (+0000) Subject: formslib dates: MDL-16592 fix a couple of remaining niggles. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=bd55319b37359a783af428f242a0da9f111d76c4;p=moodle.git formslib dates: MDL-16592 fix a couple of remaining niggles. * Hide when focus leaves in almost all cases. * Reposition the calendar after a delay after changing to a month with a different number of weeks. --- diff --git a/lib/javascript-static.js b/lib/javascript-static.js index 8b60764308..136a36d8ab 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -372,12 +372,8 @@ function date_selector_calendar(el, firstdayofweek) { {iframe: false, hide_blank_weeks: true, start_weekday: firstdayofweek}); date_selector_calendar.calendar.renderEvent.subscribe(function() { date_selector_calendar.panel.fireEvent('changeContent'); + date_selector_calendar.delayed_reposition(); }); - - // TODO, find a way to hide the calendar when shift-tabbing. -// date_selector_calendar.calendar.render(); -// var prev_month_link = YAHOO.util.Dom.getElementsByClassName('calnavleft', 'a', div)[0]; -// YAHOO.util.Event.addBlurListener(prev_month_link, this.blur_event, this); } this.fieldset = el; @@ -390,7 +386,7 @@ function date_selector_calendar(el, firstdayofweek) { } else if (/\[day\]$/.test(controls[i].name)) { this.dayselect = controls[i]; } else { - YAHOO.util.Event.addFocusListener(controls[i], this.cancel_any_timeout, this); + YAHOO.util.Event.addFocusListener(controls[i], date_selector_calendar.cancel_any_timeout, this); YAHOO.util.Event.addBlurListener(controls[i], this.blur_event, this); } } @@ -421,22 +417,44 @@ date_selector_calendar.currentowner = null; * if we are just jumping from on of our controls to another. */ date_selector_calendar.hidetimeout = null; +/** Timeout for repositioning after a delay after a change of months. */ +date_selector_calendar.repositiontimeout = null; +/** Member variables. Pointers to various bits of the DOM. */ date_selector_calendar.prototype.fieldset = null; date_selector_calendar.prototype.yearselect = null; date_selector_calendar.prototype.monthselect = null; date_selector_calendar.prototype.dayselect = null; date_selector_calendar.prototype.enablecheckbox = null; -date_selector_calendar.prototype.cancel_any_timeout = function() { +date_selector_calendar.cancel_any_timeout = function() { if (date_selector_calendar.hidetimeout) { clearTimeout(date_selector_calendar.hidetimeout); date_selector_calendar.hidetimeout = null; } + if (date_selector_calendar.repositiontimeout) { + clearTimeout(date_selector_calendar.repositiontimeout); + date_selector_calendar.repositiontimeout = null; + } +} + +date_selector_calendar.delayed_reposition = function() { + if (date_selector_calendar.repositiontimeout) { + clearTimeout(date_selector_calendar.repositiontimeout); + date_selector_calendar.repositiontimeout = null; + } + date_selector_calendar.repositiontimeout = setTimeout( + function() {date_selector_calendar.fix_position();}, 500); +} + +date_selector_calendar.fix_position = function() { + if (date_selector_calendar.currentowner) { + date_selector_calendar.panel.cfg.setProperty('context', [date_selector_calendar.currentowner.fieldset, 'bl', 'tl']); + } } date_selector_calendar.prototype.focus_event = function(e, me) { - me.cancel_any_timeout(); + date_selector_calendar.cancel_any_timeout(); if (me.enablecheckbox == null || me.enablecheckbox.checked) { me.claim_calendar(); } else { @@ -465,7 +483,7 @@ date_selector_calendar.document_click = function(event) { } date_selector_calendar.prototype.claim_calendar = function() { - this.cancel_any_timeout(); + date_selector_calendar.cancel_any_timeout(); if (date_selector_calendar.currentowner == this) { return; } @@ -473,19 +491,18 @@ date_selector_calendar.prototype.claim_calendar = function() { date_selector_calendar.currentowner.release_calendar(); } + if (date_selector_calendar.currentowner != this) { + this.connect_handlers(); + } + date_selector_calendar.currentowner = this; + date_selector_calendar.calendar.cfg.setProperty('mindate', new Date(this.yearselect.options[0].value, 0, 1)); date_selector_calendar.calendar.cfg.setProperty('maxdate', new Date(this.yearselect.options[this.yearselect.options.length - 1].value, 11, 31)); - this.fieldset.insertBefore(date_selector_calendar.panel.element, this.fieldset.firstChild); + this.fieldset.insertBefore(date_selector_calendar.panel.element, this.yearselect.nextSibling); this.set_date_from_selects(); date_selector_calendar.panel.show(); var me = this; - setTimeout(function() {me.cancel_any_timeout()}, 100); - - if (date_selector_calendar.currentowner != this) { - this.connect_handlers(); - } - - date_selector_calendar.currentowner = this; + setTimeout(function() {date_selector_calendar.cancel_any_timeout()}, 100); } date_selector_calendar.prototype.set_date_from_selects = function() { @@ -495,8 +512,8 @@ date_selector_calendar.prototype.set_date_from_selects = function() { date_selector_calendar.calendar.select(new Date(year, month, day)); date_selector_calendar.calendar.setMonth(month); date_selector_calendar.calendar.setYear(year); - date_selector_calendar.calendar.render(); - date_selector_calendar.panel.cfg.setProperty('context', [this.fieldset, 'bl', 'tl']); + date_selector_calendar.calendar.render(); + date_selector_calendar.fix_position(); } date_selector_calendar.prototype.set_selects_from_date = function(eventtype, args) {