/src/main/resources/org/apache/struts2/static/calendar/calendar-debug.js
JavaScript | 7178 lines | 3040 code | 916 blank | 3222 comment | 560 complexity | e465b111e655819506047a645708c328 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /*
- Copyright (c) 2009, Yahoo! Inc. All rights reserved.
- Code licensed under the BSD License:
- http://developer.yahoo.net/yui/license.txt
- version: 2.7.0
- */
- (function () {
- /**
- * Config is a utility used within an Object to allow the implementer to
- * maintain a list of local configuration properties and listen for changes
- * to those properties dynamically using CustomEvent. The initial values are
- * also maintained so that the configuration can be reset at any given point
- * to its initial state.
- * @namespace YAHOO.util
- * @class Config
- * @constructor
- * @param {Object} owner The owner Object to which this Config Object belongs
- */
- YAHOO.util.Config = function (owner) {
- if (owner) {
- this.init(owner);
- }
- if (!owner) { YAHOO.log("No owner specified for Config object", "error", "Config"); }
- };
- var Lang = YAHOO.lang,
- CustomEvent = YAHOO.util.CustomEvent,
- Config = YAHOO.util.Config;
- /**
- * Constant representing the CustomEvent type for the config changed event.
- * @property YAHOO.util.Config.CONFIG_CHANGED_EVENT
- * @private
- * @static
- * @final
- */
- Config.CONFIG_CHANGED_EVENT = "configChanged";
-
- /**
- * Constant representing the boolean type string
- * @property YAHOO.util.Config.BOOLEAN_TYPE
- * @private
- * @static
- * @final
- */
- Config.BOOLEAN_TYPE = "boolean";
-
- Config.prototype = {
-
- /**
- * Object reference to the owner of this Config Object
- * @property owner
- * @type Object
- */
- owner: null,
-
- /**
- * Boolean flag that specifies whether a queue is currently
- * being executed
- * @property queueInProgress
- * @type Boolean
- */
- queueInProgress: false,
-
- /**
- * Maintains the local collection of configuration property objects and
- * their specified values
- * @property config
- * @private
- * @type Object
- */
- config: null,
-
- /**
- * Maintains the local collection of configuration property objects as
- * they were initially applied.
- * This object is used when resetting a property.
- * @property initialConfig
- * @private
- * @type Object
- */
- initialConfig: null,
-
- /**
- * Maintains the local, normalized CustomEvent queue
- * @property eventQueue
- * @private
- * @type Object
- */
- eventQueue: null,
-
- /**
- * Custom Event, notifying subscribers when Config properties are set
- * (setProperty is called without the silent flag
- * @event configChangedEvent
- */
- configChangedEvent: null,
-
- /**
- * Initializes the configuration Object and all of its local members.
- * @method init
- * @param {Object} owner The owner Object to which this Config
- * Object belongs
- */
- init: function (owner) {
-
- this.owner = owner;
-
- this.configChangedEvent =
- this.createEvent(Config.CONFIG_CHANGED_EVENT);
-
- this.configChangedEvent.signature = CustomEvent.LIST;
- this.queueInProgress = false;
- this.config = {};
- this.initialConfig = {};
- this.eventQueue = [];
-
- },
-
- /**
- * Validates that the value passed in is a Boolean.
- * @method checkBoolean
- * @param {Object} val The value to validate
- * @return {Boolean} true, if the value is valid
- */
- checkBoolean: function (val) {
- return (typeof val == Config.BOOLEAN_TYPE);
- },
-
- /**
- * Validates that the value passed in is a number.
- * @method checkNumber
- * @param {Object} val The value to validate
- * @return {Boolean} true, if the value is valid
- */
- checkNumber: function (val) {
- return (!isNaN(val));
- },
-
- /**
- * Fires a configuration property event using the specified value.
- * @method fireEvent
- * @private
- * @param {String} key The configuration property's name
- * @param {value} Object The value of the correct type for the property
- */
- fireEvent: function ( key, value ) {
- YAHOO.log("Firing Config event: " + key + "=" + value, "info", "Config");
- var property = this.config[key];
-
- if (property && property.event) {
- property.event.fire(value);
- }
- },
-
- /**
- * Adds a property to the Config Object's private config hash.
- * @method addProperty
- * @param {String} key The configuration property's name
- * @param {Object} propertyObject The Object containing all of this
- * property's arguments
- */
- addProperty: function ( key, propertyObject ) {
- key = key.toLowerCase();
- YAHOO.log("Added property: " + key, "info", "Config");
-
- this.config[key] = propertyObject;
-
- propertyObject.event = this.createEvent(key, { scope: this.owner });
- propertyObject.event.signature = CustomEvent.LIST;
-
-
- propertyObject.key = key;
-
- if (propertyObject.handler) {
- propertyObject.event.subscribe(propertyObject.handler,
- this.owner);
- }
-
- this.setProperty(key, propertyObject.value, true);
-
- if (! propertyObject.suppressEvent) {
- this.queueProperty(key, propertyObject.value);
- }
-
- },
-
- /**
- * Returns a key-value configuration map of the values currently set in
- * the Config Object.
- * @method getConfig
- * @return {Object} The current config, represented in a key-value map
- */
- getConfig: function () {
-
- var cfg = {},
- currCfg = this.config,
- prop,
- property;
-
- for (prop in currCfg) {
- if (Lang.hasOwnProperty(currCfg, prop)) {
- property = currCfg[prop];
- if (property && property.event) {
- cfg[prop] = property.value;
- }
- }
- }
- return cfg;
- },
-
- /**
- * Returns the value of specified property.
- * @method getProperty
- * @param {String} key The name of the property
- * @return {Object} The value of the specified property
- */
- getProperty: function (key) {
- var property = this.config[key.toLowerCase()];
- if (property && property.event) {
- return property.value;
- } else {
- return undefined;
- }
- },
-
- /**
- * Resets the specified property's value to its initial value.
- * @method resetProperty
- * @param {String} key The name of the property
- * @return {Boolean} True is the property was reset, false if not
- */
- resetProperty: function (key) {
-
- key = key.toLowerCase();
-
- var property = this.config[key];
-
- if (property && property.event) {
-
- if (this.initialConfig[key] &&
- !Lang.isUndefined(this.initialConfig[key])) {
-
- this.setProperty(key, this.initialConfig[key]);
- return true;
-
- }
-
- } else {
-
- return false;
- }
-
- },
-
- /**
- * Sets the value of a property. If the silent property is passed as
- * true, the property's event will not be fired.
- * @method setProperty
- * @param {String} key The name of the property
- * @param {String} value The value to set the property to
- * @param {Boolean} silent Whether the value should be set silently,
- * without firing the property event.
- * @return {Boolean} True, if the set was successful, false if it failed.
- */
- setProperty: function (key, value, silent) {
-
- var property;
-
- key = key.toLowerCase();
- YAHOO.log("setProperty: " + key + "=" + value, "info", "Config");
-
- if (this.queueInProgress && ! silent) {
- // Currently running through a queue...
- this.queueProperty(key,value);
- return true;
-
- } else {
- property = this.config[key];
- if (property && property.event) {
- if (property.validator && !property.validator(value)) {
- return false;
- } else {
- property.value = value;
- if (! silent) {
- this.fireEvent(key, value);
- this.configChangedEvent.fire([key, value]);
- }
- return true;
- }
- } else {
- return false;
- }
- }
- },
-
- /**
- * Sets the value of a property and queues its event to execute. If the
- * event is already scheduled to execute, it is
- * moved from its current position to the end of the queue.
- * @method queueProperty
- * @param {String} key The name of the property
- * @param {String} value The value to set the property to
- * @return {Boolean} true, if the set was successful, false if
- * it failed.
- */
- queueProperty: function (key, value) {
-
- key = key.toLowerCase();
- YAHOO.log("queueProperty: " + key + "=" + value, "info", "Config");
-
- var property = this.config[key],
- foundDuplicate = false,
- iLen,
- queueItem,
- queueItemKey,
- queueItemValue,
- sLen,
- supercedesCheck,
- qLen,
- queueItemCheck,
- queueItemCheckKey,
- queueItemCheckValue,
- i,
- s,
- q;
-
- if (property && property.event) {
-
- if (!Lang.isUndefined(value) && property.validator &&
- !property.validator(value)) { // validator
- return false;
- } else {
-
- if (!Lang.isUndefined(value)) {
- property.value = value;
- } else {
- value = property.value;
- }
-
- foundDuplicate = false;
- iLen = this.eventQueue.length;
-
- for (i = 0; i < iLen; i++) {
- queueItem = this.eventQueue[i];
-
- if (queueItem) {
- queueItemKey = queueItem[0];
- queueItemValue = queueItem[1];
- if (queueItemKey == key) {
-
- /*
- found a dupe... push to end of queue, null
- current item, and break
- */
-
- this.eventQueue[i] = null;
-
- this.eventQueue.push(
- [key, (!Lang.isUndefined(value) ?
- value : queueItemValue)]);
-
- foundDuplicate = true;
- break;
- }
- }
- }
-
- // this is a refire, or a new property in the queue
-
- if (! foundDuplicate && !Lang.isUndefined(value)) {
- this.eventQueue.push([key, value]);
- }
- }
-
- if (property.supercedes) {
- sLen = property.supercedes.length;
- for (s = 0; s < sLen; s++) {
- supercedesCheck = property.supercedes[s];
- qLen = this.eventQueue.length;
- for (q = 0; q < qLen; q++) {
- queueItemCheck = this.eventQueue[q];
- if (queueItemCheck) {
- queueItemCheckKey = queueItemCheck[0];
- queueItemCheckValue = queueItemCheck[1];
- if (queueItemCheckKey ==
- supercedesCheck.toLowerCase() ) {
- this.eventQueue.push([queueItemCheckKey,
- queueItemCheckValue]);
- this.eventQueue[q] = null;
- break;
- }
- }
- }
- }
- }
- YAHOO.log("Config event queue: " + this.outputEventQueue(), "info", "Config");
- return true;
- } else {
- return false;
- }
- },
-
- /**
- * Fires the event for a property using the property's current value.
- * @method refireEvent
- * @param {String} key The name of the property
- */
- refireEvent: function (key) {
-
- key = key.toLowerCase();
-
- var property = this.config[key];
-
- if (property && property.event &&
-
- !Lang.isUndefined(property.value)) {
-
- if (this.queueInProgress) {
-
- this.queueProperty(key);
-
- } else {
-
- this.fireEvent(key, property.value);
-
- }
-
- }
- },
-
- /**
- * Applies a key-value Object literal to the configuration, replacing
- * any existing values, and queueing the property events.
- * Although the values will be set, fireQueue() must be called for their
- * associated events to execute.
- * @method applyConfig
- * @param {Object} userConfig The configuration Object literal
- * @param {Boolean} init When set to true, the initialConfig will
- * be set to the userConfig passed in, so that calling a reset will
- * reset the properties to the passed values.
- */
- applyConfig: function (userConfig, init) {
-
- var sKey,
- oConfig;
- if (init) {
- oConfig = {};
- for (sKey in userConfig) {
- if (Lang.hasOwnProperty(userConfig, sKey)) {
- oConfig[sKey.toLowerCase()] = userConfig[sKey];
- }
- }
- this.initialConfig = oConfig;
- }
- for (sKey in userConfig) {
- if (Lang.hasOwnProperty(userConfig, sKey)) {
- this.queueProperty(sKey, userConfig[sKey]);
- }
- }
- },
-
- /**
- * Refires the events for all configuration properties using their
- * current values.
- * @method refresh
- */
- refresh: function () {
- var prop;
- for (prop in this.config) {
- if (Lang.hasOwnProperty(this.config, prop)) {
- this.refireEvent(prop);
- }
- }
- },
-
- /**
- * Fires the normalized list of queued property change events
- * @method fireQueue
- */
- fireQueue: function () {
-
- var i,
- queueItem,
- key,
- value,
- property;
-
- this.queueInProgress = true;
- for (i = 0;i < this.eventQueue.length; i++) {
- queueItem = this.eventQueue[i];
- if (queueItem) {
-
- key = queueItem[0];
- value = queueItem[1];
- property = this.config[key];
- property.value = value;
- // Clear out queue entry, to avoid it being
- // re-added to the queue by any queueProperty/supercedes
- // calls which are invoked during fireEvent
- this.eventQueue[i] = null;
- this.fireEvent(key,value);
- }
- }
-
- this.queueInProgress = false;
- this.eventQueue = [];
- },
-
- /**
- * Subscribes an external handler to the change event for any
- * given property.
- * @method subscribeToConfigEvent
- * @param {String} key The property name
- * @param {Function} handler The handler function to use subscribe to
- * the property's event
- * @param {Object} obj The Object to use for scoping the event handler
- * (see CustomEvent documentation)
- * @param {Boolean} override Optional. If true, will override "this"
- * within the handler to map to the scope Object passed into the method.
- * @return {Boolean} True, if the subscription was successful,
- * otherwise false.
- */
- subscribeToConfigEvent: function (key, handler, obj, override) {
-
- var property = this.config[key.toLowerCase()];
-
- if (property && property.event) {
- if (!Config.alreadySubscribed(property.event, handler, obj)) {
- property.event.subscribe(handler, obj, override);
- }
- return true;
- } else {
- return false;
- }
-
- },
-
- /**
- * Unsubscribes an external handler from the change event for any
- * given property.
- * @method unsubscribeFromConfigEvent
- * @param {String} key The property name
- * @param {Function} handler The handler function to use subscribe to
- * the property's event
- * @param {Object} obj The Object to use for scoping the event
- * handler (see CustomEvent documentation)
- * @return {Boolean} True, if the unsubscription was successful,
- * otherwise false.
- */
- unsubscribeFromConfigEvent: function (key, handler, obj) {
- var property = this.config[key.toLowerCase()];
- if (property && property.event) {
- return property.event.unsubscribe(handler, obj);
- } else {
- return false;
- }
- },
-
- /**
- * Returns a string representation of the Config object
- * @method toString
- * @return {String} The Config object in string format.
- */
- toString: function () {
- var output = "Config";
- if (this.owner) {
- output += " [" + this.owner.toString() + "]";
- }
- return output;
- },
-
- /**
- * Returns a string representation of the Config object's current
- * CustomEvent queue
- * @method outputEventQueue
- * @return {String} The string list of CustomEvents currently queued
- * for execution
- */
- outputEventQueue: function () {
- var output = "",
- queueItem,
- q,
- nQueue = this.eventQueue.length;
-
- for (q = 0; q < nQueue; q++) {
- queueItem = this.eventQueue[q];
- if (queueItem) {
- output += queueItem[0] + "=" + queueItem[1] + ", ";
- }
- }
- return output;
- },
- /**
- * Sets all properties to null, unsubscribes all listeners from each
- * property's change event and all listeners from the configChangedEvent.
- * @method destroy
- */
- destroy: function () {
- var oConfig = this.config,
- sProperty,
- oProperty;
- for (sProperty in oConfig) {
-
- if (Lang.hasOwnProperty(oConfig, sProperty)) {
- oProperty = oConfig[sProperty];
- oProperty.event.unsubscribeAll();
- oProperty.event = null;
- }
-
- }
-
- this.configChangedEvent.unsubscribeAll();
-
- this.configChangedEvent = null;
- this.owner = null;
- this.config = null;
- this.initialConfig = null;
- this.eventQueue = null;
-
- }
- };
-
-
-
- /**
- * Checks to determine if a particular function/Object pair are already
- * subscribed to the specified CustomEvent
- * @method YAHOO.util.Config.alreadySubscribed
- * @static
- * @param {YAHOO.util.CustomEvent} evt The CustomEvent for which to check
- * the subscriptions
- * @param {Function} fn The function to look for in the subscribers list
- * @param {Object} obj The execution scope Object for the subscription
- * @return {Boolean} true, if the function/Object pair is already subscribed
- * to the CustomEvent passed in
- */
- Config.alreadySubscribed = function (evt, fn, obj) {
-
- var nSubscribers = evt.subscribers.length,
- subsc,
- i;
- if (nSubscribers > 0) {
- i = nSubscribers - 1;
- do {
- subsc = evt.subscribers[i];
- if (subsc && subsc.obj == obj && subsc.fn == fn) {
- return true;
- }
- }
- while (i--);
- }
- return false;
- };
- YAHOO.lang.augmentProto(Config, YAHOO.util.EventProvider);
- }());
- /**
- * YAHOO.widget.DateMath is used for simple date manipulation. The class is a static utility
- * used for adding, subtracting, and comparing dates.
- * @namespace YAHOO.widget
- * @class DateMath
- */
- YAHOO.widget.DateMath = {
- /**
- * Constant field representing Day
- * @property DAY
- * @static
- * @final
- * @type String
- */
- DAY : "D",
- /**
- * Constant field representing Week
- * @property WEEK
- * @static
- * @final
- * @type String
- */
- WEEK : "W",
- /**
- * Constant field representing Year
- * @property YEAR
- * @static
- * @final
- * @type String
- */
- YEAR : "Y",
- /**
- * Constant field representing Month
- * @property MONTH
- * @static
- * @final
- * @type String
- */
- MONTH : "M",
- /**
- * Constant field representing one day, in milliseconds
- * @property ONE_DAY_MS
- * @static
- * @final
- * @type Number
- */
- ONE_DAY_MS : 1000*60*60*24,
-
- /**
- * Constant field representing the date in first week of January
- * which identifies the first week of the year.
- * <p>
- * In the U.S, Jan 1st is normally used based on a Sunday start of week.
- * ISO 8601, used widely throughout Europe, uses Jan 4th, based on a Monday start of week.
- * </p>
- * @property WEEK_ONE_JAN_DATE
- * @static
- * @type Number
- */
- WEEK_ONE_JAN_DATE : 1,
- /**
- * Adds the specified amount of time to the this instance.
- * @method add
- * @param {Date} date The JavaScript Date object to perform addition on
- * @param {String} field The field constant to be used for performing addition.
- * @param {Number} amount The number of units (measured in the field constant) to add to the date.
- * @return {Date} The resulting Date object
- */
- add : function(date, field, amount) {
- var d = new Date(date.getTime());
- switch (field) {
- case this.MONTH:
- var newMonth = date.getMonth() + amount;
- var years = 0;
- if (newMonth < 0) {
- while (newMonth < 0) {
- newMonth += 12;
- years -= 1;
- }
- } else if (newMonth > 11) {
- while (newMonth > 11) {
- newMonth -= 12;
- years += 1;
- }
- }
- d.setMonth(newMonth);
- d.setFullYear(date.getFullYear() + years);
- break;
- case this.DAY:
- this._addDays(d, amount);
- // d.setDate(date.getDate() + amount);
- break;
- case this.YEAR:
- d.setFullYear(date.getFullYear() + amount);
- break;
- case this.WEEK:
- this._addDays(d, (amount * 7));
- // d.setDate(date.getDate() + (amount * 7));
- break;
- }
- return d;
- },
- /**
- * Private helper method to account for bug in Safari 2 (webkit < 420)
- * when Date.setDate(n) is called with n less than -128 or greater than 127.
- * <p>
- * Fix approach and original findings are available here:
- * http://brianary.blogspot.com/2006/03/safari-date-bug.html
- * </p>
- * @method _addDays
- * @param {Date} d JavaScript date object
- * @param {Number} nDays The number of days to add to the date object (can be negative)
- * @private
- */
- _addDays : function(d, nDays) {
- if (YAHOO.env.ua.webkit && YAHOO.env.ua.webkit < 420) {
- if (nDays < 0) {
- // Ensure we don't go below -128 (getDate() is always 1 to 31, so we won't go above 127)
- for(var min = -128; nDays < min; nDays -= min) {
- d.setDate(d.getDate() + min);
- }
- } else {
- // Ensure we don't go above 96 + 31 = 127
- for(var max = 96; nDays > max; nDays -= max) {
- d.setDate(d.getDate() + max);
- }
- }
- // nDays should be remainder between -128 and 96
- }
- d.setDate(d.getDate() + nDays);
- },
- /**
- * Subtracts the specified amount of time from the this instance.
- * @method subtract
- * @param {Date} date The JavaScript Date object to perform subtraction on
- * @param {Number} field The this field constant to be used for performing subtraction.
- * @param {Number} amount The number of units (measured in the field constant) to subtract from the date.
- * @return {Date} The resulting Date object
- */
- subtract : function(date, field, amount) {
- return this.add(date, field, (amount*-1));
- },
- /**
- * Determines whether a given date is before another date on the calendar.
- * @method before
- * @param {Date} date The Date object to compare with the compare argument
- * @param {Date} compareTo The Date object to use for the comparison
- * @return {Boolean} true if the date occurs before the compared date; false if not.
- */
- before : function(date, compareTo) {
- var ms = compareTo.getTime();
- if (date.getTime() < ms) {
- return true;
- } else {
- return false;
- }
- },
- /**
- * Determines whether a given date is after another date on the calendar.
- * @method after
- * @param {Date} date The Date object to compare with the compare argument
- * @param {Date} compareTo The Date object to use for the comparison
- * @return {Boolean} true if the date occurs after the compared date; false if not.
- */
- after : function(date, compareTo) {
- var ms = compareTo.getTime();
- if (date.getTime() > ms) {
- return true;
- } else {
- return false;
- }
- },
- /**
- * Determines whether a given date is between two other dates on the calendar.
- * @method between
- * @param {Date} date The date to check for
- * @param {Date} dateBegin The start of the range
- * @param {Date} dateEnd The end of the range
- * @return {Boolean} true if the date occurs between the compared dates; false if not.
- */
- between : function(date, dateBegin, dateEnd) {
- if (this.after(date, dateBegin) && this.before(date, dateEnd)) {
- return true;
- } else {
- return false;
- }
- },
-
- /**
- * Retrieves a JavaScript Date object representing January 1 of any given year.
- * @method getJan1
- * @param {Number} calendarYear The calendar year for which to retrieve January 1
- * @return {Date} January 1 of the calendar year specified.
- */
- getJan1 : function(calendarYear) {
- return this.getDate(calendarYear,0,1);
- },
- /**
- * Calculates the number of days the specified date is from January 1 of the specified calendar year.
- * Passing January 1 to this function would return an offset value of zero.
- * @method getDayOffset
- * @param {Date} date The JavaScript date for which to find the offset
- * @param {Number} calendarYear The calendar year to use for determining the offset
- * @return {Number} The number of days since January 1 of the given year
- */
- getDayOffset : function(date, calendarYear) {
- var beginYear = this.getJan1(calendarYear); // Find the start of the year. This will be in week 1.
-
- // Find the number of days the passed in date is away from the calendar year start
- var dayOffset = Math.ceil((date.getTime()-beginYear.getTime()) / this.ONE_DAY_MS);
- return dayOffset;
- },
- /**
- * Calculates the week number for the given date. Can currently support standard
- * U.S. week numbers, based on Jan 1st defining the 1st week of the year, and
- * ISO8601 week numbers, based on Jan 4th defining the 1st week of the year.
- *
- * @method getWeekNumber
- * @param {Date} date The JavaScript date for which to find the week number
- * @param {Number} firstDayOfWeek The index of the first day of the week (0 = Sun, 1 = Mon ... 6 = Sat).
- * Defaults to 0
- * @param {Number} janDate The date in the first week of January which defines week one for the year
- * Defaults to the value of YAHOO.widget.DateMath.WEEK_ONE_JAN_DATE, which is 1 (Jan 1st).
- * For the U.S, this is normally Jan 1st. ISO8601 uses Jan 4th to define the first week of the year.
- *
- * @return {Number} The number of the week containing the given date.
- */
- getWeekNumber : function(date, firstDayOfWeek, janDate) {
- // Setup Defaults
- firstDayOfWeek = firstDayOfWeek || 0;
- janDate = janDate || this.WEEK_ONE_JAN_DATE;
- var targetDate = this.clearTime(date),
- startOfWeek,
- endOfWeek;
- if (targetDate.getDay() === firstDayOfWeek) {
- startOfWeek = targetDate;
- } else {
- startOfWeek = this.getFirstDayOfWeek(targetDate, firstDayOfWeek);
- }
- var startYear = startOfWeek.getFullYear(),
- startTime = startOfWeek.getTime();
- // DST shouldn't be a problem here, math is quicker than setDate();
- endOfWeek = new Date(startOfWeek.getTime() + 6*this.ONE_DAY_MS);
- var weekNum;
- if (startYear !== endOfWeek.getFullYear() && endOfWeek.getDate() >= janDate) {
- // If years don't match, endOfWeek is in Jan. and if the
- // week has WEEK_ONE_JAN_DATE in it, it's week one by definition.
- weekNum = 1;
- } else {
- // Get the 1st day of the 1st week, and
- // find how many days away we are from it.
- var weekOne = this.clearTime(this.getDate(startYear, 0, janDate)),
- weekOneDayOne = this.getFirstDayOfWeek(weekOne, firstDayOfWeek);
- // Round days to smoothen out 1 hr DST diff
- var daysDiff = Math.round((targetDate.getTime() - weekOneDayOne.getTime())/this.ONE_DAY_MS);
- // Calc. Full Weeks
- var rem = daysDiff % 7;
- var weeksDiff = (daysDiff - rem)/7;
- weekNum = weeksDiff + 1;
- }
- return weekNum;
- },
- /**
- * Get the first day of the week, for the give date.
- * @param {Date} dt The date in the week for which the first day is required.
- * @param {Number} startOfWeek The index for the first day of the week, 0 = Sun, 1 = Mon ... 6 = Sat (defaults to 0)
- * @return {Date} The first day of the week
- */
- getFirstDayOfWeek : function (dt, startOfWeek) {
- startOfWeek = startOfWeek || 0;
- var dayOfWeekIndex = dt.getDay(),
- dayOfWeek = (dayOfWeekIndex - startOfWeek + 7) % 7;
- return this.subtract(dt, this.DAY, dayOfWeek);
- },
- /**
- * Determines if a given week overlaps two different years.
- * @method isYearOverlapWeek
- * @param {Date} weekBeginDate The JavaScript Date representing the first day of the week.
- * @return {Boolean} true if the date overlaps two different years.
- */
- isYearOverlapWeek : function(weekBeginDate) {
- var overlaps = false;
- var nextWeek = this.add(weekBeginDate, this.DAY, 6);
- if (nextWeek.getFullYear() != weekBeginDate.getFullYear()) {
- overlaps = true;
- }
- return overlaps;
- },
- /**
- * Determines if a given week overlaps two different months.
- * @method isMonthOverlapWeek
- * @param {Date} weekBeginDate The JavaScript Date representing the first day of the week.
- * @return {Boolean} true if the date overlaps two different months.
- */
- isMonthOverlapWeek : function(weekBeginDate) {
- var overlaps = false;
- var nextWeek = this.add(weekBeginDate, this.DAY, 6);
- if (nextWeek.getMonth() != weekBeginDate.getMonth()) {
- overlaps = true;
- }
- return overlaps;
- },
- /**
- * Gets the first day of a month containing a given date.
- * @method findMonthStart
- * @param {Date} date The JavaScript Date used to calculate the month start
- * @return {Date} The JavaScript Date representing the first day of the month
- */
- findMonthStart : function(date) {
- var start = this.getDate(date.getFullYear(), date.getMonth(), 1);
- return start;
- },
- /**
- * Gets the last day of a month containing a given date.
- * @method findMonthEnd
- * @param {Date} date The JavaScript Date used to calculate the month end
- * @return {Date} The JavaScript Date representing the last day of the month
- */
- findMonthEnd : function(date) {
- var start = this.findMonthStart(date);
- var nextMonth = this.add(start, this.MONTH, 1);
- var end = this.subtract(nextMonth, this.DAY, 1);
- return end;
- },
- /**
- * Clears the time fields from a given date, effectively setting the time to 12 noon.
- * @method clearTime
- * @param {Date} date The JavaScript Date for which the time fields will be cleared
- * @return {Date} The JavaScript Date cleared of all time fields
- */
- clearTime : function(date) {
- date.setHours(12,0,0,0);
- return date;
- },
- /**
- * Returns a new JavaScript Date object, representing the given year, month and date. Time fields (hr, min, sec, ms) on the new Date object
- * are set to 0. The method allows Date instances to be created with the a year less than 100. "new Date(year, month, date)" implementations
- * set the year to 19xx if a year (xx) which is less than 100 is provided.
- * <p>
- * <em>NOTE:</em>Validation on argument values is not performed. It is the caller's responsibility to ensure
- * arguments are valid as per the ECMAScript-262 Date object specification for the new Date(year, month[, date]) constructor.
- * </p>
- * @method getDate
- * @param {Number} y Year.
- * @param {Number} m Month index from 0 (Jan) to 11 (Dec).
- * @param {Number} d (optional) Date from 1 to 31. If not provided, defaults to 1.
- * @return {Date} The JavaScript date object with year, month, date set as provided.
- */
- getDate : function(y, m, d) {
- var dt = null;
- if (YAHOO.lang.isUndefined(d)) {
- d = 1;
- }
- if (y >= 100) {
- dt = new Date(y, m, d);
- } else {
- dt = new Date();
- dt.setFullYear(y);
- dt.setMonth(m);
- dt.setDate(d);
- dt.setHours(0,0,0,0);
- }
- return dt;
- }
- };
- /**
- * The Calendar component is a UI control that enables users to choose one or more dates from a graphical calendar presented in a one-month or
- * multi-month interface. Calendars are generated entirely via script and can be navigated without any page refreshes.
- * @module calendar
- * @title Calendar
- * @namespace YAHOO.widget
- * @requires yahoo,dom,event
- */
- (function(){
- var Dom = YAHOO.util.Dom,
- Event = YAHOO.util.Event,
- Lang = YAHOO.lang,
- DateMath = YAHOO.widget.DateMath;
- /**
- * Calendar is the base class for the Calendar widget. In its most basic
- * implementation, it has the ability to render a calendar widget on the page
- * that can be manipulated to select a single date, move back and forth between
- * months and years.
- * <p>To construct the placeholder for the calendar widget, the code is as
- * follows:
- * <xmp>
- * <div id="calContainer"></div>
- * </xmp>
- * </p>
- * <p>
- * <strong>NOTE: As of 2.4.0, the constructor's ID argument is optional.</strong>
- * The Calendar can be constructed by simply providing a container ID string,
- * or a reference to a container DIV HTMLElement (the element needs to exist
- * in the document).
- *
- * E.g.:
- * <xmp>
- * var c = new YAHOO.widget.Calendar("calContainer", configOptions);
- * </xmp>
- * or:
- * <xmp>
- * var containerDiv = YAHOO.util.Dom.get("calContainer");
- * var c = new YAHOO.widget.Calendar(containerDiv, configOptions);
- * </xmp>
- * </p>
- * <p>
- * If not provided, the ID will be generated from the container DIV ID by adding an "_t" suffix.
- * For example if an ID is not provided, and the container's ID is "calContainer", the Calendar's ID will be set to "calContainer_t".
- * </p>
- *
- * @namespace YAHOO.widget
- * @class Calendar
- * @constructor
- * @param {String} id optional The id of the table element that will represent the Calendar widget. As of 2.4.0, this argument is optional.
- * @param {String | HTMLElement} container The id of the container div element that will wrap the Calendar table, or a reference to a DIV element which exists in the document.
- * @param {Object} config optional The configuration object containing the initial configuration values for the Calendar.
- */
- function Calendar(id, containerId, config) {
- this.init.apply(this, arguments);
- }
- /**
- * The path to be used for images loaded for the Calendar
- * @property YAHOO.widget.Calendar.IMG_ROOT
- * @static
- * @deprecated You can now customize images by overriding the calclose, calnavleft and calnavright default CSS classes for the close icon, left arrow and right arrow respectively
- * @type String
- */
- Calendar.IMG_ROOT = null;
- /**
- * Type constant used for renderers to represent an individual date (M/D/Y)
- * @property YAHOO.widget.Calendar.DATE
- * @static
- * @final
- * @type String
- */
- Calendar.DATE = "D";
- /**
- * Type constant used for renderers to represent an individual date across any year (M/D)
- * @property YAHOO.widget.Calendar.MONTH_DAY
- * @static
- * @final
- * @type String
- */
- Calendar.MONTH_DAY = "MD";
- /**
- * Type constant used for renderers to represent a weekday
- * @property YAHOO.widget.Calendar.WEEKDAY
- * @static
- * @final
- * @type String
- */
- Calendar.WEEKDAY = "WD";
- /**
- * Type constant used for renderers to represent a range of individual dates (M/D/Y-M/D/Y)
- * @property YAHOO.widget.Calendar.RANGE
- * @static
- * @final
- * @type String
- */
- Calendar.RANGE = "R";
- /**
- * Type constant used for renderers to represent a month across any year
- * @property YAHOO.widget.Calendar.MONTH
- * @static
- * @final
- * @type String
- */
- Calendar.MONTH = "M";
- /**
- * Constant that represents the total number of date cells that are displayed in a given month
- * @property YAHOO.widget.Calendar.DISPLAY_DAYS
- * @static
- * @final
- * @type Number
- */
- Calendar.DISPLAY_DAYS = 42;
- /**
- * Constant used for halting the execution of the remainder of the render stack
- * @property YAHOO.widget.Calendar.STOP_RENDER
- * @static
- * @final
- * @type String
- */
- Calendar.STOP_RENDER = "S";
- /**
- * Constant used to represent short date field string formats (e.g. Tu or Feb)
- * @property YAHOO.widget.Calendar.SHORT
- * @static
- * @final
- * @type String
- */
- Calendar.SHORT = "short";
- /**
- * Constant used to represent long date field string formats (e.g. Monday or February)
- * @property YAHOO.widget.Calendar.LONG
- * @static
- * @final
- * @type String
- */
- Calendar.LONG = "long";
- /**
- * Constant used to represent medium date field string formats (e.g. Mon)
- * @property YAHOO.widget.Calendar.MEDIUM
- * @static
- * @final
- * @type String
- */
- Calendar.MEDIUM = "medium";
- /**
- * Constant used to represent single character date field string formats (e.g. M, T, W)
- * @property YAHOO.widget.Calendar.ONE_CHAR
- * @static
- * @final
- * @type String
- */
- Calendar.ONE_CHAR = "1char";
- /**
- * The set of default Config property keys and values for the Calendar
- * @property YAHOO.widget.Calendar._DEFAULT_CONFIG
- * @final
- * @static
- * @private
- * @type Object
- */
- Calendar._DEFAULT_CONFIG = {
- // Default values for pagedate and selected are not class level constants - they are set during instance creation
- PAGEDATE : {key:"pagedate", value:null},
- SELECTED : {key:"selected", value:null},
- TITLE : {key:"title", value:""},
- CLOSE : {key:"close", value:false},
- IFRAME : {key:"iframe", value:(YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 6) ? true : false},
- MINDATE : {key:"mindate", value:null},
- MAXDATE : {key:"maxdate", value:null},
- MULTI_SELECT : {key:"multi_select", value:false},
- START_WEEKDAY : {key:"start_weekday", value:0},
- SHOW_WEEKDAYS : {key:"show_weekdays", value:true},
- SHOW_WEEK_HEADER : {key:"show_week_header", value:false},
- SHOW_WEEK_FOOTER : {key:"show_week_footer", value:false},
- HIDE_BLANK_WEEKS : {key:"hide_blank_weeks", value:false},
- NAV_ARROW_LEFT: {key:"nav_arrow_left", value:null} ,
- NAV_ARROW_RIGHT : {key:"nav_arrow_right", value:null} ,
- MONTHS_SHORT : {key:"months_short", value:["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]},
- MONTHS_LONG: {key:"months_long", value:["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]},
- WEEKDAYS_1CHAR: {key:"weekdays_1char", value:["S", "M", "T", "W", "T", "F", "S"]},
- WEEKDAYS_SHORT: {key:"weekdays_short", value:["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]},
- WEEKDAYS_MEDIUM: {key:"weekdays_medium", value:["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]},
- WEEKDAYS_LONG: {key:"weekdays_long", value:["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]},
- LOCALE_MONTHS:{key:"locale_months", value:"long"},
- LOCALE_WEEKDAYS:{key:"locale_weekdays", value:"short"},
- DATE_DELIMITER:{key:"date_delimiter", value:","},
- DATE_FIELD_DELIMITER:{key:"date_field_delimiter", value:"/"},
- DATE_RANGE_DELIMITER:{key:"date_range_delimiter", value:"-"},
- MY_MONTH_POSITION:{key:"my_month_position", value:1},
- MY_YEAR_POSITION:{key:"my_year_position", value:2},
- MD_MONTH_POSITION:{key:"md_month_position", value:1},
- MD_DAY_POSITION:{key:"md_day_position", value:2},
- MDY_MONTH_POSITION:{key:"mdy_month_position", value:1},
- MDY_DAY_POSITION:{key:"mdy_day_position", value:2},
- MDY_YEAR_POSITION:{key:"mdy_year_position", value:3},
- MY_LABEL_MONTH_POSITION:{key:"my_label_month_position", value:1},
- MY_LABEL_YEAR_POSITION:{key:"my_label_year_position", value:2},
- MY_LABEL_MONTH_SUFFIX:{key:"my_label_month_suffix", value:" "},
- MY_LABEL_YEAR_SUFFIX:{key:"my_label_year_suffix", value:""},
- NAV: {key:"navigator", value: null},
- STRINGS : {
- key:"strings",
- value: {
- previousMonth : "Previous Month",
- nextMonth : "Next Month",
- close: "Close"
- },
- supercedes : ["close", "title"]
- }
- };
- var DEF_CFG = Calendar._DEFAULT_CONFIG;
- /**
- * The set of Custom Event types supported by the Calendar
- * @property YAHOO.widget.Calendar._EVENT_TYPES
- * @final
- * @static
- * @private
- * @type Object
- */
- Calendar._EVENT_TYPES = {
- BEFORE_SELECT : "beforeSelect",
- SELECT : "select",
- BEFORE_DESELECT : "beforeDeselect",
- DESELECT : "deselect",
- CHANGE_PAGE : "changePage",
- BEFORE_RENDER : "beforeRender",
- RENDER : "render",
- BEFORE_DESTROY : "beforeDestroy",
- DESTROY : "destroy",
- RESET : "reset",
- CLEAR : "clear",
- BEFORE_HIDE : "beforeHide",
- HIDE : "hide",
- BEFORE_SHOW : "beforeShow",
- SHOW : "show",
- BEFORE_HIDE_NAV : "beforeHideNav",
- HIDE_NAV : "hideNav",
- BEFORE_SHOW_NAV : "beforeShowNav",
- SHOW_NAV : "showNav",
- BEFORE_RENDER_NAV : "beforeRenderNav",
- RENDER_NAV : "renderNav"
- };
- /**
- * The set of default style constants for the Calendar
- * @property YAHOO.widget.Calendar._STYLES
- * @final
- * @static
- * @private
- * @type Object
- */
- Calendar._STYLES = {
- CSS_ROW_HEADER: "calrowhead",
- CSS_ROW_FOOTER: "calrowfoot",
- CSS_CELL : "calcell",
- CSS_CELL_SELECTOR : "selector",
- CSS_CELL_SELECTED : "selected",
- CSS_CELL_SELECTABLE : "selectable",
- CSS_CELL_RESTRICTED : "restricted",
- CSS_CELL_TODAY : "today",
- CSS_CELL_OOM : "oom",
- CSS_CELL_OOB : "previous",
- CSS_HEADER : "calheader",
- CSS_HEADER_TEXT : "calhead",
- CSS_BODY : "calbody",
- CSS_WEEKDAY_CELL : "calweekdaycell",
- CSS_WEEKDAY_ROW : "calweekdayrow",
- CSS_FOOTER : "calfoot",
- CSS_CALENDAR : "yui-calendar",
- CSS_SINGLE : "single",
- CSS_CONTAINER : "yui-calcontainer",
- CSS_NAV_LEFT : "calnavleft",
- CSS_NAV_RIGHT : "calnavright",
- CSS_NAV : "calnav",
- CSS_CLOSE : "calclose",
- CSS_CELL_TOP : "calcelltop",
- CSS_CELL_LEFT : "calcellleft",
- CSS_CELL_RIGHT : "calcellright",
- CSS_CELL_BOTTOM : "calcellbottom",
- CSS_CELL_HOVER : "calcellhover",
- CSS_CELL_HIGHLIGHT1 : "highlight1",
- CSS_CELL_HIGHLIGHT2 : "highlight2",
- CSS_CELL_HIGHLIGHT3 : "highlight3",
- CSS_CELL_HIGHLIGHT4 : "highlight4"
- };
- Calendar.prototype = {
- /**
- * The configuration object used to set up the calendars various locale and style options.
- * @property Config
- * @private
- * @deprecated Configuration properties should be set by calling Calendar.cfg.setProperty.
- * @type Object
- */
- Config : null,
- /**
- * The parent CalendarGroup, only to be set explicitly by the parent group
- * @property parent
- * @type CalendarGroup
- */
- parent : null,
- /**
- * The index of this item in the parent group
- * @property index
- * @type Number
- */
- index : -1,
- /**
- * The collection of calendar table cells
- * @property cells
- * @type HTMLTableCellElement[]
- */
- cells : null,
- /**
- * The collection of calendar cell dates that is parallel to the cells collection. The array contains dates field arrays in the format of [YYYY, M, D].
- * @property cellDates
- * @type Array[](Number[])
- */
- cellDates : null,
- /**
- * The id that uniquely identifies this Calendar.
- * @property id
- * @type String
- */
- id : null,
- /**
- * The unique id associated with the Calendar's container
- * @property containerId
- * @type String
- */
- containerId: null,
- /**
- * The DOM element reference that points to this calendar's container element. The calendar will be inserted into this element when the shell is rendered.
- * @property oDomContainer
- * @type HTMLElement
- */
- oDomContainer : null,
- /**
- * A Date object representing today's date.
- * @property today
- * @type Date
- */
- today : null,
- /**
- * The list of render functions, along with required parameters, used to render cells.
- * @property renderStack
- * @type Array[]
- */
- renderStack : null,
- /**
- * A copy of the initial render functions created before rendering.
- * @property _renderStack
- * @private
- * @type Array
- */
- _renderStack : null,
- /**
- * A reference to the CalendarNavigator instance created for this Calendar.
- * Will be null if the "navigator" configuration property has not been set
- * @property oNavigator
- * @type CalendarNavigator
- */
- oNavigator : null,
- /**
- * The private list of initially selected dates.
- * @property _selectedDates
- * @private
- * @type Array
- */
- _selectedDates : null,
- /**
- * A map of DOM event handlers to attach to cells associated with specific CSS class names
- * @property domEventMap
- * @type Object
- */
- domEventMap : null,
- /**
- * Protected helper used to parse Calendar constructor/init arguments.
- *
- * As of 2.4.0, Calendar supports a simpler constructor
- * signature. This method reconciles arguments
- * received in the pre 2.4.0 and 2.4.0 formats.
- *
- * @protected
- * @method _parseArgs
- * @param {Array} Function "arguments" array
- * @return {Object} Object with id, container, config properties containing
- * the reconciled argument values.
- **/
- _parseArgs : function(args) {
- /*
- 2.4.0 Constructors signatures
- new Calendar(String)
- new Calendar(HTMLElement)
- new Calendar(String, ConfigObject)
- new Calendar(HTMLElement, ConfigObject)
- Pre 2.4.0 Constructor signatures
- new Calendar(String, String)
- new Calendar(String, HTMLElement)
- new Calendar(String, String, ConfigObject)
- new Calendar(String, HTMLElement, ConfigObject)
- */
- var nArgs = {id:null, container:null, config:null};
- if (args && args.length && args.length > 0) {
- switch (args.length) {
- case 1:
- nArgs.id = null;
- nArgs.container = args[0];
- nArgs.config = null;
- break;
- case 2:
- if (Lang.isObject(args[1]) && !args[1].tagName && !(args[1] instanceof String)) {
- nArgs.id = null;
- nArgs.container = args[0];
- nArgs.config = args[1];
- } else {
- nArgs.id = args[0];
- nArgs.container = args[1];
- nArgs.config = null;
- }
- break;
- default: // 3+
- nArgs.id = args[0];
- nArgs.container = args[1];
- nArgs.config = args[2];
- break;
- }
- } else {
- this.logger.log("Invalid constructor/init arguments", "error");
- }
- return nArgs;
- },
- /**
- * Initializes the Calendar widget.
- * @method init
- *
- * @param {String} id optional The id of the table element that will represent the Calendar widget. As of 2.4.0, this argument is optional.
- * @param {String | HTMLElement} container The id of the container div element that will wrap the Calendar table, or a reference to a DIV element which exists in the document.
- * @param {Object} config optional The configuration object containing the initial configuration values for the Calendar.
- */
- init : function(id, container, config) {
- // Normalize 2.4.0, pre 2.4.0 args
- var nArgs = this._parseArgs(arguments);
- id = nArgs.id;
- container = nArgs.container;
- config = nArgs.config;
- this.oDomContainer = Dom.get(container);
- if (!this.oDomContainer) { this.logger.log("Container not found in document.", "error"); }
- if (!this.oDomContainer.id) {
- this.oDomContainer.id = Dom.generateId();
- }
- if (!id) {
- id = this.oDomContainer.id + "_t";
- }
- this.id = id;
- this.containerId = this.oDomContainer.id;
- this.logger = new YAHOO.widget.LogWriter("Calendar " + this.id);
- this.initEvents();
- this.today = new Date();
- DateMath.clearTime(this.today);
- /**
- * The Config object used to hold the configuration variables for the Calendar
- * @property cfg
- * @type YAHOO.util.Config
- */
- this.cfg = new YAHOO.util.Config(this);
- /**
- * The local object which contains the Calendar's options
- * @property Options
- * @type Object
- */
- this.Options = {};
- /**
- * The local object which contains the Calendar's …
Large files files are truncated, but you can click here to view the full file