?? calendar-core.js
字號:
/* * $Id: calendar-core.js 7495 2007-06-27 14:12:11Z vasyl $ * The Zapatec DHTML Calendar * * Copyright (c) 2004-2006 by Zapatec, Inc. * http://www.zapatec.com * 1700 MLK Way, Berkeley, California, * 94709, U.S.A. * All rights reserved. * * Main Calendar file. Creates a popup or flat calendar with various options. * * Original version written by Mihai Bazon, * http://www.bazon.net/mishoo/calendar.epl */// $Id: calendar-core.js 7495 2007-06-27 14:12:11Z vasyl $/** * The Calendar object constructor. Call it, for example, like this: * * \code * // the following function is called when a date is clicked * function selFunc(cal) { * alert(cal.date); * } * // the following function is called when the calendar should be closed * function closeFunc(cal) { * cal.destroy(); * } * var cal = new Zapatec.Calendar(1, new Date(), selFunc, closeFunc); * \endcode * * The above creates a new Calendar object. The Calendar isn't displayed * instantly; using the "cal" variable, the programmer can now set certain * configuration variables, hook his own event handlers and then display the * calendar using Zapatec.Calendar.create(). * * @param firstDayOfWeek [int] the first day of week (0 for Sun, 1 for Mon, ...) * @param dateStr [string or Date] a string to be the default date, or a reference to a Date object * @param onSelected [function] this function will be called when a date is selected * @param onClose [function] this is called when the calendar should be closed */Zapatec.Calendar = function (firstDayOfWeek, dateStr, onSelected, onClose) { // Add this widget to the list if (typeof this.id == 'undefined') { // Find id var iId = 0; while (Zapatec.Widget.all[iId]) { iId++; } this.id = iId; Zapatec.Widget.all[iId] = this; } // member variables this.bShowHistoryEvent=false; // did the History event on Today fire? this.activeDiv = null; this.currentDateEl = null; this.getDateStatus = null; this.getDateToolTip = null; this.getDateText = null; this.timeout = null; this.onSelected = onSelected || null; this.onClose = onClose || null; this.onFDOW = null; this.dragging = false; this.hidden = false; this.minYear = 1970; this.maxYear = 2050; this.minMonth = 0; this.maxMonth = 11; this.dateFormat = Zapatec.Calendar.i18n("DEF_DATE_FORMAT"); this.ttDateFormat = Zapatec.Calendar.i18n("TT_DATE_FORMAT"); this.historyDateFormat = "%B %d, %Y"; this.isPopup = true; this.weekNumbers = true; this.noGrab = false; if (Zapatec.Calendar.prefs.fdow || (Zapatec.Calendar.prefs.fdow == 0)) { this.firstDayOfWeek = parseInt(Zapatec.Calendar.prefs.fdow, 10); } else { var fd = 0; if (typeof firstDayOfWeek == "number") { fd = firstDayOfWeek; } else if (typeof Zapatec.Calendar._FD == 'number') { fd = Zapatec.Calendar._FD; } this.firstDayOfWeek = fd; } this.showsOtherMonths = false; this.dateStr = dateStr; this.showsTime = false; this.sortOrder = "asc"; //Sort for multiple dates in ascending order this.time24 = true; this.timeInterval = null; //step for changing time this.yearStep = 2; this.hiliteToday = true; this.multiple = null; // HTML elements this.table = null; this.element = null; this.tbody = new Array(); //array of rows of months this.firstdayname = null; // Combo boxes this.monthsCombo = null; // months this.hilitedMonth = null; this.activeMonth = null; this.yearsCombo = null; // years this.hilitedYear = null; this.activeYear = null; this.histCombo = null; // history this.hilitedHist = null; // Information this.dateClicked = false; this.numberMonths = 1; //number of months displayed this.controlMonth = 1; //the number of month with all the combos to control the date this.vertical = false; //vertical or horizontal positioning of months this.monthsInRow = 1; //number of months in one row this.titles = new Array(); //array of titles for the months this.rowsOfDayNames = new Array(); //array of rows of day names this.helpButton = true; this.disableFdowClick = true; this.disableDrag = false; this.yearNav = true; this.closeButton = true; // one-time initializations Zapatec.Calendar._initSDN();};/** * \internal This function is called from the constructor, only once, to * initialize some internal arrays containing translation strings. It is also * called from the calendar wizard in order to reconfigure the calendar with a * language different than the initially selected one. */Zapatec.Calendar._initSDN = function() { if (typeof Zapatec.Calendar._TT._SDN == "undefined") { // table of short day names if (typeof Zapatec.Calendar._TT._SDN_len == "undefined") Zapatec.Calendar._TT._SDN_len = 3; var ar = []; for (var i = 8; i > 0;) { ar[--i] = Zapatec.Calendar._TT._DN[i].substr(0, Zapatec.Calendar._TT._SDN_len); } Zapatec.Calendar._TT._SDN = ar; // table of short month names if (typeof Zapatec.Calendar._TT._SMN_len == "undefined") Zapatec.Calendar._TT._SMN_len = 3; ar = []; for (var i = 12; i > 0;) { ar[--i] = Zapatec.Calendar._TT._MN[i].substr(0, Zapatec.Calendar._TT._SMN_len); } Zapatec.Calendar._TT._SMN = ar; } if (typeof Zapatec.Calendar._TT._AMPM == "undefined") { Zapatec.Calendar._TT._AMPM = {am : "am", pm : "pm"}; }};/** * Translate a string according to the currently loaded language table. The * \em type variable can be null or missing, or can have one of the following * values: "dn", "sdn", "mn", "smn". * * -# if \em type is null or missing, the given \em str will be looked up in * the translation table. If a value is found, it is returned. Otherwise, * the string is looked up in the English table (if present). If still not * found, the value of \em str itself is returned. * -# if \em type is passed, then the value of \em str is looked up in one of * the following internal arrays, depending on the value of \em type: * - DN (day name) * - SDN (short day name) * - MN (month name) * - SMN (short month name) * * @param str [string] ID of translation text (can be the English text) * @param type [string, optional] domain to search through * * @return the translation according to the current language. */Zapatec.Calendar.i18n = function(str, type) { var tr = ''; if (!type) { // normal _TT request if (Zapatec.Calendar._TT) tr = Zapatec.Calendar._TT[str]; if (!tr && Zapatec.Calendar._TT_en) tr = Zapatec.Calendar._TT_en[str]; } else switch(type) { case "dn" : tr = Zapatec.Calendar._TT._DN[str]; break; case "sdn" : tr = Zapatec.Calendar._TT._SDN[str]; break; case "mn" : tr = Zapatec.Calendar._TT._MN[str]; break; case "smn" : tr = Zapatec.Calendar._TT._SMN[str]; break; case "ampm" : tr = Zapatec.Calendar._TT._AMPM[str]; break; } if (!tr) tr = "" + str; return tr;};// ** constants/// "static", needed for event handlers.Zapatec.Calendar._C = null;/// preferencesZapatec.Calendar.prefs = { fdow : null, /**< when NULL we will use the options passed at Zapatec.Calendar.setup */ history : "", /**< keeps the history as one big string */ sortOrder : "asc", /**< Sort order for multiple dates. Ascending by default */ hsize : 9 /**< maximum history size (number of stored items) */};// BEGIN: CALENDAR STATIC FUNCTIONS/** * Writes the preferences cookie. */Zapatec.Calendar.savePrefs = function() { // FIXME: should we make the domain, path and expiration time configurable? // I guess these defaults are right though.. Zapatec.Utils.writeCookie("ZP_CAL", Zapatec.Utils.makePref(this.prefs), null, '/', 30);};/** * Loads the preference cookie and merges saved prefs to Zapatec.Calendar.prefs. */Zapatec.Calendar.loadPrefs = function() { var txt = Zapatec.Utils.getCookie("ZP_CAL"), tmp; if (txt) { tmp = Zapatec.Utils.loadPref(txt); if (tmp) Zapatec.Utils.mergeObjects(this.prefs, tmp); } // FIXME: DEBUG! //this.prefs.history = "1979/03/08,1976/12/28,1978/08/31,1998/09/21"; //this.prefs.history = null;};/** * \internal Adds a set of events to make some element behave like a button. * * @param el [HTMLElement] reference to your element. */Zapatec.Calendar._add_evs = function(el) { var C = Zapatec.Calendar; el.onmouseover = C.dayMouseOver; el.onmousedown = C.dayMouseDown; el.onmouseout = C.dayMouseOut; if (Zapatec.is_ie) el.ondblclick = C.dayMouseDblClick;};/** * \internal This function undoes what Zapatec.Calendar._add_evs did, therefore * unregisters the event handlers. * * @param el [HTMLElement] reference to your element. */Zapatec.Calendar._del_evs = function(el) { el.onmouseover = null; el.onmousedown = null; el.onmouseout = null; if (Zapatec.is_ie) el.ondblclick = null;};/** * Given an HTML element, this function determines if it's part of the "months" * combo box and if so it returns the element containing the month name. * * @param el [HTMLElement] some element (usually that triggered onclick) * @return [HTMLElement] element with the month */Zapatec.Calendar.findMonth = function(el) { if (typeof el.month != "undefined") { return el; } else if (el.parentNode && typeof el.parentNode.month != "undefined") { return el.parentNode; } return null;};/** Similar to findMonth() but for the history combo. */Zapatec.Calendar.findHist = function(el) { if (typeof el.histDate != "undefined") { return el; } else if (el.parentNode && typeof el.parentNode.histDate != "undefined") { return el.parentNode; } return null;};/** Similar to the above functions, but for the years combo. */Zapatec.Calendar.findYear = function(el) { if (typeof el.year != "undefined") { return el; } else if (el.parentNode && typeof el.parentNode.year != "undefined") { return el.parentNode; } return null;};/** * This function displays the months combo box. It doesn't need any parameters * because it uses the static _C variable which maintains a reference to the * last calendar that was clicked in the page. */Zapatec.Calendar.showMonthsCombo = function () { var cal = Zapatec.Calendar._C; if (!cal) { return false; } var cd = cal.activeDiv; var mc = cal.monthsCombo; var date = cal.date, MM = cal.date.getMonth(), YY = cal.date.getFullYear(), min = (YY == cal.minYear), max = (YY == cal.maxYear); for (var i = mc.firstChild; i; i = i.nextSibling) { var m = i.month; Zapatec.Utils.removeClass(i, "hilite"); Zapatec.Utils.removeClass(i, "active"); Zapatec.Utils.removeClass(i, "disabled"); i.disabled = false; if ((min && m < cal.minMonth) || (max && m > cal.maxMonth)) { Zapatec.Utils.addClass(i, "disabled"); i.disabled = true; } if (m == MM) Zapatec.Utils.addClass(cal.activeMonth = i, "active"); } var s = mc.style; s.display = "block"; if (cd.navtype < 0) s.left = cd.offsetLeft + "px"; else { var mcw = mc.offsetWidth; if (typeof mcw == "undefined") // Konqueror brain-dead techniques mcw = 50; s.left = (cd.offsetLeft + cd.offsetWidth - mcw) + "px"; } s.top = (cd.offsetTop + cd.offsetHeight) + "px"; cal.updateWCH(mc);};/** * Same as the above, this function displays the history combo box for the * active calendar. */Zapatec.Calendar.showHistoryCombo = function() { var cal = Zapatec.Calendar._C, a, h, i, cd, hc, s, tmp, div; if (!cal) return false; hc = cal.histCombo; while (hc.firstChild) hc.removeChild(hc.lastChild); if (Zapatec.Calendar.prefs.history) { a = Zapatec.Calendar.prefs.history.split(/,/); i = 0; while (tmp = a[i++]) { tmp = tmp.split(/\//); h = Zapatec.Utils.createElement("div"); h.className = Zapatec.is_ie ? "label-IEfix" : "label"; h.id = "zpCal" + cal.id + "HistoryDropdownItem" + (i - 1); h.histDate = new Date(parseInt(tmp[0], 10), parseInt(tmp[1], 10)-1, parseInt(tmp[2], 10), tmp[3] ? parseInt(tmp[3], 10) : 0, tmp[4] ? parseInt(tmp[4], 10) : 0); h.appendChild(window.document.createTextNode(h.histDate.print(cal.historyDateFormat)));
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -