[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 /* Copyright Mihai Bazon, 2002, 2003 | http://dynarch.com/mishoo/ 2 * --------------------------------------------------------------------------- 3 * 4 * The DHTML Calendar 5 * 6 * Details and latest version at: 7 * http://dynarch.com/mishoo/calendar.epl 8 * 9 * This script is distributed under the GNU Lesser General Public License. 10 * Read the entire license text here: http://www.gnu.org/licenses/lgpl.html 11 * 12 * This file defines helper functions for setting up the calendar. They are 13 * intended to help non-programmers get a working calendar on their site 14 * quickly. This script should not be seen as part of the calendar. It just 15 * shows you what one can do with the calendar, while in the same time 16 * providing a quick and simple method for setting it up. If you need 17 * exhaustive customization of the calendar creation process feel free to 18 * modify this code to suit your needs (this is recommended and much better 19 * than modifying calendar.js itself). 20 */ 21 22 // $Id: calendar-setup.js 20295 2006-02-15 12:31:25Z $ 23 24 /** 25 * This function "patches" an input field (or other element) to use a calendar 26 * widget for date selection. 27 * 28 * The "params" is a single object that can have the following properties: 29 * 30 * prop. name | description 31 * ------------------------------------------------------------------------------------------------- 32 * inputField | the ID of an input field to store the date 33 * displayArea | the ID of a DIV or other element to show the date 34 * button | ID of a button or other element that will trigger the calendar 35 * eventName | event that will trigger the calendar, without the "on" prefix (default: "click") 36 * ifFormat | date format that will be stored in the input field 37 * daFormat | the date format that will be used to display the date in displayArea 38 * titleFormat | the format to show the month in the title, default '%B, %Y' 39 * singleClick | (true/false) wether the calendar is in single click mode or not (default: true) 40 * firstDay | numeric: 0 to 6. "0" means display Sunday first, "1" means display Monday first, etc. 41 * disableFirstDowChange| (true/false) disables manual change of first day of week 42 * align | alignment (default: "Br"); if you don't know what's this see the calendar documentation 43 * range | array with 2 elements. Default: [1900, 2999] -- the range of years available 44 * weekNumbers | (true/false) if it's true (default) the calendar will display week numbers 45 * flat | null or element ID; if not null the calendar will be a flat calendar having the parent with the given ID 46 * flatCallback | function that receives a JS Date object and returns an URL to point the browser to (for flat calendar) 47 * flatWeekCallback| gets called if a weeknumber get clicked, params are the cal-object and a date-object representing the start of the week 48 * flatWeekTTip | Tooltip for the weeknumber (shown only if flatWeekCallback is set) 49 * flatMonthCallback| gets called if a month (title) get clicked, params are the cal-object and a date-object representing the start of the month 50 * flatMonthTTip | Tooltip for the month (shown only if flatMonthCallback is set) 51 * disableFunc | function that receives a JS Date object and should return true if that date has to be disabled in the calendar 52 * onSelect | function that gets called when a date is selected. You don't _have_ to supply this (the default is generally okay) 53 * onClose | function that gets called when the calendar is closed. [default] 54 * onUpdate | function that gets called after the date is updated in the input field. Receives a reference to the calendar. 55 * date | the date that the calendar will be initially displayed to 56 * showsTime | default: false; if true the calendar will include a time selector 57 * timeFormat | the time format; can be "12" or "24", default is "12" 58 * electric | if true (default) then given fields/date areas are updated for each move; otherwise they're updated only on close 59 * step | configures the step of the years in drop-down boxes; default: 2 60 * position | configures the calendar absolute position; default: null 61 * cache | if "true" (but default: "false") it will reuse the same calendar object, where possible 62 * showOthers | if "true" (but default: "false") it will show days from other months too 63 * 64 * None of them is required, they all have default values. However, if you 65 * pass none of "inputField", "displayArea" or "button" you'll get a warning 66 * saying "nothing to setup". 67 */ 68 Calendar.setup = function (params) { 69 function param_default(pname, def) { if (typeof params[pname] == "undefined") { params[pname] = def; } }; 70 71 param_default("inputField", null); 72 param_default("displayArea", null); 73 param_default("button", null); 74 param_default("eventName", "click"); 75 param_default("ifFormat", "%Y/%m/%d"); 76 param_default("daFormat", "%Y/%m/%d"); 77 param_default("titleFormat", "%B, %Y"); 78 param_default("singleClick", true); 79 param_default("disableFunc", null); 80 param_default("dateStatusFunc", params["disableFunc"]); // takes precedence if both are defined 81 param_default("firstDay", 0); // defaults to "Sunday" first 82 param_default("disableFirstDowChange", false); 83 param_default("align", "Br"); 84 param_default("range", [1900, 2999]); 85 param_default("weekNumbers", true); 86 param_default("flat", null); 87 param_default("flatCallback", null); 88 param_default("flatWeekCallback",null); 89 param_default("flatWeekTTip", null); 90 param_default("flatmonthCallback",null); 91 param_default("flatmonthTTip", null); 92 param_default("onSelect", null); 93 param_default("onClose", null); 94 param_default("onUpdate", null); 95 param_default("date", null); 96 param_default("showsTime", false); 97 param_default("timeFormat", "24"); 98 param_default("electric", true); 99 param_default("step", 2); 100 param_default("position", null); 101 param_default("cache", false); 102 param_default("showOthers", false); 103 104 var tmp = ["inputField", "displayArea", "button"]; 105 for (var i in tmp) { 106 if (typeof params[tmp[i]] == "string") { 107 params[tmp[i]] = document.getElementById(params[tmp[i]]); 108 } 109 } 110 if (!(params.flat || params.inputField || params.displayArea || params.button)) { 111 alert("Calendar.setup:\n Nothing to setup (no fields found). Please check your code"); 112 return false; 113 } 114 115 function onSelect(cal) { 116 var p = cal.params; 117 var update = (cal.dateClicked || p.electric); 118 if (update && p.flat) { 119 if (typeof p.flatCallback == "function") 120 p.flatCallback(cal); 121 else 122 alert("No flatCallback given -- doing nothing."); 123 return false; 124 } 125 if (update && p.inputField) { 126 p.inputField.value = cal.date.print(p.ifFormat); 127 if (typeof p.inputField.onchange == "function") 128 p.inputField.onchange(); 129 } 130 if (update && p.displayArea) 131 p.displayArea.innerHTML = cal.date.print(p.daFormat); 132 if (update && p.singleClick && cal.dateClicked) 133 cal.callCloseHandler(); 134 if (update && typeof p.onUpdate == "function") 135 p.onUpdate(cal); 136 }; 137 138 if (params.flat != null) { 139 if (typeof params.flat == "string") 140 params.flat = document.getElementById(params.flat); 141 if (!params.flat) { 142 alert("Calendar.setup:\n Flat specified but can't find parent."); 143 return false; 144 } 145 var cal = new Calendar(params.firstDay, params.date, params.onSelect || onSelect); 146 cal.showsTime = params.showsTime; 147 cal.time24 = (params.timeFormat == "24"); 148 cal.params = params; 149 cal.weekNumbers = params.weekNumbers; 150 cal.setRange(params.range[0], params.range[1]); 151 cal.setDateStatusHandler(params.dateStatusFunc); 152 cal.showsOtherMonths = params.showOthers; 153 cal.create(params.flat); 154 cal.show(); 155 return false; 156 } 157 158 var triggerEl = params.button || params.displayArea || params.inputField; 159 triggerEl["on" + params.eventName] = function() { 160 var dateEl = params.inputField || params.displayArea; 161 var dateFmt = params.inputField ? params.ifFormat : params.daFormat; 162 var mustCreate = false; 163 var cal = window.calendar; 164 if (!(cal && params.cache)) { 165 window.calendar = cal = new Calendar(params.firstDay, 166 params.date, 167 params.onSelect || onSelect, 168 params.onClose || function(cal) { cal.hide(); }); 169 cal.showsTime = params.showsTime; 170 cal.time24 = (params.timeFormat == "24"); 171 cal.weekNumbers = params.weekNumbers; 172 mustCreate = true; 173 } else { 174 if (params.date) 175 cal.setDate(params.date); 176 cal.hide(); 177 } 178 cal.showsOtherMonths = params.showOthers; 179 cal.yearStep = params.step; 180 cal.setRange(params.range[0], params.range[1]); 181 cal.params = params; 182 cal.setDateStatusHandler(params.dateStatusFunc); 183 cal.setDateFormat(dateFmt); 184 if (mustCreate) 185 cal.create(); 186 cal.parseDate(dateEl.value || dateEl.innerHTML); 187 cal.refresh(); 188 if (!params.position) 189 cal.showAtElement(params.button || params.displayArea || params.inputField, params.align); 190 else 191 cal.showAt(params.position[0], params.position[1]); 192 return false; 193 }; 194 };
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |