/jdk-1.5-parent/yui-parent/yui/src/main/java/org/wicketstuff/yui/inc/2.5.2/calendar/calendar-debug.js

https://github.com/adben/core · JavaScript · 1610 lines · 682 code · 224 blank · 704 comment · 129 complexity · 172c588829f3b5a694be46930a71052c MD5 · raw file

  1. /*
  2. Copyright (c) 2008, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.net/yui/license.txt
  5. version: 2.5.2
  6. */
  7. (function () {
  8. /**
  9. * Config is a utility used within an Object to allow the implementer to
  10. * maintain a list of local configuration properties and listen for changes
  11. * to those properties dynamically using CustomEvent. The initial values are
  12. * also maintained so that the configuration can be reset at any given point
  13. * to its initial state.
  14. * @namespace YAHOO.util
  15. * @class Config
  16. * @constructor
  17. * @param {Object} owner The owner Object to which this Config Object belongs
  18. */
  19. YAHOO.util.Config = function (owner) {
  20. if (owner) {
  21. this.init(owner);
  22. }
  23. if (!owner) { YAHOO.log("No owner specified for Config object", "error", "Config"); }
  24. };
  25. var Lang = YAHOO.lang,
  26. CustomEvent = YAHOO.util.CustomEvent,
  27. Config = YAHOO.util.Config;
  28. /**
  29. * Constant representing the CustomEvent type for the config changed event.
  30. * @property YAHOO.util.Config.CONFIG_CHANGED_EVENT
  31. * @private
  32. * @static
  33. * @final
  34. */
  35. Config.CONFIG_CHANGED_EVENT = "configChanged";
  36. /**
  37. * Constant representing the boolean type string
  38. * @property YAHOO.util.Config.BOOLEAN_TYPE
  39. * @private
  40. * @static
  41. * @final
  42. */
  43. Config.BOOLEAN_TYPE = "boolean";
  44. Config.prototype = {
  45. /**
  46. * Object reference to the owner of this Config Object
  47. * @property owner
  48. * @type Object
  49. */
  50. owner: null,
  51. /**
  52. * Boolean flag that specifies whether a queue is currently
  53. * being executed
  54. * @property queueInProgress
  55. * @type Boolean
  56. */
  57. queueInProgress: false,
  58. /**
  59. * Maintains the local collection of configuration property objects and
  60. * their specified values
  61. * @property config
  62. * @private
  63. * @type Object
  64. */
  65. config: null,
  66. /**
  67. * Maintains the local collection of configuration property objects as
  68. * they were initially applied.
  69. * This object is used when resetting a property.
  70. * @property initialConfig
  71. * @private
  72. * @type Object
  73. */
  74. initialConfig: null,
  75. /**
  76. * Maintains the local, normalized CustomEvent queue
  77. * @property eventQueue
  78. * @private
  79. * @type Object
  80. */
  81. eventQueue: null,
  82. /**
  83. * Custom Event, notifying subscribers when Config properties are set
  84. * (setProperty is called without the silent flag
  85. * @event configChangedEvent
  86. */
  87. configChangedEvent: null,
  88. /**
  89. * Initializes the configuration Object and all of its local members.
  90. * @method init
  91. * @param {Object} owner The owner Object to which this Config
  92. * Object belongs
  93. */
  94. init: function (owner) {
  95. this.owner = owner;
  96. this.configChangedEvent =
  97. this.createEvent(Config.CONFIG_CHANGED_EVENT);
  98. this.configChangedEvent.signature = CustomEvent.LIST;
  99. this.queueInProgress = false;
  100. this.config = {};
  101. this.initialConfig = {};
  102. this.eventQueue = [];
  103. },
  104. /**
  105. * Validates that the value passed in is a Boolean.
  106. * @method checkBoolean
  107. * @param {Object} val The value to validate
  108. * @return {Boolean} true, if the value is valid
  109. */
  110. checkBoolean: function (val) {
  111. return (typeof val == Config.BOOLEAN_TYPE);
  112. },
  113. /**
  114. * Validates that the value passed in is a number.
  115. * @method checkNumber
  116. * @param {Object} val The value to validate
  117. * @return {Boolean} true, if the value is valid
  118. */
  119. checkNumber: function (val) {
  120. return (!isNaN(val));
  121. },
  122. /**
  123. * Fires a configuration property event using the specified value.
  124. * @method fireEvent
  125. * @private
  126. * @param {String} key The configuration property's name
  127. * @param {value} Object The value of the correct type for the property
  128. */
  129. fireEvent: function ( key, value ) {
  130. YAHOO.log("Firing Config event: " + key + "=" + value, "info", "Config");
  131. var property = this.config[key];
  132. if (property && property.event) {
  133. property.event.fire(value);
  134. }
  135. },
  136. /**
  137. * Adds a property to the Config Object's private config hash.
  138. * @method addProperty
  139. * @param {String} key The configuration property's name
  140. * @param {Object} propertyObject The Object containing all of this
  141. * property's arguments
  142. */
  143. addProperty: function ( key, propertyObject ) {
  144. key = key.toLowerCase();
  145. YAHOO.log("Added property: " + key, "info", "Config");
  146. this.config[key] = propertyObject;
  147. propertyObject.event = this.createEvent(key, { scope: this.owner });
  148. propertyObject.event.signature = CustomEvent.LIST;
  149. propertyObject.key = key;
  150. if (propertyObject.handler) {
  151. propertyObject.event.subscribe(propertyObject.handler,
  152. this.owner);
  153. }
  154. this.setProperty(key, propertyObject.value, true);
  155. if (! propertyObject.suppressEvent) {
  156. this.queueProperty(key, propertyObject.value);
  157. }
  158. },
  159. /**
  160. * Returns a key-value configuration map of the values currently set in
  161. * the Config Object.
  162. * @method getConfig
  163. * @return {Object} The current config, represented in a key-value map
  164. */
  165. getConfig: function () {
  166. var cfg = {},
  167. prop,
  168. property;
  169. for (prop in this.config) {
  170. property = this.config[prop];
  171. if (property && property.event) {
  172. cfg[prop] = property.value;
  173. }
  174. }
  175. return cfg;
  176. },
  177. /**
  178. * Returns the value of specified property.
  179. * @method getProperty
  180. * @param {String} key The name of the property
  181. * @return {Object} The value of the specified property
  182. */
  183. getProperty: function (key) {
  184. var property = this.config[key.toLowerCase()];
  185. if (property && property.event) {
  186. return property.value;
  187. } else {
  188. return undefined;
  189. }
  190. },
  191. /**
  192. * Resets the specified property's value to its initial value.
  193. * @method resetProperty
  194. * @param {String} key The name of the property
  195. * @return {Boolean} True is the property was reset, false if not
  196. */
  197. resetProperty: function (key) {
  198. key = key.toLowerCase();
  199. var property = this.config[key];
  200. if (property && property.event) {
  201. if (this.initialConfig[key] &&
  202. !Lang.isUndefined(this.initialConfig[key])) {
  203. this.setProperty(key, this.initialConfig[key]);
  204. return true;
  205. }
  206. } else {
  207. return false;
  208. }
  209. },
  210. /**
  211. * Sets the value of a property. If the silent property is passed as
  212. * true, the property's event will not be fired.
  213. * @method setProperty
  214. * @param {String} key The name of the property
  215. * @param {String} value The value to set the property to
  216. * @param {Boolean} silent Whether the value should be set silently,
  217. * without firing the property event.
  218. * @return {Boolean} True, if the set was successful, false if it failed.
  219. */
  220. setProperty: function (key, value, silent) {
  221. var property;
  222. key = key.toLowerCase();
  223. YAHOO.log("setProperty: " + key + "=" + value, "info", "Config");
  224. if (this.queueInProgress && ! silent) {
  225. // Currently running through a queue...
  226. this.queueProperty(key,value);
  227. return true;
  228. } else {
  229. property = this.config[key];
  230. if (property && property.event) {
  231. if (property.validator && !property.validator(value)) {
  232. return false;
  233. } else {
  234. property.value = value;
  235. if (! silent) {
  236. this.fireEvent(key, value);
  237. this.configChangedEvent.fire([key, value]);
  238. }
  239. return true;
  240. }
  241. } else {
  242. return false;
  243. }
  244. }
  245. },
  246. /**
  247. * Sets the value of a property and queues its event to execute. If the
  248. * event is already scheduled to execute, it is
  249. * moved from its current position to the end of the queue.
  250. * @method queueProperty
  251. * @param {String} key The name of the property
  252. * @param {String} value The value to set the property to
  253. * @return {Boolean} true, if the set was successful, false if
  254. * it failed.
  255. */
  256. queueProperty: function (key, value) {
  257. key = key.toLowerCase();
  258. YAHOO.log("queueProperty: " + key + "=" + value, "info", "Config");
  259. var property = this.config[key],
  260. foundDuplicate = false,
  261. iLen,
  262. queueItem,
  263. queueItemKey,
  264. queueItemValue,
  265. sLen,
  266. supercedesCheck,
  267. qLen,
  268. queueItemCheck,
  269. queueItemCheckKey,
  270. queueItemCheckValue,
  271. i,
  272. s,
  273. q;
  274. if (property && property.event) {
  275. if (!Lang.isUndefined(value) && property.validator &&
  276. !property.validator(value)) { // validator
  277. return false;
  278. } else {
  279. if (!Lang.isUndefined(value)) {
  280. property.value = value;
  281. } else {
  282. value = property.value;
  283. }
  284. foundDuplicate = false;
  285. iLen = this.eventQueue.length;
  286. for (i = 0; i < iLen; i++) {
  287. queueItem = this.eventQueue[i];
  288. if (queueItem) {
  289. queueItemKey = queueItem[0];
  290. queueItemValue = queueItem[1];
  291. if (queueItemKey == key) {
  292. /*
  293. found a dupe... push to end of queue, null
  294. current item, and break
  295. */
  296. this.eventQueue[i] = null;
  297. this.eventQueue.push(
  298. [key, (!Lang.isUndefined(value) ?
  299. value : queueItemValue)]);
  300. foundDuplicate = true;
  301. break;
  302. }
  303. }
  304. }
  305. // this is a refire, or a new property in the queue
  306. if (! foundDuplicate && !Lang.isUndefined(value)) {
  307. this.eventQueue.push([key, value]);
  308. }
  309. }
  310. if (property.supercedes) {
  311. sLen = property.supercedes.length;
  312. for (s = 0; s < sLen; s++) {
  313. supercedesCheck = property.supercedes[s];
  314. qLen = this.eventQueue.length;
  315. for (q = 0; q < qLen; q++) {
  316. queueItemCheck = this.eventQueue[q];
  317. if (queueItemCheck) {
  318. queueItemCheckKey = queueItemCheck[0];
  319. queueItemCheckValue = queueItemCheck[1];
  320. if (queueItemCheckKey ==
  321. supercedesCheck.toLowerCase() ) {
  322. this.eventQueue.push([queueItemCheckKey,
  323. queueItemCheckValue]);
  324. this.eventQueue[q] = null;
  325. break;
  326. }
  327. }
  328. }
  329. }
  330. }
  331. YAHOO.log("Config event queue: " + this.outputEventQueue(), "info", "Config");
  332. return true;
  333. } else {
  334. return false;
  335. }
  336. },
  337. /**
  338. * Fires the event for a property using the property's current value.
  339. * @method refireEvent
  340. * @param {String} key The name of the property
  341. */
  342. refireEvent: function (key) {
  343. key = key.toLowerCase();
  344. var property = this.config[key];
  345. if (property && property.event &&
  346. !Lang.isUndefined(property.value)) {
  347. if (this.queueInProgress) {
  348. this.queueProperty(key);
  349. } else {
  350. this.fireEvent(key, property.value);
  351. }
  352. }
  353. },
  354. /**
  355. * Applies a key-value Object literal to the configuration, replacing
  356. * any existing values, and queueing the property events.
  357. * Although the values will be set, fireQueue() must be called for their
  358. * associated events to execute.
  359. * @method applyConfig
  360. * @param {Object} userConfig The configuration Object literal
  361. * @param {Boolean} init When set to true, the initialConfig will
  362. * be set to the userConfig passed in, so that calling a reset will
  363. * reset the properties to the passed values.
  364. */
  365. applyConfig: function (userConfig, init) {
  366. var sKey,
  367. oConfig;
  368. if (init) {
  369. oConfig = {};
  370. for (sKey in userConfig) {
  371. if (Lang.hasOwnProperty(userConfig, sKey)) {
  372. oConfig[sKey.toLowerCase()] = userConfig[sKey];
  373. }
  374. }
  375. this.initialConfig = oConfig;
  376. }
  377. for (sKey in userConfig) {
  378. if (Lang.hasOwnProperty(userConfig, sKey)) {
  379. this.queueProperty(sKey, userConfig[sKey]);
  380. }
  381. }
  382. },
  383. /**
  384. * Refires the events for all configuration properties using their
  385. * current values.
  386. * @method refresh
  387. */
  388. refresh: function () {
  389. var prop;
  390. for (prop in this.config) {
  391. this.refireEvent(prop);
  392. }
  393. },
  394. /**
  395. * Fires the normalized list of queued property change events
  396. * @method fireQueue
  397. */
  398. fireQueue: function () {
  399. var i,
  400. queueItem,
  401. key,
  402. value,
  403. property;
  404. this.queueInProgress = true;
  405. for (i = 0;i < this.eventQueue.length; i++) {
  406. queueItem = this.eventQueue[i];
  407. if (queueItem) {
  408. key = queueItem[0];
  409. value = queueItem[1];
  410. property = this.config[key];
  411. property.value = value;
  412. this.fireEvent(key,value);
  413. }
  414. }
  415. this.queueInProgress = false;
  416. this.eventQueue = [];
  417. },
  418. /**
  419. * Subscribes an external handler to the change event for any
  420. * given property.
  421. * @method subscribeToConfigEvent
  422. * @param {String} key The property name
  423. * @param {Function} handler The handler function to use subscribe to
  424. * the property's event
  425. * @param {Object} obj The Object to use for scoping the event handler
  426. * (see CustomEvent documentation)
  427. * @param {Boolean} override Optional. If true, will override "this"
  428. * within the handler to map to the scope Object passed into the method.
  429. * @return {Boolean} True, if the subscription was successful,
  430. * otherwise false.
  431. */
  432. subscribeToConfigEvent: function (key, handler, obj, override) {
  433. var property = this.config[key.toLowerCase()];
  434. if (property && property.event) {
  435. if (!Config.alreadySubscribed(property.event, handler, obj)) {
  436. property.event.subscribe(handler, obj, override);
  437. }
  438. return true;
  439. } else {
  440. return false;
  441. }
  442. },
  443. /**
  444. * Unsubscribes an external handler from the change event for any
  445. * given property.
  446. * @method unsubscribeFromConfigEvent
  447. * @param {String} key The property name
  448. * @param {Function} handler The handler function to use subscribe to
  449. * the property's event
  450. * @param {Object} obj The Object to use for scoping the event
  451. * handler (see CustomEvent documentation)
  452. * @return {Boolean} True, if the unsubscription was successful,
  453. * otherwise false.
  454. */
  455. unsubscribeFromConfigEvent: function (key, handler, obj) {
  456. var property = this.config[key.toLowerCase()];
  457. if (property && property.event) {
  458. return property.event.unsubscribe(handler, obj);
  459. } else {
  460. return false;
  461. }
  462. },
  463. /**
  464. * Returns a string representation of the Config object
  465. * @method toString
  466. * @return {String} The Config object in string format.
  467. */
  468. toString: function () {
  469. var output = "Config";
  470. if (this.owner) {
  471. output += " [" + this.owner.toString() + "]";
  472. }
  473. return output;
  474. },
  475. /**
  476. * Returns a string representation of the Config object's current
  477. * CustomEvent queue
  478. * @method outputEventQueue
  479. * @return {String} The string list of CustomEvents currently queued
  480. * for execution
  481. */
  482. outputEventQueue: function () {
  483. var output = "",
  484. queueItem,
  485. q,
  486. nQueue = this.eventQueue.length;
  487. for (q = 0; q < nQueue; q++) {
  488. queueItem = this.eventQueue[q];
  489. if (queueItem) {
  490. output += queueItem[0] + "=" + queueItem[1] + ", ";
  491. }
  492. }
  493. return output;
  494. },
  495. /**
  496. * Sets all properties to null, unsubscribes all listeners from each
  497. * property's change event and all listeners from the configChangedEvent.
  498. * @method destroy
  499. */
  500. destroy: function () {
  501. var oConfig = this.config,
  502. sProperty,
  503. oProperty;
  504. for (sProperty in oConfig) {
  505. if (Lang.hasOwnProperty(oConfig, sProperty)) {
  506. oProperty = oConfig[sProperty];
  507. oProperty.event.unsubscribeAll();
  508. oProperty.event = null;
  509. }
  510. }
  511. this.configChangedEvent.unsubscribeAll();
  512. this.configChangedEvent = null;
  513. this.owner = null;
  514. this.config = null;
  515. this.initialConfig = null;
  516. this.eventQueue = null;
  517. }
  518. };
  519. /**
  520. * Checks to determine if a particular function/Object pair are already
  521. * subscribed to the specified CustomEvent
  522. * @method YAHOO.util.Config.alreadySubscribed
  523. * @static
  524. * @param {YAHOO.util.CustomEvent} evt The CustomEvent for which to check
  525. * the subscriptions
  526. * @param {Function} fn The function to look for in the subscribers list
  527. * @param {Object} obj The execution scope Object for the subscription
  528. * @return {Boolean} true, if the function/Object pair is already subscribed
  529. * to the CustomEvent passed in
  530. */
  531. Config.alreadySubscribed = function (evt, fn, obj) {
  532. var nSubscribers = evt.subscribers.length,
  533. subsc,
  534. i;
  535. if (nSubscribers > 0) {
  536. i = nSubscribers - 1;
  537. do {
  538. subsc = evt.subscribers[i];
  539. if (subsc && subsc.obj == obj && subsc.fn == fn) {
  540. return true;
  541. }
  542. }
  543. while (i--);
  544. }
  545. return false;
  546. };
  547. YAHOO.lang.augmentProto(Config, YAHOO.util.EventProvider);
  548. }());
  549. /**
  550. * YAHOO.widget.DateMath is used for simple date manipulation. The class is a static utility
  551. * used for adding, subtracting, and comparing dates.
  552. * @namespace YAHOO.widget
  553. * @class DateMath
  554. */
  555. YAHOO.widget.DateMath = {
  556. /**
  557. * Constant field representing Day
  558. * @property DAY
  559. * @static
  560. * @final
  561. * @type String
  562. */
  563. DAY : "D",
  564. /**
  565. * Constant field representing Week
  566. * @property WEEK
  567. * @static
  568. * @final
  569. * @type String
  570. */
  571. WEEK : "W",
  572. /**
  573. * Constant field representing Year
  574. * @property YEAR
  575. * @static
  576. * @final
  577. * @type String
  578. */
  579. YEAR : "Y",
  580. /**
  581. * Constant field representing Month
  582. * @property MONTH
  583. * @static
  584. * @final
  585. * @type String
  586. */
  587. MONTH : "M",
  588. /**
  589. * Constant field representing one day, in milliseconds
  590. * @property ONE_DAY_MS
  591. * @static
  592. * @final
  593. * @type Number
  594. */
  595. ONE_DAY_MS : 1000*60*60*24,
  596. /**
  597. * Constant field representing the date in first week of January
  598. * which identifies the first week of the year.
  599. * <p>
  600. * In the U.S, Jan 1st is normally used based on a Sunday start of week.
  601. * ISO 8601, used widely throughout Europe, uses Jan 4th, based on a Monday start of week.
  602. * </p>
  603. * @property WEEK_ONE_JAN_DATE
  604. * @static
  605. * @type Number
  606. */
  607. WEEK_ONE_JAN_DATE : 1,
  608. /**
  609. * Adds the specified amount of time to the this instance.
  610. * @method add
  611. * @param {Date} date The JavaScript Date object to perform addition on
  612. * @param {String} field The field constant to be used for performing addition.
  613. * @param {Number} amount The number of units (measured in the field constant) to add to the date.
  614. * @return {Date} The resulting Date object
  615. */
  616. add : function(date, field, amount) {
  617. var d = new Date(date.getTime());
  618. switch (field) {
  619. case this.MONTH:
  620. var newMonth = date.getMonth() + amount;
  621. var years = 0;
  622. if (newMonth < 0) {
  623. while (newMonth < 0) {
  624. newMonth += 12;
  625. years -= 1;
  626. }
  627. } else if (newMonth > 11) {
  628. while (newMonth > 11) {
  629. newMonth -= 12;
  630. years += 1;
  631. }
  632. }
  633. d.setMonth(newMonth);
  634. d.setFullYear(date.getFullYear() + years);
  635. break;
  636. case this.DAY:
  637. this._addDays(d, amount);
  638. // d.setDate(date.getDate() + amount);
  639. break;
  640. case this.YEAR:
  641. d.setFullYear(date.getFullYear() + amount);
  642. break;
  643. case this.WEEK:
  644. this._addDays(d, (amount * 7));
  645. // d.setDate(date.getDate() + (amount * 7));
  646. break;
  647. }
  648. return d;
  649. },
  650. /**
  651. * Private helper method to account for bug in Safari 2 (webkit < 420)
  652. * when Date.setDate(n) is called with n less than -128 or greater than 127.
  653. * <p>
  654. * Fix approach and original findings are available here:
  655. * http://brianary.blogspot.com/2006/03/safari-date-bug.html
  656. * </p>
  657. * @method _addDays
  658. * @param {Date} d JavaScript date object
  659. * @param {Number} nDays The number of days to add to the date object (can be negative)
  660. * @private
  661. */
  662. _addDays : function(d, nDays) {
  663. if (YAHOO.env.ua.webkit && YAHOO.env.ua.webkit < 420) {
  664. if (nDays < 0) {
  665. // Ensure we don't go below -128 (getDate() is always 1 to 31, so we won't go above 127)
  666. for(var min = -128; nDays < min; nDays -= min) {
  667. d.setDate(d.getDate() + min);
  668. }
  669. } else {
  670. // Ensure we don't go above 96 + 31 = 127
  671. for(var max = 96; nDays > max; nDays -= max) {
  672. d.setDate(d.getDate() + max);
  673. }
  674. }
  675. // nDays should be remainder between -128 and 96
  676. }
  677. d.setDate(d.getDate() + nDays);
  678. },
  679. /**
  680. * Subtracts the specified amount of time from the this instance.
  681. * @method subtract
  682. * @param {Date} date The JavaScript Date object to perform subtraction on
  683. * @param {Number} field The this field constant to be used for performing subtraction.
  684. * @param {Number} amount The number of units (measured in the field constant) to subtract from the date.
  685. * @return {Date} The resulting Date object
  686. */
  687. subtract : function(date, field, amount) {
  688. return this.add(date, field, (amount*-1));
  689. },
  690. /**
  691. * Determines whether a given date is before another date on the calendar.
  692. * @method before
  693. * @param {Date} date The Date object to compare with the compare argument
  694. * @param {Date} compareTo The Date object to use for the comparison
  695. * @return {Boolean} true if the date occurs before the compared date; false if not.
  696. */
  697. before : function(date, compareTo) {
  698. var ms = compareTo.getTime();
  699. if (date.getTime() < ms) {
  700. return true;
  701. } else {
  702. return false;
  703. }
  704. },
  705. /**
  706. * Determines whether a given date is after another date on the calendar.
  707. * @method after
  708. * @param {Date} date The Date object to compare with the compare argument
  709. * @param {Date} compareTo The Date object to use for the comparison
  710. * @return {Boolean} true if the date occurs after the compared date; false if not.
  711. */
  712. after : function(date, compareTo) {
  713. var ms = compareTo.getTime();
  714. if (date.getTime() > ms) {
  715. return true;
  716. } else {
  717. return false;
  718. }
  719. },
  720. /**
  721. * Determines whether a given date is between two other dates on the calendar.
  722. * @method between
  723. * @param {Date} date The date to check for
  724. * @param {Date} dateBegin The start of the range
  725. * @param {Date} dateEnd The end of the range
  726. * @return {Boolean} true if the date occurs between the compared dates; false if not.
  727. */
  728. between : function(date, dateBegin, dateEnd) {
  729. if (this.after(date, dateBegin) && this.before(date, dateEnd)) {
  730. return true;
  731. } else {
  732. return false;
  733. }
  734. },
  735. /**
  736. * Retrieves a JavaScript Date object representing January 1 of any given year.
  737. * @method getJan1
  738. * @param {Number} calendarYear The calendar year for which to retrieve January 1
  739. * @return {Date} January 1 of the calendar year specified.
  740. */
  741. getJan1 : function(calendarYear) {
  742. return this.getDate(calendarYear,0,1);
  743. },
  744. /**
  745. * Calculates the number of days the specified date is from January 1 of the specified calendar year.
  746. * Passing January 1 to this function would return an offset value of zero.
  747. * @method getDayOffset
  748. * @param {Date} date The JavaScript date for which to find the offset
  749. * @param {Number} calendarYear The calendar year to use for determining the offset
  750. * @return {Number} The number of days since January 1 of the given year
  751. */
  752. getDayOffset : function(date, calendarYear) {
  753. var beginYear = this.getJan1(calendarYear); // Find the start of the year. This will be in week 1.
  754. // Find the number of days the passed in date is away from the calendar year start
  755. var dayOffset = Math.ceil((date.getTime()-beginYear.getTime()) / this.ONE_DAY_MS);
  756. return dayOffset;
  757. },
  758. /**
  759. * Calculates the week number for the given date. Can currently support standard
  760. * U.S. week numbers, based on Jan 1st defining the 1st week of the year, and
  761. * ISO8601 week numbers, based on Jan 4th defining the 1st week of the year.
  762. *
  763. * @method getWeekNumber
  764. * @param {Date} date The JavaScript date for which to find the week number
  765. * @param {Number} firstDayOfWeek The index of the first day of the week (0 = Sun, 1 = Mon ... 6 = Sat).
  766. * Defaults to 0
  767. * @param {Number} janDate The date in the first week of January which defines week one for the year
  768. * Defaults to the value of YAHOO.widget.DateMath.WEEK_ONE_JAN_DATE, which is 1 (Jan 1st).
  769. * For the U.S, this is normally Jan 1st. ISO8601 uses Jan 4th to define the first week of the year.
  770. *
  771. * @return {Number} The number of the week containing the given date.
  772. */
  773. getWeekNumber : function(date, firstDayOfWeek, janDate) {
  774. // Setup Defaults
  775. firstDayOfWeek = firstDayOfWeek || 0;
  776. janDate = janDate || this.WEEK_ONE_JAN_DATE;
  777. var targetDate = this.clearTime(date),
  778. startOfWeek,
  779. endOfWeek;
  780. if (targetDate.getDay() === firstDayOfWeek) {
  781. startOfWeek = targetDate;
  782. } else {
  783. startOfWeek = this.getFirstDayOfWeek(targetDate, firstDayOfWeek);
  784. }
  785. var startYear = startOfWeek.getFullYear(),
  786. startTime = startOfWeek.getTime();
  787. // DST shouldn't be a problem here, math is quicker than setDate();
  788. endOfWeek = new Date(startOfWeek.getTime() + 6*this.ONE_DAY_MS);
  789. var weekNum;
  790. if (startYear !== endOfWeek.getFullYear() && endOfWeek.getDate() >= janDate) {
  791. // If years don't match, endOfWeek is in Jan. and if the
  792. // week has WEEK_ONE_JAN_DATE in it, it's week one by definition.
  793. weekNum = 1;
  794. } else {
  795. // Get the 1st day of the 1st week, and
  796. // find how many days away we are from it.
  797. var weekOne = this.clearTime(this.getDate(startYear, 0, janDate)),
  798. weekOneDayOne = this.getFirstDayOfWeek(weekOne, firstDayOfWeek);
  799. // Round days to smoothen out 1 hr DST diff
  800. var daysDiff = Math.round((targetDate.getTime() - weekOneDayOne.getTime())/this.ONE_DAY_MS);
  801. // Calc. Full Weeks
  802. var rem = daysDiff % 7;
  803. var weeksDiff = (daysDiff - rem)/7;
  804. weekNum = weeksDiff + 1;
  805. }
  806. return weekNum;
  807. },
  808. /**
  809. * Get the first day of the week, for the give date.
  810. * @param {Date} dt The date in the week for which the first day is required.
  811. * @param {Number} startOfWeek The index for the first day of the week, 0 = Sun, 1 = Mon ... 6 = Sat (defaults to 0)
  812. * @return {Date} The first day of the week
  813. */
  814. getFirstDayOfWeek : function (dt, startOfWeek) {
  815. startOfWeek = startOfWeek || 0;
  816. var dayOfWeekIndex = dt.getDay(),
  817. dayOfWeek = (dayOfWeekIndex - startOfWeek + 7) % 7;
  818. return this.subtract(dt, this.DAY, dayOfWeek);
  819. },
  820. /**
  821. * Determines if a given week overlaps two different years.
  822. * @method isYearOverlapWeek
  823. * @param {Date} weekBeginDate The JavaScript Date representing the first day of the week.
  824. * @return {Boolean} true if the date overlaps two different years.
  825. */
  826. isYearOverlapWeek : function(weekBeginDate) {
  827. var overlaps = false;
  828. var nextWeek = this.add(weekBeginDate, this.DAY, 6);
  829. if (nextWeek.getFullYear() != weekBeginDate.getFullYear()) {
  830. overlaps = true;
  831. }
  832. return overlaps;
  833. },
  834. /**
  835. * Determines if a given week overlaps two different months.
  836. * @method isMonthOverlapWeek
  837. * @param {Date} weekBeginDate The JavaScript Date representing the first day of the week.
  838. * @return {Boolean} true if the date overlaps two different months.
  839. */
  840. isMonthOverlapWeek : function(weekBeginDate) {
  841. var overlaps = false;
  842. var nextWeek = this.add(weekBeginDate, this.DAY, 6);
  843. if (nextWeek.getMonth() != weekBeginDate.getMonth()) {
  844. overlaps = true;
  845. }
  846. return overlaps;
  847. },
  848. /**
  849. * Gets the first day of a month containing a given date.
  850. * @method findMonthStart
  851. * @param {Date} date The JavaScript Date used to calculate the month start
  852. * @return {Date} The JavaScript Date representing the first day of the month
  853. */
  854. findMonthStart : function(date) {
  855. var start = this.getDate(date.getFullYear(), date.getMonth(), 1);
  856. return start;
  857. },
  858. /**
  859. * Gets the last day of a month containing a given date.
  860. * @method findMonthEnd
  861. * @param {Date} date The JavaScript Date used to calculate the month end
  862. * @return {Date} The JavaScript Date representing the last day of the month
  863. */
  864. findMonthEnd : function(date) {
  865. var start = this.findMonthStart(date);
  866. var nextMonth = this.add(start, this.MONTH, 1);
  867. var end = this.subtract(nextMonth, this.DAY, 1);
  868. return end;
  869. },
  870. /**
  871. * Clears the time fields from a given date, effectively setting the time to 12 noon.
  872. * @method clearTime
  873. * @param {Date} date The JavaScript Date for which the time fields will be cleared
  874. * @return {Date} The JavaScript Date cleared of all time fields
  875. */
  876. clearTime : function(date) {
  877. date.setHours(12,0,0,0);
  878. return date;
  879. },
  880. /**
  881. * Returns a new JavaScript Date object, representing the given year, month and date. Time fields (hr, min, sec, ms) on the new Date object
  882. * 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
  883. * set the year to 19xx if a year (xx) which is less than 100 is provided.
  884. * <p>
  885. * <em>NOTE:</em>Validation on argument values is not performed. It is the caller's responsibility to ensure
  886. * arguments are valid as per the ECMAScript-262 Date object specification for the new Date(year, month[, date]) constructor.
  887. * </p>
  888. * @method getDate
  889. * @param {Number} y Year.
  890. * @param {Number} m Month index from 0 (Jan) to 11 (Dec).
  891. * @param {Number} d (optional) Date from 1 to 31. If not provided, defaults to 1.
  892. * @return {Date} The JavaScript date object with year, month, date set as provided.
  893. */
  894. getDate : function(y, m, d) {
  895. var dt = null;
  896. if (YAHOO.lang.isUndefined(d)) {
  897. d = 1;
  898. }
  899. if (y >= 100) {
  900. dt = new Date(y, m, d);
  901. } else {
  902. dt = new Date();
  903. dt.setFullYear(y);
  904. dt.setMonth(m);
  905. dt.setDate(d);
  906. dt.setHours(0,0,0,0);
  907. }
  908. return dt;
  909. }
  910. };
  911. /**
  912. * 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
  913. * multi-month interface. Calendars are generated entirely via script and can be navigated without any page refreshes.
  914. * @module calendar
  915. * @title Calendar
  916. * @namespace YAHOO.widget
  917. * @requires yahoo,dom,event
  918. */
  919. /**
  920. * Calendar is the base class for the Calendar widget. In its most basic
  921. * implementation, it has the ability to render a calendar widget on the page
  922. * that can be manipulated to select a single date, move back and forth between
  923. * months and years.
  924. * <p>To construct the placeholder for the calendar widget, the code is as
  925. * follows:
  926. * <xmp>
  927. * <div id="calContainer"></div>
  928. * </xmp>
  929. * </p>
  930. * <p>
  931. * <strong>NOTE: As of 2.4.0, the constructor's ID argument is optional.</strong>
  932. * The Calendar can be constructed by simply providing a container ID string,
  933. * or a reference to a container DIV HTMLElement (the element needs to exist
  934. * in the document).
  935. *
  936. * E.g.:
  937. * <xmp>
  938. * var c = new YAHOO.widget.Calendar("calContainer", configOptions);
  939. * </xmp>
  940. * or:
  941. * <xmp>
  942. * var containerDiv = YAHOO.util.Dom.get("calContainer");
  943. * var c = new YAHOO.widget.Calendar(containerDiv, configOptions);
  944. * </xmp>
  945. * </p>
  946. * <p>
  947. * If not provided, the ID will be generated from the container DIV ID by adding an "_t" suffix.
  948. * 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".
  949. * </p>
  950. *
  951. * @namespace YAHOO.widget
  952. * @class Calendar
  953. * @constructor
  954. * @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.
  955. * @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.
  956. * @param {Object} config optional The configuration object containing the initial configuration values for the Calendar.
  957. */
  958. YAHOO.widget.Calendar = function(id, containerId, config) {
  959. this.init.apply(this, arguments);
  960. };
  961. /**
  962. * The path to be used for images loaded for the Calendar
  963. * @property YAHOO.widget.Calendar.IMG_ROOT
  964. * @static
  965. * @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
  966. * @type String
  967. */
  968. YAHOO.widget.Calendar.IMG_ROOT = null;
  969. /**
  970. * Type constant used for renderers to represent an individual date (M/D/Y)
  971. * @property YAHOO.widget.Calendar.DATE
  972. * @static
  973. * @final
  974. * @type String
  975. */
  976. YAHOO.widget.Calendar.DATE = "D";
  977. /**
  978. * Type constant used for renderers to represent an individual date across any year (M/D)
  979. * @property YAHOO.widget.Calendar.MONTH_DAY
  980. * @static
  981. * @final
  982. * @type String
  983. */
  984. YAHOO.widget.Calendar.MONTH_DAY = "MD";
  985. /**
  986. * Type constant used for renderers to represent a weekday
  987. * @property YAHOO.widget.Calendar.WEEKDAY
  988. * @static
  989. * @final
  990. * @type String
  991. */
  992. YAHOO.widget.Calendar.WEEKDAY = "WD";
  993. /**
  994. * Type constant used for renderers to represent a range of individual dates (M/D/Y-M/D/Y)
  995. * @property YAHOO.widget.Calendar.RANGE
  996. * @static
  997. * @final
  998. * @type String
  999. */
  1000. YAHOO.widget.Calendar.RANGE = "R";
  1001. /**
  1002. * Type constant used for renderers to represent a month across any year
  1003. * @property YAHOO.widget.Calendar.MONTH
  1004. * @static
  1005. * @final
  1006. * @type String
  1007. */
  1008. YAHOO.widget.Calendar.MONTH = "M";
  1009. /**
  1010. * Constant that represents the total number of date cells that are displayed in a given month
  1011. * @property YAHOO.widget.Calendar.DISPLAY_DAYS
  1012. * @static
  1013. * @final
  1014. * @type Number
  1015. */
  1016. YAHOO.widget.Calendar.DISPLAY_DAYS = 42;
  1017. /**
  1018. * Constant used for halting the execution of the remainder of the render stack
  1019. * @property YAHOO.widget.Calendar.STOP_RENDER
  1020. * @static
  1021. * @final
  1022. * @type String
  1023. */
  1024. YAHOO.widget.Calendar.STOP_RENDER = "S";
  1025. /**
  1026. * Constant used to represent short date field string formats (e.g. Tu or Feb)
  1027. * @property YAHOO.widget.Calendar.SHORT
  1028. * @static
  1029. * @final
  1030. * @type String
  1031. */
  1032. YAHOO.widget.Calendar.SHORT = "short";
  1033. /**
  1034. * Constant used to represent long date field string formats (e.g. Monday or February)
  1035. * @property YAHOO.widget.Calendar.LONG
  1036. * @static
  1037. * @final
  1038. * @type String
  1039. */
  1040. YAHOO.widget.Calendar.LONG = "long";
  1041. /**
  1042. * Constant used to represent medium date field string formats (e.g. Mon)
  1043. * @property YAHOO.widget.Calendar.MEDIUM
  1044. * @static
  1045. * @final
  1046. * @type String
  1047. */
  1048. YAHOO.widget.Calendar.MEDIUM = "medium";
  1049. /**
  1050. * Constant used to represent single character date field string formats (e.g. M, T, W)
  1051. * @property YAHOO.widget.Calendar.ONE_CHAR
  1052. * @static
  1053. * @final
  1054. * @type String
  1055. */
  1056. YAHOO.widget.Calendar.ONE_CHAR = "1char";
  1057. /**
  1058. * The set of default Config property keys and values for the Calendar
  1059. * @property YAHOO.widget.Calendar._DEFAULT_CONFIG
  1060. * @final
  1061. * @static
  1062. * @private
  1063. * @type Object
  1064. */
  1065. YAHOO.widget.Calendar._DEFAULT_CONFIG = {
  1066. // Default values for pagedate and selected are not class level constants - they are set during instance creation
  1067. PAGEDATE : {key:"pagedate", value:null},
  1068. SELECTED : {key:"selected", value:null},
  1069. TITLE : {key:"title", value:""},
  1070. CLOSE : {key:"close", value:false},
  1071. IFRAME : {key:"iframe", value:(YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 6) ? true : false},
  1072. MINDATE : {key:"mindate", value:null},
  1073. MAXDATE : {key:"maxdate", value:null},
  1074. MULTI_SELECT : {key:"multi_select", value:false},
  1075. START_WEEKDAY : {key:"start_weekday", value:0},
  1076. SHOW_WEEKDAYS : {key:"show_weekdays", value:true},
  1077. SHOW_WEEK_HEADER : {key:"show_week_header", value:false},
  1078. SHOW_WEEK_FOOTER : {key:"show_week_footer", value:false},
  1079. HIDE_BLANK_WEEKS : {key:"hide_blank_weeks", value:false},
  1080. NAV_ARROW_LEFT: {key:"nav_arrow_left", value:null} ,
  1081. NAV_ARROW_RIGHT : {key:"nav_arrow_right", value:null} ,
  1082. MONTHS_SHORT : {key:"months_short", value:["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]},
  1083. MONTHS_LONG: {key:"months_long", value:["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]},
  1084. WEEKDAYS_1CHAR: {key:"weekdays_1char", value:["S", "M", "T", "W", "T", "F", "S"]},
  1085. WEEKDAYS_SHORT: {key:"weekdays_short", value:["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]},
  1086. WEEKDAYS_MEDIUM: {key:"weekdays_medium", value:["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]},
  1087. WEEKDAYS_LONG: {key:"weekdays_long", value:["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]},
  1088. LOCALE_MONTHS:{key:"locale_months", value:"long"},
  1089. LOCALE_WEEKDAYS:{key:"locale_weekdays", value:"short"},
  1090. DATE_DELIMITER:{key:"date_delimiter", value:","},
  1091. DATE_FIELD_DELIMITER:{key:"date_field_delimiter", value:"/"},
  1092. DATE_RANGE_DELIMITER:{key:"date_range_delimiter", value:"-"},
  1093. MY_MONTH_POSITION:{key:"my_month_position", value:1},
  1094. MY_YEAR_POSITION:{key:"my_year_position", value:2},
  1095. MD_MONTH_POSITION:{key:"md_month_position", value:1},
  1096. MD_DAY_POSITION:{key:"md_day_position", value:2},
  1097. MDY_MONTH_POSITION:{key:"mdy_month_position", value:1},
  1098. MDY_DAY_POSITION:{key:"mdy_day_position", value:2},
  1099. MDY_YEAR_POSITION:{key:"mdy_year_position", value:3},
  1100. MY_LABEL_MONTH_POSITION:{key:"my_label_month_position", value:1},
  1101. MY_LABEL_YEAR_POSITION:{key:"my_label_year_position", value:2},
  1102. MY_LABEL_MONTH_SUFFIX:{key:"my_label_month_suffix", value:" "},
  1103. MY_LABEL_YEAR_SUFFIX:{key:"my_label_year_suffix", value:""},
  1104. NAV: {key:"navigator", value: null}
  1105. };
  1106. /**
  1107. * The set of Custom Event types supported by the Calendar
  1108. * @property YAHOO.widget.Calendar._EVENT_TYPES
  1109. * @final
  1110. * @static
  1111. * @private
  1112. * @type Object
  1113. */
  1114. YAHOO.widget.Calendar._EVENT_TYPES = {
  1115. BEFORE_SELECT : "beforeSelect",
  1116. SELECT : "select",
  1117. BEFORE_DESELECT : "beforeDeselect",
  1118. DESELECT : "deselect",
  1119. CHANGE_PAGE : "changePage",
  1120. BEFORE_RENDER : "beforeRender",
  1121. RENDER : "render",
  1122. RESET : "reset",
  1123. CLEAR : "clear",
  1124. BEFORE_HIDE : "beforeHide",
  1125. HIDE : "hide",
  1126. BEFORE_SHOW : "beforeShow",
  1127. SHOW : "show",
  1128. BEFORE_HIDE_NAV : "beforeHideNav",
  1129. HIDE_NAV : "hideNav",
  1130. BEFORE_SHOW_NAV : "beforeShowNav",
  1131. SHOW_NAV : "showNav",
  1132. BEFORE_RENDER_NAV : "beforeRenderNav",
  1133. RENDER_NAV : "renderNav"
  1134. };
  1135. /**
  1136. * The set of default style constants for the Calendar
  1137. * @property YAHOO.widget.Calendar._STYLES
  1138. * @final
  1139. * @static
  1140. * @private
  1141. * @type Object
  1142. */
  1143. YAHOO.widget.Calendar._STYLES = {
  1144. CSS_ROW_HEADER: "calrowhead",
  1145. CSS_ROW_FOOTER: "calrowfoot",
  1146. CSS_CELL : "calcell",
  1147. CSS_CELL_SELECTOR : "selector",
  1148. CSS_CELL_SELECTED : "selected",
  1149. CSS_CELL_SELECTABLE : "selectable",
  1150. CSS_CELL_RESTRICTED : "restricted",
  1151. CSS_CELL_TODAY : "today",
  1152. CSS_CELL_OOM : "oom",
  1153. CSS_CELL_OOB : "previous",
  1154. CSS_HEADER : "calheader",
  1155. CSS_HEADER_TEXT : "calhead",
  1156. CSS_BODY : "calbody",
  1157. CSS_WEEKDAY_CELL : "calweekdaycell",
  1158. CSS_WEEKDAY_ROW : "calweekdayrow",
  1159. CSS_FOOTER : "calfoot",
  1160. CSS_CALENDAR : "yui-calendar",
  1161. CSS_SINGLE : "single",
  1162. CSS_CONTAINER : "yui-calcontainer",
  1163. CSS_NAV_LEFT : "calnavleft",
  1164. CSS_NAV_RIGHT : "calnavright",
  1165. CSS_NAV : "calnav",
  1166. CSS_CLOSE : "calclose",
  1167. CSS_CELL_TOP : "calcelltop",
  1168. CSS_CELL_LEFT : "calcellleft",
  1169. CSS_CELL_RIGHT : "calcellright",
  1170. CSS_CELL_BOTTOM : "calcellbottom",
  1171. CSS_CELL_HOVER : "calcellhover",
  1172. CSS_CELL_HIGHLIGHT1 : "highlight1",
  1173. CSS_CELL_HIGHLIGHT2 : "highlight2",
  1174. CSS_CELL_HIGHLIGHT3 : "highlight3",
  1175. CSS_CELL_HIGHLIGHT4 : "highlight4"
  1176. };
  1177. YAHOO.widget.Calendar.prototype = {
  1178. /**
  1179. * The configuration object used to set up the calendars various locale and style options.
  1180. * @property Config
  1181. * @private
  1182. * @deprecated Configuration properties should be set by calling Calendar.cfg.setProperty.
  1183. * @type Object
  1184. */
  1185. Config : null,
  1186. /**
  1187. * The parent CalendarGroup, only to be set explicitly by the parent group
  1188. * @property parent
  1189. * @type CalendarGroup
  1190. */
  1191. parent : null,
  1192. /**
  1193. * The index of this item in the parent group
  1194. * @property index
  1195. * @type Number
  1196. */
  1197. index : -1,
  1198. /**
  1199. * The collection of calendar table cells
  1200. * @property cells
  1201. * @type HTMLTableCellElement[]
  1202. */
  1203. cells : null,
  1204. /**
  1205. * 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].
  1206. * @property cellDates
  1207. * @type Array[](Number[])
  1208. */
  1209. cellDates : null,
  1210. /**
  1211. * The id that uniquely identifies this Calendar.
  1212. * @property id
  1213. * @type String
  1214. */
  1215. id : null,
  1216. /**
  1217. * The unique id associated with the Calendar's container
  1218. * @property containerId
  1219. * @type String
  1220. */
  1221. containerId: null,
  1222. /**
  1223. * 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.
  1224. * @property oDomContainer
  1225. * @type HTMLElement
  1226. */
  1227. oDomContainer : null,
  1228. /**
  1229. * A Date object representing today's date.
  1230. * @property today
  1231. * @type Date
  1232. */
  1233. today : null,
  1234. /**
  1235. * The list of render functions, along with required parameters, used to render cells.
  1236. * @property renderStack
  1237. * @type Array[]
  1238. */
  1239. renderStack : null,
  1240. /**
  1241. * A copy of the initial render functions created before rendering.
  1242. * @property _renderStack
  1243. * @private
  1244. * @type Array
  1245. */
  1246. _renderStack : null,
  1247. /**
  1248. * A reference to the CalendarNavigator instance created for this Calendar.
  1249. * Will be null if the "navigator" configuration property has not been set
  1250. * @property oNavigator
  1251. * @type CalendarNavigator
  1252. */
  1253. oNavigator : null,
  1254. /**
  1255. * The private list of initially selected dates.
  1256. * @property _selectedDates
  1257. * @private
  1258. * @type Array
  1259. */
  1260. _selectedDates : null,
  1261. /**
  1262. * A map of DOM event handlers to attach to cells associated with specific CSS class names
  1263. * @property domEventMap
  1264. * @type Object
  1265. */
  1266. domEventMap : null,
  1267. /**
  1268. * Protected helper used to parse Calendar constructor/init arguments.
  1269. *
  1270. * As of 2.4.0, Calendar supports a simpler constructor
  1271. * signature. This method reconciles arguments
  1272. * received in the pre 2.4.0 and 2.4.0 formats.
  1273. *
  1274. * @protected
  1275. * @method _parseArgs
  1276. * @param {Array} Function "arguments" array
  1277. * @return {Object} Object with id, container, config properties containing
  1278. * the reconciled argument values.
  1279. **/
  1280. _parseArgs : function(args) {
  1281. /*
  1282. 2.4.0 Constructors signatures
  1283. new Calendar(String)
  1284. new Calendar(HTMLElement)
  1285. new Calendar(String, ConfigObject)
  1286. new Calendar(HTMLElement, ConfigObject)
  1287. Pre 2.4.0 Constructor signatures
  1288. new Calendar(String, String)
  1289. new Calendar(String, HTMLElement)
  1290. new Calendar(String, String, ConfigObject)
  1291. new Calendar(String, HTMLElement, ConfigObject)
  1292. */
  1293. var nArgs = {id:null, container:null, config:null};
  1294. if (args && args.length && args.length > 0) {
  1295. switch (args.length) {
  1296. case 1:
  1297. nArgs.id = null;
  1298. nArgs.container = args[0];
  1299. nArgs.config = null;
  1300. break;
  1301. case 2:
  1302. if (YAHOO.lang.isObject(args[1]) && !args[1].tagName && !(args[1] instanceof String)) {
  1303. nArgs.id = null;
  1304. nArgs.container = args[0];
  1305. nArgs.config = args[1];
  1306. } else {
  1307. nArgs.id = args[0];
  1308. nArgs.container = args[1];
  1309. nArgs.config = null;
  1310. }
  1311. break;
  1312. default: // 3+
  1313. nArgs.id = args[0];
  1314. nArgs.container = args[1];
  1315. nArgs.config = args[2];
  1316. break;
  1317. }
  1318. } else {
  1319. this.logger.log("Invalid constructor/init arguments", "error");
  1320. }
  1321. return nArgs;
  1322. },
  1323. /**
  1324. * Initializes the Calendar widget.
  1325. * @method init
  1326. *
  1327. * @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.
  1328. * @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.
  1329. * @param {Object} config optional The configuration object containing the initial configuration values for the Calendar.
  1330. */
  1331. init : function(id, container, config) {
  1332. // Normalize 2.4.0, pre 2.4.0 args
  1333. var nArgs = this._parseArgs(arguments);
  1334. id = nArgs.id;
  1335. container = nArgs.container;
  1336. config = nArgs.config;
  1337. this.oDomContainer = YAHOO.util.Dom.get(container);
  1338. if (!this.oDomContainer) { this.logger.log("Container not found in document.", "error"); }
  1339. if (!this.oDomContainer.id) {
  1340. this.oDomContainer.id = YAHOO.util.Dom.generateId();
  1341. }
  1342. if (!id) {
  1343. id = this.oDomContainer.id + "_t";
  1344. }
  1345. this.id = id;
  1346. this.containerId = this.oDomContainer.id;
  1347. this.logger = new YAHOO.widget.LogWriter("Calendar " + this.id);
  1348. this.initEvents();
  1349. this.today = new Date();
  1350. YAHOO.widget.DateMath.clearTime(this.today);
  1351. /**
  1352. * The Config object used to hold the configuration variables for the Calendar
  1353. * @property cfg
  1354. * @type YAHOO.util.Config
  1355. */
  1356. this.cfg = new YAHOO.util.Config(this);
  1357. /**
  1358. * The local object which contains the Calendar's options
  1359. * @property Options
  1360. * @type Object
  1361. */
  1362. this.Options = {};
  1363. /**
  1364. * The local object which contains the Calendar's locale settings
  1365. * @property Locale
  1366. * @type Object
  1367. */
  1368. this.Locale = {};
  1369. this.initStyles();
  1370. YAHOO.util.Dom.addClass(this.oDomContainer, this.Style.CSS_CONTAINER);
  1371. YAHOO.util.Dom.addClass(this.oDomContainer, this.Style.CSS_SINGLE);
  1372. this.cellDates = [];
  1373. this.cells = [];
  1374. this.renderStack = [];
  1375. this._renderStack = [];
  1376. this.setupConfig();
  1377. if (config) {
  1378. this.cfg.applyConfig(config, true);
  1379. }
  1380. this.cfg.fireQueue();
  1381. },
  1382. /**
  1383. * Default Config listener for the iframe property. If the iframe config property is se