PageRenderTime 311ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/src/main/resources/org/apache/struts2/static/calendar/calendar-debug.js

http://struts2yuiplugin.googlecode.com/
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

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

Large files files are truncated, but you can click here to view the full file