liquid_feedback_frontend

changeset 1609:f84824aa529b

Removed gregor library
author bsw
date Mon Feb 01 21:32:37 2021 +0100 (2021-02-01)
parents 89818dc70cb6
children 62fcb5ca1371
files app/main/_layout/default.html env/util/gregor.lua static/gregor.js/gregor.css static/gregor.js/gregor.js
line diff
     1.1 --- a/app/main/_layout/default.html	Mon Feb 01 21:32:03 2021 +0100
     1.2 +++ b/app/main/_layout/default.html	Mon Feb 01 21:32:37 2021 +0100
     1.3 @@ -6,7 +6,6 @@
     1.4    <title><!-- WEBMCP SLOTNODIV html_title --></title>
     1.5    <link rel="stylesheet" type="text/css" media="screen" href="__BASEURL__/style/style.css" />
     1.6    <link rel="stylesheet" type="text/css" media="screen" href="__BASEURL__/static/lf4.css" />
     1.7 -  <link rel="stylesheet" type="text/css" media="screen" href="__BASEURL__/static/gregor.js/gregor.css" />
     1.8    <!-- WEBMCP SLOTNODIV html_head -->
     1.9    <script type="text/javascript">jsFail = true;</script>
    1.10    <![if !IE]>
     2.1 --- a/env/util/gregor.lua	Mon Feb 01 21:32:03 2021 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,12 +0,0 @@
     2.4 -function util.gregor(el_id, relaxed)
     2.5 -  ui.script{ script =
     2.6 -       'gregor_addGui({' ..
     2.7 -          'element_id: "' .. el_id .. '",' ..
     2.8 -          'month_names: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],' ..
     2.9 -          'weekday_names: ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],' ..
    2.10 -          'week_mode: "iso",' ..
    2.11 -          'week_numbers: "left",' ..
    2.12 -          (relaxed and 'relaxed: true,' or '') ..
    2.13 -        '});'
    2.14 -  }
    2.15 -end
     3.1 --- a/static/gregor.js/gregor.css	Mon Feb 01 21:32:03 2021 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,92 +0,0 @@
     3.4 -.gregor_sheet {
     3.5 -  border:          1px solid black;
     3.6 -  border-collapse: collapse;
     3.7 -  margin:          0;
     3.8 -  padding:         0;
     3.9 -  background:      #fff;
    3.10 -  color:           #000;
    3.11 -}
    3.12 -.gregor_sheet th, .gregor_sheet td {
    3.13 -  margin: 0;
    3.14 -  font-size: 70%;
    3.15 -}
    3.16 -.gregor_year, .gregor_month {
    3.17 -  background-color: #ddd;
    3.18 -  border-bottom:    1px solid black;
    3.19 -  font-weight:      normal;
    3.20 -  text-align:       center;
    3.21 -}
    3.22 -.gregor_year a, .gregor_month a {
    3.23 -  color:           #000;
    3.24 -  text-decoration: none;
    3.25 -}
    3.26 -.gregor_year a:hover, .gregor_month a:hover {
    3.27 -  color: #f00;
    3.28 -}
    3.29 -.gregor_weekday {
    3.30 -  font-size:   80%;
    3.31 -  padding-top: 0.5em;
    3.32 -}
    3.33 -.gregor_day {
    3.34 -  padding-bottom: 0.35em;
    3.35 -}
    3.36 -
    3.37 -.gregor_weekday,
    3.38 -.gregor_day {
    3.39 -  padding-left: 0.25em;
    3.40 -  padding-right: 0.25em;
    3.41 -}
    3.42 -.gregor_weeks_left .gregor_weekday,
    3.43 -.gregor_weeks_left .gregor_day {
    3.44 -  padding-left: 0;
    3.45 -  padding-right: 0.5em;
    3.46 -}
    3.47 -.gregor_weeks_right .gregor_weekday,
    3.48 -.gregor_weeks_right .gregor_day {
    3.49 -  padding-left: 0.5em;
    3.50 -  padding-right: 0;
    3.51 -}
    3.52 -.gregor_weekday {
    3.53 -  text-align: center;
    3.54 -}
    3.55 -.gregor_weeks_left .gregor_week {
    3.56 -  padding-left:  0.25em;
    3.57 -  padding-right: 0.5em;
    3.58 -}
    3.59 -.gregor_weeks_right .gregor_week {
    3.60 -  padding-left:  1em;
    3.61 -  padding-right: 0.25em;
    3.62 -}
    3.63 -.gregor_week {
    3.64 -  color:       #666;
    3.65 -  font-size:   80%;
    3.66 -  font-weight: normal;
    3.67 -  text-align:  right;
    3.68 -}
    3.69 -td.gregor_day {
    3.70 -  text-align: right;
    3.71 -}
    3.72 -td.gregor_day a {
    3.73 -  background-color: #ddd;
    3.74 -  color:            #000;
    3.75 -  display:          block;
    3.76 -  padding-bottom:   0.25ex;
    3.77 -  padding-right:    0.25em;
    3.78 -  padding-top:      0.25ex;
    3.79 -  text-decoration:  none;
    3.80 -  width:            2em;
    3.81 -}
    3.82 -td.gregor_day.gregor_sat a {
    3.83 -  background-color: #bbb;
    3.84 -}
    3.85 -td.gregor_day.gregor_sun a {
    3.86 -  background-color: #ea9;
    3.87 -}
    3.88 -td.gregor_day.gregor_today a {
    3.89 -  font-weight: bold;
    3.90 -}
    3.91 -td.gregor_day.gregor_selected a {
    3.92 -  background-color: #444;
    3.93 -  color:            #fff;
    3.94 -}
    3.95 -
     4.1 --- a/static/gregor.js/gregor.js	Mon Feb 01 21:32:03 2021 +0100
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,849 +0,0 @@
     4.4 -//
     4.5 -// Copyright (c) 2009 Public Software Group e. V., Berlin
     4.6 -//
     4.7 -// Permission is hereby granted, free of charge, to any person obtaining a
     4.8 -// copy of this software and associated documentation files (the
     4.9 -// "Software"), to deal in the Software without restriction, including 
    4.10 -// without limitation the rights to use, copy, modify, merge, publish,
    4.11 -// distribute, sublicense, and/or sell copies of the Software, and to
    4.12 -// permit persons to whom the Software is furnished to do so, subject to
    4.13 -// the following conditions:
    4.14 -//
    4.15 -// The above copyright notice and this permission notice shall be included
    4.16 -// in all copies or substantial portions of the Software.
    4.17 -//
    4.18 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    4.19 -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    4.20 -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    4.21 -// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    4.22 -// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    4.23 -// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    4.24 -// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    4.25 -//
    4.26 -
    4.27 -//
    4.28 -// All date calculations are based on the gregorian calender, also for
    4.29 -// dates before 1582 (before the gegorian calendar was introduced).
    4.30 -// The supported range is from January 1st 0001 up to December 31st 9999.
    4.31 -//
    4.32 -// gregor_daycount({year: <year>, month: <month>, day: <day>}) returns
    4.33 -// the number of days between the given date and January 1st 0001 (greg.).
    4.34 -//
    4.35 -// gregor_completeDate({year: <year>, month: <month>, day: <day>}) returns
    4.36 -// a structure (an object) with the following properties:
    4.37 -//   - daycount     (days since January 1st 0001, see gregor_daycount)
    4.38 -//   - year         (with century)
    4.39 -//   - month        (from 1 to 12)
    4.40 -//   - day          (from 1 to 28, 29, 30 or 31)
    4.41 -//   - iso_string   (string with format YYYY-MM-DD)
    4.42 -//   - us_weekday   (from 0 for Sunday to 6 for Monday)
    4.43 -//   - iso_weekday  (from 0 for Monday to 6 for Sunday)
    4.44 -//   - iso_weekyear (Year containing greater part of week st. w. Monday)
    4.45 -//   - iso_week     (from 1 to 52 or 53)
    4.46 -//   - us_week      (from 1 to 53 or 54)
    4.47 -//
    4.48 -// The structure (the object) passed as parameter to gregor_daycount or
    4.49 -// gregor_completeDate may describe a date in the following ways:
    4.50 -//   - daycount
    4.51 -//   - year, month, day
    4.52 -//   - year, us_week, us_weekday
    4.53 -//   - year, iso_week, iso_weekday
    4.54 -//   - iso_weekyear, iso_week, iso_weekday
    4.55 -//
    4.56 -// gregor_sheet({...}) returns a calendar sheet as DOM object. The
    4.57 -// structure (the object) passed to the function as an argument is altered
    4.58 -// by the function and used to store state variables. Initially it can
    4.59 -// contain the following fields:
    4.60 -//   - year            (year to show, defaults to todays year)
    4.61 -//   - month           (month to show, defaults to todays month)
    4.62 -//   - today           (structure describing a day, e.g. year, month, day)
    4.63 -//   - selected        (structure describing a day, e.g. year, month, day)
    4.64 -//   - navigation      ("enabled", "disabled", "hidden", default "enabled")
    4.65 -//   - week_mode       ("iso" or "us", defaults to "iso")
    4.66 -//   - week_numbers    ("left", "right" or null, defaults to null)
    4.67 -//   - month_names     (e.g. ["January", "Feburary", ...])
    4.68 -//   - weekday_names   (e.g. ["Mon", "Tue", ...] or ["Sun", "Mon", ...])
    4.69 -//   - day_callback    (function to render a cell)
    4.70 -//   - select_callback (function to be called, when a date was selected)
    4.71 -//   - element         (for internal use only)
    4.72 -// If "today" is undefined, it is automatically intitialized with the
    4.73 -// current clients date. If "selected" is undefined or null, no date is
    4.74 -// be initially selected. It is mandatory to provide month_names and
    4.75 -// weekday_names.
    4.76 -//
    4.77 -// gregor_addGui({...}) alters a referenced input field in a way that
    4.78 -// focussing on it causes a calendar being shown at its right side, where a
    4.79 -// date can be selected. The structure (the object) passed to this function
    4.80 -// is only evaluated once, and never modified. All options except "element"
    4.81 -// of the gregor_sheet({...}) function may be used as options to
    4.82 -// gregor_addGui({...}) as well. In addition an "element_id" must be
    4.83 -// provided as argument, containing the id of a text input field. The
    4.84 -// behaviour caused by the options "selected" and  "select_callback" are
    4.85 -// slightly different: If "selected" === undefined, then the current value
    4.86 -// of the text field referenced by "element_id" will be parsed and used as
    4.87 -// date selection. If "selected" === null, then no date will be initially
    4.88 -// selected, and the text field will be cleared. The "select_callback"
    4.89 -// function is always called once with the pre-selected date (or with null,
    4.90 -// if no date is initially selected). Whenever the selected date is changed
    4.91 -// or unselected later, the callback function is called again with the new
    4.92 -// date (or with null, in case of deselection). When the relaxed argument is set
    4.93 -// the calendar will not normalize the parsed date. Thats usefull if you wan't to
    4.94 -// allow relaxed input.
    4.95 -//
    4.96 -// EXAMPLE:
    4.97 -//
    4.98 -// <input type="text" id="test_field" name="test_field" value=""/>
    4.99 -// <script type="text/javascript">
   4.100 -//   gregor_addGui({
   4.101 -//     element_id: 'test_field',
   4.102 -//     month_names: [
   4.103 -//       "January", "February", "March", "April", "May", "June",
   4.104 -//       "July", "August", "September", "October", "November", "December"
   4.105 -//     ],
   4.106 -//     weekday_names: ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
   4.107 -//     week_numbers: "left"
   4.108 -//   });
   4.109 -// </script>
   4.110 -//
   4.111 -
   4.112 -
   4.113 -
   4.114 -
   4.115 -// Internal constants and helper functions for date calculation
   4.116 -
   4.117 -
   4.118 -gregor_c1   = 365;                  // days of a non-leap year
   4.119 -gregor_c4   = 4 * gregor_c1 + 1;    // days of a full 4 year cycle
   4.120 -gregor_c100 = 25 * gregor_c4 - 1;   // days of a full 100 year cycle
   4.121 -gregor_c400 = 4 * gregor_c100 + 1;  // days of a full 400 year cycle
   4.122 -
   4.123 -gregor_normalMonthOffsets = [
   4.124 -  0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
   4.125 -];
   4.126 -
   4.127 -function gregor_getMonthOffset(year, month) {
   4.128 -  if (
   4.129 -    (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) &&
   4.130 -    month > 2
   4.131 -  ) return gregor_normalMonthOffsets[month-1] + 1;
   4.132 -  else return gregor_normalMonthOffsets[month-1];
   4.133 -}
   4.134 -
   4.135 -function gregor_formatInteger(int, digits) {
   4.136 -  var result = int.toFixed();
   4.137 -  if (digits != null) {
   4.138 -    while (result.length < digits) result = "0" + result;
   4.139 -  }
   4.140 -  return result;
   4.141 -}
   4.142 -
   4.143 -
   4.144 -
   4.145 -// Calculate days since January 1st 0001 (Gegorian) for a given date
   4.146 -
   4.147 -
   4.148 -function gregor_daycount(obj) {
   4.149 -  if (
   4.150 -    obj.daycount >= 0 && obj.daycount <= 3652058 && obj.daycount % 1 == 0
   4.151 -  ) {
   4.152 -    return obj.daycount;
   4.153 -  } else if (
   4.154 -    obj.year >= 1 && obj.year <= 9999 && obj.year % 1 == 0 &&
   4.155 -    obj.month >= 1 && obj.month <= 12 && obj.month % 1 == 0 &&
   4.156 -    obj.day >= 0 && obj.day <= 31 && obj.day % 1 == 0
   4.157 -  ) {
   4.158 -    var n400 = Math.floor((obj.year-1) / 400);
   4.159 -    var r400 = (obj.year-1) % 400;
   4.160 -    var n100 = Math.floor(r400 / 100);
   4.161 -    var r100 = r400 % 100;
   4.162 -    var n4 = Math.floor(r100 / 4);
   4.163 -    var n1 = r100 % 4;
   4.164 -    return (
   4.165 -      gregor_c400 * n400 +
   4.166 -      gregor_c100 * n100 +
   4.167 -      gregor_c4   * n4   +
   4.168 -      gregor_c1   * n1   +
   4.169 -      gregor_getMonthOffset(obj.year, obj.month) + (obj.day - 1)
   4.170 -    );
   4.171 -  } else if (
   4.172 -    (
   4.173 -      (
   4.174 -        obj.year >= 1 && obj.year <= 9999 &&
   4.175 -        obj.year % 1 == 0 && obj.iso_weekyear == null
   4.176 -      ) || (
   4.177 -        obj.iso_weekyear >= 1 && obj.iso_weekyear <= 9999 &&
   4.178 -        obj.iso_weekyear % 1 == 0 && obj.year == null
   4.179 -      )
   4.180 -    ) &&
   4.181 -    obj.iso_week >= 0 && obj.iso_week <= 53 && obj.iso_week % 1 == 0 &&
   4.182 -    obj.iso_weekday >= 0 && obj.iso_weekday <= 6 &&
   4.183 -    obj.iso_weekday % 1 == 0
   4.184 -  ) {
   4.185 -    var jan4th = gregor_daycount({
   4.186 -      year:  (obj.year != null) ? obj.year : obj.iso_weekyear,
   4.187 -      month: 1,
   4.188 -      day:   4
   4.189 -    });
   4.190 -    var monday0 = jan4th - (jan4th % 7) - 7;  // monday of week 0
   4.191 -    return monday0 + 7 * obj.iso_week + obj.iso_weekday;
   4.192 -  } else if (
   4.193 -    obj.year >= 1 && obj.year <= 9999 && obj.year % 1 == 0 &&
   4.194 -    obj.us_week >= 0 && obj.us_week <= 54 && obj.us_week % 1 == 0 &&
   4.195 -    obj.us_weekday >= 0 && obj.us_weekday <= 6 && obj.us_weekday % 1 == 0
   4.196 -  ) {
   4.197 -    var jan1st = gregor_daycount({
   4.198 -      year:  obj.year,
   4.199 -      month: 1,
   4.200 -      day:   1
   4.201 -    });
   4.202 -    var sunday0 = jan1st - ((jan1st+1) % 7) - 7;  // sunday of week 0
   4.203 -    return sunday0 + 7 * obj.us_week + obj.us_weekday;
   4.204 -  }
   4.205 -}
   4.206 -
   4.207 -
   4.208 -
   4.209 -// Calculate all calendar related numbers for a given date
   4.210 -
   4.211 -
   4.212 -function gregor_completeDate(obj) {
   4.213 -  if (
   4.214 -    obj.daycount >= 0 && obj.daycount <= 3652058 && obj.daycount % 1 == 0
   4.215 -  ) {
   4.216 -    var daycount = obj.daycount;
   4.217 -    var n400 = Math.floor(daycount / gregor_c400);
   4.218 -    var r400 = daycount % gregor_c400;
   4.219 -    var n100 = Math.floor(r400 / gregor_c100);
   4.220 -    var r100 = r400 % gregor_c100;
   4.221 -    if (n100 == 4) { n100 = 3; r100 = gregor_c100; }
   4.222 -    var n4 = Math.floor(r100 / gregor_c4);
   4.223 -    var r4 = r100 % gregor_c4;
   4.224 -    var n1 = Math.floor(r4 / gregor_c1);
   4.225 -    var r1 = r4 % gregor_c1;
   4.226 -    if (n1 == 4) { n1 = 3; r1 = gregor_c1; }
   4.227 -    var year = 1 + 400 * n400 + 100 * n100 + 4 * n4 + n1;
   4.228 -    var month = 1 + Math.floor(r1 / 31);
   4.229 -    var monthOffset = gregor_getMonthOffset(year, month);
   4.230 -    if (month < 12) {
   4.231 -      var nextMonthOffset = gregor_getMonthOffset(year, month + 1);
   4.232 -      if (r1 >= nextMonthOffset) {
   4.233 -        month++;
   4.234 -        monthOffset = nextMonthOffset;
   4.235 -      }
   4.236 -    }
   4.237 -    var day = 1 + r1 - monthOffset;
   4.238 -    var iso_string = ("" +
   4.239 -      gregor_formatInteger(year, 4) + "-" +
   4.240 -      gregor_formatInteger(month, 2) + "-" +
   4.241 -      gregor_formatInteger(day, 2)
   4.242 -    );
   4.243 -    var us_weekday = (daycount+1) % 7;
   4.244 -    var iso_weekday = daycount % 7;
   4.245 -    var iso_weekyear = year;
   4.246 -    if (
   4.247 -      month == 1 && (
   4.248 -        (day == 3 && iso_weekday == 6) ||
   4.249 -        (day == 2 && iso_weekday >= 5) ||
   4.250 -        (day == 1 && iso_weekday >= 4)
   4.251 -      )
   4.252 -    ) iso_weekyear--;
   4.253 -    else if (
   4.254 -      month == 12 && (
   4.255 -        (day == 29 && iso_weekday == 0) ||
   4.256 -        (day == 30 && iso_weekday <= 1) ||
   4.257 -        (day == 31 && iso_weekday <= 2)
   4.258 -      )
   4.259 -    ) iso_weekyear++;
   4.260 -    var jan4th = gregor_daycount({year: iso_weekyear, month: 1, day: 4});
   4.261 -    var monday0 = jan4th - (jan4th % 7) - 7;  // monday of week 0
   4.262 -    var iso_week = Math.floor((daycount - monday0) / 7);
   4.263 -    var jan1st = gregor_daycount({year: year, month: 1, day: 1});
   4.264 -    var sunday0 = jan1st - ((jan1st+1) % 7) - 7;  // sunday of week 0
   4.265 -    var us_week = Math.floor((daycount - sunday0) / 7);
   4.266 -    return {
   4.267 -      daycount:     daycount,
   4.268 -      year:         year,
   4.269 -      month:        month,
   4.270 -      day:          day,
   4.271 -      iso_string:   iso_string,
   4.272 -      us_weekday:   (daycount+1) % 7,  // 0 = Sunday
   4.273 -      iso_weekday:  daycount % 7,      // 0 = Monday
   4.274 -      iso_weekyear: iso_weekyear,
   4.275 -      iso_week:     iso_week,
   4.276 -      us_week:      us_week
   4.277 -    };
   4.278 -  } else if (obj.daycount == null) {
   4.279 -    var daycount = gregor_daycount(obj);
   4.280 -    if (daycount != null) {
   4.281 -      return gregor_completeDate({daycount: gregor_daycount(obj)});
   4.282 -    }
   4.283 -  }
   4.284 -}
   4.285 -
   4.286 -
   4.287 -
   4.288 -// Test gregor_daycount and gregor_completeDate for consistency
   4.289 -// (Debugging only)
   4.290 -
   4.291 -
   4.292 -function gregor_test() {
   4.293 -  for (i=650000; i<900000; i++) {
   4.294 -    var obj = gregor_completeDate({daycount: i});
   4.295 -    var j;
   4.296 -    j = gregor_daycount({
   4.297 -      year: obj.year,
   4.298 -      month: obj.month,
   4.299 -      day: obj.day
   4.300 -    });
   4.301 -    if (i != j) { alert("ERROR"); return; }
   4.302 -    j = gregor_daycount({
   4.303 -      iso_weekyear: obj.iso_weekyear,
   4.304 -      iso_week:     obj.iso_week,
   4.305 -      iso_weekday:  obj.iso_weekday
   4.306 -    });
   4.307 -    if (i != j) { alert("ERROR"); return; }
   4.308 -    j = gregor_daycount({
   4.309 -      year: obj.year,
   4.310 -      iso_week:
   4.311 -        (obj.iso_weekyear == obj.year + 1) ? 53 :
   4.312 -        (obj.iso_weekyear == obj.year - 1) ? 0 :
   4.313 -        obj.iso_week,
   4.314 -      iso_weekday: obj.iso_weekday
   4.315 -    });
   4.316 -    if (i != j) { alert("ERROR"); return; }
   4.317 -    j = gregor_daycount({
   4.318 -      year: obj.year,
   4.319 -      us_week: obj.us_week,
   4.320 -      us_weekday: obj.us_weekday
   4.321 -    });
   4.322 -    if (i != j) { alert("ERROR"); return; }
   4.323 -  }
   4.324 -  alert("SUCCESS");
   4.325 -}
   4.326 -
   4.327 -
   4.328 -
   4.329 -// Graphical calendar
   4.330 -
   4.331 -
   4.332 -gregor_iso_weekday_css = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
   4.333 -
   4.334 -function gregor_sheet(args) {
   4.335 -
   4.336 -  // setting args.today and args.selected
   4.337 -  if (args.today === undefined) {
   4.338 -    var js_date = new Date();
   4.339 -    args.today = gregor_completeDate({
   4.340 -      year:  js_date.getFullYear(),
   4.341 -      month: js_date.getMonth() + 1,
   4.342 -      day:   js_date.getDate()
   4.343 -    });
   4.344 -  } else if (args.today != null) {
   4.345 -    args.today = gregor_completeDate(args.today);
   4.346 -  }
   4.347 -  if (args.selected == "today") {
   4.348 -    args.selected = args.today;
   4.349 -  } else if (args.selected != null) {
   4.350 -    args.selected = gregor_completeDate(args.selected);
   4.351 -  }
   4.352 -
   4.353 -  // setting args.year and args.month
   4.354 -  if (args.year == null) {
   4.355 -    if (args.selected != null) args.year = args.selected.year;
   4.356 -    else args.year = args.today.year;
   4.357 -  }
   4.358 -  if (args.month == null) {
   4.359 -    if (args.selected != null) args.month = args.selected.month;
   4.360 -    else args.month = args.today.month;
   4.361 -  }
   4.362 -
   4.363 -  // setting first_day
   4.364 -  var first_day = gregor_completeDate({
   4.365 -    year:  args.year,
   4.366 -    month: args.month,
   4.367 -    day: 1
   4.368 -  });
   4.369 -  if (first_day == null) return;
   4.370 -
   4.371 -  // checking args.navigation, args.week_mode and args.week_numbers
   4.372 -  if (args.navigation == null) args.navigation = "enabled";
   4.373 -  else if (
   4.374 -    args.navigation != "enabled" &&
   4.375 -    args.navigation != "disabled" &&
   4.376 -    args.navigation != "hidden"
   4.377 -  ) return;
   4.378 -  if (args.week_mode == null) args.week_mode = "iso";
   4.379 -  else if (args.week_mode != "iso" && args.week_mode != "us") return;
   4.380 -  if (
   4.381 -    args.week_numbers != null &&
   4.382 -    args.week_numbers != "left" &&
   4.383 -    args.week_numbers != "right"
   4.384 -  ) return;
   4.385 -
   4.386 -  // checking args.month.names and args.weekday_names
   4.387 -  if (args.month_names.length != 12) return;
   4.388 -  if (args.weekday_names.length != 7) return;
   4.389 -
   4.390 -  // calculating number of days in month
   4.391 -  var count;
   4.392 -  if (args.year < 9999 || args.month < 12) {
   4.393 -    count = gregor_daycount({
   4.394 -      year:  (args.month == 12) ? (args.year + 1) : args.year,
   4.395 -      month: (args.month == 12) ? 1 : (args.month + 1),
   4.396 -      day:   1
   4.397 -    }) - first_day.daycount;
   4.398 -  } else {
   4.399 -    // workaround for year 9999
   4.400 -    count = 31;
   4.401 -  }
   4.402 -
   4.403 -  // locale variables for UI construction
   4.404 -  var table, row, cell, element;
   4.405 -
   4.406 -  // take table element from args.element,
   4.407 -  // if neccessary create and store it
   4.408 -  if (args.element == null) {
   4.409 -    table = document.createElement("table");
   4.410 -    args.element = table;
   4.411 -  } else {
   4.412 -    table = args.element;
   4.413 -    while (table.firstChild) table.removeChild(table.firstChild);
   4.414 -  }
   4.415 -
   4.416 -  // set CSS class of table according to args.week_numbers
   4.417 -  if (args.week_numbers == "left") {
   4.418 -    table.className = "gregor_sheet gregor_weeks_left";
   4.419 -  } else if (args.week_numbers == "right") {
   4.420 -    table.className = "gregor_sheet gregor_weeks_right";
   4.421 -  } else {
   4.422 -    table.className = "gregor_sheet gregor_weeks_none";
   4.423 -  }
   4.424 -
   4.425 -  // begin of table head
   4.426 -  var thead = document.createElement("thead");
   4.427 -
   4.428 -  // navigation
   4.429 -  if (args.navigation != "hidden") {
   4.430 -
   4.431 -    // UI head row containing the year
   4.432 -    row = document.createElement("tr");
   4.433 -    row.className = "gregor_year_row";
   4.434 -    cell = document.createElement("th");
   4.435 -    cell.className = "gregor_year";
   4.436 -    cell.colSpan = args.week_numbers ? 8 : 7;
   4.437 -    if (args.navigation == "enabled") {
   4.438 -      element = document.createElement("a");
   4.439 -      element.className = "gregor_turn gregor_turn_left";
   4.440 -      element.style.cssFloat   = "left";
   4.441 -      element.style.styleFloat = "left";
   4.442 -      element.href = "#";
   4.443 -      element.onclick = function() {
   4.444 -        if (args.year > 1) args.year--;
   4.445 -        gregor_sheet(args);
   4.446 -        return false;
   4.447 -      }
   4.448 -      element.ondblclick = element.onclick;
   4.449 -      element.appendChild(document.createTextNode("<<"));
   4.450 -      cell.appendChild(element);
   4.451 -      element = document.createElement("a");
   4.452 -      element.className = "gregor_turn gregor_turn_right";
   4.453 -      element.style.cssFloat   = "right";
   4.454 -      element.style.styleFloat = "right";
   4.455 -      element.href = "#";
   4.456 -      element.onclick = function() {
   4.457 -        if (args.year < 9999) args.year++;
   4.458 -        gregor_sheet(args);
   4.459 -        return false;
   4.460 -      }
   4.461 -      element.ondblclick = element.onclick;
   4.462 -      element.appendChild(document.createTextNode(">>"));
   4.463 -      cell.appendChild(element);
   4.464 -    }
   4.465 -    cell.appendChild(document.createTextNode(first_day.year));
   4.466 -    row.appendChild(cell);
   4.467 -    thead.appendChild(row);
   4.468 -
   4.469 -    // UI head row containing the month
   4.470 -    row = document.createElement("tr");
   4.471 -    row.className = "gregor_month_row";
   4.472 -    cell = document.createElement("th");
   4.473 -    cell.className = "gregor_month";
   4.474 -    cell.colSpan = args.week_numbers ? 8 : 7;
   4.475 -    if (args.navigation == "enabled") {
   4.476 -      element = document.createElement("a");
   4.477 -      element.className = "gregor_turn gregor_turn_left";
   4.478 -      element.style.cssFloat   = "left";
   4.479 -      element.style.styleFloat = "left";
   4.480 -      element.href = "#";
   4.481 -      element.onclick = function() {
   4.482 -        if (args.year > 1 || args.month > 1) {
   4.483 -          args.month--;
   4.484 -          if (args.month < 1) {
   4.485 -            args.month = 12;
   4.486 -            args.year--;
   4.487 -          }
   4.488 -        }
   4.489 -        gregor_sheet(args);
   4.490 -        return false;
   4.491 -      }
   4.492 -      element.ondblclick = element.onclick;
   4.493 -      element.appendChild(document.createTextNode("<<"));
   4.494 -      cell.appendChild(element);
   4.495 -      element = document.createElement("a");
   4.496 -      element.className = "gregor_turn gregor_turn_right";
   4.497 -      element.style.cssFloat   = "right";
   4.498 -      element.style.styleFloat = "right";
   4.499 -      element.href = "#";
   4.500 -      element.onclick = function() {
   4.501 -        if (args.year < 9999 || args.month < 12) {
   4.502 -          args.month++;
   4.503 -          if (args.month > 12) {
   4.504 -            args.month = 1;
   4.505 -            args.year++;
   4.506 -          }
   4.507 -        }
   4.508 -        gregor_sheet(args);
   4.509 -        return false;
   4.510 -      }
   4.511 -      element.ondblclick = element.onclick;
   4.512 -      element.appendChild(document.createTextNode(">>"));
   4.513 -      cell.appendChild(element);
   4.514 -    }
   4.515 -    cell.appendChild(document.createTextNode(
   4.516 -      args.month_names[first_day.month-1]
   4.517 -    ));
   4.518 -    row.appendChild(cell);
   4.519 -    thead.appendChild(row);
   4.520 -
   4.521 -  // end of navigation
   4.522 -  }
   4.523 -
   4.524 -  // UI weekday row
   4.525 -  row = document.createElement("tr");
   4.526 -  row.className = "gregor_weekday_row";
   4.527 -  if (args.week_numbers == "left") {
   4.528 -    cell = document.createElement("th");
   4.529 -    cell.className = "gregor_corner";
   4.530 -    row.appendChild(cell);
   4.531 -  }
   4.532 -  for (var i=0; i<7; i++) {
   4.533 -    cell = document.createElement("th");
   4.534 -    cell.className = (
   4.535 -      "gregor_weekday gregor_" +
   4.536 -      gregor_iso_weekday_css[(args.week_mode == "us") ? ((i+6)%7) : i]
   4.537 -    );
   4.538 -    cell.appendChild(document.createTextNode(args.weekday_names[i]));
   4.539 -    row.appendChild(cell);
   4.540 -  }
   4.541 -  if (args.week_numbers == "right") {
   4.542 -    cell = document.createElement("th");
   4.543 -    cell.className = "gregor_corner";
   4.544 -    row.appendChild(cell);
   4.545 -  }
   4.546 -  thead.appendChild(row);
   4.547 -
   4.548 -  // end of table head and begin of table body
   4.549 -  table.appendChild(thead);
   4.550 -  var tbody = document.createElement("tbody");
   4.551 -
   4.552 -  // definition of insert_week function
   4.553 -  var week = (
   4.554 -    (args.week_mode == "us") ? first_day.us_week : first_day.iso_week
   4.555 -  );
   4.556 -  insert_week = function() {
   4.557 -    cell = document.createElement("th");
   4.558 -    cell.className = "gregor_week";
   4.559 -    cell.appendChild(document.createTextNode(
   4.560 -      (week < 10) ? ("0" + week) : week)
   4.561 -    );
   4.562 -    week++;
   4.563 -    if (
   4.564 -      args.week_mode == "iso" && (
   4.565 -        (
   4.566 -          args.month == 1 && week > 52
   4.567 -        ) || (
   4.568 -          args.month == 12 && week == 53 && (
   4.569 -            first_day.iso_weekday == 0 ||
   4.570 -            first_day.iso_weekday == 5 ||
   4.571 -            first_day.iso_weekday == 6
   4.572 -          )
   4.573 -        )
   4.574 -      )
   4.575 -    ) week = 1;
   4.576 -    row.appendChild(cell);
   4.577 -  }
   4.578 -
   4.579 -  // output data fields
   4.580 -  row = document.createElement("tr");
   4.581 -  if (args.week_numbers == "left") insert_week();
   4.582 -  var filler_count = (
   4.583 -    (args.week_mode == "us") ? first_day.us_weekday : first_day.iso_weekday
   4.584 -  );
   4.585 -  for (var i=0; i<filler_count; i++) {
   4.586 -    cell = document.createElement("td");
   4.587 -    cell.className = "gregor_empty";
   4.588 -    row.appendChild(cell);
   4.589 -  }
   4.590 -  for (var i=0; i<count; i++) {
   4.591 -    var date = gregor_completeDate({daycount: first_day.daycount + i});
   4.592 -    if (row == null) {
   4.593 -      row = document.createElement("tr");
   4.594 -      if (args.week_numbers == "left") insert_week();
   4.595 -    }
   4.596 -    cell = document.createElement("td");
   4.597 -    var cssClass = (
   4.598 -      "gregor_day gregor_" + gregor_iso_weekday_css[date.iso_weekday]
   4.599 -    );
   4.600 -    if (args.today != null && date.daycount == args.today.daycount) {
   4.601 -      cssClass += " gregor_today";
   4.602 -    }
   4.603 -    if (args.selected != null && date.daycount == args.selected.daycount) {
   4.604 -      cssClass += " gregor_selected";
   4.605 -    }
   4.606 -    cell.className = cssClass;
   4.607 -    if (args.day_callback) {
   4.608 -      args.day_callback(cell, date);
   4.609 -    } else {
   4.610 -      element = document.createElement("a");
   4.611 -      element.href = "#";
   4.612 -      var generate_onclick = function(date) {
   4.613 -        return function() {
   4.614 -          args.selected = date;
   4.615 -          gregor_sheet(args);
   4.616 -          if (args.select_callback != null) {
   4.617 -            args.select_callback(date);
   4.618 -          }
   4.619 -          return false;
   4.620 -        }
   4.621 -      }
   4.622 -      element.onclick = generate_onclick(date);
   4.623 -      element.ondblclick = element.onclick;
   4.624 -      element.appendChild(document.createTextNode(first_day.day + i));
   4.625 -      cell.appendChild(element);
   4.626 -    }
   4.627 -    row.appendChild(cell);
   4.628 -    if (row.childNodes.length == ((args.week_numbers == "left") ? 8 : 7)) {
   4.629 -      if (args.week_numbers == "right") insert_week();
   4.630 -      tbody.appendChild(row);
   4.631 -      row = null;
   4.632 -    }
   4.633 -  }
   4.634 -  if (row != null) {
   4.635 -    while (row.childNodes.length < ((args.week_numbers == "left") ? 8 : 7)) {
   4.636 -      cell = document.createElement("td");
   4.637 -      cell.className = "gregor_empty";
   4.638 -      row.appendChild(cell);
   4.639 -    }
   4.640 -    if (args.week_numbers == "right") insert_week();
   4.641 -    tbody.appendChild(row);
   4.642 -  }
   4.643 -
   4.644 -  // end of table body
   4.645 -  table.appendChild(tbody);
   4.646 -
   4.647 -  // return table
   4.648 -  return table;
   4.649 -}
   4.650 -
   4.651 -
   4.652 -
   4.653 -// Rich form field support
   4.654 -
   4.655 -
   4.656 -function gregor_getAbsoluteLeft(elem) {
   4.657 - var result = 0;
   4.658 - while (elem && elem.style.position != "static") {
   4.659 -  result += elem.offsetLeft;
   4.660 -  elem = elem.offsetParent;
   4.661 - }
   4.662 - return result;
   4.663 -}
   4.664 -
   4.665 -function gregor_getAbsoluteTop(elem) {
   4.666 - var result = 0;
   4.667 - while (elem && elem.style.position != "static") {
   4.668 -  result += elem.offsetTop;
   4.669 -  elem = elem.offsetParent;
   4.670 - }
   4.671 - return result;
   4.672 -}
   4.673 -
   4.674 -function gregor_formatDate(format, date) {
   4.675 -  if (date == null) return "";
   4.676 -  var result = format;
   4.677 -  result = result.replace(/Y+/, function(s) {
   4.678 -    if (s.length == 2) return gregor_formatInteger(date.year % 100, 2);
   4.679 -    else return gregor_formatInteger(date.year, s.length);
   4.680 -  });
   4.681 -  result = result.replace(/M+/, function(s) {
   4.682 -    return gregor_formatInteger(date.month, s.length);
   4.683 -  });
   4.684 -  result = result.replace(/D+/, function(s) {
   4.685 -    return gregor_formatInteger(date.day, s.length);
   4.686 -  });
   4.687 -  return result;
   4.688 -}
   4.689 -
   4.690 -function gregor_map2digitYear(y2, maxYear) {
   4.691 -  var guess = Math.floor(maxYear / 100) * 100 + y2;
   4.692 -  if (guess <= maxYear) return guess;
   4.693 -  else return guess - 100;
   4.694 -}
   4.695 -
   4.696 -function gregor_parseDate(format, string, terminated, maxYear) {
   4.697 -  var numericParts, formatParts;
   4.698 -  numericParts = string.match(/^\s*([0-9]{4})-([0-9]{2})-([0-9]{2})\s*$/);
   4.699 -  if (numericParts != null) {
   4.700 -    return gregor_completeDate({
   4.701 -      year:  numericParts[1],
   4.702 -      month: numericParts[2],
   4.703 -      day:   numericParts[3]
   4.704 -    });
   4.705 -  }
   4.706 -  numericParts = string.match(/[0-9]+/g);
   4.707 -  if (numericParts == null) return null;
   4.708 -  formatParts = format.match(/[YMD]+/g);
   4.709 -  if (numericParts.length != formatParts.length) return null;
   4.710 -  if (
   4.711 -    !terminated && (
   4.712 -      numericParts[numericParts.length-1].length <
   4.713 -      formatParts[formatParts.length-1].length
   4.714 -    )
   4.715 -  ) return null;
   4.716 -  var year, month, day;
   4.717 -  for (var i=0; i<numericParts.length; i++) {
   4.718 -    var numericPart = numericParts[i];
   4.719 -    var formatPart = formatParts[i];
   4.720 -    if (formatPart.match(/^Y+$/)) {
   4.721 -      if (numericPart.length == 2 && maxYear != null) {
   4.722 -        year = gregor_map2digitYear(parseInt(numericPart, 10), maxYear);
   4.723 -      } else if (numericPart.length > 2) {
   4.724 -        year = parseInt(numericPart, 10);
   4.725 -      }
   4.726 -    } else if (formatPart.match(/^M+$/)) {
   4.727 -      month = parseInt(numericPart, 10);
   4.728 -    } else if (formatPart.match(/^D+$/)) {
   4.729 -      day = parseInt(numericPart, 10);
   4.730 -    } else {
   4.731 -      //alert("Not implemented.");
   4.732 -      return null;
   4.733 -    }
   4.734 -  }
   4.735 -  return gregor_completeDate({year: year, month: month, day: day});
   4.736 -}
   4.737 -
   4.738 -function gregor_addGui(args) {
   4.739 -
   4.740 -  // copy argument structure
   4.741 -  var state = {};
   4.742 -  for (key in args) state[key] = args[key];
   4.743 -
   4.744 -  // unset state.element, which should never be set anyway
   4.745 -  state.element = null;
   4.746 -
   4.747 -  // save original values of "year" and "month" options
   4.748 -  var original_year = state.year;
   4.749 -  var original_month = state.month;
   4.750 -
   4.751 -  // get text field element
   4.752 -  var element = document.getElementById(state.element_id);
   4.753 -  state.element_id = null;
   4.754 -
   4.755 -  // setup state.today, state.selected and state.format options
   4.756 -  if (state.today === undefined) {
   4.757 -    var js_date = new Date();
   4.758 -    state.today = gregor_completeDate({
   4.759 -      year:  js_date.getFullYear(),
   4.760 -      month: js_date.getMonth() + 1,
   4.761 -      day:   js_date.getDate()
   4.762 -    });
   4.763 -  } else if (state.today != null) {
   4.764 -    state.today = gregor_completeDate(args.today);
   4.765 -  }
   4.766 -  if (state.selected == "today") {
   4.767 -    state.selected = state.today;
   4.768 -  } else if (args.selected != null) {
   4.769 -    state.selected = gregor_completeDate(state.selected);
   4.770 -  }
   4.771 -  if (state.format == null) state.format = "YYYY-MM-DD";
   4.772 -
   4.773 -  // using state.future to calculate maxYear (for 2 digit year conversions)
   4.774 -  var maxYear = (state.today == null) ? null : (
   4.775 -    state.today.year +
   4.776 -    ((state.future == null) ? 12 : state.future)
   4.777 -  );
   4.778 -
   4.779 -  // hook into state.select_callback
   4.780 -  var select_callback = state.select_callback;
   4.781 -  state.select_callback = function(date) {
   4.782 -    element.value = gregor_formatDate(state.format, date);
   4.783 -    if (select_callback) select_callback(date);
   4.784 -  };
   4.785 -  // function to parse text field and update calendar sheet state
   4.786 -  var updateSheet = function(terminated) {
   4.787 -    var date = gregor_parseDate(
   4.788 -      state.format, element.value, terminated, maxYear
   4.789 -    );
   4.790 -    if (date) {
   4.791 -      state.year = null;
   4.792 -      state.month = null;
   4.793 -    }
   4.794 -    state.selected = date;
   4.795 -    gregor_sheet(state);
   4.796 -  };
   4.797 -
   4.798 -  // Initial synchronization
   4.799 -  if (state.selected === undefined) updateSheet(true);
   4.800 -  if (!state.relaxed)
   4.801 -    element.value = gregor_formatDate(state.format, state.selected);
   4.802 -
   4.803 -  if (select_callback) select_callback(state.selected);
   4.804 -
   4.805 -  // variables storing popup status
   4.806 -  var visible = false;
   4.807 -  var focus = false;
   4.808 -  var protection = false;
   4.809 -
   4.810 -  // event handlers for text field
   4.811 -  element.onfocus = function() {
   4.812 -    focus = true;
   4.813 -    if (!visible) {
   4.814 -      state.year = original_year;
   4.815 -      state.month = original_month;
   4.816 -      gregor_sheet(state);
   4.817 -      state.element.style.position = "absolute";
   4.818 -      state.element.style.top = gregor_getAbsoluteTop(element) + element.offsetHeight;
   4.819 -      state.element.style.left = gregor_getAbsoluteLeft(element);
   4.820 -      state.element.onmousedown = function() {
   4.821 -        protection = true;
   4.822 -      };
   4.823 -      state.element.onmouseup = function() {
   4.824 -        protection = false;
   4.825 -        element.focus();
   4.826 -      };
   4.827 -      state.element.onmouseout = state.element.onmouseup;
   4.828 -      element.parentNode.appendChild(state.element);
   4.829 -      visible = true;
   4.830 -    }
   4.831 -  };
   4.832 -  element.onblur = function() {
   4.833 -    focus = false;
   4.834 -    window.setTimeout(function() {
   4.835 -      if (visible && !focus && !protection) {
   4.836 -        updateSheet(true);
   4.837 -        if(!state.relaxed)
   4.838 -          element.value = gregor_formatDate(state.format, state.selected);
   4.839 -        if (select_callback) select_callback(state.selected);
   4.840 -        state.element.parentNode.removeChild(state.element);
   4.841 -        visible = false;
   4.842 -        protection = false;
   4.843 -      }
   4.844 -    }, 1);
   4.845 -  };
   4.846 -  element.onkeyup = function() {
   4.847 -    updateSheet(false);
   4.848 -    if (select_callback) select_callback(state.selected);
   4.849 -  };
   4.850 -
   4.851 -}
   4.852 -

Impressum / About Us