diff options
author | Frédéric Buclin <LpSolit@gmail.com> | 2015-09-25 18:34:42 +0200 |
---|---|---|
committer | Frédéric Buclin <LpSolit@gmail.com> | 2015-09-25 18:34:42 +0200 |
commit | b92f32dd334617e74ab931c1db1801cf1c2897ba (patch) | |
tree | 47d93475fb94fab18432cf9a5b2b6b6efc9add0a /js | |
parent | b3abb29f2814bafd69095f3ef91bc40cbe5f866c (diff) | |
download | bugzilla-b92f32dd334617e74ab931c1db1801cf1c2897ba.tar.gz bugzilla-b92f32dd334617e74ab931c1db1801cf1c2897ba.tar.xz |
Bug 1201266: Migrate YUI calendar to jQuery
r=gerv
Diffstat (limited to 'js')
-rw-r--r-- | js/field.js | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/js/field.js b/js/field.js index 380901d96..2bd8868f8 100644 --- a/js/field.js +++ b/js/field.js @@ -87,129 +87,6 @@ function _errorFor(field, name) { YAHOO.util.Dom.addClass(field, 'validation_error_field'); } -/* This function is never to be called directly, but only indirectly - * using template/en/default/global/calendar.js.tmpl, so that localization - * works. For the same reason, if you modify this function's parameter list, - * you need to modify the documentation in said template as well. */ -function createCalendar(name, start_weekday, months_long, weekdays_short) { - var cal = new YAHOO.widget.Calendar('calendar_' + name, - 'con_calendar_' + name, - { START_WEEKDAY: start_weekday, - MONTHS_LONG: months_long, - WEEKDAYS_SHORT: weekdays_short - }); - YAHOO.bugzilla['calendar_' + name] = cal; - var field = document.getElementById(name); - cal.selectEvent.subscribe(setFieldFromCalendar, field, false); - updateCalendarFromField(field); - cal.render(); -} - -/* The onclick handlers for the button that shows the calendar. */ -function showCalendar(field_name) { - var calendar = YAHOO.bugzilla["calendar_" + field_name]; - var field = document.getElementById(field_name); - var button = document.getElementById('button_calendar_' + field_name); - - bz_overlayBelow(calendar.oDomContainer, field); - calendar.show(); - button.onclick = function() { hideCalendar(field_name); }; - - // Because of the way removeListener works, this has to be a function - // attached directly to this calendar. - calendar.bz_myBodyCloser = function(event) { - var container = this.oDomContainer; - var target = YAHOO.util.Event.getTarget(event); - if (target != container && target != button - && !YAHOO.util.Dom.isAncestor(container, target)) - { - hideCalendar(field_name); - } - }; - - // If somebody clicks outside the calendar, hide it. - YAHOO.util.Event.addListener(document.body, 'click', - calendar.bz_myBodyCloser, calendar, true); - - // Make Esc close the calendar. - calendar.bz_escCal = function (event) { - var key = YAHOO.util.Event.getCharCode(event); - if (key == 27) { - hideCalendar(field_name); - } - }; - YAHOO.util.Event.addListener(document.body, 'keydown', calendar.bz_escCal); -} - -function hideCalendar(field_name) { - var cal = YAHOO.bugzilla["calendar_" + field_name]; - cal.hide(); - var button = document.getElementById('button_calendar_' + field_name); - button.onclick = function() { showCalendar(field_name); }; - YAHOO.util.Event.removeListener(document.body, 'click', - cal.bz_myBodyCloser); - YAHOO.util.Event.removeListener(document.body, 'keydown', cal.bz_escCal); -} - -/* This is the selectEvent for our Calendar objects on our custom - * DateTime fields. - */ -function setFieldFromCalendar(type, args, date_field) { - var dates = args[0]; - var setDate = dates[0]; - - // We can't just write the date straight into the field, because there - // might already be a time there. - var timeRe = /\b(\d{1,2}):(\d\d)(?::(\d\d))?/; - var currentTime = timeRe.exec(date_field.value); - var d = new Date(setDate[0], setDate[1] - 1, setDate[2]); - if (currentTime) { - d.setHours(currentTime[1], currentTime[2]); - if (currentTime[3]) { - d.setSeconds(currentTime[3]); - } - } - - var year = d.getFullYear(); - // JavaScript's "Date" represents January as 0 and December as 11. - var month = d.getMonth() + 1; - if (month < 10) month = '0' + String(month); - var day = d.getDate(); - if (day < 10) day = '0' + String(day); - var dateStr = year + '-' + month + '-' + day; - - if (currentTime) { - var minutes = d.getMinutes(); - if (minutes < 10) minutes = '0' + String(minutes); - var seconds = d.getSeconds(); - if (seconds > 0 && seconds < 10) { - seconds = '0' + String(seconds); - } - - dateStr = dateStr + ' ' + d.getHours() + ':' + minutes; - if (seconds) dateStr = dateStr + ':' + seconds; - } - - date_field.value = dateStr; - hideCalendar(date_field.id); -} - -/* Sets the calendar based on the current field value. - */ -function updateCalendarFromField(date_field) { - var dateRe = /(\d\d\d\d)-(\d\d?)-(\d\d?)/; - var pieces = dateRe.exec(date_field.value); - if (pieces) { - var cal = YAHOO.bugzilla["calendar_" + date_field.id]; - cal.select(new Date(pieces[1], pieces[2] - 1, pieces[3])); - var selectedArray = cal.getSelectedDates(); - var selected = selectedArray[0]; - cal.cfg.setProperty("pagedate", (selected.getMonth() + 1) + '/' - + selected.getFullYear()); - cal.render(); - } -} - function setupEditLink(id) { var link_container = 'container_showhide_' + id; var input_container = 'container_' + id; |