From 22d919cb7dd2ae3c69f420c3dc0df7a419904e73 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 27 Jul 2010 21:34:56 -0600 Subject: [PATCH] Update goto.js script to use Horde_Calendar js lib. --- kronolith/js/goto.js | 63 +++++++ kronolith/lib/Kronolith.php | 16 +- kronolith/templates/javascript/goto.js | 316 --------------------------------- kronolith/themes/screen.css | 2 +- 4 files changed, 78 insertions(+), 319 deletions(-) create mode 100644 kronolith/js/goto.js delete mode 100644 kronolith/templates/javascript/goto.js diff --git a/kronolith/js/goto.js b/kronolith/js/goto.js new file mode 100644 index 000000000..3684169ef --- /dev/null +++ b/kronolith/js/goto.js @@ -0,0 +1,63 @@ +/** + * goto.js - Menu goto handling. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @author Michael Slusarz + * @category Horde + * @package Kronolith + */ + +var KronolithGoto = +{ + // Variables defined externally: dayurl, monthurl, weekurl, yearurl + + calendarSelect: function(e, type) + { + var q, url, + params = $H({ date: e.memo.getFullYear() + (e.memo.getMonth() + 1).toPaddedString(2) + (e.memo.getDate()).toPaddedString(2) }); + + switch (type) { + case 'day': + url = this.dayurl; + break; + + case 'month': + url = this.monthurl; + break; + + case 'week': + url = this.weekurl; + break; + + case 'year': + url = this.yearurl; + break; + } + + q = url.indexOf('?'); + if (q != -1) { + params.update(url.toQueryParams()); + url = url.substring(0, q); + } + + window.location = url + '?' + params.toQueryString(); + }, + + onDomLoad: function() + { + $('menu').down('A.kgotomenu').observe('click', function(e) { + Horde_Calendar.open(e.element(), Object.isUndefined(window.kronolithDate) ? new Date() : window.kronolithDate); + }); + } + +}; + +document.observe('dom:loaded', KronolithGoto.onDomLoad.bind(KronolithGoto)); +document.observe('Horde_Calendar:select', KronolithGoto.calendarSelect.bindAsEventListener(KronolithGoto, 'day')); +document.observe('Horde_Calendar:selectMonth', KronolithGoto.calendarSelect.bindAsEventListener(KronolithGoto, 'month')); +document.observe('Horde_Calendar:selectWeek', KronolithGoto.calendarSelect.bindAsEventListener(KronolithGoto, 'week')); +document.observe('Horde_Calendar:selectYear', KronolithGoto.calendarSelect.bindAsEventListener(KronolithGoto, 'year')); diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 3fdf1efae..59296abc9 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -2888,8 +2888,20 @@ class Kronolith $menu->add(Horde::applicationUrl('new.php')->add('url', Horde::selfUrl(true, false, true)), _("_New Event"), 'new.png'); } if ($browser->hasFeature('dom')) { - Horde::addScriptFile('goto.js', 'kronolith', array('direct' => false)); - $menu->add('#', _("_Goto"), 'goto.png', null, '', 'openKGoto(kronolithDate, event); return false;'); + Horde_Core_Ui_JsCalendar::init(array( + 'click_month' => true, + 'click_week' => true, + 'click_year' => true, + 'full_weekdays' => true + )); + Horde::addScriptFile('goto.js', 'kronolith'); + Horde::addInlineScript(array( + 'KronolithGoto.dayurl = ' . Horde_Serialize::serialize(strval(Horde::applicationUrl('day.php')), Horde_Serialize::JSON, $registry->getCharset()), + 'KronolithGoto.monthurl = ' . Horde_Serialize::serialize(strval(Horde::applicationUrl('month.php')), Horde_Serialize::JSON, $registry->getCharset()), + 'KronolithGoto.weekurl = ' . Horde_Serialize::serialize(strval(Horde::applicationUrl('week.php')), Horde_Serialize::JSON, $registry->getCharset()), + 'KronolithGoto.yearurl = ' . Horde_Serialize::serialize(strval(Horde::applicationUrl('year.php')), Horde_Serialize::JSON, $registry->getCharset()), + )); + $menu->add('#', _("_Goto"), 'goto.png', null, '', null, 'kgotomenu'); } $menu->add(Horde::applicationUrl('search.php'), _("_Search"), 'search.png', Horde_Themes::img(null, 'horde')); diff --git a/kronolith/templates/javascript/goto.js b/kronolith/templates/javascript/goto.js deleted file mode 100644 index 0c78b041d..000000000 --- a/kronolith/templates/javascript/goto.js +++ /dev/null @@ -1,316 +0,0 @@ -var currentDate, currentYear; - -function weekOfYear(d) -{ - // Adapted from http://www.merlyn.demon.co.uk/js-date7.htm#WkConv. - var ms1d = 86400000, ms3d = 3 * ms1d, ms7d = 7 * ms1d; - - var year = d.getYear(); - if (year < 1900) { - year += 1900; - } - var D3 = Date.UTC(year, d.getMonth(), d.getDate()) + ms3d; - var wk = Math.floor(D3 / ms7d); - var yy = new Date(wk * ms7d).getUTCFullYear(); - return 1 + wk - Math.floor((Date.UTC(yy, 0, 4) + ms3d) / ms7d); -} - -function formatDate(year, month, day) -{ - return year.toPaddedString(4) + (month + 1).toPaddedString(2) + day.toPaddedString(2); -} - -function openKGoto(d, event) -{ - var row, cell, img, link, days; - - currentDate = d; - var month = d.getMonth(); - var year = d.getYear(); - if (year < 1900) { - year += 1900; - } - currentYear = year; - var firstOfMonth = new Date(year, month, 1); - var diff = firstOfMonth.getDay() - 1; - if (diff == -1) { - diff = 6; - } - switch (month) { - case 3: - case 5: - case 8: - case 10: - days = 30; - break; - - case 1: - if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) { - days = 29; - } else { - days = 28; - } - break; - - default: - days = 31; - break; - } - - var wdays = [ - '', - '', - '', - '', - '', - '', - '' - ]; - var months = [ - '', - '', - '', - '', - '', - '', - '', - '', - '', - '', - '', - '' - ]; - - var table = document.createElement('TABLE'); - var thead = document.createElement('THEAD'); - var tbody = document.createElement('TBODY'); - table.appendChild(thead); - table.appendChild(tbody); - table.className = 'hordeCalendarPopup'; - table.cellSpacing = 0; - - // Title. - row = document.createElement('TR'); - cell = document.createElement('TD'); - cell.colSpan = 8; - cell.className = 'rightAlign'; - link = document.createElement('A'); - link.href = '#'; - link.onclick = function() { - Element.hide('kgoto'); - if ($('kgoto_iefix')) { - Element.hide('kgoto_iefix'); - } - return false; - }; - link.appendChild(document.createTextNode('x')); - cell.appendChild(link); - row.appendChild(cell); - thead.appendChild(row); - - // Year. - row = document.createElement('TR'); - cell = document.createElement('TD'); - link = document.createElement('A'); - link.href = '#'; - link.innerHTML = '«'; - link.onclick = function() { - newDate = new Date(currentYear - 1, currentDate.getMonth(), 1); - openKGoto(newDate); - return false; - }; - cell.appendChild(link); - row.appendChild(cell); - - cell = document.createElement('TD'); - cell.colSpan = 6; - cell.align = 'center'; - link = document.createElement('A'); - link.href = ''; - if (link.href.indexOf('?') != -1) { - link.href += '&'; - } else { - link.href += '?'; - } - link.href += 'date=' + formatDate(year, 1, 1); - cell.appendChild(link); - var m = document.createTextNode(year); - link.appendChild(m); - row.appendChild(cell); - - cell = document.createElement('TD'); - cell.className = 'rightAlign'; - link = document.createElement('A'); - link.href = '#'; - link.innerHTML = '»'; - link.onclick = function() { - newDate = new Date(currentYear + 1, currentDate.getMonth(), 1); - openKGoto(newDate); - return false; - }; - cell.appendChild(link); - row.appendChild(cell); - thead.appendChild(row); - - // Month name. - row = document.createElement('TR'); - cell = document.createElement('TD'); - link = document.createElement('A'); - link.href = '#'; - link.innerHTML = '«'; - link.onclick = function() { - var newMonth = currentDate.getMonth() - 1; - var newYear = currentYear; - if (newMonth == -1) { - newMonth = 11; - newYear -= 1; - } - newDate = new Date(newYear, newMonth, currentDate.getDate()); - openKGoto(newDate); - return false; - }; - cell.appendChild(link); - row.appendChild(cell); - - cell = document.createElement('TD'); - cell.colSpan = 6; - cell.align = 'center'; - link = document.createElement('A'); - link.href = ''; - if (link.href.indexOf('?') != -1) { - link.href += '&'; - } else { - link.href += '?'; - } - link.href += 'date=' + formatDate(year, month, 1); - cell.appendChild(link); - var m = document.createTextNode(months[month]); - link.appendChild(m); - row.appendChild(cell); - - cell = document.createElement('TD'); - cell.className = 'rightAlign'; - link = document.createElement('A'); - link.href = '#'; - link.innerHTML = '»'; - link.onclick = function() { - newDate = new Date(currentYear, currentDate.getMonth() + 1, 1); - openKGoto(newDate); - return false; - }; - cell.appendChild(link); - row.appendChild(cell); - thead.appendChild(row); - - // Weekdays. - row = document.createElement('TR'); - cell = document.createElement('TH'); - cell.innerHTML = ' '; - row.appendChild(cell); - for (var i = 0; i < 7; i++) { - cell = document.createElement('TH'); - weekday = document.createTextNode(wdays[i]); - cell.appendChild(weekday); - row.appendChild(cell); - } - tbody.appendChild(row); - - // Rows. - var weekInfo, dateUrl; - var count = 1; - var today = new Date(); - var thisYear = today.getYear(); - if (thisYear < 1900) { - thisYear += 1900; - } - for (var i = 1; i <= days; i++) { - dateUrl = formatDate(year, month, i); - if (count == 1) { - row = document.createElement('TR'); - cell = document.createElement('TD'); - cell.className = 'week'; - link = document.createElement('A'); - link.href = ''; - if (link.href.indexOf('?') != -1) { - link.href += '&'; - } else { - link.href += '?'; - } - link.href += 'date=' + dateUrl; - cell.appendChild(link); - link.appendChild(document.createTextNode(weekOfYear(new Date(year, month, i)))); - row.appendChild(cell); - } - if (i == 1) { - for (var j = 0; j < diff; j++) { - cell = document.createElement('TD'); - row.appendChild(cell); - count++; - } - } - cell = document.createElement('TD'); - if (thisYear == year && - today.getMonth() == month && - today.getDate() == i) { - cell.className = 'hordeCalendarToday'; - } - link = document.createElement('A'); - link.href = ''; - if (link.href.indexOf('?') != -1) { - link.href += '&'; - } else { - link.href += '?'; - } - link.href += 'date=' + dateUrl; - cell.appendChild(link); - day = document.createTextNode(i); - link.appendChild(day); - row.appendChild(cell); - if (count == 7) { - tbody.appendChild(row); - count = 0; - } - count++; - } - if (count > 1) { - for (i = count; i <= 7; i++) { - cell = document.createElement('TD'); - row.appendChild(cell); - } - tbody.appendChild(row); - } - - // Show popup div. - var div = $('kgoto'); - if (!div) { - div = document.createElement('DIV'); - div.id = 'kgoto'; - div.style.position = 'absolute'; - document.body.appendChild(div); - } else if (div.firstChild) { - div.removeChild(div.firstChild); - } - Element.show(div); - div.appendChild(table); - - // Position the div if this is the initial click. - if (event) { - Position.clone(Event.element(event), div, { setWidth: false, setHeight: false, offsetLeft: 10, offsetTop: 10 }); - } - -isBrowser('msie') && version_compare($GLOBALS['browser']->getVersion(), '5.5', 'ge')): ?> - var iefix = $('kgoto_iefix'); - if (!iefix) { - new Insertion.After(div, - ''); - iefix = $('kgoto_iefix'); - } - - Position.clone(div, iefix); - iefix.style.zIndex = 1; - div.style.zIndex = 2; - Element.show(iefix); - -} diff --git a/kronolith/themes/screen.css b/kronolith/themes/screen.css index eebe883e1..56485393f 100644 --- a/kronolith/themes/screen.css +++ b/kronolith/themes/screen.css @@ -1542,7 +1542,7 @@ li.panel-tags { color: #000; } -#color-picker, #hordeCalendar { +#color-picker { z-index: 103; } -- 2.11.0