imported version 0.9.6 from jscalendar

This commit is contained in:
Ralf Becker 2004-05-06 12:58:31 +00:00
parent a0aba2ae40
commit 41a3f88199

View File

@ -70,8 +70,8 @@ $jsLongDateFormat = '%a, '.($dayFirst ? '%e' : '%b').($dateformat[1] == '.' ? '.
* ifFormat | date format that will be stored in the input field * ifFormat | date format that will be stored in the input field
* daFormat | the date format that will be used to display the date in displayArea * daFormat | the date format that will be used to display the date in displayArea
* singleClick | (true/false) wether the calendar is in single click mode or not (default: true) * singleClick | (true/false) wether the calendar is in single click mode or not (default: true)
* mondayFirst | (true/false) if true Monday is the first day of week, Sunday otherwise (default: true) * firstDay | numeric: 0 to 6. "0" means display Sunday first, "1" means display Monday first, etc.
* align | alignment (default: "Bl"); if you don't know what's this see the calendar documentation * align | alignment (default: "Br"); if you don't know what's this see the calendar documentation
* range | array with 2 elements. Default: [1900, 2999] -- the range of years available * range | array with 2 elements. Default: [1900, 2999] -- the range of years available
* weekNumbers | (true/false) if it's true (default) the calendar will display week numbers * weekNumbers | (true/false) if it's true (default) the calendar will display week numbers
* flat | null or element ID; if not null the calendar will be a flat calendar having the parent with the given ID * flat | null or element ID; if not null the calendar will be a flat calendar having the parent with the given ID
@ -83,12 +83,18 @@ $jsLongDateFormat = '%a, '.($dayFirst ? '%e' : '%b').($dateformat[1] == '.' ? '.
* date | the date that the calendar will be initially displayed to * date | the date that the calendar will be initially displayed to
* showsTime | default: false; if true the calendar will include a time selector * showsTime | default: false; if true the calendar will include a time selector
* timeFormat | the time format; can be "12" or "24", default is "12" * timeFormat | the time format; can be "12" or "24", default is "12"
* electric | if true (default) then given fields/date areas are updated for each move; otherwise they're updated only on close
* step | configures the step of the years in drop-down boxes; default: 2
* position | configures the calendar absolute position; default: null
* cache | if "true" (but default: "false") it will reuse the same calendar object, where possible
* showOthers | if "true" (but default: "false") it will show days from other months too
* *
* None of them is required, they all have default values. However, if you * None of them is required, they all have default values. However, if you
* pass none of "inputField", "displayArea" or "button" you'll get a warning * pass none of "inputField", "displayArea" or "button" you'll get a warning
* saying "nothing to setup". * saying "nothing to setup".
*/ */
?> ?>
//<pre>
Calendar.setup = function (params) { Calendar.setup = function (params) {
function param_default(pname, def) { if (typeof params[pname] == "undefined") { params[pname] = def; } }; function param_default(pname, def) { if (typeof params[pname] == "undefined") { params[pname] = def; } };
@ -96,15 +102,14 @@ Calendar.setup = function (params) {
param_default("displayArea", null); param_default("displayArea", null);
param_default("button", null); param_default("button", null);
param_default("eventName", "click"); param_default("eventName", "click");
// param_default("ifFormat", "%Y/%m/%d"); param_default("ifFormat", "<?php /* was "%Y/%m/%d" */ echo $jsDateFormat; ?>");
param_default("ifFormat", "<?php echo $jsDateFormat; ?>"); param_default("daFormat", "<?php /* was "%Y/%m/%d" */ echo $jsDateFormat; ?>");
// param_default("daFormat", "%Y/%m/%d");
param_default("daFormat", "<?php echo $jsDateFormat; ?>");
param_default("singleClick", true); param_default("singleClick", true);
param_default("disableFunc", null); param_default("disableFunc", null);
param_default("dateStatusFunc", params["disableFunc"]); // takes precedence if both are defined param_default("dateStatusFunc", params["disableFunc"]); // takes precedence if both are defined
// param_default("mondayFirst", true); param_default("firstDay", <?php // was 0 defaults to "Sunday" first
param_default("mondayFirst", <?php echo $GLOBALS['phpgw_info']['user']['preferences']['common']['weekdaysstarts'] != 'sunday' ? 'true' : 'false'; ?>); $day2int = array('Sunday'=>0,'Monday'=>1,'Tuesday'=>2,'Wednesday'=>3,'Thursday'=>4,'Friday'=>5,'Saturday'=>6);
echo (int) @$day2int[$GLOBALS['phpgw_info']['user']['preferences']['calendar']['weekdaystarts']]; ?>); // <?php echo $GLOBALS['phpgw_info']['user']['preferences']['calendar']['weekdaystarts']."\n"; ?>
param_default("align", "Bl"); param_default("align", "Bl");
param_default("range", [1900, 2999]); param_default("range", [1900, 2999]);
param_default("weekNumbers", true); param_default("weekNumbers", true);
@ -115,8 +120,12 @@ Calendar.setup = function (params) {
param_default("onUpdate", null); param_default("onUpdate", null);
param_default("date", null); param_default("date", null);
param_default("showsTime", false); param_default("showsTime", false);
// param_default("timeFormat", "24"); param_default("timeFormat", "<?php /* was 24 */ echo $GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat']; ?>");
param_default("timeFormat", "<?php echo $GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat']; ?>"); param_default("electric", true);
param_default("step", 2);
param_default("position", null);
param_default("cache", true);
param_default("showOthers", true); <?php /* was false */ ?>
var tmp = ["inputField", "displayArea", "button"]; var tmp = ["inputField", "displayArea", "button"];
for (var i in tmp) { for (var i in tmp) {
@ -130,35 +139,36 @@ Calendar.setup = function (params) {
} }
function onSelect(cal) { function onSelect(cal) {
if (cal.params.flat) { var p = cal.params;
if (typeof cal.params.flatCallback == "function") { var update = (cal.dateClicked || p.electric);
cal.params.flatCallback(cal); if (update && p.flat) {
} else { if (typeof p.flatCallback == "function")
p.flatCallback(cal);
else
alert("No flatCallback given -- doing nothing."); alert("No flatCallback given -- doing nothing.");
}
return false; return false;
} }
if (cal.params.inputField) { if (update && p.inputField) {
cal.params.inputField.value = cal.date.print(cal.params.ifFormat); p.inputField.value = cal.date.print(p.ifFormat);
if (typeof p.inputField.onchange == "function")
p.inputField.onchange();
} }
if (cal.params.displayArea) { if (update && p.displayArea)
cal.params.displayArea.innerHTML = cal.date.print(cal.params.daFormat); p.displayArea.innerHTML = cal.date.print(p.daFormat);
} if (update && p.singleClick && cal.dateClicked)
if (cal.params.singleClick && cal.dateClicked) {
cal.callCloseHandler(); cal.callCloseHandler();
} if (update && typeof p.onUpdate == "function")
if (typeof cal.params.onUpdate == "function") { p.onUpdate(cal);
cal.params.onUpdate(cal);
}
}; };
if (params.flat != null) { if (params.flat != null) {
params.flat = document.getElementById(params.flat); if (typeof params.flat == "string")
params.flat = document.getElementById(params.flat);
if (!params.flat) { if (!params.flat) {
alert("Calendar.setup:\n Flat specified but can't find parent."); alert("Calendar.setup:\n Flat specified but can't find parent.");
return false; return false;
} }
var cal = new Calendar(params.mondayFirst, params.date, params.onSelect || onSelect); var cal = new Calendar(params.firstDay, params.date, params.onSelect || onSelect);
cal.showsTime = params.showsTime; cal.showsTime = params.showsTime;
cal.time24 = (params.timeFormat == "24"); cal.time24 = (params.timeFormat == "24");
cal.params = params; cal.params = params;
@ -176,8 +186,8 @@ Calendar.setup = function (params) {
var dateFmt = params.inputField ? params.ifFormat : params.daFormat; var dateFmt = params.inputField ? params.ifFormat : params.daFormat;
var mustCreate = false; var mustCreate = false;
var cal = window.calendar; var cal = window.calendar;
if (!window.calendar) { if (!(cal && params.cache)) {
window.calendar = cal = new Calendar(params.mondayFirst, window.calendar = cal = new Calendar(params.firstDay,
params.date, params.date,
params.onSelect || onSelect, params.onSelect || onSelect,
params.onClose || function(cal) { cal.hide(); }); params.onClose || function(cal) { cal.hide(); });
@ -186,8 +196,12 @@ Calendar.setup = function (params) {
cal.weekNumbers = params.weekNumbers; cal.weekNumbers = params.weekNumbers;
mustCreate = true; mustCreate = true;
} else { } else {
if (params.date)
cal.setDate(params.date);
cal.hide(); cal.hide();
} }
cal.showsOtherMonths = params.showOthers;
cal.yearStep = params.step;
cal.setRange(params.range[0], params.range[1]); cal.setRange(params.range[0], params.range[1]);
cal.params = params; cal.params = params;
cal.setDateStatusHandler(params.dateStatusFunc); cal.setDateStatusHandler(params.dateStatusFunc);
@ -196,7 +210,10 @@ Calendar.setup = function (params) {
cal.create(); cal.create();
cal.parseDate(dateEl.value || dateEl.innerHTML); cal.parseDate(dateEl.value || dateEl.innerHTML);
cal.refresh(); cal.refresh();
cal.showAtElement(params.displayArea || params.inputField, params.align); if (!params.position)
cal.showAtElement(params.button || params.displayArea || params.inputField, params.align);
else
cal.showAt(params.position[0], params.position[1]);
return false; return false;
}; };
}; };
@ -210,33 +227,41 @@ Calendar.setup = function (params) {
// Encoding: any // Encoding: any
// Distributed under the same terms as the calendar itself. // Distributed under the same terms as the calendar itself.
// full day names
Calendar._DN = new Array Calendar._DN = new Array
("<?php echo lang('Sunday') ?>", (<?php // full day names
"<?php echo lang('Monday'); ?>", foreach($day2int as $name => $n)
"<?php echo lang('Tuesday'); ?>", {
"<?php echo lang('Wednesday'); ?>", echo "\n \"".lang($name).'"'.($n < 6 ? ',' : '');
"<?php echo lang('Thursday'); ?>", }
"<?php echo lang('Friday'); ?>", ?>);
"<?php echo lang('Saturday'); ?>",
"<?php echo lang('Sunday'); ?>");
// please note eGW does NOT use the short month-names atm. Calendar._SDN = new Array
(<?php // short day names
foreach($day2int as $name => $n)
{
echo "\n \"".substr(lang($name),0,(int)lang('3 number of chars for day-shortcut')).'"'.($n < 6 ? ',' : '');
}
?>);
Calendar._SDN_len = <?php echo (int) lang('3 number of chars for day-shortcut'); ?>2;
// full month names
Calendar._MN = new Array Calendar._MN = new Array
("<?php echo lang('January'); ?>", (<?php // full month names
"<?php echo lang('February'); ?>", $monthnames = array('January','February','March','April','May','June','July','August','September','October','November','December');
"<?php echo lang('March'); ?>", foreach($monthnames as $n => $name)
"<?php echo lang('April'); ?>", {
"<?php echo lang('May'); ?>", echo "\n \"".lang($name).'"'.($n < 11 ? ',' : '');
"<?php echo lang('June'); ?>", }
"<?php echo lang('July'); ?>", ?>);
"<?php echo lang('August'); ?>",
"<?php echo lang('September'); ?>", Calendar._SMN = new Array
"<?php echo lang('October'); ?>", (<?php // short month names
"<?php echo lang('November'); ?>", $monthnames = array('January','February','March','April','May','June','July','August','September','October','November','December');
"<?php echo lang('December'); ?>"); foreach($monthnames as $n => $name)
{
echo "\n \"".substr(lang($name),0,(int)lang('3 number of chars for month-shortcut')).'"'.($n < 11 ? ',' : '');
}
?>);
Calendar._SMN_len = <?php echo (int) lang('3 number of chars for month-shortcut'); ?>2;
// tooltips // tooltips
Calendar._TT = {}; Calendar._TT = {};
@ -267,8 +292,16 @@ Calendar._TT["NEXT_YEAR"] = "<?php echo lang('Next year (hold for menu)'); ?>";
Calendar._TT["SEL_DATE"] = "<?php echo lang('Select date'); ?>"; Calendar._TT["SEL_DATE"] = "<?php echo lang('Select date'); ?>";
Calendar._TT["DRAG_TO_MOVE"] = "<?php echo lang('Drag to move'); ?>"; Calendar._TT["DRAG_TO_MOVE"] = "<?php echo lang('Drag to move'); ?>";
Calendar._TT["PART_TODAY"] = " (<?php echo lang('today'); ?>)"; Calendar._TT["PART_TODAY"] = " (<?php echo lang('today'); ?>)";
Calendar._TT["MON_FIRST"] = "<?php echo lang('Display Monday first'); ?>";
Calendar._TT["SUN_FIRST"] = "<?php echo lang('Display Sunday first'); ?>"; // the following is to inform that "%s" is to be the first day of week
// %s will be replaced with the day name.
Calendar._TT["DAY_FIRST"] = "<?php echo lang('Display %s first'); ?>";
// This may be locale-dependent. It specifies the week-end days, as an array
// of comma-separated numbers. The numbers are from 0 to 6: 0 means Sunday, 1
// means Monday, etc.
Calendar._TT["WEEKEND"] = "0,6";
Calendar._TT["CLOSE"] = "<?php echo lang('Close'); ?>"; Calendar._TT["CLOSE"] = "<?php echo lang('Close'); ?>";
Calendar._TT["TODAY"] = "<?php echo lang('Today'); ?>"; Calendar._TT["TODAY"] = "<?php echo lang('Today'); ?>";
Calendar._TT["TIME_PART"] = "<?php echo lang('(Shift-)Click or drag to change value'); ?>"; Calendar._TT["TIME_PART"] = "<?php echo lang('(Shift-)Click or drag to change value'); ?>";
@ -280,3 +313,4 @@ Calendar._TT["DEF_DATE_FORMAT"] = "<?php echo $jsDateFormat; ?>";
Calendar._TT["TT_DATE_FORMAT"] = "<?php echo $jsLongDateFormat; ?>"; Calendar._TT["TT_DATE_FORMAT"] = "<?php echo $jsLongDateFormat; ?>";
Calendar._TT["WK"] = "<?php echo lang('Wk'); ?>"; Calendar._TT["WK"] = "<?php echo lang('Wk'); ?>";
Calendar._TT["TIME"] = "<?php echo lang('Time'); ?>:";