Update goto.js script to use Horde_Calendar js lib.
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 28 Jul 2010 03:34:56 +0000 (21:34 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 28 Jul 2010 05:42:38 +0000 (23:42 -0600)
kronolith/js/goto.js [new file with mode: 0644]
kronolith/lib/Kronolith.php
kronolith/templates/javascript/goto.js [deleted file]
kronolith/themes/screen.css

diff --git a/kronolith/js/goto.js b/kronolith/js/goto.js
new file mode 100644 (file)
index 0000000..3684169
--- /dev/null
@@ -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 <slusarz@curecanti.org>
+ * @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'));
index 3fdf1ef..59296ab 100644 (file)
@@ -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 (file)
index 0c78b04..0000000
+++ /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 = [
-        '<?php echo _("Mo") ?>',
-        '<?php echo _("Tu") ?>',
-        '<?php echo _("We") ?>',
-        '<?php echo _("Th") ?>',
-        '<?php echo _("Fr") ?>',
-        '<?php echo _("Sa") ?>',
-        '<?php echo _("Su") ?>'
-    ];
-    var months = [
-        '<?php echo _("January") ?>',
-        '<?php echo _("February") ?>',
-        '<?php echo _("March") ?>',
-        '<?php echo _("April") ?>',
-        '<?php echo _("May") ?>',
-        '<?php echo _("June") ?>',
-        '<?php echo _("July") ?>',
-        '<?php echo _("August") ?>',
-        '<?php echo _("September") ?>',
-        '<?php echo _("October") ?>',
-        '<?php echo _("November") ?>',
-        '<?php echo _("December") ?>'
-    ];
-
-    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 = '&laquo;';
-    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 = '<?php echo Horde::applicationUrl('year.php') ?>';
-    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 = '&raquo;';
-    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 = '&laquo;';
-    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 = '<?php echo Horde::applicationUrl('month.php') ?>';
-    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 = '&raquo;';
-    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 = '&nbsp;';
-    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 = '<?php echo Horde::applicationUrl('week.php') ?>';
-            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 = '<?php echo Horde::applicationUrl('day.php') ?>';
-        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 });
-    }
-
-<?php if ($GLOBALS['browser']->isBrowser('msie') && version_compare($GLOBALS['browser']->getVersion(), '5.5', 'ge')): ?>
-    var iefix = $('kgoto_iefix');
-    if (!iefix) {
-        new Insertion.After(div,
-                            '<iframe id="kgoto_iefix" ' +
-                            'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
-                            'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
-        iefix = $('kgoto_iefix');
-    }
-
-    Position.clone(div, iefix);
-    iefix.style.zIndex = 1;
-    div.style.zIndex = 2;
-    Element.show(iefix);
-<?php endif; ?>
-}
index eebe883..5648539 100644 (file)
@@ -1542,7 +1542,7 @@ li.panel-tags {
     color: #000;
 }
 
-#color-picker, #hordeCalendar {
+#color-picker {
     z-index: 103;
 }