From 541bb378ddece2eab135a8066a16994e94436dea Mon Sep 17 00:00:00 2001
From: Giulio Cesare Solaroli Usage: var myAnim = new YAHOO.util.Anim(el, { width: { from: 10, to: 100 } }, 1, YAHOO.util.Easing.easeOut); Usage: Usage: Usage: To construct the placeholder for the calendar widget, the code is as
+* follows:
+* var myAnim = new Y.ColorAnim(el, { backgroundColor: { from: '#FF0000', to: '#FFFFFF' } }, 1, Y.Easing.easeOut);
Color values can be specified with either 112233, #112233,
+ * [255,255,255], or rgb(255,255,255)var myAnim = new YAHOO.util.Motion(el, { points: { to: [800, 800] } }, 1, YAHOO.util.Easing.easeOut);
var myAnim = new YAHOO.util.Scroll(el, { scroll: { to: [0, 800] } }, 1, YAHOO.util.Easing.easeOut);
+ *
+ *
+ * @class AutoComplete
+ * @constructor
+ * @param elInput {HTMLElement} DOM element reference of an input field
+ * @param elInput {String} String ID of an input field
+ * @param elContainer {HTMLElement} DOM element reference of an existing DIV
+ * @param elContainer {String} String ID of an existing DIV
+ * @param oDataSource {Object} Instance of YAHOO.widget.DataSource for query/results
+ * @param oConfigs {Object} (optional) Object literal of configuration params
+ */
+YAHOO.widget.AutoComplete = function(elInput,elContainer,oDataSource,oConfigs) {
+ if(elInput && elContainer && oDataSource) {
+ // Validate DataSource
+ if (oDataSource && (oDataSource instanceof YAHOO.widget.DataSource)) {
+ this.dataSource = oDataSource;
+ }
+ else {
+ return;
+ }
+
+ // Validate input element
+ if(YAHOO.util.Dom.inDocument(elInput)) {
+ if(typeof elInput == "string") {
+ this._sName = "instance" + YAHOO.widget.AutoComplete._nIndex + " " + elInput;
+ this._oTextbox = document.getElementById(elInput);
+ }
+ else {
+ this._sName = (elInput.id) ?
+ "instance" + YAHOO.widget.AutoComplete._nIndex + " " + elInput.id:
+ "instance" + YAHOO.widget.AutoComplete._nIndex;
+ this._oTextbox = elInput;
+ }
+ }
+ else {
+ return;
+ }
+
+ // Validate container element
+ if(YAHOO.util.Dom.inDocument(elContainer)) {
+ if(typeof elContainer == "string") {
+ this._oContainer = document.getElementById(elContainer);
+ }
+ else {
+ this._oContainer = elContainer;
+ }
+ if(this._oContainer.style.display == "none") {
+ }
+ }
+ else {
+ return;
+ }
+
+ // Set any config params passed in to override defaults
+ if (typeof oConfigs == "object") {
+ for(var sConfig in oConfigs) {
+ if (sConfig) {
+ this[sConfig] = oConfigs[sConfig];
+ }
+ }
+ }
+
+ // Initialization sequence
+ this._initContainer();
+ this._initProps();
+ this._initList();
+ this._initContainerHelpers();
+
+ // Set up events
+ var oSelf = this;
+ var oTextbox = this._oTextbox;
+ // Events are actually for the content module within the container
+ var oContent = this._oContainer._oContent;
+
+ // Dom events
+ YAHOO.util.Event.addListener(oTextbox,"keyup",oSelf._onTextboxKeyUp,oSelf);
+ YAHOO.util.Event.addListener(oTextbox,"keydown",oSelf._onTextboxKeyDown,oSelf);
+ YAHOO.util.Event.addListener(oTextbox,"focus",oSelf._onTextboxFocus,oSelf);
+ YAHOO.util.Event.addListener(oTextbox,"blur",oSelf._onTextboxBlur,oSelf);
+ YAHOO.util.Event.addListener(oContent,"mouseover",oSelf._onContainerMouseover,oSelf);
+ YAHOO.util.Event.addListener(oContent,"mouseout",oSelf._onContainerMouseout,oSelf);
+ YAHOO.util.Event.addListener(oContent,"scroll",oSelf._onContainerScroll,oSelf);
+ YAHOO.util.Event.addListener(oContent,"resize",oSelf._onContainerResize,oSelf);
+ if(oTextbox.form) {
+ YAHOO.util.Event.addListener(oTextbox.form,"submit",oSelf._onFormSubmit,oSelf);
+ }
+ YAHOO.util.Event.addListener(oTextbox,"keypress",oSelf._onTextboxKeyPress,oSelf);
+
+ // Custom events
+ this.textboxFocusEvent = new YAHOO.util.CustomEvent("textboxFocus", this);
+ this.textboxKeyEvent = new YAHOO.util.CustomEvent("textboxKey", this);
+ this.dataRequestEvent = new YAHOO.util.CustomEvent("dataRequest", this);
+ this.dataReturnEvent = new YAHOO.util.CustomEvent("dataReturn", this);
+ this.dataErrorEvent = new YAHOO.util.CustomEvent("dataError", this);
+ this.containerExpandEvent = new YAHOO.util.CustomEvent("containerExpand", this);
+ this.typeAheadEvent = new YAHOO.util.CustomEvent("typeAhead", this);
+ this.itemMouseOverEvent = new YAHOO.util.CustomEvent("itemMouseOver", this);
+ this.itemMouseOutEvent = new YAHOO.util.CustomEvent("itemMouseOut", this);
+ this.itemArrowToEvent = new YAHOO.util.CustomEvent("itemArrowTo", this);
+ this.itemArrowFromEvent = new YAHOO.util.CustomEvent("itemArrowFrom", this);
+ this.itemSelectEvent = new YAHOO.util.CustomEvent("itemSelect", this);
+ this.unmatchedItemSelectEvent = new YAHOO.util.CustomEvent("unmatchedItemSelect", this);
+ this.selectionEnforceEvent = new YAHOO.util.CustomEvent("selectionEnforce", this);
+ this.containerCollapseEvent = new YAHOO.util.CustomEvent("containerCollapse", this);
+ this.textboxBlurEvent = new YAHOO.util.CustomEvent("textboxBlur", this);
+
+ // Finish up
+ oTextbox.setAttribute("autocomplete","off");
+ YAHOO.widget.AutoComplete._nIndex++;
+ }
+ // Required arguments were not found
+ else {
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Public member variables
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ * The DataSource object that encapsulates the data used for auto completion.
+ * This object should be an inherited object from YAHOO.widget.DataSource.
+ *
+ * @property dataSource
+ * @type Object
+ */
+YAHOO.widget.AutoComplete.prototype.dataSource = null;
+
+/**
+ * Number of characters that must be entered before querying for results. A negative value
+ * effectively turns off the widget. A value of 0 allows queries of null or empty string
+ * values.
+ *
+ * @property minQueryLength
+ * @type Number
+ * @default 1
+ */
+YAHOO.widget.AutoComplete.prototype.minQueryLength = 1;
+
+/**
+ * Maximum number of results to display in results container.
+ *
+ * @property maxResultsDisplayed
+ * @type Number
+ * @default 10
+ */
+YAHOO.widget.AutoComplete.prototype.maxResultsDisplayed = 10;
+
+/**
+ * Number of seconds to delay before submitting a query request. If a query
+ * request is received before a previous one has completed its delay, the
+ * previous request is cancelled and the new request is set to the delay.
+ *
+ * @property queryDelay
+ * @type Number
+ * @default 0.5
+ */
+YAHOO.widget.AutoComplete.prototype.queryDelay = 0.5;
+
+/**
+ * Class name of a highlighted item within results container.
+ *
+ * @property highlighClassName
+ * @type String
+ * @default "yui-ac-highlight"
+ */
+YAHOO.widget.AutoComplete.prototype.highlightClassName = "yui-ac-highlight";
+
+/**
+ * Class name of a pre-highlighted item within results container.
+ *
+ * @property prehighlightClassName
+ * @type String
+ */
+YAHOO.widget.AutoComplete.prototype.prehighlightClassName = null;
+
+/**
+ * Query delimiter. A single character separator for multiple delimited
+ * selections. Multiple delimiter characteres may be defined as an array of
+ * strings. A null value or empty string indicates that query results cannot
+ * be delimited. This feature is not recommended if you need forceSelection to
+ * be true.
+ *
+ * @property delimChar
+ * @type String | String[]
+ */
+YAHOO.widget.AutoComplete.prototype.delimChar = null;
+
+/**
+ * Whether or not the first item in results container should be automatically highlighted
+ * on expand.
+ *
+ * @property autoHighlight
+ * @type Boolean
+ * @default true
+ */
+YAHOO.widget.AutoComplete.prototype.autoHighlight = true;
+
+/**
+ * Whether or not the input field should be automatically updated
+ * with the first query result as the user types, auto-selecting the substring
+ * that the user has not typed.
+ *
+ * @property typeAhead
+ * @type Boolean
+ * @default false
+ */
+YAHOO.widget.AutoComplete.prototype.typeAhead = false;
+
+/**
+ * Whether or not to animate the expansion/collapse of the results container in the
+ * horizontal direction.
+ *
+ * @property animHoriz
+ * @type Boolean
+ * @default false
+ */
+YAHOO.widget.AutoComplete.prototype.animHoriz = false;
+
+/**
+ * Whether or not to animate the expansion/collapse of the results container in the
+ * vertical direction.
+ *
+ * @property animVert
+ * @type Boolean
+ * @default true
+ */
+YAHOO.widget.AutoComplete.prototype.animVert = true;
+
+/**
+ * Speed of container expand/collapse animation, in seconds..
+ *
+ * @property animSpeed
+ * @type Number
+ * @default 0.3
+ */
+YAHOO.widget.AutoComplete.prototype.animSpeed = 0.3;
+
+/**
+ * Whether or not to force the user's selection to match one of the query
+ * results. Enabling this feature essentially transforms the input field into a
+ * <select> field. This feature is not recommended with delimiter character(s)
+ * defined.
+ *
+ * @property forceSelection
+ * @type Boolean
+ * @default false
+ */
+YAHOO.widget.AutoComplete.prototype.forceSelection = false;
+
+/**
+ * Whether or not to allow browsers to cache user-typed input in the input
+ * field. Disabling this feature will prevent the widget from setting the
+ * autocomplete="off" on the input field. When autocomplete="off"
+ * and users click the back button after form submission, user-typed input can
+ * be prefilled by the browser from its cache. This caching of user input may
+ * not be desired for sensitive data, such as credit card numbers, in which
+ * case, implementers should consider setting allowBrowserAutocomplete to false.
+ *
+ * @property allowBrowserAutocomplete
+ * @type Boolean
+ * @default true
+ */
+YAHOO.widget.AutoComplete.prototype.allowBrowserAutocomplete = true;
+
+/**
+ * Whether or not the results container should always be displayed.
+ * Enabling this feature displays the container when the widget is instantiated
+ * and prevents the toggling of the container to a collapsed state.
+ *
+ * @property alwaysShowContainer
+ * @type Boolean
+ * @default false
+ */
+YAHOO.widget.AutoComplete.prototype.alwaysShowContainer = false;
+
+/**
+ * Whether or not to use an iFrame to layer over Windows form elements in
+ * IE. Set to true only when the results container will be on top of a
+ * <select> field in IE and thus exposed to the IE z-index bug (i.e.,
+ * 5.5 < IE < 7).
+ *
+ * @property useIFrame
+ * @type Boolean
+ * @default false
+ */
+YAHOO.widget.AutoComplete.prototype.useIFrame = false;
+
+/**
+ * Whether or not the results container should have a shadow.
+ *
+ * @property useShadow
+ * @type Boolean
+ * @default false
+ */
+YAHOO.widget.AutoComplete.prototype.useShadow = false;
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Public methods
+//
+/////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Public accessor to the unique name of the AutoComplete instance.
+ *
+ * @method toString
+ * @return {String} Unique name of the AutoComplete instance.
+ */
+YAHOO.widget.AutoComplete.prototype.toString = function() {
+ return "AutoComplete " + this._sName;
+};
+
+ /**
+ * Returns true if container is in an expanded state, false otherwise.
+ *
+ * @method isContainerOpen
+ * @return {Boolean} Returns true if container is in an expanded state, false otherwise.
+ */
+YAHOO.widget.AutoComplete.prototype.isContainerOpen = function() {
+ return this._bContainerOpen;
+};
+
+/**
+ * Public accessor to the internal array of DOM <li> elements that
+ * display query results within the results container.
+ *
+ * @method getListItems
+ * @return {HTMLElement[]} Array of <li> elements within the results container.
+ */
+YAHOO.widget.AutoComplete.prototype.getListItems = function() {
+ return this._aListItems;
+};
+
+/**
+ * Public accessor to the data held in an <li> element of the
+ * results container.
+ *
+ * @method getListItemData
+ * @return {Object | Array} Object or array of result data or null
+ */
+YAHOO.widget.AutoComplete.prototype.getListItemData = function(oListItem) {
+ if(oListItem._oResultData) {
+ return oListItem._oResultData;
+ }
+ else {
+ return false;
+ }
+};
+
+/**
+ * Sets HTML markup for the results container header. This markup will be
+ * inserted within a <div> tag with a class of "ac_hd".
+ *
+ * @method setHeader
+ * @param sHeader {String} HTML markup for results container header.
+ */
+YAHOO.widget.AutoComplete.prototype.setHeader = function(sHeader) {
+ if(sHeader) {
+ if(this._oContainer._oContent._oHeader) {
+ this._oContainer._oContent._oHeader.innerHTML = sHeader;
+ this._oContainer._oContent._oHeader.style.display = "block";
+ }
+ }
+ else {
+ this._oContainer._oContent._oHeader.innerHTML = "";
+ this._oContainer._oContent._oHeader.style.display = "none";
+ }
+};
+
+/**
+ * Sets HTML markup for the results container footer. This markup will be
+ * inserted within a <div> tag with a class of "ac_ft".
+ *
+ * @method setFooter
+ * @param sFooter {String} HTML markup for results container footer.
+ */
+YAHOO.widget.AutoComplete.prototype.setFooter = function(sFooter) {
+ if(sFooter) {
+ if(this._oContainer._oContent._oFooter) {
+ this._oContainer._oContent._oFooter.innerHTML = sFooter;
+ this._oContainer._oContent._oFooter.style.display = "block";
+ }
+ }
+ else {
+ this._oContainer._oContent._oFooter.innerHTML = "";
+ this._oContainer._oContent._oFooter.style.display = "none";
+ }
+};
+
+/**
+ * Sets HTML markup for the results container body. This markup will be
+ * inserted within a <div> tag with a class of "ac_bd".
+ *
+ * @method setBody
+ * @param sHeader {String} HTML markup for results container body.
+ */
+YAHOO.widget.AutoComplete.prototype.setBody = function(sBody) {
+ if(sBody) {
+ if(this._oContainer._oContent._oBody) {
+ this._oContainer._oContent._oBody.innerHTML = sBody;
+ this._oContainer._oContent._oBody.style.display = "block";
+ this._oContainer._oContent.style.display = "block";
+ }
+ }
+ else {
+ this._oContainer._oContent._oBody.innerHTML = "";
+ this._oContainer._oContent.style.display = "none";
+ }
+ this._maxResultsDisplayed = 0;
+};
+
+/**
+ * Overridable method that converts a result item object into HTML markup
+ * for display. Return data values are accessible via the oResultItem object,
+ * and the key return value will always be oResultItem[0]. Markup will be
+ * displayed within <li> element tags in the container.
+ *
+ * @method formatResult
+ * @param oResultItem {Object} Result item representing one query result. Data is held in an array.
+ * @param sQuery {String} The current query string.
+ * @return {String} HTML markup of formatted result data.
+ */
+YAHOO.widget.AutoComplete.prototype.formatResult = function(oResultItem, sQuery) {
+ var sResult = oResultItem[0];
+ if(sResult) {
+ return sResult;
+ }
+ else {
+ return "";
+ }
+};
+
+/**
+ * Overridable method called before container expands allows implementers to access data
+ * and DOM elements.
+ *
+ * @method doBeforeExpandContainer
+ * @return {Boolean} Return true to continue expanding container, false to cancel the expand.
+ */
+YAHOO.widget.AutoComplete.prototype.doBeforeExpandContainer = function(oResultItem, sQuery) {
+ return true;
+};
+
+/**
+ * Makes query request to the DataSource.
+ *
+ * @method sendQuery
+ * @param sQuery {String} Query string.
+ */
+YAHOO.widget.AutoComplete.prototype.sendQuery = function(sQuery) {
+ this._sendQuery(sQuery);
+};
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Public events
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Fired when the input field receives focus.
+ *
+ * @event textboxFocusEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ */
+YAHOO.widget.AutoComplete.prototype.textboxFocusEvent = null;
+
+/**
+ * Fired when the input field receives key input.
+ *
+ * @event textboxKeyEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ * @param nKeycode {Number} The keycode number.
+ */
+YAHOO.widget.AutoComplete.prototype.textboxKeyEvent = null;
+
+/**
+ * Fired when the AutoComplete instance makes a query to the DataSource.
+ *
+ * @event dataRequestEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ * @param sQuery {String} The query string.
+ */
+YAHOO.widget.AutoComplete.prototype.dataRequestEvent = null;
+
+/**
+ * Fired when the AutoComplete instance receives query results from the data
+ * source.
+ *
+ * @event dataReturnEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ * @param sQuery {String} The query string.
+ * @param aResults {Array} Results array.
+ */
+YAHOO.widget.AutoComplete.prototype.dataReturnEvent = null;
+
+/**
+ * Fired when the AutoComplete instance does not receive query results from the
+ * DataSource due to an error.
+ *
+ * @event dataErrorEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ * @param sQuery {String} The query string.
+ */
+YAHOO.widget.AutoComplete.prototype.dataErrorEvent = null;
+
+/**
+ * Fired when the results container is expanded.
+ *
+ * @event containerExpandEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ */
+YAHOO.widget.AutoComplete.prototype.containerExpandEvent = null;
+
+/**
+ * Fired when the input field has been prefilled by the type-ahead
+ * feature.
+ *
+ * @event typeAheadEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ * @param sQuery {String} The query string.
+ * @param sPrefill {String} The prefill string.
+ */
+YAHOO.widget.AutoComplete.prototype.typeAheadEvent = null;
+
+/**
+ * Fired when result item has been moused over.
+ *
+ * @event itemMouseOverEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ * @param elItem {HTMLElement} The <li> element item moused to.
+ */
+YAHOO.widget.AutoComplete.prototype.itemMouseOverEvent = null;
+
+/**
+ * Fired when result item has been moused out.
+ *
+ * @event itemMouseOutEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ * @param elItem {HTMLElement} The <li> element item moused from.
+ */
+YAHOO.widget.AutoComplete.prototype.itemMouseOutEvent = null;
+
+/**
+ * Fired when result item has been arrowed to.
+ *
+ * @event itemArrowToEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ * @param elItem {HTMLElement} The <li> element item arrowed to.
+ */
+YAHOO.widget.AutoComplete.prototype.itemArrowToEvent = null;
+
+/**
+ * Fired when result item has been arrowed away from.
+ *
+ * @event itemArrowFromEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ * @param elItem {HTMLElement} The <li> element item arrowed from.
+ */
+YAHOO.widget.AutoComplete.prototype.itemArrowFromEvent = null;
+
+/**
+ * Fired when an item is selected via mouse click, ENTER key, or TAB key.
+ *
+ * @event itemSelectEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ * @param elItem {HTMLElement} The selected <li> element item.
+ * @param oData {Object} The data returned for the item, either as an object,
+ * or mapped from the schema into an array.
+ */
+YAHOO.widget.AutoComplete.prototype.itemSelectEvent = null;
+
+/**
+ * Fired when a user selection does not match any of the displayed result items.
+ * Note that this event may not behave as expected when delimiter characters
+ * have been defined.
+ *
+ * @event unmatchedItemSelectEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ * @param sQuery {String} The user-typed query string.
+ */
+YAHOO.widget.AutoComplete.prototype.unmatchedItemSelectEvent = null;
+
+/**
+ * Fired if forceSelection is enabled and the user's input has been cleared
+ * because it did not match one of the returned query results.
+ *
+ * @event selectionEnforceEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ */
+YAHOO.widget.AutoComplete.prototype.selectionEnforceEvent = null;
+
+/**
+ * Fired when the results container is collapsed.
+ *
+ * @event containerCollapseEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ */
+YAHOO.widget.AutoComplete.prototype.containerCollapseEvent = null;
+
+/**
+ * Fired when the input field loses focus.
+ *
+ * @event textboxBlurEvent
+ * @param oSelf {Object} The AutoComplete instance.
+ */
+YAHOO.widget.AutoComplete.prototype.textboxBlurEvent = null;
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Private member variables
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Internal class variable to index multiple AutoComplete instances.
+ *
+ * @property _nIndex
+ * @type Number
+ * @default 0
+ * @private
+ */
+YAHOO.widget.AutoComplete._nIndex = 0;
+
+/**
+ * Name of AutoComplete instance.
+ *
+ * @property _sName
+ * @type String
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._sName = null;
+
+/**
+ * Text input field DOM element.
+ *
+ * @property _oTextbox
+ * @type HTMLElement
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._oTextbox = null;
+
+/**
+ * Whether or not the input field is currently in focus. If query results come back
+ * but the user has already moved on, do not proceed with auto complete behavior.
+ *
+ * @property _bFocused
+ * @type Boolean
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._bFocused = true;
+
+/**
+ * Animation instance for container expand/collapse.
+ *
+ * @property _oAnim
+ * @type Boolean
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._oAnim = null;
+
+/**
+ * Container DOM element.
+ *
+ * @property _oContainer
+ * @type HTMLElement
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._oContainer = null;
+
+/**
+ * Whether or not the results container is currently open.
+ *
+ * @property _bContainerOpen
+ * @type Boolean
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._bContainerOpen = false;
+
+/**
+ * Whether or not the mouse is currently over the results
+ * container. This is necessary in order to prevent clicks on container items
+ * from being text input field blur events.
+ *
+ * @property _bOverContainer
+ * @type Boolean
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._bOverContainer = false;
+
+/**
+ * Array of <li> elements references that contain query results within the
+ * results container.
+ *
+ * @property _aListItems
+ * @type Array
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._aListItems = null;
+
+/**
+ * Number of <li> elements currently displayed in results container.
+ *
+ * @property _nDisplayedItems
+ * @type Number
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._nDisplayedItems = 0;
+
+/**
+ * Internal count of <li> elements displayed and hidden in results container.
+ *
+ * @property _maxResultsDisplayed
+ * @type Number
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._maxResultsDisplayed = 0;
+
+/**
+ * Current query string
+ *
+ * @property _sCurQuery
+ * @type String
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._sCurQuery = null;
+
+/**
+ * Past queries this session (for saving delimited queries).
+ *
+ * @property _sSavedQuery
+ * @type String
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._sSavedQuery = null;
+
+/**
+ * Pointer to the currently highlighted <li> element in the container.
+ *
+ * @property _oCurItem
+ * @type HTMLElement
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._oCurItem = null;
+
+/**
+ * Whether or not an item has been selected since the container was populated
+ * with results. Reset to false by _populateList, and set to true when item is
+ * selected.
+ *
+ * @property _bItemSelected
+ * @type Boolean
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._bItemSelected = false;
+
+/**
+ * Key code of the last key pressed in textbox.
+ *
+ * @property _nKeyCode
+ * @type Number
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._nKeyCode = null;
+
+/**
+ * Delay timeout ID.
+ *
+ * @property _nDelayID
+ * @type Number
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._nDelayID = -1;
+
+/**
+ * Src to iFrame used when useIFrame = true. Supports implementations over SSL
+ * as well.
+ *
+ * @property _iFrameSrc
+ * @type String
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._iFrameSrc = "javascript:false;";
+
+/**
+ * For users typing via certain IMEs, queries must be triggered by intervals,
+ * since key events yet supported across all browsers for all IMEs.
+ *
+ * @property _queryInterval
+ * @type Object
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._queryInterval = null;
+
+/**
+ * Internal tracker to last known textbox value, used to determine whether or not
+ * to trigger a query via interval for certain IME users.
+ *
+ * @event _sLastTextboxValue
+ * @type String
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._sLastTextboxValue = null;
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Private methods
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Updates and validates latest public config properties.
+ *
+ * @method __initProps
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._initProps = function() {
+ // Correct any invalid values
+ var minQueryLength = this.minQueryLength;
+ if(isNaN(minQueryLength) || (minQueryLength < 1)) {
+ minQueryLength = 1;
+ }
+ var maxResultsDisplayed = this.maxResultsDisplayed;
+ if(isNaN(this.maxResultsDisplayed) || (this.maxResultsDisplayed < 1)) {
+ this.maxResultsDisplayed = 10;
+ }
+ var queryDelay = this.queryDelay;
+ if(isNaN(this.queryDelay) || (this.queryDelay < 0)) {
+ this.queryDelay = 0.5;
+ }
+ var aDelimChar = (this.delimChar) ? this.delimChar : null;
+ if(aDelimChar) {
+ if(typeof aDelimChar == "string") {
+ this.delimChar = [aDelimChar];
+ }
+ else if(aDelimChar.constructor != Array) {
+ this.delimChar = null;
+ }
+ }
+ var animSpeed = this.animSpeed;
+ if((this.animHoriz || this.animVert) && YAHOO.util.Anim) {
+ if(isNaN(animSpeed) || (animSpeed < 0)) {
+ animSpeed = 0.3;
+ }
+ if(!this._oAnim ) {
+ oAnim = new YAHOO.util.Anim(this._oContainer._oContent, {}, this.animSpeed);
+ this._oAnim = oAnim;
+ }
+ else {
+ this._oAnim.duration = animSpeed;
+ }
+ }
+ if(this.forceSelection && this.delimChar) {
+ }
+};
+
+/**
+ * Initializes the results container helpers if they are enabled and do
+ * not exist
+ *
+ * @method _initContainerHelpers
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._initContainerHelpers = function() {
+ if(this.useShadow && !this._oContainer._oShadow) {
+ var oShadow = document.createElement("div");
+ oShadow.className = "yui-ac-shadow";
+ this._oContainer._oShadow = this._oContainer.appendChild(oShadow);
+ }
+ if(this.useIFrame && !this._oContainer._oIFrame) {
+ var oIFrame = document.createElement("iframe");
+ oIFrame.src = this._iFrameSrc;
+ oIFrame.frameBorder = 0;
+ oIFrame.scrolling = "no";
+ oIFrame.style.position = "absolute";
+ oIFrame.style.width = "100%";
+ oIFrame.style.height = "100%";
+ oIFrame.tabIndex = -1;
+ this._oContainer._oIFrame = this._oContainer.appendChild(oIFrame);
+ }
+};
+
+/**
+ * Initializes the results container once at object creation
+ *
+ * @method _initContainer
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._initContainer = function() {
+ if(!this._oContainer._oContent) {
+ // The oContent div helps size the iframe and shadow properly
+ var oContent = document.createElement("div");
+ oContent.className = "yui-ac-content";
+ oContent.style.display = "none";
+ this._oContainer._oContent = this._oContainer.appendChild(oContent);
+
+ var oHeader = document.createElement("div");
+ oHeader.className = "yui-ac-hd";
+ oHeader.style.display = "none";
+ this._oContainer._oContent._oHeader = this._oContainer._oContent.appendChild(oHeader);
+
+ var oBody = document.createElement("div");
+ oBody.className = "yui-ac-bd";
+ this._oContainer._oContent._oBody = this._oContainer._oContent.appendChild(oBody);
+
+ var oFooter = document.createElement("div");
+ oFooter.className = "yui-ac-ft";
+ oFooter.style.display = "none";
+ this._oContainer._oContent._oFooter = this._oContainer._oContent.appendChild(oFooter);
+ }
+ else {
+ }
+};
+
+/**
+ * Clears out contents of container body and creates up to
+ * YAHOO.widget.AutoComplete#maxResultsDisplayed <li> elements in an
+ * <ul> element.
+ *
+ * @method _initList
+ * @private
+ */
+YAHOO.widget.AutoComplete.prototype._initList = function() {
+ this._aListItems = [];
+ while(this._oContainer._oContent._oBody.hasChildNodes()) {
+ var oldListItems = this.getListItems();
+ if(oldListItems) {
+ for(var oldi = oldListItems.length-1; oldi >= 0; i--) {
+ oldListItems[oldi] = null;
+ }
+ }
+ this._oContainer._oContent._oBody.innerHTML = "";
+ }
+
+ var oList = document.createElement("ul");
+ oList = this._oContainer._oContent._oBody.appendChild(oList);
+ for(var i=0; i
+ * dd = new YAHOO.util.DragDrop("div1", "group1"); + *+ * Since none of the event handlers have been implemented, nothing would + * actually happen if you were to run the code above. Normally you would + * override this class or one of the default implementations, but you can + * also override the methods you want on an instance of the class... + *
+ * dd.onDragDrop = function(e, id) { + * alert("dd was dropped on " + id); + * } + *+ * @namespace YAHOO.util + * @class DragDrop + * @constructor + * @param {String} id of the element that is linked to this instance + * @param {String} sGroup the group of related DragDrop objects + * @param {object} config an object containing configurable attributes + * Valid properties for DragDrop: + * padding, isTarget, maintainOffset, primaryButtonOnly + */ +YAHOO.util.DragDrop = function(id, sGroup, config) { + if (id) { + this.init(id, sGroup, config); + } +}; + +YAHOO.util.DragDrop.prototype = { + + /** + * The id of the element associated with this object. This is what we + * refer to as the "linked element" because the size and position of + * this element is used to determine when the drag and drop objects have + * interacted. + * @property id + * @type String + */ + id: null, + + /** + * Configuration attributes passed into the constructor + * @property config + * @type object + */ + config: null, + + /** + * The id of the element that will be dragged. By default this is same + * as the linked element , but could be changed to another element. Ex: + * YAHOO.util.DDProxy + * @property dragElId + * @type String + * @private + */ + dragElId: null, + + /** + * the id of the element that initiates the drag operation. By default + * this is the linked element, but could be changed to be a child of this + * element. This lets us do things like only starting the drag when the + * header element within the linked html element is clicked. + * @property handleElId + * @type String + * @private + */ + handleElId: null, + + /** + * An associative array of HTML tags that will be ignored if clicked. + * @property invalidHandleTypes + * @type {string: string} + */ + invalidHandleTypes: null, + + /** + * An associative array of ids for elements that will be ignored if clicked + * @property invalidHandleIds + * @type {string: string} + */ + invalidHandleIds: null, + + /** + * An indexted array of css class names for elements that will be ignored + * if clicked. + * @property invalidHandleClasses + * @type string[] + */ + invalidHandleClasses: null, + + /** + * The linked element's absolute X position at the time the drag was + * started + * @property startPageX + * @type int + * @private + */ + startPageX: 0, + + /** + * The linked element's absolute X position at the time the drag was + * started + * @property startPageY + * @type int + * @private + */ + startPageY: 0, + + /** + * The group defines a logical collection of DragDrop objects that are + * related. Instances only get events when interacting with other + * DragDrop object in the same group. This lets us define multiple + * groups using a single DragDrop subclass if we want. + * @property groups + * @type {string: string} + */ + groups: null, + + /** + * Individual drag/drop instances can be locked. This will prevent + * onmousedown start drag. + * @property locked + * @type boolean + * @private + */ + locked: false, + + /** + * Lock this instance + * @method lock + */ + lock: function() { this.locked = true; }, + + /** + * Unlock this instace + * @method unlock + */ + unlock: function() { this.locked = false; }, + + /** + * By default, all insances can be a drop target. This can be disabled by + * setting isTarget to false. + * @method isTarget + * @type boolean + */ + isTarget: true, + + /** + * The padding configured for this drag and drop object for calculating + * the drop zone intersection with this object. + * @method padding + * @type int[] + */ + padding: null, + + /** + * Cached reference to the linked element + * @property _domRef + * @private + */ + _domRef: null, + + /** + * Internal typeof flag + * @property __ygDragDrop + * @private + */ + __ygDragDrop: true, + + /** + * Set to true when horizontal contraints are applied + * @property constrainX + * @type boolean + * @private + */ + constrainX: false, + + /** + * Set to true when vertical contraints are applied + * @property constrainY + * @type boolean + * @private + */ + constrainY: false, + + /** + * The left constraint + * @property minX + * @type int + * @private + */ + minX: 0, + + /** + * The right constraint + * @property maxX + * @type int + * @private + */ + maxX: 0, + + /** + * The up constraint + * @property minY + * @type int + * @type int + * @private + */ + minY: 0, + + /** + * The down constraint + * @property maxY + * @type int + * @private + */ + maxY: 0, + + /** + * Maintain offsets when we resetconstraints. Set to true when you want + * the position of the element relative to its parent to stay the same + * when the page changes + * + * @property maintainOffset + * @type boolean + */ + maintainOffset: false, + + /** + * Array of pixel locations the element will snap to if we specified a + * horizontal graduation/interval. This array is generated automatically + * when you define a tick interval. + * @property xTicks + * @type int[] + */ + xTicks: null, + + /** + * Array of pixel locations the element will snap to if we specified a + * vertical graduation/interval. This array is generated automatically + * when you define a tick interval. + * @property yTicks + * @type int[] + */ + yTicks: null, + + /** + * By default the drag and drop instance will only respond to the primary + * button click (left button for a right-handed mouse). Set to true to + * allow drag and drop to start with any mouse click that is propogated + * by the browser + * @property primaryButtonOnly + * @type boolean + */ + primaryButtonOnly: true, + + /** + * The availabe property is false until the linked dom element is accessible. + * @property available + * @type boolean + */ + available: false, + + /** + * By default, drags can only be initiated if the mousedown occurs in the + * region the linked element is. This is done in part to work around a + * bug in some browsers that mis-report the mousedown if the previous + * mouseup happened outside of the window. This property is set to true + * if outer handles are defined. + * + * @property hasOuterHandles + * @type boolean + * @default false + */ + hasOuterHandles: false, + + /** + * Code that executes immediately before the startDrag event + * @method b4StartDrag + * @private + */ + b4StartDrag: function(x, y) { }, + + /** + * Abstract method called after a drag/drop object is clicked + * and the drag or mousedown time thresholds have beeen met. + * @method startDrag + * @param {int} X click location + * @param {int} Y click location + */ + startDrag: function(x, y) { /* override this */ }, + + /** + * Code that executes immediately before the onDrag event + * @method b4Drag + * @private + */ + b4Drag: function(e) { }, + + /** + * Abstract method called during the onMouseMove event while dragging an + * object. + * @method onDrag + * @param {Event} e the mousemove event + */ + onDrag: function(e) { /* override this */ }, + + /** + * Abstract method called when this element fist begins hovering over + * another DragDrop obj + * @method onDragEnter + * @param {Event} e the mousemove event + * @param {String|DragDrop[]} id In POINT mode, the element + * id this is hovering over. In INTERSECT mode, an array of one or more + * dragdrop items being hovered over. + */ + onDragEnter: function(e, id) { /* override this */ }, + + /** + * Code that executes immediately before the onDragOver event + * @method b4DragOver + * @private + */ + b4DragOver: function(e) { }, + + /** + * Abstract method called when this element is hovering over another + * DragDrop obj + * @method onDragOver + * @param {Event} e the mousemove event + * @param {String|DragDrop[]} id In POINT mode, the element + * id this is hovering over. In INTERSECT mode, an array of dd items + * being hovered over. + */ + onDragOver: function(e, id) { /* override this */ }, + + /** + * Code that executes immediately before the onDragOut event + * @method b4DragOut + * @private + */ + b4DragOut: function(e) { }, + + /** + * Abstract method called when we are no longer hovering over an element + * @method onDragOut + * @param {Event} e the mousemove event + * @param {String|DragDrop[]} id In POINT mode, the element + * id this was hovering over. In INTERSECT mode, an array of dd items + * that the mouse is no longer over. + */ + onDragOut: function(e, id) { /* override this */ }, + + /** + * Code that executes immediately before the onDragDrop event + * @method b4DragDrop + * @private + */ + b4DragDrop: function(e) { }, + + /** + * Abstract method called when this item is dropped on another DragDrop + * obj + * @method onDragDrop + * @param {Event} e the mouseup event + * @param {String|DragDrop[]} id In POINT mode, the element + * id this was dropped on. In INTERSECT mode, an array of dd items this + * was dropped on. + */ + onDragDrop: function(e, id) { /* override this */ }, + + /** + * Abstract method called when this item is dropped on an area with no + * drop target + * @method onInvalidDrop + * @param {Event} e the mouseup event + */ + onInvalidDrop: function(e) { /* override this */ }, + + /** + * Code that executes immediately before the endDrag event + * @method b4EndDrag + * @private + */ + b4EndDrag: function(e) { }, + + /** + * Fired when we are done dragging the object + * @method endDrag + * @param {Event} e the mouseup event + */ + endDrag: function(e) { /* override this */ }, + + /** + * Code executed immediately before the onMouseDown event + * @method b4MouseDown + * @param {Event} e the mousedown event + * @private + */ + b4MouseDown: function(e) { }, + + /** + * Event handler that fires when a drag/drop obj gets a mousedown + * @method onMouseDown + * @param {Event} e the mousedown event + */ + onMouseDown: function(e) { /* override this */ }, + + /** + * Event handler that fires when a drag/drop obj gets a mouseup + * @method onMouseUp + * @param {Event} e the mouseup event + */ + onMouseUp: function(e) { /* override this */ }, + + /** + * Override the onAvailable method to do what is needed after the initial + * position was determined. + * @method onAvailable + */ + onAvailable: function () { + }, + + /** + * Returns a reference to the linked element + * @method getEl + * @return {HTMLElement} the html element + */ + getEl: function() { + if (!this._domRef) { + this._domRef = Dom.get(this.id); + } + + return this._domRef; + }, + + /** + * Returns a reference to the actual element to drag. By default this is + * the same as the html element, but it can be assigned to another + * element. An example of this can be found in YAHOO.util.DDProxy + * @method getDragEl + * @return {HTMLElement} the html element + */ + getDragEl: function() { + return Dom.get(this.dragElId); + }, + + /** + * Sets up the DragDrop object. Must be called in the constructor of any + * YAHOO.util.DragDrop subclass + * @method init + * @param id the id of the linked element + * @param {String} sGroup the group of related items + * @param {object} config configuration attributes + */ + init: function(id, sGroup, config) { + this.initTarget(id, sGroup, config); + Event.on(this.id, "mousedown", this.handleMouseDown, this, true); + // Event.on(this.id, "selectstart", Event.preventDefault); + }, + + /** + * Initializes Targeting functionality only... the object does not + * get a mousedown handler. + * @method initTarget + * @param id the id of the linked element + * @param {String} sGroup the group of related items + * @param {object} config configuration attributes + */ + initTarget: function(id, sGroup, config) { + + // configuration attributes + this.config = config || {}; + + // create a local reference to the drag and drop manager + this.DDM = YAHOO.util.DDM; + // initialize the groups array + this.groups = {}; + + // assume that we have an element reference instead of an id if the + // parameter is not a string + if (typeof id !== "string") { + YAHOO.log("id is not a string, assuming it is an HTMLElement"); + id = Dom.generateId(id); + } + + // set the id + this.id = id; + + // add to an interaction group + this.addToGroup((sGroup) ? sGroup : "default"); + + // We don't want to register this as the handle with the manager + // so we just set the id rather than calling the setter. + this.handleElId = id; + + Event.onAvailable(id, this.handleOnAvailable, this, true); + + + // the linked element is the element that gets dragged by default + this.setDragElId(id); + + // by default, clicked anchors will not start drag operations. + // @TODO what else should be here? Probably form fields. + this.invalidHandleTypes = { A: "A" }; + this.invalidHandleIds = {}; + this.invalidHandleClasses = []; + + this.applyConfig(); + }, + + /** + * Applies the configuration parameters that were passed into the constructor. + * This is supposed to happen at each level through the inheritance chain. So + * a DDProxy implentation will execute apply config on DDProxy, DD, and + * DragDrop in order to get all of the parameters that are available in + * each object. + * @method applyConfig + */ + applyConfig: function() { + + // configurable properties: + // padding, isTarget, maintainOffset, primaryButtonOnly + this.padding = this.config.padding || [0, 0, 0, 0]; + this.isTarget = (this.config.isTarget !== false); + this.maintainOffset = (this.config.maintainOffset); + this.primaryButtonOnly = (this.config.primaryButtonOnly !== false); + + }, + + /** + * Executed when the linked element is available + * @method handleOnAvailable + * @private + */ + handleOnAvailable: function() { + this.available = true; + this.resetConstraints(); + this.onAvailable(); + }, + + /** + * Configures the padding for the target zone in px. Effectively expands + * (or reduces) the virtual object size for targeting calculations. + * Supports css-style shorthand; if only one parameter is passed, all sides + * will have that padding, and if only two are passed, the top and bottom + * will have the first param, the left and right the second. + * @method setPadding + * @param {int} iTop Top pad + * @param {int} iRight Right pad + * @param {int} iBot Bot pad + * @param {int} iLeft Left pad + */ + setPadding: function(iTop, iRight, iBot, iLeft) { + // this.padding = [iLeft, iRight, iTop, iBot]; + if (!iRight && 0 !== iRight) { + this.padding = [iTop, iTop, iTop, iTop]; + } else if (!iBot && 0 !== iBot) { + this.padding = [iTop, iRight, iTop, iRight]; + } else { + this.padding = [iTop, iRight, iBot, iLeft]; + } + }, + + /** + * Stores the initial placement of the linked element. + * @method setInitialPosition + * @param {int} diffX the X offset, default 0 + * @param {int} diffY the Y offset, default 0 + */ + setInitPosition: function(diffX, diffY) { + var el = this.getEl(); + + if (!this.DDM.verifyEl(el)) { + return; + } + + var dx = diffX || 0; + var dy = diffY || 0; + + var p = Dom.getXY( el ); + + this.initPageX = p[0] - dx; + this.initPageY = p[1] - dy; + + this.lastPageX = p[0]; + this.lastPageY = p[1]; + + + this.setStartPosition(p); + }, + + /** + * Sets the start position of the element. This is set when the obj + * is initialized, the reset when a drag is started. + * @method setStartPosition + * @param pos current position (from previous lookup) + * @private + */ + setStartPosition: function(pos) { + var p = pos || Dom.getXY( this.getEl() ); + this.deltaSetXY = null; + + this.startPageX = p[0]; + this.startPageY = p[1]; + }, + + /** + * Add this instance to a group of related drag/drop objects. All + * instances belong to at least one group, and can belong to as many + * groups as needed. + * @method addToGroup + * @param sGroup {string} the name of the group + */ + addToGroup: function(sGroup) { + this.groups[sGroup] = true; + this.DDM.regDragDrop(this, sGroup); + }, + + /** + * Remove's this instance from the supplied interaction group + * @method removeFromGroup + * @param {string} sGroup The group to drop + */ + removeFromGroup: function(sGroup) { + if (this.groups[sGroup]) { + delete this.groups[sGroup]; + } + + this.DDM.removeDDFromGroup(this, sGroup); + }, + + /** + * Allows you to specify that an element other than the linked element + * will be moved with the cursor during a drag + * @method setDragElId + * @param id {string} the id of the element that will be used to initiate the drag + */ + setDragElId: function(id) { + this.dragElId = id; + }, + + /** + * Allows you to specify a child of the linked element that should be + * used to initiate the drag operation. An example of this would be if + * you have a content div with text and links. Clicking anywhere in the + * content area would normally start the drag operation. Use this method + * to specify that an element inside of the content div is the element + * that starts the drag operation. + * @method setHandleElId + * @param id {string} the id of the element that will be used to + * initiate the drag. + */ + setHandleElId: function(id) { + if (typeof id !== "string") { + YAHOO.log("id is not a string, assuming it is an HTMLElement"); + id = Dom.generateId(id); + } + this.handleElId = id; + this.DDM.regHandle(this.id, id); + }, + + /** + * Allows you to set an element outside of the linked element as a drag + * handle + * @method setOuterHandleElId + * @param id the id of the element that will be used to initiate the drag + */ + setOuterHandleElId: function(id) { + if (typeof id !== "string") { + YAHOO.log("id is not a string, assuming it is an HTMLElement"); + id = Dom.generateId(id); + } + Event.on(id, "mousedown", + this.handleMouseDown, this, true); + this.setHandleElId(id); + + this.hasOuterHandles = true; + }, + + /** + * Remove all drag and drop hooks for this element + * @method unreg + */ + unreg: function() { + Event.removeListener(this.id, "mousedown", + this.handleMouseDown); + this._domRef = null; + this.DDM._remove(this); + }, + + /** + * Returns true if this instance is locked, or the drag drop mgr is locked + * (meaning that all drag/drop is disabled on the page.) + * @method isLocked + * @return {boolean} true if this obj or all drag/drop is locked, else + * false + */ + isLocked: function() { + return (this.DDM.isLocked() || this.locked); + }, + + /** + * Fired when this object is clicked + * @method handleMouseDown + * @param {Event} e + * @param {YAHOO.util.DragDrop} oDD the clicked dd object (this dd obj) + * @private + */ + handleMouseDown: function(e, oDD) { + + var button = e.which || e.button; + + if (this.primaryButtonOnly && button > 1) { + return; + } + + if (this.isLocked()) { + return; + } + + this.DDM.refreshCache(this.groups); + // var self = this; + // setTimeout( function() { self.DDM.refreshCache(self.groups); }, 0); + + // Only process the event if we really clicked within the linked + // element. The reason we make this check is that in the case that + // another element was moved between the clicked element and the + // cursor in the time between the mousedown and mouseup events. When + // this happens, the element gets the next mousedown event + // regardless of where on the screen it happened. + var pt = new YAHOO.util.Point(Event.getPageX(e), Event.getPageY(e)); + if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) ) { + } else { + if (this.clickValidator(e)) { + + + // set the initial element position + this.setStartPosition(); + + + this.b4MouseDown(e); + this.onMouseDown(e); + this.DDM.handleMouseDown(e, this); + + this.DDM.stopEvent(e); + } else { + + + } + } + }, + + clickValidator: function(e) { + var target = Event.getTarget(e); + return ( this.isValidHandleChild(target) && + (this.id == this.handleElId || + this.DDM.handleWasClicked(target, this.id)) ); + }, + + /** + * Allows you to specify a tag name that should not start a drag operation + * when clicked. This is designed to facilitate embedding links within a + * drag handle that do something other than start the drag. + * @method addInvalidHandleType + * @param {string} tagName the type of element to exclude + */ + addInvalidHandleType: function(tagName) { + var type = tagName.toUpperCase(); + this.invalidHandleTypes[type] = type; + }, + + /** + * Lets you to specify an element id for a child of a drag handle + * that should not initiate a drag + * @method addInvalidHandleId + * @param {string} id the element id of the element you wish to ignore + */ + addInvalidHandleId: function(id) { + if (typeof id !== "string") { + YAHOO.log("id is not a string, assuming it is an HTMLElement"); + id = Dom.generateId(id); + } + this.invalidHandleIds[id] = id; + }, + + /** + * Lets you specify a css class of elements that will not initiate a drag + * @method addInvalidHandleClass + * @param {string} cssClass the class of the elements you wish to ignore + */ + addInvalidHandleClass: function(cssClass) { + this.invalidHandleClasses.push(cssClass); + }, + + /** + * Unsets an excluded tag name set by addInvalidHandleType + * @method removeInvalidHandleType + * @param {string} tagName the type of element to unexclude + */ + removeInvalidHandleType: function(tagName) { + var type = tagName.toUpperCase(); + // this.invalidHandleTypes[type] = null; + delete this.invalidHandleTypes[type]; + }, + + /** + * Unsets an invalid handle id + * @method removeInvalidHandleId + * @param {string} id the id of the element to re-enable + */ + removeInvalidHandleId: function(id) { + if (typeof id !== "string") { + YAHOO.log("id is not a string, assuming it is an HTMLElement"); + id = Dom.generateId(id); + } + delete this.invalidHandleIds[id]; + }, + + /** + * Unsets an invalid css class + * @method removeInvalidHandleClass + * @param {string} cssClass the class of the element(s) you wish to + * re-enable + */ + removeInvalidHandleClass: function(cssClass) { + for (var i=0, len=this.invalidHandleClasses.length; i
+ * YAHOO.util.DragDropMgr.refreshCache({group1:true, group2:true});
+ *
+ * @TODO this really should be an indexed array. Alternatively this
+ * method could accept both.
+ * @method refreshCache
+ * @param {Object} groups an associative array of groups to refresh
+ * @static
+ */
+ refreshCache: function(groups) {
+ for (var sGroup in groups) {
+ if ("string" != typeof sGroup) {
+ continue;
+ }
+ for (var i in this.ids[sGroup]) {
+ var oDD = this.ids[sGroup][i];
+
+ if (this.isTypeOfDD(oDD)) {
+ // if (this.isTypeOfDD(oDD) && oDD.isTarget) {
+ var loc = this.getLocation(oDD);
+ if (loc) {
+ this.locationCache[oDD.id] = loc;
+ } else {
+ delete this.locationCache[oDD.id];
+ // this will unregister the drag and drop object if
+ // the element is not in a usable state
+ // oDD.unreg();
+ }
+ }
+ }
+ }
+ },
+
+ /**
+ * This checks to make sure an element exists and is in the DOM. The
+ * main purpose is to handle cases where innerHTML is used to remove
+ * drag and drop objects from the DOM. IE provides an 'unspecified
+ * error' when trying to access the offsetParent of such an element
+ * @method verifyEl
+ * @param {HTMLElement} el the element to check
+ * @return {boolean} true if the element looks usable
+ * @static
+ */
+ verifyEl: function(el) {
+ try {
+ if (el) {
+ var parent = el.offsetParent;
+ if (parent) {
+ return true;
+ }
+ }
+ } catch(e) {
+ }
+
+ return false;
+ },
+
+ /**
+ * Returns a Region object containing the drag and drop element's position
+ * and size, including the padding configured for it
+ * @method getLocation
+ * @param {DragDrop} oDD the drag and drop object to get the
+ * location for
+ * @return {YAHOO.util.Region} a Region object representing the total area
+ * the element occupies, including any padding
+ * the instance is configured for.
+ * @static
+ */
+ getLocation: function(oDD) {
+ if (! this.isTypeOfDD(oDD)) {
+ return null;
+ }
+
+ var el = oDD.getEl(), pos, x1, x2, y1, y2, t, r, b, l;
+
+ try {
+ pos= YAHOO.util.Dom.getXY(el);
+ } catch (e) { }
+
+ if (!pos) {
+ return null;
+ }
+
+ x1 = pos[0];
+ x2 = x1 + el.offsetWidth;
+ y1 = pos[1];
+ y2 = y1 + el.offsetHeight;
+
+ t = y1 - oDD.padding[0];
+ r = x2 + oDD.padding[1];
+ b = y2 + oDD.padding[2];
+ l = x1 - oDD.padding[3];
+
+ return new YAHOO.util.Region( t, r, b, l );
+ },
+
+ /**
+ * Checks the cursor location to see if it over the target
+ * @method isOverTarget
+ * @param {YAHOO.util.Point} pt The point to evaluate
+ * @param {DragDrop} oTarget the DragDrop object we are inspecting
+ * @return {boolean} true if the mouse is over the target
+ * @private
+ * @static
+ */
+ isOverTarget: function(pt, oTarget, intersect) {
+ // use cache if available
+ var loc = this.locationCache[oTarget.id];
+ if (!loc || !this.useCache) {
+ loc = this.getLocation(oTarget);
+ this.locationCache[oTarget.id] = loc;
+
+ }
+
+ if (!loc) {
+ return false;
+ }
+
+ oTarget.cursorIsOver = loc.contains( pt );
+
+ // DragDrop is using this as a sanity check for the initial mousedown
+ // in this case we are done. In POINT mode, if the drag obj has no
+ // contraints, we are also done. Otherwise we need to evaluate the
+ // location of the target as related to the actual location of the
+ // dragged element.
+ var dc = this.dragCurrent;
+ if (!dc || !dc.getTargetCoord ||
+ (!intersect && !dc.constrainX && !dc.constrainY)) {
+ return oTarget.cursorIsOver;
+ }
+
+ oTarget.overlap = null;
+
+ // Get the current location of the drag element, this is the
+ // location of the mouse event less the delta that represents
+ // where the original mousedown happened on the element. We
+ // need to consider constraints and ticks as well.
+ var pos = dc.getTargetCoord(pt.x, pt.y);
+
+ var el = dc.getDragEl();
+ var curRegion = new YAHOO.util.Region( pos.y,
+ pos.x + el.offsetWidth,
+ pos.y + el.offsetHeight,
+ pos.x );
+
+ var overlap = curRegion.intersect(loc);
+
+ if (overlap) {
+ oTarget.overlap = overlap;
+ return (intersect) ? true : oTarget.cursorIsOver;
+ } else {
+ return false;
+ }
+ },
+
+ /**
+ * unload event handler
+ * @method _onUnload
+ * @private
+ * @static
+ */
+ _onUnload: function(e, me) {
+ this.unregAll();
+ },
+
+ /**
+ * Cleans up the drag and drop events and objects.
+ * @method unregAll
+ * @private
+ * @static
+ */
+ unregAll: function() {
+
+ if (this.dragCurrent) {
+ this.stopDrag();
+ this.dragCurrent = null;
+ }
+
+ this._execOnAll("unreg", []);
+
+ for (i in this.elementCache) {
+ delete this.elementCache[i];
+ }
+
+ this.elementCache = {};
+ this.ids = {};
+ },
+
+ /**
+ * A cache of DOM elements
+ * @property elementCache
+ * @private
+ * @static
+ */
+ elementCache: {},
+
+ /**
+ * Get the wrapper for the DOM element specified
+ * @method getElWrapper
+ * @param {String} id the id of the element to get
+ * @return {YAHOO.util.DDM.ElementWrapper} the wrapped element
+ * @private
+ * @deprecated This wrapper isn't that useful
+ * @static
+ */
+ getElWrapper: function(id) {
+ var oWrapper = this.elementCache[id];
+ if (!oWrapper || !oWrapper.el) {
+ oWrapper = this.elementCache[id] =
+ new this.ElementWrapper(YAHOO.util.Dom.get(id));
+ }
+ return oWrapper;
+ },
+
+ /**
+ * Returns the actual DOM element
+ * @method getElement
+ * @param {String} id the id of the elment to get
+ * @return {Object} The element
+ * @deprecated use YAHOO.util.Dom.get instead
+ * @static
+ */
+ getElement: function(id) {
+ return YAHOO.util.Dom.get(id);
+ },
+
+ /**
+ * Returns the style property for the DOM element (i.e.,
+ * document.getElById(id).style)
+ * @method getCss
+ * @param {String} id the id of the elment to get
+ * @return {Object} The style property of the element
+ * @deprecated use YAHOO.util.Dom instead
+ * @static
+ */
+ getCss: function(id) {
+ var el = YAHOO.util.Dom.get(id);
+ return (el) ? el.style : null;
+ },
+
+ /**
+ * Inner class for cached elements
+ * @class DragDropMgr.ElementWrapper
+ * @for DragDropMgr
+ * @private
+ * @deprecated
+ */
+ ElementWrapper: function(el) {
+ /**
+ * The element
+ * @property el
+ */
+ this.el = el || null;
+ /**
+ * The element id
+ * @property id
+ */
+ this.id = this.el && el.id;
+ /**
+ * A reference to the style property
+ * @property css
+ */
+ this.css = this.el && el.style;
+ },
+
+ /**
+ * Returns the X position of an html element
+ * @method getPosX
+ * @param el the element for which to get the position
+ * @return {int} the X coordinate
+ * @for DragDropMgr
+ * @deprecated use YAHOO.util.Dom.getX instead
+ * @static
+ */
+ getPosX: function(el) {
+ return YAHOO.util.Dom.getX(el);
+ },
+
+ /**
+ * Returns the Y position of an html element
+ * @method getPosY
+ * @param el the element for which to get the position
+ * @return {int} the Y coordinate
+ * @deprecated use YAHOO.util.Dom.getY instead
+ * @static
+ */
+ getPosY: function(el) {
+ return YAHOO.util.Dom.getY(el);
+ },
+
+ /**
+ * Swap two nodes. In IE, we use the native method, for others we
+ * emulate the IE behavior
+ * @method swapNode
+ * @param n1 the first node to swap
+ * @param n2 the other node to swap
+ * @static
+ */
+ swapNode: function(n1, n2) {
+ if (n1.swapNode) {
+ n1.swapNode(n2);
+ } else {
+ var p = n2.parentNode;
+ var s = n2.nextSibling;
+
+ if (s == n1) {
+ p.insertBefore(n1, n2);
+ } else if (n2 == n1.nextSibling) {
+ p.insertBefore(n2, n1);
+ } else {
+ n1.parentNode.replaceChild(n2, n1);
+ p.insertBefore(n1, s);
+ }
+ }
+ },
+
+ /**
+ * Returns the current scroll position
+ * @method getScroll
+ * @private
+ * @static
+ */
+ getScroll: function () {
+ var t, l, dde=document.documentElement, db=document.body;
+ if (dde && (dde.scrollTop || dde.scrollLeft)) {
+ t = dde.scrollTop;
+ l = dde.scrollLeft;
+ } else if (db) {
+ t = db.scrollTop;
+ l = db.scrollLeft;
+ } else {
+ YAHOO.log("could not get scroll property");
+ }
+ return { top: t, left: l };
+ },
+
+ /**
+ * Returns the specified element style property
+ * @method getStyle
+ * @param {HTMLElement} el the element
+ * @param {string} styleProp the style property
+ * @return {string} The value of the style property
+ * @deprecated use YAHOO.util.Dom.getStyle
+ * @static
+ */
+ getStyle: function(el, styleProp) {
+ return YAHOO.util.Dom.getStyle(el, styleProp);
+ },
+
+ /**
+ * Gets the scrollTop
+ * @method getScrollTop
+ * @return {int} the document's scrollTop
+ * @static
+ */
+ getScrollTop: function () { return this.getScroll().top; },
+
+ /**
+ * Gets the scrollLeft
+ * @method getScrollLeft
+ * @return {int} the document's scrollTop
+ * @static
+ */
+ getScrollLeft: function () { return this.getScroll().left; },
+
+ /**
+ * Sets the x/y position of an element to the location of the
+ * target element.
+ * @method moveToEl
+ * @param {HTMLElement} moveEl The element to move
+ * @param {HTMLElement} targetEl The position reference element
+ * @static
+ */
+ moveToEl: function (moveEl, targetEl) {
+ var aCoord = YAHOO.util.Dom.getXY(targetEl);
+ YAHOO.util.Dom.setXY(moveEl, aCoord);
+ },
+
+ /**
+ * Gets the client height
+ * @method getClientHeight
+ * @return {int} client height in px
+ * @deprecated use YAHOO.util.Dom.getViewportHeight instead
+ * @static
+ */
+ getClientHeight: function() {
+ return YAHOO.util.Dom.getViewportHeight();
+ },
+
+ /**
+ * Gets the client width
+ * @method getClientWidth
+ * @return {int} client width in px
+ * @deprecated use YAHOO.util.Dom.getViewportWidth instead
+ * @static
+ */
+ getClientWidth: function() {
+ return YAHOO.util.Dom.getViewportWidth();
+ },
+
+ /**
+ * Numeric array sort function
+ * @method numericSort
+ * @static
+ */
+ numericSort: function(a, b) { return (a - b); },
+
+ /**
+ * Internal counter
+ * @property _timeoutCount
+ * @private
+ * @static
+ */
+ _timeoutCount: 0,
+
+ /**
+ * Trying to make the load order less important. Without this we get
+ * an error if this file is loaded before the Event Utility.
+ * @method _addListeners
+ * @private
+ * @static
+ */
+ _addListeners: function() {
+ var DDM = YAHOO.util.DDM;
+ if ( YAHOO.util.Event && document ) {
+ DDM._onLoad();
+ } else {
+ if (DDM._timeoutCount > 2000) {
+ } else {
+ setTimeout(DDM._addListeners, 10);
+ if (document && document.body) {
+ DDM._timeoutCount += 1;
+ }
+ }
+ }
+ },
+
+ /**
+ * Recursively searches the immediate parent and all child nodes for
+ * the handle element in order to determine wheter or not it was
+ * clicked.
+ * @method handleWasClicked
+ * @param node the html element to inspect
+ * @static
+ */
+ handleWasClicked: function(node, id) {
+ if (this.isHandle(id, node.id)) {
+ return true;
+ } else {
+ // check to see if this is a text node child of the one we want
+ var p = node.parentNode;
+
+ while (p) {
+ if (this.isHandle(id, p.id)) {
+ return true;
+ } else {
+ p = p.parentNode;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ };
+
+}();
+
+// shorter alias, save a few bytes
+YAHOO.util.DDM = YAHOO.util.DragDropMgr;
+YAHOO.util.DDM._addListeners();
+
+}
+
+/**
+ * A DragDrop implementation where the linked element follows the
+ * mouse cursor during a drag.
+ * @class DD
+ * @extends YAHOO.util.DragDrop
+ * @constructor
+ * @param {String} id the id of the linked element
+ * @param {String} sGroup the group of related DragDrop items
+ * @param {object} config an object containing configurable attributes
+ * Valid properties for DD:
+ * scroll
+ */
+YAHOO.util.DD = function(id, sGroup, config) {
+ if (id) {
+ this.init(id, sGroup, config);
+ }
+};
+
+YAHOO.extend(YAHOO.util.DD, YAHOO.util.DragDrop, {
+
+ /**
+ * When set to true, the utility automatically tries to scroll the browser
+ * window wehn a drag and drop element is dragged near the viewport boundary.
+ * Defaults to true.
+ * @property scroll
+ * @type boolean
+ */
+ scroll: true,
+
+ /**
+ * Sets the pointer offset to the distance between the linked element's top
+ * left corner and the location the element was clicked
+ * @method autoOffset
+ * @param {int} iPageX the X coordinate of the click
+ * @param {int} iPageY the Y coordinate of the click
+ */
+ autoOffset: function(iPageX, iPageY) {
+ var x = iPageX - this.startPageX;
+ var y = iPageY - this.startPageY;
+ this.setDelta(x, y);
+ },
+
+ /**
+ * Sets the pointer offset. You can call this directly to force the
+ * offset to be in a particular location (e.g., pass in 0,0 to set it
+ * to the center of the object, as done in YAHOO.widget.Slider)
+ * @method setDelta
+ * @param {int} iDeltaX the distance from the left
+ * @param {int} iDeltaY the distance from the top
+ */
+ setDelta: function(iDeltaX, iDeltaY) {
+ this.deltaX = iDeltaX;
+ this.deltaY = iDeltaY;
+ },
+
+ /**
+ * Sets the drag element to the location of the mousedown or click event,
+ * maintaining the cursor location relative to the location on the element
+ * that was clicked. Override this if you want to place the element in a
+ * location other than where the cursor is.
+ * @method setDragElPos
+ * @param {int} iPageX the X coordinate of the mousedown or drag event
+ * @param {int} iPageY the Y coordinate of the mousedown or drag event
+ */
+ setDragElPos: function(iPageX, iPageY) {
+ // the first time we do this, we are going to check to make sure
+ // the element has css positioning
+
+ var el = this.getDragEl();
+ this.alignElWithMouse(el, iPageX, iPageY);
+ },
+
+ /**
+ * Sets the element to the location of the mousedown or click event,
+ * maintaining the cursor location relative to the location on the element
+ * that was clicked. Override this if you want to place the element in a
+ * location other than where the cursor is.
+ * @method alignElWithMouse
+ * @param {HTMLElement} el the element to move
+ * @param {int} iPageX the X coordinate of the mousedown or drag event
+ * @param {int} iPageY the Y coordinate of the mousedown or drag event
+ */
+ alignElWithMouse: function(el, iPageX, iPageY) {
+ var oCoord = this.getTargetCoord(iPageX, iPageY);
+
+ if (!this.deltaSetXY) {
+ var aCoord = [oCoord.x, oCoord.y];
+ YAHOO.util.Dom.setXY(el, aCoord);
+ var newLeft = parseInt( YAHOO.util.Dom.getStyle(el, "left"), 10 );
+ var newTop = parseInt( YAHOO.util.Dom.getStyle(el, "top" ), 10 );
+
+ this.deltaSetXY = [ newLeft - oCoord.x, newTop - oCoord.y ];
+ } else {
+ YAHOO.util.Dom.setStyle(el, "left", (oCoord.x + this.deltaSetXY[0]) + "px");
+ YAHOO.util.Dom.setStyle(el, "top", (oCoord.y + this.deltaSetXY[1]) + "px");
+ }
+
+ this.cachePosition(oCoord.x, oCoord.y);
+ this.autoScroll(oCoord.x, oCoord.y, el.offsetHeight, el.offsetWidth);
+ },
+
+ /**
+ * Saves the most recent position so that we can reset the constraints and
+ * tick marks on-demand. We need to know this so that we can calculate the
+ * number of pixels the element is offset from its original position.
+ * @method cachePosition
+ * @param iPageX the current x position (optional, this just makes it so we
+ * don't have to look it up again)
+ * @param iPageY the current y position (optional, this just makes it so we
+ * don't have to look it up again)
+ */
+ cachePosition: function(iPageX, iPageY) {
+ if (iPageX) {
+ this.lastPageX = iPageX;
+ this.lastPageY = iPageY;
+ } else {
+ var aCoord = YAHOO.util.Dom.getXY(this.getEl());
+ this.lastPageX = aCoord[0];
+ this.lastPageY = aCoord[1];
+ }
+ },
+
+ /**
+ * Auto-scroll the window if the dragged object has been moved beyond the
+ * visible window boundary.
+ * @method autoScroll
+ * @param {int} x the drag element's x position
+ * @param {int} y the drag element's y position
+ * @param {int} h the height of the drag element
+ * @param {int} w the width of the drag element
+ * @private
+ */
+ autoScroll: function(x, y, h, w) {
+
+ if (this.scroll) {
+ // The client height
+ var clientH = this.DDM.getClientHeight();
+
+ // The client width
+ var clientW = this.DDM.getClientWidth();
+
+ // The amt scrolled down
+ var st = this.DDM.getScrollTop();
+
+ // The amt scrolled right
+ var sl = this.DDM.getScrollLeft();
+
+ // Location of the bottom of the element
+ var bot = h + y;
+
+ // Location of the right of the element
+ var right = w + x;
+
+ // The distance from the cursor to the bottom of the visible area,
+ // adjusted so that we don't scroll if the cursor is beyond the
+ // element drag constraints
+ var toBot = (clientH + st - y - this.deltaY);
+
+ // The distance from the cursor to the right of the visible area
+ var toRight = (clientW + sl - x - this.deltaX);
+
+
+ // How close to the edge the cursor must be before we scroll
+ // var thresh = (document.all) ? 100 : 40;
+ var thresh = 40;
+
+ // How many pixels to scroll per autoscroll op. This helps to reduce
+ // clunky scrolling. IE is more sensitive about this ... it needs this
+ // value to be higher.
+ var scrAmt = (document.all) ? 80 : 30;
+
+ // Scroll down if we are near the bottom of the visible page and the
+ // obj extends below the crease
+ if ( bot > clientH && toBot < thresh ) {
+ window.scrollTo(sl, st + scrAmt);
+ }
+
+ // Scroll up if the window is scrolled down and the top of the object
+ // goes above the top border
+ if ( y < st && st > 0 && y - st < thresh ) {
+ window.scrollTo(sl, st - scrAmt);
+ }
+
+ // Scroll right if the obj is beyond the right border and the cursor is
+ // near the border.
+ if ( right > clientW && toRight < thresh ) {
+ window.scrollTo(sl + scrAmt, st);
+ }
+
+ // Scroll left if the window has been scrolled to the right and the obj
+ // extends past the left border
+ if ( x < sl && sl > 0 && x - sl < thresh ) {
+ window.scrollTo(sl - scrAmt, st);
+ }
+ }
+ },
+
+ /**
+ * Finds the location the element should be placed if we want to move
+ * it to where the mouse location less the click offset would place us.
+ * @method getTargetCoord
+ * @param {int} iPageX the X coordinate of the click
+ * @param {int} iPageY the Y coordinate of the click
+ * @return an object that contains the coordinates (Object.x and Object.y)
+ * @private
+ */
+ getTargetCoord: function(iPageX, iPageY) {
+
+
+ var x = iPageX - this.deltaX;
+ var y = iPageY - this.deltaY;
+
+ if (this.constrainX) {
+ if (x < this.minX) { x = this.minX; }
+ if (x > this.maxX) { x = this.maxX; }
+ }
+
+ if (this.constrainY) {
+ if (y < this.minY) { y = this.minY; }
+ if (y > this.maxY) { y = this.maxY; }
+ }
+
+ x = this.getTick(x, this.xTicks);
+ y = this.getTick(y, this.yTicks);
+
+
+ return {x:x, y:y};
+ },
+
+ /*
+ * Sets up config options specific to this class. Overrides
+ * YAHOO.util.DragDrop, but all versions of this method through the
+ * inheritance chain are called
+ */
+ applyConfig: function() {
+ YAHOO.util.DD.superclass.applyConfig.call(this);
+ this.scroll = (this.config.scroll !== false);
+ },
+
+ /*
+ * Event that fires prior to the onMouseDown event. Overrides
+ * YAHOO.util.DragDrop.
+ */
+ b4MouseDown: function(e) {
+ // this.resetConstraints();
+ this.autoOffset(YAHOO.util.Event.getPageX(e),
+ YAHOO.util.Event.getPageY(e));
+ },
+
+ /*
+ * Event that fires prior to the onDrag event. Overrides
+ * YAHOO.util.DragDrop.
+ */
+ b4Drag: function(e) {
+ this.setDragElPos(YAHOO.util.Event.getPageX(e),
+ YAHOO.util.Event.getPageY(e));
+ },
+
+ toString: function() {
+ return ("DD " + this.id);
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ // Debugging ygDragDrop events that can be overridden
+ //////////////////////////////////////////////////////////////////////////
+ /*
+ startDrag: function(x, y) {
+ },
+
+ onDrag: function(e) {
+ },
+
+ onDragEnter: function(e, id) {
+ },
+
+ onDragOver: function(e, id) {
+ },
+
+ onDragOut: function(e, id) {
+ },
+
+ onDragDrop: function(e, id) {
+ },
+
+ endDrag: function(e) {
+ }
+
+ */
+
+});
+/**
+ * A DragDrop implementation that inserts an empty, bordered div into
+ * the document that follows the cursor during drag operations. At the time of
+ * the click, the frame div is resized to the dimensions of the linked html
+ * element, and moved to the exact location of the linked element.
+ *
+ * References to the "frame" element refer to the single proxy element that
+ * was created to be dragged in place of all DDProxy elements on the
+ * page.
+ *
+ * @class DDProxy
+ * @extends YAHOO.util.DD
+ * @constructor
+ * @param {String} id the id of the linked html element
+ * @param {String} sGroup the group of related DragDrop objects
+ * @param {object} config an object containing configurable attributes
+ * Valid properties for DDProxy in addition to those in DragDrop:
+ * resizeFrame, centerFrame, dragElId
+ */
+YAHOO.util.DDProxy = function(id, sGroup, config) {
+ if (id) {
+ this.init(id, sGroup, config);
+ this.initFrame();
+ }
+};
+
+/**
+ * The default drag frame div id
+ * @property YAHOO.util.DDProxy.dragElId
+ * @type String
+ * @static
+ */
+YAHOO.util.DDProxy.dragElId = "ygddfdiv";
+
+YAHOO.extend(YAHOO.util.DDProxy, YAHOO.util.DD, {
+
+ /**
+ * By default we resize the drag frame to be the same size as the element
+ * we want to drag (this is to get the frame effect). We can turn it off
+ * if we want a different behavior.
+ * @property resizeFrame
+ * @type boolean
+ */
+ resizeFrame: true,
+
+ /**
+ * By default the frame is positioned exactly where the drag element is, so
+ * we use the cursor offset provided by YAHOO.util.DD. Another option that works only if
+ * you do not have constraints on the obj is to have the drag frame centered
+ * around the cursor. Set centerFrame to true for this effect.
+ * @property centerFrame
+ * @type boolean
+ */
+ centerFrame: false,
+
+ /**
+ * Creates the proxy element if it does not yet exist
+ * @method createFrame
+ */
+ createFrame: function() {
+ var self = this;
+ var body = document.body;
+
+ if (!body || !body.firstChild) {
+ setTimeout( function() { self.createFrame(); }, 50 );
+ return;
+ }
+
+ var div = this.getDragEl();
+
+ if (!div) {
+ div = document.createElement("div");
+ div.id = this.dragElId;
+ var s = div.style;
+
+ s.position = "absolute";
+ s.visibility = "hidden";
+ s.cursor = "move";
+ s.border = "2px solid #aaa";
+ s.zIndex = 999;
+
+ // appendChild can blow up IE if invoked prior to the window load event
+ // while rendering a table. It is possible there are other scenarios
+ // that would cause this to happen as well.
+ body.insertBefore(div, body.firstChild);
+ }
+ },
+
+ /**
+ * Initialization for the drag frame element. Must be called in the
+ * constructor of all subclasses
+ * @method initFrame
+ */
+ initFrame: function() {
+ this.createFrame();
+ },
+
+ applyConfig: function() {
+ YAHOO.util.DDProxy.superclass.applyConfig.call(this);
+
+ this.resizeFrame = (this.config.resizeFrame !== false);
+ this.centerFrame = (this.config.centerFrame);
+ this.setDragElId(this.config.dragElId || YAHOO.util.DDProxy.dragElId);
+ },
+
+ /**
+ * Resizes the drag frame to the dimensions of the clicked object, positions
+ * it over the object, and finally displays it
+ * @method showFrame
+ * @param {int} iPageX X click position
+ * @param {int} iPageY Y click position
+ * @private
+ */
+ showFrame: function(iPageX, iPageY) {
+ var el = this.getEl();
+ var dragEl = this.getDragEl();
+ var s = dragEl.style;
+
+ this._resizeProxy();
+
+ if (this.centerFrame) {
+ this.setDelta( Math.round(parseInt(s.width, 10)/2),
+ Math.round(parseInt(s.height, 10)/2) );
+ }
+
+ this.setDragElPos(iPageX, iPageY);
+
+ YAHOO.util.Dom.setStyle(dragEl, "visibility", "visible");
+ },
+
+ /**
+ * The proxy is automatically resized to the dimensions of the linked
+ * element when a drag is initiated, unless resizeFrame is set to false
+ * @method _resizeProxy
+ * @private
+ */
+ _resizeProxy: function() {
+ if (this.resizeFrame) {
+ var DOM = YAHOO.util.Dom;
+ var el = this.getEl();
+ var dragEl = this.getDragEl();
+
+ var bt = parseInt( DOM.getStyle(dragEl, "borderTopWidth" ), 10);
+ var br = parseInt( DOM.getStyle(dragEl, "borderRightWidth" ), 10);
+ var bb = parseInt( DOM.getStyle(dragEl, "borderBottomWidth" ), 10);
+ var bl = parseInt( DOM.getStyle(dragEl, "borderLeftWidth" ), 10);
+
+ if (isNaN(bt)) { bt = 0; }
+ if (isNaN(br)) { br = 0; }
+ if (isNaN(bb)) { bb = 0; }
+ if (isNaN(bl)) { bl = 0; }
+
+
+ var newWidth = Math.max(0, el.offsetWidth - br - bl);
+ var newHeight = Math.max(0, el.offsetHeight - bt - bb);
+
+
+ DOM.setStyle( dragEl, "width", newWidth + "px" );
+ DOM.setStyle( dragEl, "height", newHeight + "px" );
+ }
+ },
+
+ // overrides YAHOO.util.DragDrop
+ b4MouseDown: function(e) {
+ var x = YAHOO.util.Event.getPageX(e);
+ var y = YAHOO.util.Event.getPageY(e);
+ this.autoOffset(x, y);
+ this.setDragElPos(x, y);
+ },
+
+ // overrides YAHOO.util.DragDrop
+ b4StartDrag: function(x, y) {
+ // show the drag frame
+ this.showFrame(x, y);
+ },
+
+ // overrides YAHOO.util.DragDrop
+ b4EndDrag: function(e) {
+ YAHOO.util.Dom.setStyle(this.getDragEl(), "visibility", "hidden");
+ },
+
+ // overrides YAHOO.util.DragDrop
+ // By default we try to move the element to the last location of the frame.
+ // This is so that the default behavior mirrors that of YAHOO.util.DD.
+ endDrag: function(e) {
+ var DOM = YAHOO.util.Dom;
+ var lel = this.getEl();
+ var del = this.getDragEl();
+
+ // Show the drag frame briefly so we can get its position
+ // del.style.visibility = "";
+ DOM.setStyle(del, "visibility", "");
+
+ // Hide the linked element before the move to get around a Safari
+ // rendering bug.
+ //lel.style.visibility = "hidden";
+ DOM.setStyle(lel, "visibility", "hidden");
+ YAHOO.util.DDM.moveToEl(lel, del);
+ //del.style.visibility = "hidden";
+ DOM.setStyle(del, "visibility", "hidden");
+ //lel.style.visibility = "";
+ DOM.setStyle(lel, "visibility", "");
+ },
+
+ toString: function() {
+ return ("DDProxy " + this.id);
+ }
+
+});
+/**
+ * A DragDrop implementation that does not move, but can be a drop
+ * target. You would get the same result by simply omitting implementation
+ * for the event callbacks, but this way we reduce the processing cost of the
+ * event listener and the callbacks.
+ * @class DDTarget
+ * @extends YAHOO.util.DragDrop
+ * @constructor
+ * @param {String} id the id of the element that is a drop target
+ * @param {String} sGroup the group of related DragDrop objects
+ * @param {object} config an object containing configurable attributes
+ * Valid properties for DDTarget in addition to those in
+ * DragDrop:
+ * none
+ */
+YAHOO.util.DDTarget = function(id, sGroup, config) {
+ if (id) {
+ this.initTarget(id, sGroup, config);
+ }
+};
+
+// YAHOO.util.DDTarget.prototype = new YAHOO.util.DragDrop();
+YAHOO.extend(YAHOO.util.DDTarget, YAHOO.util.DragDrop, {
+ toString: function() {
+ return ("DDTarget " + this.id);
+ }
+});
diff --git a/frontend/beta/js/YUI/event.js b/frontend/beta/js/YUI/event.js
new file mode 100644
index 0000000..7bfac3b
--- a/dev/null
+++ b/frontend/beta/js/YUI/event.js
@@ -0,0 +1,1738 @@
+/*
+Copyright (c) 2006, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 0.12.0
+*/
+
+/**
+ * The CustomEvent class lets you define events for your application
+ * that can be subscribed to by one or more independent component.
+ *
+ * @param {String} type The type of event, which is passed to the callback
+ * when the event fires
+ * @param {Object} oScope The context the event will fire from. "this" will
+ * refer to this object in the callback. Default value:
+ * the window object. The listener can override this.
+ * @param {boolean} silent pass true to prevent the event from writing to
+ * the log system
+ * @namespace YAHOO.util
+ * @class CustomEvent
+ * @constructor
+ */
+YAHOO.util.CustomEvent = function(type, oScope, silent, signature) {
+
+ /**
+ * The type of event, returned to subscribers when the event fires
+ * @property type
+ * @type string
+ */
+ this.type = type;
+
+ /**
+ * The scope the the event will fire from by default. Defaults to the window
+ * obj
+ * @property scope
+ * @type object
+ */
+ this.scope = oScope || window;
+
+ /**
+ * By default all custom events are logged in the debug build, set silent
+ * to true to disable logging for this event.
+ * @property silent
+ * @type boolean
+ */
+ this.silent = silent;
+
+ /**
+ * Custom events support two styles of arguments provided to the event
+ * subscribers.
+ * ", + sourceAndDetail, + ":
", + msg, + "
"] : + + ["", label, " ", + totalTime, "ms (+", elapsedTime, ") ", + localTime, ": ", + sourceAndDetail, ": ", + msg,"
"]; + + return output.join(""); +}; + +/** + * Converts input chars "<", ">", and "&" to HTML entities. + * + * @method html2Text + * @param sHtml {String} String to convert. + * @private + */ +YAHOO.widget.LogReader.prototype.html2Text = function(sHtml) { + if(sHtml) { + sHtml += ""; + return sHtml.replace(/&/g, "&").replace(//g, ">"); + } + return ""; +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Private member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Internal class member to index multiple log reader instances. + * + * @property _memberName + * @static + * @type Number + * @default 0 + * @private + */ +YAHOO.widget.LogReader._index = 0; + +/** + * Name of LogReader instance. + * + * @property _sName + * @type String + * @private + */ +YAHOO.widget.LogReader.prototype._sName = null; + +/** + * A class member shared by all log readers if a container needs to be + * created during instantiation. Will be null if a container element never needs to + * be created on the fly, such as when the implementer passes in their own element. + * + * @property _elDefaultContainer + * @type HTMLElement + * @private + */ +YAHOO.widget.LogReader._elDefaultContainer = null; + +/** + * Buffer of log message objects for batch output. + * + * @property _buffer + * @type Object[] + * @private + */ +YAHOO.widget.LogReader.prototype._buffer = null; + +/** + * Number of log messages output to console. + * + * @property _consoleMsgCount + * @type Number + * @default 0 + * @private + */ +YAHOO.widget.LogReader.prototype._consoleMsgCount = 0; + +/** + * Date of last output log message. + * + * @property _lastTime + * @type Date + * @private + */ +YAHOO.widget.LogReader.prototype._lastTime = null; + +/** + * Batched output timeout ID. + * + * @property _timeout + * @type Number + * @private + */ +YAHOO.widget.LogReader.prototype._timeout = null; + +/** + * Array of filters for log message categories. + * + * @property _categoryFilters + * @type String[] + * @private + */ +YAHOO.widget.LogReader.prototype._categoryFilters = null; + +/** + * Array of filters for log message sources. + * + * @property _sourceFilters + * @type String[] + * @private + */ +YAHOO.widget.LogReader.prototype._sourceFilters = null; + +/** + * Log reader container element. + * + * @property _elContainer + * @type HTMLElement + * @private + */ +YAHOO.widget.LogReader.prototype._elContainer = null; + +/** + * Log reader header element. + * + * @property _elHd + * @type HTMLElement + * @private + */ +YAHOO.widget.LogReader.prototype._elHd = null; + +/** + * Log reader collapse element. + * + * @property _elCollapse + * @type HTMLElement + * @private + */ +YAHOO.widget.LogReader.prototype._elCollapse = null; + +/** + * Log reader collapse button element. + * + * @property _btnCollapse + * @type HTMLElement + * @private + */ +YAHOO.widget.LogReader.prototype._btnCollapse = null; + +/** + * Log reader title header element. + * + * @property _title + * @type HTMLElement + * @private + */ +YAHOO.widget.LogReader.prototype._title = null; + +/** + * Log reader console element. + * + * @property _elConsole + * @type HTMLElement + * @private + */ +YAHOO.widget.LogReader.prototype._elConsole = null; + +/** + * Log reader footer element. + * + * @property _elFt + * @type HTMLElement + * @private + */ +YAHOO.widget.LogReader.prototype._elFt = null; + +/** + * Log reader buttons container element. + * + * @property _elBtns + * @type HTMLElement + * @private + */ +YAHOO.widget.LogReader.prototype._elBtns = null; + +/** + * Container element for log reader category filter checkboxes. + * + * @property _elCategoryFilters + * @type HTMLElement + * @private + */ +YAHOO.widget.LogReader.prototype._elCategoryFilters = null; + +/** + * Container element for log reader source filter checkboxes. + * + * @property _elSourceFilters + * @type HTMLElement + * @private + */ +YAHOO.widget.LogReader.prototype._elSourceFilters = null; + +/** + * Log reader pause button element. + * + * @property _btnPause + * @type HTMLElement + * @private + */ +YAHOO.widget.LogReader.prototype._btnPause = null; + +/** + * Clear button element. + * + * @property _btnClear + * @type HTMLElement + * @private + */ +YAHOO.widget.LogReader.prototype._btnClear = null; + +///////////////////////////////////////////////////////////////////////////// +// +// Private methods +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Creates the UI for a category filter in the log reader footer element. + * + * @method _createCategoryCheckbox + * @param sCategory {String} Category name. + * @private + */ +YAHOO.widget.LogReader.prototype._createCategoryCheckbox = function(sCategory) { + var oSelf = this; + + if(this._elFt) { + var elParent = this._elCategoryFilters; + var filters = this._categoryFilters; + + var elFilter = elParent.appendChild(document.createElement("span")); + elFilter.className = "yui-log-filtergrp"; + // Append el at the end so IE 5.5 can set "type" attribute + // and THEN set checked property + var chkCategory = document.createElement("input"); + chkCategory.id = "yui-log-filter-" + sCategory + this._sName; + chkCategory.className = "yui-log-filter-" + sCategory; + chkCategory.type = "checkbox"; + chkCategory.category = sCategory; + chkCategory = elFilter.appendChild(chkCategory); + chkCategory.checked = true; + + // Add this checked filter to the internal array of filters + filters.push(sCategory); + // Subscribe to the click event + YAHOO.util.Event.addListener(chkCategory,'click',oSelf._onCheckCategory,oSelf); + + // Create and class the text label + var lblCategory = elFilter.appendChild(document.createElement("label")); + lblCategory.htmlFor = chkCategory.id; + lblCategory.className = sCategory; + lblCategory.innerHTML = sCategory; + } +}; + +/** + * Creates a checkbox in the log reader footer element to filter by source. + * + * @method _createSourceCheckbox + * @param sSource {String} Source name. + * @private + */ +YAHOO.widget.LogReader.prototype._createSourceCheckbox = function(sSource) { + var oSelf = this; + + if(this._elFt) { + var elParent = this._elSourceFilters; + var filters = this._sourceFilters; + + var elFilter = elParent.appendChild(document.createElement("span")); + elFilter.className = "yui-log-filtergrp"; + + // Append el at the end so IE 5.5 can set "type" attribute + // and THEN set checked property + var chkSource = document.createElement("input"); + chkSource.id = "yui-log-filter" + sSource + this._sName; + chkSource.className = "yui-log-filter" + sSource; + chkSource.type = "checkbox"; + chkSource.source = sSource; + chkSource = elFilter.appendChild(chkSource); + chkSource.checked = true; + + // Add this checked filter to the internal array of filters + filters.push(sSource); + // Subscribe to the click event + YAHOO.util.Event.addListener(chkSource,'click',oSelf._onCheckSource,oSelf); + + // Create and class the text label + var lblSource = elFilter.appendChild(document.createElement("label")); + lblSource.htmlFor = chkSource.id; + lblSource.className = sSource; + lblSource.innerHTML = sSource; + } +}; + +/** + * Reprints all log messages in the stack through filters. + * + * @method _filterLogs + * @private + */ +YAHOO.widget.LogReader.prototype._filterLogs = function() { + // Reprint stack with new filters + if (this._elConsole !== null) { + this._clearConsole(); + this._printToConsole(YAHOO.widget.Logger.getStack()); + } +}; + +/** + * Clears all outputted log messages from the console and resets the time of the + * last output log message. + * + * @method _clearConsole + * @private + */ +YAHOO.widget.LogReader.prototype._clearConsole = function() { + // Clear the buffer of any pending messages + this._timeout = null; + this._buffer = []; + this._consoleMsgCount = 0; + + // Reset the rolling timer + this._lastTime = YAHOO.widget.Logger.getStartTime(); + + var elConsole = this._elConsole; + while(elConsole.hasChildNodes()) { + elConsole.removeChild(elConsole.firstChild); + } +}; + +/** + * Sends buffer of log messages to output and clears buffer. + * + * @method _printBuffer + * @private + */ +YAHOO.widget.LogReader.prototype._printBuffer = function() { + this._timeout = null; + + if(this._elConsole !== null) { + var thresholdMax = this.thresholdMax; + thresholdMax = (thresholdMax && !isNaN(thresholdMax)) ? thresholdMax : 500; + if(this._consoleMsgCount < thresholdMax) { + var entries = []; + for (var i=0; itag (for wrapping) + var container = (this.verboseOutput) ? "CODE" : "PRE"; + var oNewElement = (this.newestOnTop) ? + this._elConsole.insertBefore( + document.createElement(container),this._elConsole.firstChild): + this._elConsole.appendChild(document.createElement(container)); + + oNewElement.innerHTML = output; + this._consoleMsgCount++; + this._lastTime = entry.time.getTime(); + } + } +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Private event handlers +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Handles Logger's categoryCreateEvent. + * + * @method _onCategoryCreate + * @param sType {String} The event. + * @param aArgs {Object[]} Data passed from event firer. + * @param oSelf {Object} The LogReader instance. + * @private + */ +YAHOO.widget.LogReader.prototype._onCategoryCreate = function(sType, aArgs, oSelf) { + var category = aArgs[0]; + if(oSelf._elFt) { + oSelf._createCategoryCheckbox(category); + } +}; + +/** + * Handles Logger's sourceCreateEvent. + * + * @method _onSourceCreate + * @param sType {String} The event. + * @param aArgs {Object[]} Data passed from event firer. + * @param oSelf {Object} The LogReader instance. + * @private + */ +YAHOO.widget.LogReader.prototype._onSourceCreate = function(sType, aArgs, oSelf) { + var source = aArgs[0]; + if(oSelf._elFt) { + oSelf._createSourceCheckbox(source); + } +}; + +/** + * Handles check events on the category filter checkboxes. + * + * @method _onCheckCategory + * @param v {HTMLEvent} The click event. + * @param oSelf {Object} The LogReader instance. + * @private + */ +YAHOO.widget.LogReader.prototype._onCheckCategory = function(v, oSelf) { + var newFilter = this.category; + var filtersArray = oSelf._categoryFilters; + + if(!this.checked) { // Remove category from filters + for(var i=0; i0) { + // Substring until first space + sClass = sSource.substring(0,spaceIndex); + // The rest of the source + sDetail = sSource.substring(spaceIndex,sSource.length); + } + else { + sClass = sSource; + } + if(this._isNewSource(sClass)) { + this._createNewSource(sClass); + } + } + + var timestamp = new Date(); + var logEntry = new YAHOO.widget.LogMsg({ + msg: sMsg, + time: timestamp, + category: sCategory, + source: sClass, + sourceDetail: sDetail + }); + + var stack = this._stack; + var maxStackEntries = this.maxStackEntries; + if(maxStackEntries && !isNaN(maxStackEntries) && + (stack.length >= maxStackEntries)) { + stack.shift(); + } + stack.push(logEntry); + this.newLogEvent.fire(logEntry); + + if(this._browserConsoleEnabled) { + this._printToBrowserConsole(logEntry); + } + return true; + } + else { + return false; + } +}; + +/** + * Resets internal stack and startTime, enables Logger, and fires logResetEvent. + * + * @method reset + */ +YAHOO.widget.Logger.reset = function() { + this._stack = []; + this._startTime = new Date().getTime(); + this.loggerEnabled = true; + this.log("Logger reset"); + this.logResetEvent.fire(); +}; + +/** + * Public accessor to internal stack of log message objects. + * + * @method getStack + * @return {Object[]} Array of log message objects. + */ +YAHOO.widget.Logger.getStack = function() { + return this._stack; +}; + +/** + * Public accessor to internal start time. + * + * @method getStartTime + * @return {Date} Internal date of when Logger singleton was initialized. + */ +YAHOO.widget.Logger.getStartTime = function() { + return this._startTime; +}; + +/** + * Disables output to the browser's global console.log() function, which is used + * by the Firebug extension to Firefox as well as Safari. + * + * @method disableBrowserConsole + */ +YAHOO.widget.Logger.disableBrowserConsole = function() { + YAHOO.log("Logger output to the function console.log() has been disabled."); + this._browserConsoleEnabled = false; +}; + +/** + * Enables output to the browser's global console.log() function, which is used + * by the Firebug extension to Firefox as well as Safari. + * + * @method enableBrowserConsole + */ +YAHOO.widget.Logger.enableBrowserConsole = function() { + this._browserConsoleEnabled = true; + YAHOO.log("Logger output to the function console.log() has been enabled."); +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Public events +// +///////////////////////////////////////////////////////////////////////////// + + /** + * Fired when a new category has been created. + * + * @event categoryCreateEvent + * @param sCategory {String} Category name. + */ +YAHOO.widget.Logger.categoryCreateEvent = + new YAHOO.util.CustomEvent("categoryCreate", this, true); + + /** + * Fired when a new source has been named. + * + * @event sourceCreateEvent + * @param sSource {String} Source name. + */ +YAHOO.widget.Logger.sourceCreateEvent = + new YAHOO.util.CustomEvent("sourceCreate", this, true); + + /** + * Fired when a new log message has been created. + * + * @event newLogEvent + * @param sMsg {String} Log message. + */ +YAHOO.widget.Logger.newLogEvent = new YAHOO.util.CustomEvent("newLog", this, true); + +/** + * Fired when the Logger has been reset has been created. + * + * @event logResetEvent + */ +YAHOO.widget.Logger.logResetEvent = new YAHOO.util.CustomEvent("logReset", this, true); + +///////////////////////////////////////////////////////////////////////////// +// +// Private methods +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Creates a new category of log messages and fires categoryCreateEvent. + * + * @method _createNewCategory + * @param sCategory {String} Category name. + * @private + */ +YAHOO.widget.Logger._createNewCategory = function(sCategory) { + this.categories.push(sCategory); + this.categoryCreateEvent.fire(sCategory); +}; + +/** + * Checks to see if a category has already been created. + * + * @method _isNewCategory + * @param sCategory {String} Category name. + * @return {Boolean} Returns true if category is unknown, else returns false. + * @private + */ +YAHOO.widget.Logger._isNewCategory = function(sCategory) { + for(var i=0; i < this.categories.length; i++) { + if(sCategory == this.categories[i]) { + return false; + } + } + return true; +}; + +/** + * Creates a new source of log messages and fires sourceCreateEvent. + * + * @method _createNewSource + * @param sSource {String} Source name. + * @private + */ +YAHOO.widget.Logger._createNewSource = function(sSource) { + this.sources.push(sSource); + this.sourceCreateEvent.fire(sSource); +}; + +/** + * Checks to see if a source already exists. + * + * @method _isNewSource + * @param sSource {String} Source name. + * @return {Boolean} Returns true if source is unknown, else returns false. + * @private + */ +YAHOO.widget.Logger._isNewSource = function(sSource) { + if(sSource) { + for(var i=0; i < this.sources.length; i++) { + if(sSource == this.sources[i]) { + return false; + } + } + return true; + } +}; + +/** + * Outputs a log message to global console.log() function. + * + * @method _printToBrowserConsole + * @param oEntry {Object} Log entry object. + * @private + */ +YAHOO.widget.Logger._printToBrowserConsole = function(oEntry) { + if(window.console && console.log) { + var category = oEntry.category; + var label = oEntry.category.substring(0,4).toUpperCase(); + + var time = oEntry.time; + if (time.toLocaleTimeString) { + var localTime = time.toLocaleTimeString(); + } + else { + localTime = time.toString(); + } + + var msecs = time.getTime(); + var elapsedTime = (YAHOO.widget.Logger._lastTime) ? + (msecs - YAHOO.widget.Logger._lastTime) : 0; + YAHOO.widget.Logger._lastTime = msecs; + + var output = + localTime + " (" + + elapsedTime + "ms): " + + oEntry.source + ": " + + oEntry.msg; + + console.log(output); + } +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Private event handlers +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Handles logging of messages due to window error events. + * + * @method _onWindowError + * @param sMsg {String} The error message. + * @param sUrl {String} URL of the error. + * @param sLine {String} Line number of the error. + * @private + */ +YAHOO.widget.Logger._onWindowError = function(sMsg,sUrl,sLine) { + // Logger is not in scope of this event handler + try { + YAHOO.widget.Logger.log(sMsg+' ('+sUrl+', line '+sLine+')', "window"); + if(YAHOO.widget.Logger._origOnWindowError) { + YAHOO.widget.Logger._origOnWindowError(); + } + } + catch(e) { + return false; + } +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Enable handling of native JavaScript errors +// NB: Not all browsers support the window.onerror event +// +///////////////////////////////////////////////////////////////////////////// + +if(window.onerror) { + // Save any previously defined handler to call + YAHOO.widget.Logger._origOnWindowError = window.onerror; +} +window.onerror = YAHOO.widget.Logger._onWindowError; + +///////////////////////////////////////////////////////////////////////////// +// +// First log +// +///////////////////////////////////////////////////////////////////////////// + +YAHOO.widget.Logger.log("Logger initialized"); + diff --git a/frontend/beta/js/YUI/menu.js b/frontend/beta/js/YUI/menu.js new file mode 100644 index 0000000..50eb0cf --- a/dev/null +++ b/frontend/beta/js/YUI/menu.js @@ -0,0 +1,6780 @@ +/* +Copyright (c) 2006, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.com/yui/license.txt +version: 0.12.0 +*/ + +/** +* @module menu +* @description The Menu Library features a collection of widgets that make +* it easy to add menus to your website or web application. With the Menu +* Library you can create website fly-out menus, customized context menus, or +* application-style menu bars with just a small amount of scripting.
+*+*
+* @title Menu Library +* @namespace YAHOO.widget +* @requires Event, Dom, Container +*/ +(function() { + +var Dom = YAHOO.util.Dom; +var Event = YAHOO.util.Event; + +/** +* Singleton that manages a collection of all menus and menu items. Listens for +* DOM events at the document level and dispatches the events to the +* corresponding menu or menu item. +* +* @namespace YAHOO.widget +* @class MenuManager +* @static +*/ +YAHOO.widget.MenuManager = new function() { + + // Private member variables + + // Flag indicating if the DOM event handlers have been attached + + var m_bInitializedEventHandlers = false; + + // Collection of menus + + var m_oMenus = {}; + + + // Collection of menu items + + var m_oItems = {}; + + // Collection of visible menus + + var m_oVisibleMenus = {}; + + // Logger + + + // Private methods + + /** + * Adds an item to the collection of known menu items. + * @private + * @param {YAHOO.widget.MenuItem} p_oItem Object specifying the MenuItem + * instance to be added. + */ + var addItem = function(p_oItem) { + + var sYUIId = Dom.generateId(); + + if(p_oItem && m_oItems[sYUIId] != p_oItem) { + + p_oItem.element.setAttribute("yuiid", sYUIId); + + m_oItems[sYUIId] = p_oItem; + + p_oItem.destroyEvent.subscribe(onItemDestroy, p_oItem); + + + } + + }; + + /** + * Removes an item from the collection of known menu items. + * @private + * @param {YAHOO.widget.MenuItem} p_oItem Object specifying the MenuItem + * instance to be removed. + */ + var removeItem = function(p_oItem) { + + var sYUIId = p_oItem.element.getAttribute("yuiid"); + + if(sYUIId && m_oItems[sYUIId]) { + + delete m_oItems[sYUIId]; + + + } + + }; + + /** + * Finds the root DIV node of a menu or the root LI node of a menu item. + * @private + * @param {HTMLElement} p_oElement Object specifying + * an HTML element. + */ + var getMenuRootElement = function(p_oElement) { + + var oParentNode; + + if(p_oElement && p_oElement.tagName) { + + switch(p_oElement.tagName.toUpperCase()) { + + case "DIV": + + oParentNode = p_oElement.parentNode; + + // Check if the DIV is the inner "body" node of a menu + + if( + Dom.hasClass(p_oElement, "bd") && + oParentNode && + oParentNode.tagName && + oParentNode.tagName.toUpperCase() == "DIV" + ) { + + return oParentNode; + + } + else { + + return p_oElement; + + } + + break; + + case "LI": + + return p_oElement; + + default: + + oParentNode = p_oElement.parentNode; + + if(oParentNode) { + + return getMenuRootElement(oParentNode); + + } + + break; + + } + + } + + }; + + // Private event handlers + + /** + * Generic, global event handler for all of a menu's DOM-based + * events. This listens for events against the document object. If the + * target of a given event is a member of a menu or menu item's DOM, the + * instance's corresponding Custom Event is fired. + * @private + * @param {Event} p_oEvent Object representing the DOM event object passed + * back by the event utility (YAHOO.util.Event). + */ + var onDOMEvent = function(p_oEvent) { + + // Get the target node of the DOM event + + var oTarget = Event.getTarget(p_oEvent); + + // See if the target of the event was a menu, or a menu item + + var oElement = getMenuRootElement(oTarget); + + var oMenuItem; + var oMenu; + + if(oElement) { + + var sTagName = oElement.tagName.toUpperCase(); + + if(sTagName == "LI") { + + var sYUIId = oElement.getAttribute("yuiid"); + + if(sYUIId) { + + oMenuItem = m_oItems[sYUIId]; + oMenu = oMenuItem.parent; + + } + + } + else if(sTagName == "DIV") { + + if(oElement.id) { + + oMenu = m_oMenus[oElement.id]; + + } + + } + + } + + if(oMenu) { + + // Map of DOM event names to CustomEvent names + + var oEventTypes = { + "click": "clickEvent", + "mousedown": "mouseDownEvent", + "mouseup": "mouseUpEvent", + "mouseover": "mouseOverEvent", + "mouseout": "mouseOutEvent", + "keydown": "keyDownEvent", + "keyup": "keyUpEvent", + "keypress": "keyPressEvent" + }; + + var sCustomEventType = oEventTypes[p_oEvent.type]; + + // Fire the Custom Even that corresponds the current DOM event + + if(oMenuItem && !oMenuItem.cfg.getProperty("disabled")) { + + oMenuItem[sCustomEventType].fire(p_oEvent); + + } + + oMenu[sCustomEventType].fire(p_oEvent, oMenuItem); + + } + else if(p_oEvent.type == "mousedown") { + + /* + If the target of the event wasn't a menu, hide all + dynamically positioned menus + */ + + var oActiveItem; + + for(var i in m_oMenus) { + + if(m_oMenus.hasOwnProperty(i)) { + + oMenu = m_oMenus[i]; + + if( + oMenu.cfg.getProperty("clicktohide") && + oMenu.cfg.getProperty("position") == "dynamic" + ) { + + oMenu.hide(); + + } + else { + + oMenu.clearActiveItem(true); + + } + + } + + } + + } + + }; + + /** + * "destroy" event handler for a menu. + * @private + * @param {String} p_sType String representing the name of the event that + * was fired. + * @param {Array} p_aArgs Array of arguments sent when the event was fired. + * @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that + * fired the event. + */ + var onMenuDestroy = function(p_sType, p_aArgs, p_oMenu) { + + this.removeMenu(p_oMenu); + + }; + + /** + * "destroy" event handler for a MenuItem instance. + * @private + * @param {String} p_sType String representing the name of the event that + * was fired. + * @param {Array} p_aArgs Array of arguments sent when the event was fired. + * @param {YAHOO.widget.MenuItem} p_oItem Object representing the menu item + * that fired the event. + */ + var onItemDestroy = function(p_sType, p_aArgs, p_oItem) { + + var sYUIId = p_oItem.element.getAttribute("yuiid"); + + if(sYUIId) { + + delete m_oItems[sYUIId]; + + } + + }; + + /** + * Event handler for when the "visible" configuration property + * of a Menu instance changes. + * @private + * @param {String} p_sType String representing the name of the event that + * was fired. + * @param {Array} p_aArgs Array of arguments sent when the event was fired. + * @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that + * fired the event. + */ + var onMenuVisibleConfigChange = function(p_sType, p_aArgs, p_oMenu) { + + var bVisible = p_aArgs[0]; + + if(bVisible) { + + m_oVisibleMenus[p_oMenu.id] = p_oMenu; + + + } + else if(m_oVisibleMenus[p_oMenu.id]) { + + delete m_oVisibleMenus[p_oMenu.id]; + + + } + + }; + + /** + * "itemadded" event handler for a Menu instance. + * @private + * @param {String} p_sType String representing the name of the event that + * was fired. + * @param {Array} p_aArgs Array of arguments sent when the event was fired. + */ + var onItemAdded = function(p_sType, p_aArgs) { + + addItem(p_aArgs[0]); + + }; + + + /** + * "itemremoved" event handler for a Menu instance. + * @private + * @param {String} p_sType String representing the name of the event that + * was fired. + * @param {Array} p_aArgs Array of arguments sent when the event was fired. + */ + var onItemRemoved = function(p_sType, p_aArgs) { + + removeItem(p_aArgs[0]); + + }; + + // Privileged methods + + /** + * @method addMenu + * @description Adds a menu to the collection of known menus. + * @param {YAHOO.widget.Menu} p_oMenu Object specifying the Menu instance + * to be added. + */ + this.addMenu = function(p_oMenu) { + + if(p_oMenu && p_oMenu.id && !m_oMenus[p_oMenu.id]) { + + m_oMenus[p_oMenu.id] = p_oMenu; + + + if(!m_bInitializedEventHandlers) { + + var oDoc = document; + + Event.addListener(oDoc, "mouseover", onDOMEvent, this, true); + Event.addListener(oDoc, "mouseout", onDOMEvent, this, true); + Event.addListener(oDoc, "mousedown", onDOMEvent, this, true); + Event.addListener(oDoc, "mouseup", onDOMEvent, this, true); + Event.addListener(oDoc, "click", onDOMEvent, this, true); + Event.addListener(oDoc, "keydown", onDOMEvent, this, true); + Event.addListener(oDoc, "keyup", onDOMEvent, this, true); + Event.addListener(oDoc, "keypress", onDOMEvent, this, true); + + m_bInitializedEventHandlers = true; + + + } + + p_oMenu.destroyEvent.subscribe(onMenuDestroy, p_oMenu, this); + + p_oMenu.cfg.subscribeToConfigEvent( + "visible", + onMenuVisibleConfigChange, + p_oMenu + ); + + p_oMenu.itemAddedEvent.subscribe(onItemAdded); + p_oMenu.itemRemovedEvent.subscribe(onItemRemoved); + + + } + + }; + + /** + * @method removeMenu + * @description Removes a menu from the collection of known menus. + * @param {YAHOO.widget.Menu} p_oMenu Object specifying the Menu instance + * to be removed. + */ + this.removeMenu = function(p_oMenu) { + + if(p_oMenu && m_oMenus[p_oMenu.id]) { + + delete m_oMenus[p_oMenu.id]; + + + } + + }; + + /** + * @method hideVisible + * @description Hides all visible, dynamically positioned menus. + */ + this.hideVisible = function() { + + var oMenu; + + for(var i in m_oVisibleMenus) { + + if(m_oVisibleMenus.hasOwnProperty(i)) { + + oMenu = m_oVisibleMenus[i]; + + if(oMenu.cfg.getProperty("position") == "dynamic") { + + oMenu.hide(); + + } + + } + + } + + }; + + /** + * @method getMenus + * @description Returns an array of all menus registered with the + * menu manger. + * @return {Array} + */ + this.getMenus = function() { + + return m_oMenus; + + }; + + /** + * @method getMenu + * @description Returns a menu with the specified id. + * @param {String} p_sId String specifying the id of the menu to + * be retrieved. + * @return {YAHOO.widget.Menu} + */ + this.getMenu = function(p_sId) { + + if(m_oMenus[p_sId]) { + + return m_oMenus[p_sId]; + + } + + }; + + + /** + * @method toString + * @description Returns a string representing the menu manager. + * @return {String} + */ + this.toString = function() { + + return ("MenuManager"); + + }; + +}; + +})(); + +(function() { + +var Dom = YAHOO.util.Dom; +var Event = YAHOO.util.Event; + +/** +* The Menu class creates a container that holds a vertical list representing +* a set of options or commands. Menu is the base class for all +* menu containers. +* @param {String} p_oElement String specifying the id attribute of the +*- Screen-reader accessibility.
+*- Keyboard and mouse navigation.
+*- A rich event model that provides access to all of a menu's +* interesting moments.
+*- Support for +* Progressive +* Enhancement; Menus can be created from simple, +* semantic markup on the page or purely through JavaScript.
+*<div>
element of the menu. +* @param {String} p_oElement String specifying the id attribute of the +*<select>
element to be used as the data source +* for the menu. +* @param {HTMLDivElement} p_oElement Object +* specifying the<div>
element of the menu. +* @param {HTMLSelectElement} p_oElement +* Object specifying the<select>
element to be used as +* the data source for the menu. +* @param {Object} p_oConfig Optional. Object literal specifying the +* configuration for the menu. See configuration class documentation for +* more details. +* @namespace YAHOO.widget +* @class Menu +* @constructor +* @extends YAHOO.widget.Overlay +*/ +YAHOO.widget.Menu = function(p_oElement, p_oConfig) { + + if(p_oConfig) { + + this.parent = p_oConfig.parent; + + this.lazyLoad = p_oConfig.lazyLoad || p_oConfig.lazyload; + + this.itemData = p_oConfig.itemData || p_oConfig.itemdata; + + } + + YAHOO.widget.Menu.superclass.constructor.call( + this, + p_oElement, + p_oConfig + ); + +}; + +YAHOO.extend(YAHOO.widget.Menu, YAHOO.widget.Overlay, { + +// Constants + +/** +* @property CSS_CLASS_NAME +* @description String representing the CSS class(es) to be applied to the +* menu's<div>
element. +* @default "yuimenu" +* @final +* @type String +*/ +CSS_CLASS_NAME: "yuimenu", + +/** +* @property ITEM_TYPE +* @description Object representing the type of menu item to instantiate and +* add when parsing the child nodes (either<li>
element, +*<optgroup>
element or<option>
) +* of the menu's source HTML element. +* @default YAHOO.widget.MenuItem +* @final +* @type YAHOO.widget.MenuItem +*/ +ITEM_TYPE: null, + +/** +* @property GROUP_TITLE_TAG_NAME +* @description String representing the tagname of the HTML element used to +* title the menu's item groups. +* @default H6 +* @final +* @type String +*/ +GROUP_TITLE_TAG_NAME: "h6", + +// Private properties + +/** +* @property _nHideDelayId +* @description Number representing the time-out setting used to cancel the +* hiding of a menu. +* @default null +* @private +* @type Number +*/ +_nHideDelayId: null, + +/** +* @property _nShowDelayId +* @description Number representing the time-out setting used to cancel the +* showing of a menu. +* @default null +* @private +* @type Number +*/ +_nShowDelayId: null, + +/** +* @property _hideDelayEventHandlersAssigned +* @description Boolean indicating if the "mouseover" and "mouseout" event +* handlers used for hiding the menu via a call to "window.setTimeout" have +* already been assigned. +* @default false +* @private +* @type Boolean +*/ +_hideDelayEventHandlersAssigned: false, + +/** +* @property _bHandledMouseOverEvent +* @description Boolean indicating the current state of the menu's +* "mouseover" event. +* @default false +* @private +* @type Boolean +*/ +_bHandledMouseOverEvent: false, + +/** +* @property _bHandledMouseOutEvent +* @description Boolean indicating the current state of the menu's +* "mouseout" event. +* @default false +* @private +* @type Boolean +*/ +_bHandledMouseOutEvent: false, + +/** +* @property _aGroupTitleElements +* @description Array of HTML element used to title groups of menu items. +* @default [] +* @private +* @type Array +*/ +_aGroupTitleElements: null, + +/** +* @property _aItemGroups +* @description Array of menu items. +* @default [] +* @private +* @type Array +*/ +_aItemGroups: null, + +/** +* @property _aListElements +* @description Array of<ul>
elements, each of which is +* the parent node for each item's<li>
element. +* @default [] +* @private +* @type Array +*/ +_aListElements: null, + +// Public properties + +/** +* @property lazyLoad +* @description Boolean indicating if the menu's "lazy load" feature is +* enabled. If set to "true," initialization and rendering of the menu's +* items will be deferred until the first time it is made visible. This +* property should be set via the constructor using the configuration +* object literal. +* @default false +* @type Boolean +*/ +lazyLoad: false, + +/** +* @property itemData +* @description Array of items to be added to the menu. The array can contain +* strings representing the text for each item to be created, object literals +* representing the menu item configuration properties, or MenuItem instances. +* This property should be set via the constructor using the configuration +* object literal. +* @default null +* @type Array +*/ +itemData: null, + +/** +* @property activeItem +* @description Object reference to the item in the menu that has focus. +* @default null +* @type YAHOO.widget.MenuItem +*/ +activeItem: null, + +/** +* @property parent +* @description Object reference to the menu's parent menu or menu item. +* This property can be set via the constructor using the configuration +* object literal. +* @default null +* @type YAHOO.widget.MenuItem +*/ +parent: null, + +/** +* @property srcElement +* @description Object reference to the HTML element (either +*<select>
or<div>
) used to +* create the menu. +* @default null +* @type HTMLSelectElement|HTMLDivElement +*/ +srcElement: null, + +// Events + +/** +* @event mouseOverEvent +* @description Fires when the mouse has entered the menu. Passes back +* the DOM Event object as an argument. +*/ +mouseOverEvent: null, + +/** +* @event mouseOutEvent +* @description Fires when the mouse has left the menu. Passes back the DOM +* Event object as an argument. +* @type YAHOO.util.CustomEvent +*/ +mouseOutEvent: null, + +/** +* @event mouseDownEvent +* @description Fires when the user mouses down on the menu. Passes back the +* DOM Event object as an argument. +* @type YAHOO.util.CustomEvent +*/ +mouseDownEvent: null, + +/** +* @event mouseUpEvent +* @description Fires when the user releases a mouse button while the mouse is +* over the menu. Passes back the DOM Event object as an argument. +* @type YAHOO.util.CustomEvent +*/ +mouseUpEvent: null, + +/** +* @event clickEvent +* @description Fires when the user clicks the on the menu. Passes back the +* DOM Event object as an argument. +* @type YAHOO.util.CustomEvent +*/ +clickEvent: null, + +/** +* @event keyPressEvent +* @description Fires when the user presses an alphanumeric key when one of the +* menu's items has focus. Passes back the DOM Event object as an argument. +* @type YAHOO.util.CustomEvent +*/ +keyPressEvent: null, + +/** +* @event keyDownEvent +* @description Fires when the user presses a key when one of the menu's items +* has focus. Passes back the DOM Event object as an argument. +* @type YAHOO.util.CustomEvent +*/ +keyDownEvent: null, + +/** +* @event keyUpEvent +* @description Fires when the user releases a key when one of the menu's items +* has focus. Passes back the DOM Event object as an argument. +* @type YAHOO.util.CustomEvent +*/ +keyUpEvent: null, + +/** +* @event itemAddedEvent +* @description Fires when an item is added to the menu. +* @type YAHOO.util.CustomEvent +*/ +itemAddedEvent: null, + +/** +* @event itemRemovedEvent +* @description Fires when an item is removed to the menu. +* @type YAHOO.util.CustomEvent +*/ +itemRemovedEvent: null, + +/** +* @method init +* @description The Menu class's initialization method. This method is +* automatically called by the constructor, and sets up all DOM references +* for pre-existing markup, and creates required markup if it is not +* already present. +* @param {String} p_oElement String specifying the id attribute of the +*<div>
element of the menu. +* @param {String} p_oElement String specifying the id attribute of the +*<select>
element to be used as the data source +* for the menu. +* @param {HTMLDivElement} p_oElement Object +* specifying the<div>
element of the menu. +* @param {HTMLSelectElement} p_oElement +* Object specifying the<select>
element to be used as +* the data source for the menu. +* @param {Object} p_oConfig Optional. Object literal specifying the +* configuration for the menu. See configuration class documentation for +* more details. +*/ +init: function(p_oElement, p_oConfig) { + + this._aItemGroups = []; + this._aListElements = []; + this._aGroupTitleElements = []; + + if(!this.ITEM_TYPE) { + + this.ITEM_TYPE = YAHOO.widget.MenuItem; + + } + + var oElement; + + if(typeof p_oElement == "string") { + + oElement = document.getElementById(p_oElement); + + } + else if(p_oElement.tagName) { + + oElement = p_oElement; + + } + + if(oElement && oElement.tagName) { + + switch(oElement.tagName.toUpperCase()) { + + case "DIV": + + this.srcElement = oElement; + + if(!oElement.id) { + + oElement.setAttribute("id", Dom.generateId()); + + } + + /* + Note: we don't pass the user config in here yet + because we only want it executed once, at the lowest + subclass level. + */ + + YAHOO.widget.Menu.superclass.init.call(this, oElement); + + this.beforeInitEvent.fire(YAHOO.widget.Menu); + + + break; + + case "SELECT": + + this.srcElement = oElement; + + + /* + The source element is not something that we can use + outright, so we need to create a new Overlay + + Note: we don't pass the user config in here yet + because we only want it executed once, at the lowest + subclass level. + */ + + YAHOO.widget.Menu.superclass.init.call(this, Dom.generateId()); + + this.beforeInitEvent.fire(YAHOO.widget.Menu); + + break; + + } + + } + else { + + /* + Note: we don't pass the user config in here yet + because we only want it executed once, at the lowest + subclass level. + */ + + YAHOO.widget.Menu.superclass.init.call(this, p_oElement); + + this.beforeInitEvent.fire(YAHOO.widget.Menu); + + } + + if(this.element) { + + var oEl = this.element; + + Dom.addClass(oEl, this.CSS_CLASS_NAME); + + // Subscribe to Custom Events + + this.initEvent.subscribe(this._onInit, this, true); + this.beforeRenderEvent.subscribe(this._onBeforeRender, this, true); + this.renderEvent.subscribe(this._onRender, this, true); + this.beforeShowEvent.subscribe(this._onBeforeShow, this, true); + this.showEvent.subscribe(this._onShow, this, true); + this.beforeHideEvent.subscribe(this._onBeforeHide, this, true); + this.mouseOverEvent.subscribe(this._onMouseOver, this, true); + this.mouseOutEvent.subscribe(this._onMouseOut, this, true); + this.clickEvent.subscribe(this._onClick, this, true); + this.keyDownEvent.subscribe(this._onKeyDown, this, true); + + if(p_oConfig) { + + this.cfg.applyConfig(p_oConfig, true); + + } + + // Register the Menu instance with the MenuManager + + YAHOO.widget.MenuManager.addMenu(this); + + + this.initEvent.fire(YAHOO.widget.Menu); + + } + +}, + +// Private methods + +/** +* @method _initSubTree +* @description Iterates the childNodes of the source element to find nodes +* used to instantiate menu and menu items. +* @private +*/ +_initSubTree: function() { + + var oNode; + + if(this.srcElement.tagName == "DIV") { + + /* + Populate the collection of item groups and item + group titles + */ + + oNode = this.body.firstChild; + + var nGroup = 0; + var sGroupTitleTagName = this.GROUP_TITLE_TAG_NAME.toUpperCase(); + + do { + + if(oNode && oNode.tagName) { + + switch(oNode.tagName.toUpperCase()) { + + case sGroupTitleTagName: + + this._aGroupTitleElements[nGroup] = oNode; + + break; + + case "UL": + + this._aListElements[nGroup] = oNode; + this._aItemGroups[nGroup] = []; + nGroup++; + + break; + + } + + } + + } + while((oNode = oNode.nextSibling)); + + /* + Apply the "first-of-type" class to the first UL to mimic + the "first-of-type" CSS3 psuedo class. + */ + + if(this._aListElements[0]) { + + Dom.addClass(this._aListElements[0], "first-of-type"); + + } + + } + + oNode = null; + + if(this.srcElement.tagName) { + + switch(this.srcElement.tagName.toUpperCase()) { + + case "DIV": + + if(this._aListElements.length > 0) { + + + var i = this._aListElements.length - 1; + + do { + + oNode = this._aListElements[i].firstChild; + + + do { + + if(oNode && oNode.tagName) { + + switch(oNode.tagName.toUpperCase()) { + + case "LI": + + + this.addItem( + new this.ITEM_TYPE( + oNode, + { parent: this } + ), + i + ); + + break; + + } + + } + + } + while((oNode = oNode.nextSibling)); + + } + while(i--); + + } + + break; + + case "SELECT": + + + oNode = this.srcElement.firstChild; + + do { + + if(oNode && oNode.tagName) { + + switch(oNode.tagName.toUpperCase()) { + + case "OPTGROUP": + case "OPTION": + + + this.addItem( + new this.ITEM_TYPE( + oNode, + { parent: this } + ) + ); + + break; + + } + + } + + } + while((oNode = oNode.nextSibling)); + + break; + + } + + } + +}, + +/** +* @method _getFirstEnabledItem +* @description Returns the first enabled item in the menu. +* @return {YAHOO.widget.MenuItem} +* @private +*/ +_getFirstEnabledItem: function() { + + var nGroups = this._aItemGroups.length; + var oItem; + var aItemGroup; + + for(var i=0; i= aGroup.length); + + if(aGroup[p_nItemIndex]) { + + aGroup.splice(p_nItemIndex, 0, oItem); + + } + else { + + aGroup[p_nItemIndex] = oItem; + + } + + oGroupItem = aGroup[p_nItemIndex]; + + if(oGroupItem) { + + if( + bAppend && + ( + !oGroupItem.element.parentNode || + oGroupItem.element.parentNode.nodeType == 11 + ) + ) { + + this._aListElements[nGroupIndex].appendChild( + oGroupItem.element + ); + + } + else { + + + /** + * Returns the next sibling of an item in an array. + * @private + * @param {p_aArray} Array to search. + * @param {p_nStartIndex} Number indicating the index to + * start searching the array. + * @return {Object} + */ + var getNextItemSibling = + + function(p_aArray, p_nStartIndex) { + + return ( + p_aArray[p_nStartIndex] || + getNextItemSibling( + p_aArray, + (p_nStartIndex+1) + ) + ); + + }; + + + var oNextItemSibling = + getNextItemSibling(aGroup, (p_nItemIndex+1)); + + if( + oNextItemSibling && + ( + !oGroupItem.element.parentNode || + oGroupItem.element.parentNode.nodeType == 11 + ) + ) { + + this._aListElements[nGroupIndex].insertBefore( + oGroupItem.element, + oNextItemSibling.element + ); + + } + + } + + + oGroupItem.parent = this; + + this._subscribeToItemEvents(oGroupItem); + + this._configureSubmenu(oGroupItem); + + this._updateItemProperties(nGroupIndex); + + + this.itemAddedEvent.fire(oGroupItem); + + return oGroupItem; + + } + + } + else { + + var nItemIndex = aGroup.length; + + aGroup[nItemIndex] = oItem; + + oGroupItem = aGroup[nItemIndex]; + + + if(oGroupItem) { + + if( + !Dom.isAncestor( + this._aListElements[nGroupIndex], + oGroupItem.element + ) + ) { + + this._aListElements[nGroupIndex].appendChild( + oGroupItem.element + ); + + } + + oGroupItem.element.setAttribute("groupindex", nGroupIndex); + oGroupItem.element.setAttribute("index", nItemIndex); + + oGroupItem.parent = this; + + oGroupItem.index = nItemIndex; + oGroupItem.groupIndex = nGroupIndex; + + this._subscribeToItemEvents(oGroupItem); + + this._configureSubmenu(oGroupItem); + + if(nItemIndex === 0) { + + Dom.addClass(oGroupItem.element, "first-of-type"); + + } + + + + this.itemAddedEvent.fire(oGroupItem); + + return oGroupItem; + + } + + } + + } + +}, + +/** +* @method _removeItemFromGroupByIndex +* @description Removes a menu item from a group by index. Returns the menu +* item that was removed. +* @private +* @param {Number} p_nGroupIndex Number indicating the group to which the menu +* item belongs. +* @param {Number} p_nItemIndex Number indicating the index of the menu item +* to be removed. +* @return {YAHOO.widget.MenuItem} +*/ +_removeItemFromGroupByIndex: function(p_nGroupIndex, p_nItemIndex) { + + var nGroupIndex = typeof p_nGroupIndex == "number" ? p_nGroupIndex : 0; + var aGroup = this._getItemGroup(nGroupIndex); + + if(aGroup) { + + var aArray = aGroup.splice(p_nItemIndex, 1); + var oItem = aArray[0]; + + if(oItem) { + + // Update the index and className properties of each member + + this._updateItemProperties(nGroupIndex); + + if(aGroup.length === 0) { + + // Remove the UL + + var oUL = this._aListElements[nGroupIndex]; + + if(this.body && oUL) { + + this.body.removeChild(oUL); + + } + + // Remove the group from the array of items + + this._aItemGroups.splice(nGroupIndex, 1); + + + // Remove the UL from the array of ULs + + this._aListElements.splice(nGroupIndex, 1); + + + /* + Assign the "first-of-type" class to the new first UL + in the collection + */ + + oUL = this._aListElements[0]; + + if(oUL) { + + Dom.addClass(oUL, "first-of-type"); + + } + + } + + + this.itemRemovedEvent.fire(oItem); + + // Return a reference to the item that was removed + + return oItem; + + } + + } + +}, + +/** +* @method _removeItemFromGroupByValue +* @description Removes a menu item from a group by reference. Returns the +* menu item that was removed. +* @private +* @param {Number} p_nGroupIndex Number indicating the group to which the +* menu item belongs. +* @param {YAHOO.widget.MenuItem} p_oItem Object reference for the MenuItem +* instance to be removed. +* @return {YAHOO.widget.MenuItem} +*/ +_removeItemFromGroupByValue: function(p_nGroupIndex, p_oItem) { + + var aGroup = this._getItemGroup(p_nGroupIndex); + + if(aGroup) { + + var nItems = aGroup.length; + var nItemIndex = -1; + + if(nItems > 0) { + + var i = nItems-1; + + do { + + if(aGroup[i] == p_oItem) { + + nItemIndex = i; + break; + + } + + } + while(i--); + + if(nItemIndex > -1) { + + return this._removeItemFromGroupByIndex( + p_nGroupIndex, + nItemIndex + ); + + } + + } + + } + +}, + +/** +* @method _updateItemProperties +* @description Updates the "index," "groupindex," and "className" properties +* of the menu items in the specified group. +* @private +* @param {Number} p_nGroupIndex Number indicating the group of items to update. +*/ +_updateItemProperties: function(p_nGroupIndex) { + + var aGroup = this._getItemGroup(p_nGroupIndex); + var nItems = aGroup.length; + + if(nItems > 0) { + + var i = nItems - 1; + var oItem; + var oLI; + + // Update the index and className properties of each member + + do { + + oItem = aGroup[i]; + + if(oItem) { + + oLI = oItem.element; + + oItem.index = i; + oItem.groupIndex = p_nGroupIndex; + + oLI.setAttribute("groupindex", p_nGroupIndex); + oLI.setAttribute("index", i); + + Dom.removeClass(oLI, "first-of-type"); + + } + + } + while(i--); + + if(oLI) { + + Dom.addClass(oLI, "first-of-type"); + + } + + } + +}, + +/** +* @method _createItemGroup +* @description Creates a new menu item group (array) and its associated +* <ul>
element. Returns an aray of menu item groups. +* @private +* @param {Number} p_nIndex Number indicating the group to create. +* @return {Array} +*/ +_createItemGroup: function(p_nIndex) { + + if(!this._aItemGroups[p_nIndex]) { + + this._aItemGroups[p_nIndex] = []; + + var oUL = document.createElement("ul"); + + this._aListElements[p_nIndex] = oUL; + + return this._aItemGroups[p_nIndex]; + + } + +}, + +/** +* @method _getItemGroup +* @description Returns the menu item group at the specified index. +* @private +* @param {Number} p_nIndex Number indicating the index of the menu item group +* to be retrieved. +* @return {Array} +*/ +_getItemGroup: function(p_nIndex) { + + var nIndex = ((typeof p_nIndex == "number") ? p_nIndex : 0); + + return this._aItemGroups[nIndex]; + +}, + +/** +* @method _configureSubmenu +* @description Subscribes the menu item's submenu to its parent menu's events. +* @private +* @param {YAHOO.widget.MenuItem} p_oItem Object reference for the MenuItem +* instance with the submenu to be configured. +*/ +_configureSubmenu: function(p_oItem) { + + var oSubmenu = p_oItem.cfg.getProperty("submenu"); + + if(oSubmenu) { + + /* + Listen for configuration changes to the parent menu + so they they can be applied to the submenu. + */ + + this.cfg.configChangedEvent.subscribe( + this._onParentMenuConfigChange, + oSubmenu, + true + ); + + this.renderEvent.subscribe( + this._onParentMenuRender, + oSubmenu, + true + ); + + oSubmenu.beforeShowEvent.subscribe( + this._onSubmenuBeforeShow, + oSubmenu, + true + ); + + oSubmenu.showEvent.subscribe( + this._onSubmenuShow, + oSubmenu, + true + ); + + oSubmenu.hideEvent.subscribe( + this._onSubmenuHide, + oSubmenu, + true + ); + + } + +}, + +/** +* @method _subscribeToItemEvents +* @description Subscribes a menu to a menu item's event. +* @private +* @param {YAHOO.widget.MenuItem} p_oItem Object reference for the MenuItem +* instance whose events should be subscribed to. +*/ +_subscribeToItemEvents: function(p_oItem) { + + p_oItem.focusEvent.subscribe(this._onMenuItemFocus, p_oItem, this); + + p_oItem.blurEvent.subscribe(this._onMenuItemBlur, this, true); + + p_oItem.cfg.configChangedEvent.subscribe( + this._onMenuItemConfigChange, + p_oItem, + this + ); + +}, + +/** +* @method _getOffsetWidth +* @description Returns the offset width of the menu's +*<div>
element. +* @private +*/ +_getOffsetWidth: function() { + + var oClone = this.element.cloneNode(true); + + Dom.setStyle(oClone, "width", ""); + + document.body.appendChild(oClone); + + var sWidth = oClone.offsetWidth; + + document.body.removeChild(oClone); + + return sWidth; + +}, + +/** +* @method _cancelHideDelay +* @description Cancels the call to "hideMenu." +* @private +*/ +_cancelHideDelay: function() { + + var oRoot = this.getRoot(); + + if(oRoot._nHideDelayId) { + + window.clearTimeout(oRoot._nHideDelayId); + + } + +}, + +/** +* @method _execHideDelay +* @description Hides the menu after the number of milliseconds specified by +* the "hidedelay" configuration property. +* @private +*/ +_execHideDelay: function() { + + this._cancelHideDelay(); + + var oRoot = this.getRoot(); + var me = this; + + var hideMenu = function() { + + if(oRoot.activeItem) { + + oRoot.clearActiveItem(); + + } + + if(oRoot == me && me.cfg.getProperty("position") == "dynamic") { + + me.hide(); + + } + + }; + + oRoot._nHideDelayId = + window.setTimeout(hideMenu, oRoot.cfg.getProperty("hidedelay")); + +}, + +/** +* @method _cancelShowDelay +* @description Cancels the call to the "showMenu." +* @private +*/ +_cancelShowDelay: function() { + + var oRoot = this.getRoot(); + + if(oRoot._nShowDelayId) { + + window.clearTimeout(oRoot._nShowDelayId); + + } + +}, + +/** +* @method _execShowDelay +* @description Shows the menu after the number of milliseconds specified by +* the "showdelay" configuration property have ellapsed. +* @private +* @param {YAHOO.widget.Menu} p_oMenu Object specifying the menu that should +* be made visible. +*/ +_execShowDelay: function(p_oMenu) { + + this._cancelShowDelay(); + + var oRoot = this.getRoot(); + + var showMenu = function() { + + p_oMenu.show(); + + }; + + oRoot._nShowDelayId = + window.setTimeout(showMenu, oRoot.cfg.getProperty("showdelay")); + +}, + +// Protected methods + +/** +* @method _onMouseOver +* @description "mouseover" event handler for the menu. +* @protected +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that +* fired the event. +*/ +_onMouseOver: function(p_sType, p_aArgs, p_oMenu) { + + var oEvent = p_aArgs[0]; + var oItem = p_aArgs[1]; + var oTarget = Event.getTarget(oEvent); + + if( + !this._bHandledMouseOverEvent && + (oTarget == this.element || Dom.isAncestor(this.element, oTarget)) + ) { + + // MENU MOUSEOVER LOGIC HERE + + this.clearActiveItem(); + + this._bHandledMouseOverEvent = true; + this._bHandledMouseOutEvent = false; + + } + + if( + oItem && !oItem.handledMouseOverEvent && + (oTarget == oItem.element || Dom.isAncestor(oItem.element, oTarget)) + ) { + + var oItemCfg = oItem.cfg; + + // Select and focus the current menu item + + oItemCfg.setProperty("selected", true); + oItem.focus(); + + if(this.cfg.getProperty("autosubmenudisplay")) { + + // Show the submenu this menu item + + var oSubmenu = oItemCfg.getProperty("submenu"); + + if(oSubmenu) { + + if(this.cfg.getProperty("showdelay") > 0) { + + this._execShowDelay(oSubmenu); + + } + else { + + oSubmenu.show(); + + } + + } + + } + + oItem.handledMouseOverEvent = true; + oItem.handledMouseOutEvent = false; + + } + +}, + +/** +* @method _onMouseOut +* @description "mouseout" event handler for the menu. +* @protected +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that +* fired the event. +*/ +_onMouseOut: function(p_sType, p_aArgs, p_oMenu) { + + var oEvent = p_aArgs[0]; + var oItem = p_aArgs[1]; + var oRelatedTarget = Event.getRelatedTarget(oEvent); + var bMovingToSubmenu = false; + + if(oItem) { + + var oItemCfg = oItem.cfg; + var oSubmenu = oItemCfg.getProperty("submenu"); + + if( + oSubmenu && + ( + oRelatedTarget == oSubmenu.element || + Dom.isAncestor(oSubmenu.element, oRelatedTarget) + ) + ) { + + bMovingToSubmenu = true; + + } + + if( + !oItem.handledMouseOutEvent && + ( + ( + oRelatedTarget != oItem.element && + !Dom.isAncestor(oItem.element, oRelatedTarget) + ) || bMovingToSubmenu + ) + ) { + + if(this.cfg.getProperty("showdelay") > 0) { + + this._cancelShowDelay(); + + } + + if(!bMovingToSubmenu) { + + oItemCfg.setProperty("selected", false); + + } + + if(this.cfg.getProperty("autosubmenudisplay")) { + + if(oSubmenu) { + + if( + !( + oRelatedTarget == oSubmenu.element || + YAHOO.util.Dom.isAncestor( + oSubmenu.element, + oRelatedTarget + ) + ) + ) { + + oSubmenu.hide(); + + } + + } + + } + + oItem.handledMouseOutEvent = true; + oItem.handledMouseOverEvent = false; + + } + + } + + if( + !this._bHandledMouseOutEvent && + ( + ( + oRelatedTarget != this.element && + !Dom.isAncestor(this.element, oRelatedTarget) + ) + || bMovingToSubmenu + ) + ) { + + this._bHandledMouseOutEvent = true; + this._bHandledMouseOverEvent = false; + + } + +}, + +/** +* @method _onClick +* @description "click" event handler for the menu. +* @protected +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that +* fired the event. +*/ +_onClick: function(p_sType, p_aArgs, p_oMenu) { + + var oEvent = p_aArgs[0]; + var oItem = p_aArgs[1]; + var oTarget = Event.getTarget(oEvent); + + if(oItem) { + + var oItemCfg = oItem.cfg; + var oSubmenu = oItemCfg.getProperty("submenu"); + + /* + ACCESSIBILITY FEATURE FOR SCREEN READERS: + Expand/collapse the submenu when the user clicks + on the submenu indicator image. + */ + + if(oTarget == oItem.submenuIndicator && oSubmenu) { + + if(oSubmenu.cfg.getProperty("visible")) { + + oSubmenu.hide(); + + } + else { + + this.clearActiveItem(); + + this.activeItem = oItem; + + oItem.cfg.setProperty("selected", true); + + oSubmenu.show(); + + } + + } + else { + + var sURL = oItemCfg.getProperty("url"); + var bCurrentPageURL = (sURL.substr((sURL.length-1),1) == "#"); + var sTarget = oItemCfg.getProperty("target"); + var bHasTarget = (sTarget && sTarget.length > 0); + + /* + Prevent the browser from following links + equal to "#" + */ + + if( + oTarget.tagName.toUpperCase() == "A" && + bCurrentPageURL && !bHasTarget + ) { + + Event.preventDefault(oEvent); + + } + + if( + oTarget.tagName.toUpperCase() != "A" && + !bCurrentPageURL && !bHasTarget + ) { + + /* + Follow the URL of the item regardless of + whether or not the user clicked specifically + on the anchor element. + */ + + document.location = sURL; + + } + + /* + If the item doesn't navigate to a URL and it doesn't have + a submenu, then collapse the menu tree. + */ + + if(bCurrentPageURL && !oSubmenu) { + + var oRoot = this.getRoot(); + + if(oRoot.cfg.getProperty("position") == "static") { + + oRoot.clearActiveItem(); + + } + else { + + oRoot.hide(); + + } + + } + + } + + } + +}, + +/** +* @method _onKeyDown +* @description "keydown" event handler for the menu. +* @protected +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that +* fired the event. +*/ +_onKeyDown: function(p_sType, p_aArgs, p_oMenu) { + + var oEvent = p_aArgs[0]; + var oItem = p_aArgs[1]; + var oSubmenu; + + if(oItem) { + + var oItemCfg = oItem.cfg; + var oParentItem = this.parent; + var oRoot; + var oNextItem; + + switch(oEvent.keyCode) { + + case 38: // Up arrow + case 40: // Down arrow + + if( + oItem == this.activeItem && + !oItemCfg.getProperty("selected") + ) { + + oItemCfg.setProperty("selected", true); + + } + else { + + oNextItem = (oEvent.keyCode == 38) ? + oItem.getPreviousEnabledSibling() : + oItem.getNextEnabledSibling(); + + if(oNextItem) { + + this.clearActiveItem(); + + oNextItem.cfg.setProperty("selected", true); + oNextItem.focus(); + + } + + } + + Event.preventDefault(oEvent); + + break; + + + case 39: // Right arrow + + oSubmenu = oItemCfg.getProperty("submenu"); + + if(oSubmenu) { + + if(!oItemCfg.getProperty("selected")) { + + oItemCfg.setProperty("selected", true); + + } + + oSubmenu.show(); + + oSubmenu.setInitialSelection(); + + } + else { + + oRoot = this.getRoot(); + + if(oRoot instanceof YAHOO.widget.MenuBar) { + + oNextItem = oRoot.activeItem.getNextEnabledSibling(); + + if(oNextItem) { + + oRoot.clearActiveItem(); + + oNextItem.cfg.setProperty("selected", true); + + oSubmenu = oNextItem.cfg.getProperty("submenu"); + + if(oSubmenu) { + + oSubmenu.show(); + + } + + oNextItem.focus(); + + } + + } + + } + + + Event.preventDefault(oEvent); + + break; + + + case 37: // Left arrow + + if(oParentItem) { + + var oParentMenu = oParentItem.parent; + + if(oParentMenu instanceof YAHOO.widget.MenuBar) { + + oNextItem = + oParentMenu.activeItem.getPreviousEnabledSibling(); + + if(oNextItem) { + + oParentMenu.clearActiveItem(); + + oNextItem.cfg.setProperty("selected", true); + + oSubmenu = oNextItem.cfg.getProperty("submenu"); + + if(oSubmenu) { + + oSubmenu.show(); + + } + + oNextItem.focus(); + + } + + } + else { + + this.hide(); + + oParentItem.focus(); + + } + + } + + Event.preventDefault(oEvent); + + break; + + } + + } + + if(oEvent.keyCode == 27) { // Esc key + + if(this.cfg.getProperty("position") == "dynamic") { + + this.hide(); + + if(this.parent) { + + this.parent.focus(); + + } + + } + else if(this.activeItem) { + + oSubmenu = this.activeItem.cfg.getProperty("submenu"); + + if(oSubmenu && oSubmenu.cfg.getProperty("visible")) { + + oSubmenu.hide(); + this.activeItem.focus(); + + } + else { + + this.activeItem.cfg.setProperty("selected", false); + this.activeItem.blur(); + + } + + } + + Event.preventDefault(oEvent); + + } + +}, + +// Private methods + +/** +* @method _onInit +* @description "init" event handler for the menu. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that +* fired the event. +*/ +_onInit: function(p_sType, p_aArgs, p_oMenu) { + + if( + ( + (this.parent && !this.lazyLoad) || + (!this.parent && this.cfg.getProperty("position") == "static") || + ( + !this.parent && + !this.lazyLoad && + this.cfg.getProperty("position") == "dynamic" + ) + ) && + this.getItemGroups().length === 0 + ) { + + if(this.srcElement) { + + this._initSubTree(); + + } + + if(this.itemData) { + + this.addItems(this.itemData); + + } + + } + else if(this.lazyLoad) { + + this.cfg.fireQueue(); + + } + +}, + +/** +* @method _onBeforeRender +* @description "beforerender" event handler for the menu. Appends all of the +*<ul>
,<li>
and their accompanying +* title elements to the body element of the menu. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that +* fired the event. +*/ +_onBeforeRender: function(p_sType, p_aArgs, p_oMenu) { + + var oConfig = this.cfg; + var oEl = this.element; + var nListElements = this._aListElements.length; + + if(nListElements > 0) { + + var i = 0; + var bFirstList = true; + var oUL; + var oGroupTitle; + + do { + + oUL = this._aListElements[i]; + + if(oUL) { + + if(bFirstList) { + + Dom.addClass(oUL, "first-of-type"); + bFirstList = false; + + } + + if(!Dom.isAncestor(oEl, oUL)) { + + this.appendToBody(oUL); + + } + + oGroupTitle = this._aGroupTitleElements[i]; + + if(oGroupTitle) { + + if(!Dom.isAncestor(oEl, oGroupTitle)) { + + oUL.parentNode.insertBefore(oGroupTitle, oUL); + + } + + Dom.addClass(oUL, "hastitle"); + + } + + } + + i++; + + } + while(i < nListElements); + + } + +}, + +/** +* @method _onRender +* @description "render" event handler for the menu. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that +* fired the event. +*/ +_onRender: function(p_sType, p_aArgs, p_oMenu) { + + if(this.cfg.getProperty("position") == "dynamic") { + + var sWidth = + this.element.parentNode.tagName.toUpperCase() == "BODY" ? + this.element.offsetWidth : this._getOffsetWidth(); + + this.cfg.setProperty("width", (sWidth + "px")); + + } + +}, + +/** +* @method _onBeforeShow +* @description "beforeshow" event handler for the menu. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that +* fired the event. +*/ +_onBeforeShow: function(p_sType, p_aArgs, p_oMenu) { + + if(this.lazyLoad && this.getItemGroups().length === 0) { + + if(this.srcElement) { + + this._initSubTree(); + + } + + if(this.itemData) { + + if( + this.parent && this.parent.parent && + this.parent.parent.srcElement && + this.parent.parent.srcElement.tagName.toUpperCase() == "SELECT" + ) { + + var nOptions = this.itemData.length; + + for(var n=0; n0) { + + oConfig.showdelay = nShowDelay; + + } + + var nHideDelay = oParentMenu.cfg.getProperty("hidedelay"); + + if(nHideDelay > 0) { + + oConfig.hidedelay = nHideDelay; + + } + + /* + Only sync the "iframe" configuration property if the parent + menu's "position" configuration is the same. + */ + + if( + this.cfg.getProperty("position") == + oParentMenu.cfg.getProperty("position") + ) { + + oConfig.iframe = oParentMenu.cfg.getProperty("iframe"); + + } + + + p_oSubmenu.cfg.applyConfig(oConfig); + + if(!this.lazyLoad) { + + if(Dom.inDocument(this.element)) { + + this.render(); + + } + else { + + this.render(this.parent.element); + + } + + } + +}, + +/** +* @method _onSubmenuBeforeShow +* @description "beforeshow" event handler for a submenu. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oSubmenu Object representing the submenu that +* subscribed to the event. +*/ +_onSubmenuBeforeShow: function(p_sType, p_aArgs, p_oSubmenu) { + + var oParent = this.parent; + var aAlignment = oParent.parent.cfg.getProperty("submenualignment"); + + this.cfg.setProperty( + "context", + [oParent.element, aAlignment[0], aAlignment[1]] + ); + + oParent.submenuIndicator.alt = oParent.EXPANDED_SUBMENU_INDICATOR_ALT_TEXT; + +}, + +/** +* @method _onSubmenuShow +* @description "show" event handler for a submenu. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oSubmenu Object representing the submenu that +* subscribed to the event. +*/ +_onSubmenuShow: function(p_sType, p_aArgs, p_oSubmenu) { + + var oParent = this.parent; + + oParent.submenuIndicator.alt = oParent.EXPANDED_SUBMENU_INDICATOR_ALT_TEXT; + +}, + +/** +* @method _onSubmenuHide +* @description "hide" Custom Event handler for a submenu. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oSubmenu Object representing the submenu that +* subscribed to the event. +*/ +_onSubmenuHide: function(p_sType, p_aArgs, p_oSubmenu) { + + var oParent = this.parent; + + oParent.submenuIndicator.alt = oParent.COLLAPSED_SUBMENU_INDICATOR_ALT_TEXT; + +}, + +/** +* @method _onMenuItemFocus +* @description "focus" event handler for the menu's items. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.MenuItem} p_oItem Object representing the menu item +* that fired the event. +*/ +_onMenuItemFocus: function(p_sType, p_aArgs, p_oItem) { + + this.activeItem = p_oItem; + +}, + +/** +* @method _onMenuItemBlur +* @description "blur" event handler for the menu's items. +* @private +* @param {String} p_sType String representing the name of the event +* that was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +*/ +_onMenuItemBlur: function(p_sType, p_aArgs) { + + this.activeItem = null; + +}, + +/** +* @method _onMenuItemConfigChange +* @description "configchange" event handler for the menu's items. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.MenuItem} p_oItem Object representing the menu item +* that fired the event. +*/ +_onMenuItemConfigChange: function(p_sType, p_aArgs, p_oItem) { + + var sProperty = p_aArgs[0][0]; + + switch(sProperty) { + + case "submenu": + + var oSubmenu = p_aArgs[0][1]; + + if(oSubmenu) { + + this._configureSubmenu(p_oItem); + + } + + break; + + case "text": + case "helptext": + + /* + A change to an item's "text" or "helptext" + configuration properties requires the width of the parent + menu to be recalculated. + */ + + if(this.element.style.width) { + + var sWidth = this._getOffsetWidth() + "px"; + + Dom.setStyle(this.element, "width", sWidth); + + } + + break; + + } + +}, + +// Public event handlers for configuration properties + +/** +* @method enforceConstraints +* @description The default event handler executed when the moveEvent is fired, +* if the "constraintoviewport" configuration property is set to true. +* @param {String} type The name of the event that was fired. +* @param {Array} args Collection of arguments sent when the +* event was fired. +* @param {Array} obj Array containing the current Menu instance +* and the item that fired the event. +*/ +enforceConstraints: function(type, args, obj) { + + var oConfig = this.cfg; + + var pos = args[0]; + + var x = pos[0]; + var y = pos[1]; + + var bod = document.getElementsByTagName('body')[0]; + var htm = document.getElementsByTagName('html')[0]; + + var bodyOverflow = Dom.getStyle(bod, "overflow"); + var htmOverflow = Dom.getStyle(htm, "overflow"); + + var offsetHeight = this.element.offsetHeight; + var offsetWidth = this.element.offsetWidth; + + var viewPortWidth = Dom.getClientWidth(); + var viewPortHeight = Dom.getClientHeight(); + + var scrollX = window.scrollX || document.body.scrollLeft; + var scrollY = window.scrollY || document.body.scrollTop; + + var topConstraint = scrollY + 10; + var leftConstraint = scrollX + 10; + var bottomConstraint = scrollY + viewPortHeight - offsetHeight - 10; + var rightConstraint = scrollX + viewPortWidth - offsetWidth - 10; + + var aContext = oConfig.getProperty("context"); + var oContextElement = aContext ? aContext[0] : null; + + + if (x < 10) { + + x = leftConstraint; + + } else if ((x + offsetWidth) > viewPortWidth) { + + if( + oContextElement && + ((x - oContextElement.offsetWidth) > offsetWidth) + ) { + + x = (x - (oContextElement.offsetWidth + offsetWidth)); + + } + else { + + x = rightConstraint; + + } + + } + + if (y < 10) { + + y = topConstraint; + + } else if (y > bottomConstraint) { + + if(oContextElement && (y > offsetHeight)) { + + y = ((y + oContextElement.offsetHeight) - offsetHeight); + + } + else { + + y = bottomConstraint; + + } + + } + + oConfig.setProperty("x", x, true); + oConfig.setProperty("y", y, true); + +}, + +/** +* @method configVisible +* @description Event handler for when the "visible" configuration property +* the menu changes. +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that +* fired the event. +*/ +configVisible: function(p_sType, p_aArgs, p_oMenu) { + + if(this.cfg.getProperty("position") == "dynamic") { + + YAHOO.widget.Menu.superclass.configVisible.call( + this, + p_sType, + p_aArgs, + p_oMenu + ); + + } + else { + + var bVisible = p_aArgs[0]; + var sDisplay = Dom.getStyle(this.element, "display"); + + if(bVisible) { + + if(sDisplay != "block") { + this.beforeShowEvent.fire(); + Dom.setStyle(this.element, "display", "block"); + this.showEvent.fire(); + } + + } + else { + + if(sDisplay == "block") { + this.beforeHideEvent.fire(); + Dom.setStyle(this.element, "display", "none"); + this.hideEvent.fire(); + } + + } + + } + +}, + +/** +* @method configPosition +* @description Event handler for when the "position" configuration property +* of the menu changes. +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that +* fired the event. +*/ +configPosition: function(p_sType, p_aArgs, p_oMenu) { + + var sCSSPosition = p_aArgs[0] == "static" ? "static" : "absolute"; + var oCfg = this.cfg; + + Dom.setStyle(this.element, "position", sCSSPosition); + + if(sCSSPosition == "static") { + + /* + Remove the iframe for statically positioned menus since it will + intercept mouse events. + */ + + oCfg.setProperty("iframe", false); + + // Statically positioned menus are visible by default + + Dom.setStyle(this.element, "display", "block"); + + oCfg.setProperty("visible", true); + + } + else { + + /* + Even though the "visible" property is queued to + "false" by default, we need to set the "visibility" property to + "hidden" since Overlay's "configVisible" implementation checks the + element's "visibility" style property before deciding whether + or not to show an Overlay instance. + */ + + Dom.setStyle(this.element, "visibility", "hidden"); + + } + + if(sCSSPosition == "absolute") { + + var nZIndex = oCfg.getProperty("zindex"); + + if(!nZIndex || nZIndex === 0) { + + nZIndex = this.parent ? + (this.parent.parent.cfg.getProperty("zindex") + 1) : 1; + + oCfg.setProperty("zindex", nZIndex); + + } + + } + +}, + +/** +* @method configIframe +* @description Event handler for when the "iframe" configuration property of +* the menu changes. +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that +* fired the event. +*/ +configIframe: function(p_sType, p_aArgs, p_oMenu) { + + if(this.cfg.getProperty("position") == "dynamic") { + + YAHOO.widget.Menu.superclass.configIframe.call( + this, + p_sType, + p_aArgs, + p_oMenu + ); + + } + +}, + +/** +* @method configHideDelay +* @description Event handler for when the "hidedelay" configuration property +* of the menu changes. +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that +* fired the event. +*/ +configHideDelay: function(p_sType, p_aArgs, p_oMenu) { + + var nHideDelay = p_aArgs[0]; + var oMouseOutEvent = this.mouseOutEvent; + var oMouseOverEvent = this.mouseOverEvent; + var oKeyDownEvent = this.keyDownEvent; + + if(nHideDelay > 0) { + + /* + Only assign event handlers once. This way the user change + the value for the hidedelay as many times as they want. + */ + + if(!this._hideDelayEventHandlersAssigned) { + + oMouseOutEvent.subscribe(this._execHideDelay, true); + oMouseOverEvent.subscribe(this._cancelHideDelay, this, true); + oKeyDownEvent.subscribe(this._cancelHideDelay, this, true); + + this._hideDelayEventHandlersAssigned = true; + + } + + } + else { + + oMouseOutEvent.unsubscribe(this._execHideDelay, this); + oMouseOverEvent.unsubscribe(this._cancelHideDelay, this); + oKeyDownEvent.unsubscribe(this._cancelHideDelay, this); + + this._hideDelayEventHandlersAssigned = false; + + } + +}, + +/** +* @method configContainer +* @description Event handler for when the "container" configuration property +of the menu changes. +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that +* fired the event. +*/ +configContainer: function(p_sType, p_aArgs, p_oMenu) { + + var oElement = p_aArgs[0]; + + if(typeof oElement == 'string') { + + this.cfg.setProperty( + "container", + document.getElementById(oElement), + true + ); + + } + +}, + +// Public methods + +/** +* Event handler called when the resize monitor element's "resize" evet is fired. +*/ +onDomResize: function(e, obj) { + + if(!this._handleResize) { + + this._handleResize = true; + return; + + } + + var oConfig = this.cfg; + + if(oConfig.getProperty("position") == "dynamic") { + + oConfig.setProperty("width", (this._getOffsetWidth() + "px")); + + } + + YAHOO.widget.Menu.superclass.onDomResize.call(this, e, obj); + +}, + +/** +* @method initEvents +* @description Initializes the custom events for the menu. +*/ +initEvents: function() { + + YAHOO.widget.Menu.superclass.initEvents.call(this); + + // Create custom events + + var CustomEvent = YAHOO.util.CustomEvent; + + this.mouseOverEvent = new CustomEvent("mouseOverEvent", this); + this.mouseOutEvent = new CustomEvent("mouseOutEvent", this); + this.mouseDownEvent = new CustomEvent("mouseDownEvent", this); + this.mouseUpEvent = new CustomEvent("mouseUpEvent", this); + this.clickEvent = new CustomEvent("clickEvent", this); + this.keyPressEvent = new CustomEvent("keyPressEvent", this); + this.keyDownEvent = new CustomEvent("keyDownEvent", this); + this.keyUpEvent = new CustomEvent("keyUpEvent", this); + this.itemAddedEvent = new CustomEvent("itemAddedEvent", this); + this.itemRemovedEvent = new CustomEvent("itemRemovedEvent", this); + +}, + +/** +* @method getRoot +* @description Finds the menu's root menu. +*/ +getRoot: function() { + + var oItem = this.parent; + + if(oItem) { + + var oParentMenu = oItem.parent; + + return oParentMenu ? oParentMenu.getRoot() : this; + + } + else { + + return this; + + } + +}, + +/** +* @method toString +* @description Returns a string representing the menu. +* @return {String} +*/ +toString: function() { + + return ("Menu " + this.id); + +}, + +/** +* @method setItemGroupTitle +* @description Sets the title of a group of menu items. +* @param {String} p_sGroupTitle String specifying the title of the group. +* @param {Number} p_nGroupIndex Optional. Number specifying the group to which +* the title belongs. +*/ +setItemGroupTitle: function(p_sGroupTitle, p_nGroupIndex) { + + if(typeof p_sGroupTitle == "string" && p_sGroupTitle.length > 0) { + + var nGroupIndex = typeof p_nGroupIndex == "number" ? p_nGroupIndex : 0; + var oTitle = this._aGroupTitleElements[nGroupIndex]; + + if(oTitle) { + + oTitle.innerHTML = p_sGroupTitle; + + } + else { + + oTitle = document.createElement(this.GROUP_TITLE_TAG_NAME); + + oTitle.innerHTML = p_sGroupTitle; + + this._aGroupTitleElements[nGroupIndex] = oTitle; + + } + + var i = this._aGroupTitleElements.length - 1; + var nFirstIndex; + + do { + + if(this._aGroupTitleElements[i]) { + + Dom.removeClass(this._aGroupTitleElements[i], "first-of-type"); + + nFirstIndex = i; + + } + + } + while(i--); + + if(nFirstIndex !== null) { + + Dom.addClass( + this._aGroupTitleElements[nFirstIndex], + "first-of-type" + ); + + } + + } + +}, + +/** +* @method addItem +* @description Appends an item to the menu. +* @param {YAHOO.widget.MenuItem} p_oItem Object reference for the MenuItem +* instance to be added to the menu. +* @param {String} p_oItem String specifying the text of the item to be added +* to the menu. +* @param {Object} p_oItem Object literal containing a set of menu item +* configuration properties. +* @param {Number} p_nGroupIndex Optional. Number indicating the group to +* which the item belongs. +* @return {YAHOO.widget.MenuItem} +*/ +addItem: function(p_oItem, p_nGroupIndex) { + + if(p_oItem) { + + return this._addItemToGroup(p_nGroupIndex, p_oItem); + + } + +}, + +/** +* @method addItems +* @description Adds an array of items to the menu. +* @param {Array} p_aItems Array of items to be added to the menu. The array +* can contain strings specifying the text for each item to be created, object +* literals specifying each of the menu item configuration properties, +* or MenuItem instances. +* @param {Number} p_nGroupIndex Optional. Number specifying the group to +* which the items belongs. +* @return {Array} +*/ +addItems: function(p_aItems, p_nGroupIndex) { + + function isArray(p_oValue) { + + return (typeof p_oValue == "object" && p_oValue.constructor == Array); + + } + + if(isArray(p_aItems)) { + + var nItems = p_aItems.length; + var aItems = []; + var oItem; + + for(var i=0; i <div> element +* (and accompanying child nodes) from the document. +*/ +destroy: function() { + + // Remove Custom Event listeners + + this.mouseOverEvent.unsubscribeAll(); + this.mouseOutEvent.unsubscribeAll(); + this.mouseDownEvent.unsubscribeAll(); + this.mouseUpEvent.unsubscribeAll(); + this.clickEvent.unsubscribeAll(); + this.keyPressEvent.unsubscribeAll(); + this.keyDownEvent.unsubscribeAll(); + this.keyUpEvent.unsubscribeAll(); + + var nItemGroups = this._aItemGroups.length; + var nItems; + var oItemGroup; + var oItem; + var i; + var n; + + // Remove all items + + if(nItemGroups > 0) { + + i = nItemGroups - 1; + + do { + + oItemGroup = this._aItemGroups[i]; + + if(oItemGroup) { + + nItems = oItemGroup.length; + + if(nItems > 0) { + + n = nItems - 1; + + do { + + oItem = this._aItemGroups[i][n]; + + if(oItem) { + + oItem.destroy(); + } + + } + while(n--); + + } + + } + + } + while(i--); + + } + + // Continue with the superclass implementation of this method + + YAHOO.widget.Menu.superclass.destroy.call(this); + + +}, + +/** +* @method setInitialFocus +* @description Sets focus to the menu's first enabled item. +*/ +setInitialFocus: function() { + + var oItem = this._getFirstEnabledItem(); + + if(oItem) { + + oItem.focus(); + } + +}, + +/** +* @method setInitialSelection +* @description Sets the "selected" configuration property of the menu's first +* enabled item to "true." +*/ +setInitialSelection: function() { + + var oItem = this._getFirstEnabledItem(); + + if(oItem) { + + oItem.cfg.setProperty("selected", true); + } + +}, + +/** +* @method clearActiveItem +* @description Sets the "selected" configuration property of the menu's active +* item to "false" and hides the item's submenu. +* @param {Boolean} p_bBlur Boolean indicating if the menu's active item +* should be blurred. +*/ +clearActiveItem: function(p_bBlur) { + + if(this.cfg.getProperty("showdelay") > 0) { + + this._cancelShowDelay(); + + } + + var oActiveItem = this.activeItem; + + if(oActiveItem) { + + var oConfig = oActiveItem.cfg; + + oConfig.setProperty("selected", false); + + var oSubmenu = oConfig.getProperty("submenu"); + + if(oSubmenu) { + + oSubmenu.hide(); + + } + + if(p_bBlur) { + + oActiveItem.blur(); + + } + + } + +}, + +/** +* @description Initializes the class's configurable properties which can be +* changed using the menu's Config object ("cfg"). +* @method initDefaultConfig +*/ +initDefaultConfig: function() { + + YAHOO.widget.Menu.superclass.initDefaultConfig.call(this); + + var oConfig = this.cfg; + + // Add configuration properties + + /* + Change the default value for the "visible" configuration + property to "false" by re-adding the property. + */ + + /** + * @config visible + * @description Boolean indicating whether or not the menu is visible. If + * the menu's "position" configuration property is set to "dynamic" (the + * default), this property toggles the menu's <div>
+ * element's "visibility" style property between "visible" (true) or + * "hidden" (false). If the menu's "position" configuration property is + * set to "static" this property toggles the menu's + *<div>
element's "display" style property + * between "block" (true) or "none" (false). + * @default false + * @type Boolean + */ + oConfig.addProperty( + "visible", + { + value:false, + handler:this.configVisible, + validator:this.cfg.checkBoolean + } + ); + + /* + Change the default value for the "constraintoviewport" configuration + property to "true" by re-adding the property. + */ + + /** + * @config constraintoviewport + * @description Boolean indicating if the menu will try to remain inside + * the boundaries of the size of viewport. + * @default true + * @type Boolean + */ + oConfig.addProperty( + "constraintoviewport", + { + value:true, + handler:this.configConstrainToViewport, + validator:this.cfg.checkBoolean, + supercedes:["iframe","x","y","xy"] + } + ); + + /** + * @config position + * @description String indicating how a menu should be positioned on the + * screen. Possible values are "static" and "dynamic." Static menus are + * visible by default and reside in the normal flow of the document + * (CSS position: static). Dynamic menus are hidden by default, reside + * out of the normal flow of the document (CSS position: absolute), and + * can overlay other elements on the screen. + * @default dynamic + * @type String + */ + oConfig.addProperty( + "position", + { + value: "dynamic", + handler: this.configPosition, + validator: this._checkPosition, + supercedes: ["visible"] + } + ); + + /** + * @config submenualignment + * @description Array defining how submenus should be aligned to their + * parent menu item. The format is: [itemCorner, submenuCorner]. By default + * a submenu's top left corner is aligned to its parent menu item's top + * right corner. + * @default ["tl","tr"] + * @type Array + */ + oConfig.addProperty("submenualignment", { value: ["tl","tr"] } ); + + /** + * @config autosubmenudisplay + * @description Boolean indicating if submenus are automatically made + * visible when the user mouses over the menu's items. + * @default true + * @type Boolean + */ + oConfig.addProperty( + "autosubmenudisplay", + { + value: true, + validator: oConfig.checkBoolean + } + ); + + /** + * @config showdelay + * @description Number indicating the time (in milliseconds) that should + * expire before a submenu is made visible when the user mouses over + * the menu's items. + * @default 0 + * @type Number + */ + oConfig.addProperty( + "showdelay", + { + value: 0, + validator: oConfig.checkNumber + } + ); + + /** + * @config hidedelay + * @description Number indicating the time (in milliseconds) that should + * expire before the menu is hidden. + * @default 0 + * @type Number + */ + oConfig.addProperty( + "hidedelay", + { + value: 0, + validator: oConfig.checkNumber, + handler: this.configHideDelay, + suppressEvent: true + } + ); + + /** + * @config clicktohide + * @description Boolean indicating if the menu will automatically be + * hidden if the user clicks outside of it. + * @default true + * @type Boolean + */ + oConfig.addProperty( + "clicktohide", + { + value: true, + validator: oConfig.checkBoolean + } + ); + + /** + * @config container + * @description HTML element reference or string specifying the id + * attribute of the HTML element that the menu's markup should be rendered into. + * @type HTMLElement|String + * @default document.body + */ + this.cfg.addProperty( + "container", + { value:document.body, handler:this.configContainer } + ); + +} + +}); // END YAHOO.extend + +})(); + +/** +* The base class for all menuing containers. +* +* @param {String} p_oElement String specifying the id attribute of the +*<div>
element of the menu module. +* @param {String} p_oElement String specifying the id attribute of the +*<select>
element to be used as the data source for the +* menu module. +* @param {HTMLDivElement} p_oElement Object +* specifying the<div>
element of the menu module. +* @param {HTMLSelectElement} p_oElement Object +* specifying the<select>
element to be used as the data +* source for the menu module. +* @param {Object} p_oConfig Optional. Object literal specifying the +* configuration for the menu module. See configuration class documentation for +* more details. +* @class MenuModule +* @constructor +* @extends YAHOO.widget.Overlay +* @deprecated As of version 0.12, all MenuModule functionality has been +* implemented directly in YAHOO.widget.Menu, making YAHOO.widget.Menu the base +* class for all menuing containers. +*/ +YAHOO.widget.MenuModule = YAHOO.widget.Menu; + +(function() { + +var Dom = YAHOO.util.Dom; +var Module = YAHOO.widget.Module; +var Menu = YAHOO.widget.Menu; + +/** +* Creates an item for a menu. +* +* @param {String} p_oObject String specifying the text of the menu item. +* @param {HTMLLIElement} p_oObject Object specifying +* the<li>
element of the menu item. +* @param {HTMLOptGroupElement} p_oObject Object +* specifying the<optgroup>
element of the menu item. +* @param {HTMLOptionElement} p_oObject Object +* specifying the<option>
element of the menu item. +* @param {Object} p_oConfig Optional. Object literal specifying the +* configuration for the menu item. See configuration class documentation +* for more details. +* @class MenuItem +* @constructor +*/ +YAHOO.widget.MenuItem = function(p_oObject, p_oConfig) { + + if(p_oObject) { + + if(p_oConfig) { + + this.parent = p_oConfig.parent; + this.value = p_oConfig.value; + + } + + this.init(p_oObject, p_oConfig); + + } + +}; + +YAHOO.widget.MenuItem.prototype = { + + // Constants + + /** + * @property SUBMENU_INDICATOR_IMAGE_PATH + * @description String representing the path to the image to be used for the + * menu item's submenu arrow indicator. + * @default "nt/ic/ut/alt1/menuarorght8_nrm_1.gif" + * @final + * @type String + */ + SUBMENU_INDICATOR_IMAGE_PATH: "nt/ic/ut/alt1/menuarorght8_nrm_1.gif", + + /** + * @property SELECTED_SUBMENU_INDICATOR_IMAGE_PATH + * @description String representing the path to the image to be used for the + * submenu arrow indicator when the menu item is selected. + * @default "nt/ic/ut/alt1/menuarorght8_hov_1.gif" + * @final + * @type String + */ + SELECTED_SUBMENU_INDICATOR_IMAGE_PATH: + "nt/ic/ut/alt1/menuarorght8_hov_1.gif", + + /** + * @property DISABLED_SUBMENU_INDICATOR_IMAGE_PATH + * @description String representing the path to the image to be used for the + * submenu arrow indicator when the menu item is disabled. + * @default "nt/ic/ut/alt1/menuarorght8_dim_1.gif" + * @final + * @type String + */ + DISABLED_SUBMENU_INDICATOR_IMAGE_PATH: + "nt/ic/ut/alt1/menuarorght8_dim_1.gif", + + /** + * @property COLLAPSED_SUBMENU_INDICATOR_ALT_TEXT + * @description String representing the alt text for the image to be used + * for the submenu arrow indicator. + * @default "Collapsed. Click to expand." + * @final + * @type String + */ + COLLAPSED_SUBMENU_INDICATOR_ALT_TEXT: "Collapsed. Click to expand.", + + /** + * @property EXPANDED_SUBMENU_INDICATOR_ALT_TEXT + * @description String representing the alt text for the image to be used + * for the submenu arrow indicator when the submenu is visible. + * @default "Expanded. Click to collapse." + * @final + * @type String + */ + EXPANDED_SUBMENU_INDICATOR_ALT_TEXT: "Expanded. Click to collapse.", + + /** + * @property DISABLED_SUBMENU_INDICATOR_ALT_TEXT + * @description String representing the alt text for the image to be used + * for the submenu arrow indicator when the menu item is disabled. + * @default "Disabled." + * @final + * @type String + */ + DISABLED_SUBMENU_INDICATOR_ALT_TEXT: "Disabled.", + + /** + * @property CHECKED_IMAGE_PATH + * @description String representing the path to the image to be used for + * the checked state. + * @default "nt/ic/ut/bsc/menuchk8_nrm_1.gif" + * @final + * @type String + */ + CHECKED_IMAGE_PATH: "nt/ic/ut/bsc/menuchk8_nrm_1.gif", + + + /** + * @property SELECTED_CHECKED_IMAGE_PATH + * @description String representing the path to the image to be used for + * the selected checked state. + * @default "nt/ic/ut/bsc/menuchk8_hov_1.gif" + * @final + * @type String + */ + SELECTED_CHECKED_IMAGE_PATH: "nt/ic/ut/bsc/menuchk8_hov_1.gif", + + + /** + * @property DISABLED_CHECKED_IMAGE_PATH + * @description String representing the path to the image to be used for + * the disabled checked state. + * @default "nt/ic/ut/bsc/menuchk8_dim_1.gif" + * @final + * @type String + */ + DISABLED_CHECKED_IMAGE_PATH: "nt/ic/ut/bsc/menuchk8_dim_1.gif", + + + /** + * @property CHECKED_IMAGE_ALT_TEXT + * @description String representing the alt text for the image to be used + * for the checked image. + * @default "Checked." + * @final + * @type String + */ + CHECKED_IMAGE_ALT_TEXT: "Checked.", + + + /** + * @property DISABLED_CHECKED_IMAGE_ALT_TEXT + * @description String representing the alt text for the image to be used + * for the checked image when the item is disabled. + * @default "Checked. (Item disabled.)" + * @final + * @type String + */ + DISABLED_CHECKED_IMAGE_ALT_TEXT: "Checked. (Item disabled.)", + + /** + * @property CSS_CLASS_NAME + * @description String representing the CSS class(es) to be applied to the + *<li>
element of the menu item. + * @default "yuimenuitem" + * @final + * @type String + */ + CSS_CLASS_NAME: "yuimenuitem", + + /** + * @property SUBMENU_TYPE + * @description Object representing the type of menu to instantiate and + * add when parsing the child nodes of the menu item's source HTML element. + * @final + * @type YAHOO.widget.Menu + */ + SUBMENU_TYPE: null, + + /** + * @property IMG_ROOT + * @description String representing the prefix path to use for + * non-secure images. + * @default "http://us.i1.yimg.com/us.yimg.com/i/" + * @type String + */ + IMG_ROOT: "http://us.i1.yimg.com/us.yimg.com/i/", + + + /** + * @property IMG_ROOT_SSL + * @description String representing the prefix path to use for securely + * served images. + * @default "https://a248.e.akamai.net/sec.yimg.com/i/" + * @type String + */ + IMG_ROOT_SSL: "https://a248.e.akamai.net/sec.yimg.com/i/", + + // Private member variables + + /** + * @property _oAnchor + * @description Object reference to the menu item's + *<a>
element. + * @default null + * @private + * @type HTMLAnchorElement + */ + _oAnchor: null, + + + /** + * @property _oText + * @description Object reference to the menu item's text node. + * @default null + * @private + * @type TextNode + */ + _oText: null, + + + /** + * @property _oHelpTextEM + * @description Object reference to the menu item's help text + *<em>
element. + * @default null + * @private + * @type HTMLElement + */ + _oHelpTextEM: null, + + + /** + * @property _oSubmenu + * @description Object reference to the menu item's submenu. + * @default null + * @private + * @type YAHOO.widget.Menu + */ + _oSubmenu: null, + + /** + * @property _checkImage + * @description Object reference to the menu item's checkmark image. + * @default null + * @private + * @type HTMLImageElement + */ + _checkImage: null, + + // Public properties + + /** + * @property constructor + * @description Object reference to the menu item's constructor function. + * @default YAHOO.widget.MenuItem + * @type YAHOO.widget.MenuItem + */ + constructor: YAHOO.widget.MenuItem, + + /** + * @property imageRoot + * @description String representing the root path for all of the menu + * item's images. + * @type String + */ + imageRoot: null, + + /** + * @property isSecure + * @description Boolean representing whether or not the current browsing + * context is secure (HTTPS). + * @type Boolean + */ + isSecure: Module.prototype.isSecure, + + /** + * @property index + * @description Number indicating the ordinal position of the menu item in + * its group. + * @default null + * @type Number + */ + index: null, + + /** + * @property groupIndex + * @description Number indicating the index of the group to which the menu + * item belongs. + * @default null + * @type Number + */ + groupIndex: null, + + /** + * @property parent + * @description Object reference to the menu item's parent menu. + * @default null + * @type YAHOO.widget.Menu + */ + parent: null, + + /** + * @property element + * @description Object reference to the menu item's + *<li>
element. + * @default HTMLLIElement + * @type HTMLLIElement + */ + element: null, + + /** + * @property srcElement + * @description Object reference to the HTML element (either + *<li>
,<optgroup>
or + *<option>
) used create the menu item. + * @default HTMLLIElement|HTMLOptGroupElement|HTMLOptionElement + * @type HTMLLIElement| + * HTMLOptGroupElement|HTMLOptionElement + */ + srcElement: null, + + /** + * @property value + * @description Object reference to the menu item's value. + * @default null + * @type Object + */ + value: null, + + /** + * @property submenuIndicator + * @description Object reference to the<img>
element + * used to create the submenu indicator for the menu item. + * @default HTMLImageElement + * @type HTMLImageElement + */ + submenuIndicator: null, + + /** + * @property browser + * @description String representing the browser. + * @type String + */ + browser: Module.prototype.browser, + + // Events + + /** + * @event destroyEvent + * @description Fires when the menu item's<li>
+ * element is removed from its parent<ul>
element. + * @type YAHOO.util.CustomEvent + */ + destroyEvent: null, + + /** + * @event mouseOverEvent + * @description Fires when the mouse has entered the menu item. Passes + * back the DOM Event object as an argument. + * @type YAHOO.util.CustomEvent + */ + mouseOverEvent: null, + + /** + * @event mouseOutEvent + * @description Fires when the mouse has left the menu item. Passes back + * the DOM Event object as an argument. + * @type YAHOO.util.CustomEvent + */ + mouseOutEvent: null, + + /** + * @event mouseDownEvent + * @description Fires when the user mouses down on the menu item. Passes + * back the DOM Event object as an argument. + * @type YAHOO.util.CustomEvent + */ + mouseDownEvent: null, + + /** + * @event mouseUpEvent + * @description Fires when the user releases a mouse button while the mouse + * is over the menu item. Passes back the DOM Event object as an argument. + * @type YAHOO.util.CustomEvent + */ + mouseUpEvent: null, + + /** + * @event clickEvent + * @description Fires when the user clicks the on the menu item. Passes + * back the DOM Event object as an argument. + * @type YAHOO.util.CustomEvent + */ + clickEvent: null, + + /** + * @event keyPressEvent + * @description Fires when the user presses an alphanumeric key when the + * menu item has focus. Passes back the DOM Event object as an argument. + * @type YAHOO.util.CustomEvent + */ + keyPressEvent: null, + + /** + * @event keyDownEvent + * @description Fires when the user presses a key when the menu item has + * focus. Passes back the DOM Event object as an argument. + * @type YAHOO.util.CustomEvent + */ + keyDownEvent: null, + + /** + * @event keyUpEvent + * @description Fires when the user releases a key when the menu item has + * focus. Passes back the DOM Event object as an argument. + * @type YAHOO.util.CustomEvent + */ + keyUpEvent: null, + + /** + * @event focusEvent + * @description Fires when the menu item receives focus. + * @type YAHOO.util.CustomEvent + */ + focusEvent: null, + + /** + * @event blurEvent + * @description Fires when the menu item loses the input focus. + * @type YAHOO.util.CustomEvent + */ + blurEvent: null, + + /** + * @method init + * @description The MenuItem class's initialization method. This method is + * automatically called by the constructor, and sets up all DOM references + * for pre-existing markup, and creates required markup if it is not + * already present. + * @param {String} p_oObject String specifying the text of the menu item. + * @param {HTMLLIElement} p_oObject Object specifying + * the<li>
element of the menu item. + * @param {HTMLOptGroupElement} p_oObject Object + * specifying the<optgroup>
element of the menu item. + * @param {HTMLOptionElement} p_oObject Object + * specifying the<option>
element of the menu item. + * @param {Object} p_oConfig Optional. Object literal specifying the + * configuration for the menu item. See configuration class documentation + * for more details. + */ + init: function(p_oObject, p_oConfig) { + + this.imageRoot = (this.isSecure) ? this.IMG_ROOT_SSL : this.IMG_ROOT; + + if(!this.SUBMENU_TYPE) { + + this.SUBMENU_TYPE = Menu; + + } + + // Create the config object + + this.cfg = new YAHOO.util.Config(this); + + this.initDefaultConfig(); + + var oConfig = this.cfg; + + if(this._checkString(p_oObject)) { + + this._createRootNodeStructure(); + + oConfig.setProperty("text", p_oObject); + + } + else if(this._checkDOMNode(p_oObject)) { + + switch(p_oObject.tagName.toUpperCase()) { + + case "OPTION": + + this._createRootNodeStructure(); + + oConfig.setProperty("text", p_oObject.text); + + this.srcElement = p_oObject; + + break; + + case "OPTGROUP": + + this._createRootNodeStructure(); + + oConfig.setProperty("text", p_oObject.label); + + this.srcElement = p_oObject; + + this._initSubTree(); + + break; + + case "LI": + + // Get the anchor node (if it exists) + + var oAnchor = this._getFirstElement(p_oObject, "A"); + var sURL = "#"; + var sTarget = null; + var sText = null; + + // Capture the "text" and/or the "URL" + + if(oAnchor) { + + sURL = oAnchor.getAttribute("href"); + sTarget = oAnchor.getAttribute("target"); + + if(oAnchor.innerText) { + + sText = oAnchor.innerText; + + } + else { + + var oRange = oAnchor.ownerDocument.createRange(); + + oRange.selectNodeContents(oAnchor); + + sText = oRange.toString(); + + } + + } + else { + + var oText = p_oObject.firstChild; + + sText = oText.nodeValue; + + oAnchor = document.createElement("a"); + + oAnchor.setAttribute("href", sURL); + + p_oObject.replaceChild(oAnchor, oText); + + oAnchor.appendChild(oText); + + } + + this.srcElement = p_oObject; + this.element = p_oObject; + this._oAnchor = oAnchor; + + + // Check if emphasis has been applied to the MenuItem + + var oEmphasisNode = this._getFirstElement(oAnchor); + var bEmphasis = false; + var bStrongEmphasis = false; + + if(oEmphasisNode) { + + // Set a reference to the text node + + this._oText = oEmphasisNode.firstChild; + + switch(oEmphasisNode.tagName.toUpperCase()) { + + case "EM": + + bEmphasis = true; + + break; + + case "STRONG": + + bStrongEmphasis = true; + + break; + + } + + } + else { + + // Set a reference to the text node + + this._oText = oAnchor.firstChild; + + } + + /* + Set these properties silently to sync up the + configuration object without making changes to the + element's DOM + */ + + oConfig.setProperty("text", sText, true); + oConfig.setProperty("url", sURL, true); + oConfig.setProperty("target", sTarget, true); + oConfig.setProperty("emphasis", bEmphasis, true); + oConfig.setProperty( + "strongemphasis", + bStrongEmphasis, + true + ); + + this._initSubTree(); + + break; + + } + + } + + if(this.element) { + + Dom.addClass(this.element, this.CSS_CLASS_NAME); + + // Create custom events + + var CustomEvent = YAHOO.util.CustomEvent; + + this.destroyEvent = new CustomEvent("destroyEvent", this); + this.mouseOverEvent = new CustomEvent("mouseOverEvent", this); + this.mouseOutEvent = new CustomEvent("mouseOutEvent", this); + this.mouseDownEvent = new CustomEvent("mouseDownEvent", this); + this.mouseUpEvent = new CustomEvent("mouseUpEvent", this); + this.clickEvent = new CustomEvent("clickEvent", this); + this.keyPressEvent = new CustomEvent("keyPressEvent", this); + this.keyDownEvent = new CustomEvent("keyDownEvent", this); + this.keyUpEvent = new CustomEvent("keyUpEvent", this); + this.focusEvent = new CustomEvent("focusEvent", this); + this.blurEvent = new CustomEvent("blurEvent", this); + + if(p_oConfig) { + + oConfig.applyConfig(p_oConfig); + + } + + oConfig.fireQueue(); + + } + + }, + + // Private methods + + /** + * @method _getFirstElement + * @description Returns an HTML element's first HTML element node. + * @private + * @param {HTMLElement} p_oElement Object + * reference specifying the element to be evaluated. + * @param {String} p_sTagName Optional. String specifying the tagname of + * the element to be retrieved. + * @return {HTMLElement} + */ + _getFirstElement: function(p_oElement, p_sTagName) { + + var oElement; + + if(p_oElement.firstChild && p_oElement.firstChild.nodeType == 1) { + + oElement = p_oElement.firstChild; + + } + else if( + p_oElement.firstChild && + p_oElement.firstChild.nextSibling && + p_oElement.firstChild.nextSibling.nodeType == 1 + ) { + + oElement = p_oElement.firstChild.nextSibling; + + } + + if(p_sTagName) { + + return (oElement && oElement.tagName.toUpperCase() == p_sTagName) ? + oElement : false; + + } + + return oElement; + + }, + + /** + * @method _checkString + * @description Determines if an object is a string. + * @private + * @param {Object} p_oObject Object to be evaluated. + * @return {Boolean} + */ + _checkString: function(p_oObject) { + + return (typeof p_oObject == "string"); + + }, + + /** + * @method _checkDOMNode + * @description Determines if an object is an HTML element. + * @private + * @param {Object} p_oObject Object to be evaluated. + * @return {Boolean} + */ + _checkDOMNode: function(p_oObject) { + + return (p_oObject && p_oObject.tagName); + + }, + + /** + * @method _createRootNodeStructure + * @description Creates the core DOM structure for the menu item. + * @private + */ + _createRootNodeStructure: function () { + + this.element = document.createElement("li"); + + this._oText = document.createTextNode(""); + + this._oAnchor = document.createElement("a"); + this._oAnchor.appendChild(this._oText); + + this.cfg.refireEvent("url"); + + this.element.appendChild(this._oAnchor); + + }, + + /** + * @method _initSubTree + * @description Iterates the source element's childNodes collection and uses + * the child nodes to instantiate other menus. + * @private + */ + _initSubTree: function() { + + var oSrcEl = this.srcElement; + var oConfig = this.cfg; + + if(oSrcEl.childNodes.length > 0) { + + if( + this.parent.lazyLoad && + this.parent.srcElement && + this.parent.srcElement.tagName.toUpperCase() == "SELECT" + ) { + + oConfig.setProperty( + "submenu", + { id: Dom.generateId(), itemdata: oSrcEl.childNodes } + ); + + } + else { + + var oNode = oSrcEl.firstChild; + var aOptions = []; + + do { + + if(oNode && oNode.tagName) { + + switch(oNode.tagName.toUpperCase()) { + + case "DIV": + + oConfig.setProperty("submenu", oNode); + + break; + + case "OPTION": + + aOptions[aOptions.length] = oNode; + + break; + + } + + } + + } + while((oNode = oNode.nextSibling)); + + + var nOptions = aOptions.length; + + if(nOptions > 0) { + + var oMenu = new this.SUBMENU_TYPE(Dom.generateId()); + + oConfig.setProperty("submenu", oMenu); + + for(var n=0; n0) { + + oAnchor.setAttribute("target", sTarget); + + } + else { + + oAnchor.removeAttribute("target"); + + } + + }, + + /** + * @method configEmphasis + * @description Event handler for when the "emphasis" configuration property + * of the menu item changes. + * @param {String} p_sType String representing the name of the event that + * was fired. + * @param {Array} p_aArgs Array of arguments sent when the event was fired. + * @param {YAHOO.widget.MenuItem} p_oItem Object representing the menu item + * that fired the event. + */ + configEmphasis: function(p_sType, p_aArgs, p_oItem) { + + var bEmphasis = p_aArgs[0]; + var oAnchor = this._oAnchor; + var oText = this._oText; + var oConfig = this.cfg; + var oEM; + + if(bEmphasis && oConfig.getProperty("strongemphasis")) { + + oConfig.setProperty("strongemphasis", false); + + } + + if(oAnchor) { + + if(bEmphasis) { + + oEM = document.createElement("em"); + oEM.appendChild(oText); + + oAnchor.appendChild(oEM); + + } + else { + + oEM = this._getFirstElement(oAnchor, "EM"); + + oAnchor.removeChild(oEM); + oAnchor.appendChild(oText); + + } + + } + + }, + + /** + * @method configStrongEmphasis + * @description Event handler for when the "strongemphasis" configuration + * property of the menu item changes. + * @param {String} p_sType String representing the name of the event that + * was fired. + * @param {Array} p_aArgs Array of arguments sent when the event was fired. + * @param {YAHOO.widget.MenuItem} p_oItem Object representing the menu item + * that fired the event. + */ + configStrongEmphasis: function(p_sType, p_aArgs, p_oItem) { + + var bStrongEmphasis = p_aArgs[0]; + var oAnchor = this._oAnchor; + var oText = this._oText; + var oConfig = this.cfg; + var oStrong; + + if(bStrongEmphasis && oConfig.getProperty("emphasis")) { + + oConfig.setProperty("emphasis", false); + + } + + if(oAnchor) { + + if(bStrongEmphasis) { + + oStrong = document.createElement("strong"); + oStrong.appendChild(oText); + + oAnchor.appendChild(oStrong); + + } + else { + + oStrong = this._getFirstElement(oAnchor, "STRONG"); + + oAnchor.removeChild(oStrong); + oAnchor.appendChild(oText); + + } + + } + + }, + + /** + * @method configChecked + * @description Event handler for when the "checked" configuration property + * of the menu item changes. + * @param {String} p_sType String representing the name of the event that + * was fired. + * @param {Array} p_aArgs Array of arguments sent when the event was fired. + * @param {YAHOO.widget.MenuItem} p_oItem Object representing the menu item + * that fired the event. + */ + configChecked: function(p_sType, p_aArgs, p_oItem) { + + var bChecked = p_aArgs[0]; + var oEl = this.element; + var oConfig = this.cfg; + var oImg; + + + if(bChecked) { + + this._preloadImage(this.CHECKED_IMAGE_PATH); + this._preloadImage(this.SELECTED_CHECKED_IMAGE_PATH); + this._preloadImage(this.DISABLED_CHECKED_IMAGE_PATH); + + oImg = document.createElement("img"); + oImg.src = (this.imageRoot + this.CHECKED_IMAGE_PATH); + oImg.alt = this.CHECKED_IMAGE_ALT_TEXT; + + var oSubmenu = this.cfg.getProperty("submenu"); + + if(oSubmenu) { + + oEl.insertBefore(oImg, oSubmenu.element); + + } + else { + + oEl.appendChild(oImg); + + } + + Dom.addClass([oEl, oImg], "checked"); + + this._checkImage = oImg; + + if(oConfig.getProperty("disabled")) { + + oConfig.refireEvent("disabled"); + + } + + if(oConfig.getProperty("selected")) { + + oConfig.refireEvent("selected"); + + } + + } + else { + + oImg = this._checkImage; + + Dom.removeClass([oEl, oImg], "checked"); + + if(oImg) { + + oEl.removeChild(oImg); + + } + + this._checkImage = null; + + } + + }, + + /** + * @method configDisabled + * @description Event handler for when the "disabled" configuration property + * of the menu item changes. + * @param {String} p_sType String representing the name of the event that + * was fired. + * @param {Array} p_aArgs Array of arguments sent when the event was fired. + * @param {YAHOO.widget.MenuItem} p_oItem Object representing the menu item + * that fired the event. + */ + configDisabled: function(p_sType, p_aArgs, p_oItem) { + + var bDisabled = p_aArgs[0]; + var oAnchor = this._oAnchor; + var aNodes = [this.element, oAnchor]; + var oEM = this._oHelpTextEM; + var oConfig = this.cfg; + var oImg; + var sImgSrc; + var sImgAlt; + + if(oEM) { + + aNodes[2] = oEM; + + } + + if(this.cfg.getProperty("checked")) { + + sImgAlt = this.CHECKED_IMAGE_ALT_TEXT; + sImgSrc = this.CHECKED_IMAGE_PATH; + oImg = this._checkImage; + + if(bDisabled) { + + sImgAlt = this.DISABLED_CHECKED_IMAGE_ALT_TEXT; + sImgSrc = this.DISABLED_CHECKED_IMAGE_PATH; + + } + + oImg.src = document.images[(this.imageRoot + sImgSrc)].src; + oImg.alt = sImgAlt; + + } + + oImg = this.submenuIndicator; + + if(bDisabled) { + + if(oConfig.getProperty("selected")) { + + oConfig.setProperty("selected", false); + + } + + oAnchor.removeAttribute("href"); + + Dom.addClass(aNodes, "disabled"); + + sImgSrc = this.DISABLED_SUBMENU_INDICATOR_IMAGE_PATH; + sImgAlt = this.DISABLED_SUBMENU_INDICATOR_ALT_TEXT; + + } + else { + + oAnchor.setAttribute("href", oConfig.getProperty("url")); + + Dom.removeClass(aNodes, "disabled"); + + sImgSrc = this.SUBMENU_INDICATOR_IMAGE_PATH; + sImgAlt = this.COLLAPSED_SUBMENU_INDICATOR_ALT_TEXT; + + } + + if(oImg) { + + oImg.src = this.imageRoot + sImgSrc; + oImg.alt = sImgAlt; + + } + + }, + + /** + * @method configSelected + * @description Event handler for when the "selected" configuration property + * of the menu item changes. + * @param {String} p_sType String representing the name of the event that + * was fired. + * @param {Array} p_aArgs Array of arguments sent when the event was fired. + * @param {YAHOO.widget.MenuItem} p_oItem Object representing the menu item + * that fired the event. + */ + configSelected: function(p_sType, p_aArgs, p_oItem) { + + if(!this.cfg.getProperty("disabled")) { + + var bSelected = p_aArgs[0]; + var oEM = this._oHelpTextEM; + var aNodes = [this.element, this._oAnchor]; + var oImg = this.submenuIndicator; + var sImgSrc; + + if(oEM) { + + aNodes[aNodes.length] = oEM; + + } + + if(oImg) { + + aNodes[aNodes.length] = oImg; + + } + + + if(this.cfg.getProperty("checked")) { + + sImgSrc = this.imageRoot + (bSelected ? + this.SELECTED_CHECKED_IMAGE_PATH : this.CHECKED_IMAGE_PATH); + + this._checkImage.src = document.images[sImgSrc].src; + + } + + if(bSelected) { + + Dom.addClass(aNodes, "selected"); + sImgSrc = this.SELECTED_SUBMENU_INDICATOR_IMAGE_PATH; + + } + else { + + Dom.removeClass(aNodes, "selected"); + sImgSrc = this.SUBMENU_INDICATOR_IMAGE_PATH; + + } + + if(oImg) { + + oImg.src = document.images[(this.imageRoot + sImgSrc)].src; + + } + + } + + }, + + /** + * @method configSubmenu + * @description Event handler for when the "submenu" configuration property + * of the menu item changes. + * @param {String} p_sType String representing the name of the event that + * was fired. + * @param {Array} p_aArgs Array of arguments sent when the event was fired. + * @param {YAHOO.widget.MenuItem} p_oItem Object representing the menu item + * that fired the event. + */ + configSubmenu: function(p_sType, p_aArgs, p_oItem) { + + var oEl = this.element; + var oSubmenu = p_aArgs[0]; + var oImg = this.submenuIndicator; + var oConfig = this.cfg; + var aNodes = [this.element, this._oAnchor]; + var oMenu; + var bLazyLoad = this.parent && this.parent.lazyLoad; + + if(oSubmenu) { + + if(oSubmenu instanceof Menu) { + + oMenu = oSubmenu; + oMenu.parent = this; + oMenu.lazyLoad = bLazyLoad; + + } + else if( + typeof oSubmenu == "object" && + oSubmenu.id && + !oSubmenu.nodeType + ) { + + var sSubmenuId = oSubmenu.id; + var oSubmenuConfig = oSubmenu; + + delete oSubmenu["id"]; + + oSubmenuConfig.lazyload = bLazyLoad; + oSubmenuConfig.parent = this; + + oMenu = new this.SUBMENU_TYPE(sSubmenuId, oSubmenuConfig); + + // Set the value of the property to the Menu instance + + this.cfg.setProperty("submenu", oMenu, true); + + } + else { + + oMenu = new this.SUBMENU_TYPE( + oSubmenu, + { lazyload: bLazyLoad, parent: this } + ); + + // Set the value of the property to the Menu instance + + this.cfg.setProperty("submenu", oMenu, true); + + } + + if(oMenu) { + + this._oSubmenu = oMenu; + + if(!oImg) { + + this._preloadImage(this.SUBMENU_INDICATOR_IMAGE_PATH); + this._preloadImage( + this.SELECTED_SUBMENU_INDICATOR_IMAGE_PATH + ); + + this._preloadImage( + this.DISABLED_SUBMENU_INDICATOR_IMAGE_PATH + ); + + oImg = document.createElement("img"); + + oImg.src = + (this.imageRoot + this.SUBMENU_INDICATOR_IMAGE_PATH); + + oImg.alt = this.COLLAPSED_SUBMENU_INDICATOR_ALT_TEXT; + + oEl.appendChild(oImg); + + this.submenuIndicator = oImg; + + Dom.addClass(aNodes, "hassubmenu"); + + if(oConfig.getProperty("disabled")) { + + oConfig.refireEvent("disabled"); + + } + + if(oConfig.getProperty("selected")) { + + oConfig.refireEvent("selected"); + + } + + } + + } + + } + else { + + Dom.removeClass(aNodes, "hassubmenu"); + + if(oImg) { + + oEl.removeChild(oImg); + + } + + if(this._oSubmenu) { + + this._oSubmenu.destroy(); + + } + + } + + }, + + // Public methods + + /** + * @method initDefaultConfig + * @description Initializes an item's configurable properties. + */ + initDefaultConfig : function() { + + var oConfig = this.cfg; + var CheckBoolean = oConfig.checkBoolean; + + // Define the config properties + + /** + * @config text + * @description String specifying the text label for the menu item. + * When building a menu from existing HTML the value of this property + * will be interpreted from the menu's markup. + * @default "" + * @type String + */ + oConfig.addProperty( + "text", + { + value: "", + handler: this.configText, + validator: this._checkString, + suppressEvent: true + } + ); + + + /** + * @config helptext + * @description String specifying additional instructional text to + * accompany the text for the nenu item. + * @default null + * @type String| + * HTMLElement + */ + oConfig.addProperty("helptext", { handler: this.configHelpText }); + + /** + * @config url + * @description String specifying the URL for the menu item's anchor's + * "href" attribute. When building a menu from existing HTML the value + * of this property will be interpreted from the menu's markup. + * @default "#" + * @type String + */ + oConfig.addProperty( + "url", + { value: "#", handler: this.configURL, suppressEvent: true } + ); + + /** + * @config target + * @description String specifying the value for the "target" attribute + * of the menu item's anchor element. Specifying a target will + * require the user to click directly on the menu item's anchor node in + * order to cause the browser to navigate to the specified URL. + * When building a menu from existing HTML the value of this property + * will be interpreted from the menu's markup. + * @default null + * @type String + */ + oConfig.addProperty( + "target", + { handler: this.configTarget, suppressEvent: true } + ); + + /** + * @config emphasis + * @description Boolean indicating if the text of the menu item will be + * rendered with emphasis. When building a menu from existing HTML the + * value of this property will be interpreted from the menu's markup. + * @default false + * @type Boolean + */ + oConfig.addProperty( + "emphasis", + { + value: false, + handler: this.configEmphasis, + validator: CheckBoolean, + suppressEvent: true + } + ); + + /** + * @config strongemphasis + * @description Boolean indicating if the text of the menu item will be + * rendered with strong emphasis. When building a menu from existing + * HTML the value of this property will be interpreted from the + * menu's markup. + * @default false + * @type Boolean + */ + oConfig.addProperty( + "strongemphasis", + { + value: false, + handler: this.configStrongEmphasis, + validator: CheckBoolean, + suppressEvent: true + } + ); + + /** + * @config checked + * @description Boolean indicating if the menu item should be rendered + * with a checkmark. + * @default false + * @type Boolean + */ + oConfig.addProperty( + "checked", + { + value: false, + handler: this.configChecked, + validator: this.cfg.checkBoolean, + suppressEvent: true, + supercedes:["disabled"] + } + ); + + /** + * @config disabled + * @description Boolean indicating if the menu item should be disabled. + * (Disabled menu items are dimmed and will not respond to user input + * or fire events.) + * @default false + * @type Boolean + */ + oConfig.addProperty( + "disabled", + { + value: false, + handler: this.configDisabled, + validator: CheckBoolean, + suppressEvent: true + } + ); + + /** + * @config selected + * @description Boolean indicating if the menu item should + * be highlighted. + * @default false + * @type Boolean + */ + oConfig.addProperty( + "selected", + { + value: false, + handler: this.configSelected, + validator: CheckBoolean, + suppressEvent: true + } + ); + + /** + * @config submenu + * @description Object specifying the submenu to be appended to the + * menu item. The value can be one of the following: + * @default null + * @type Menu|String|Object| + * HTMLElement + */ + oConfig.addProperty("submenu", { handler: this.configSubmenu }); + + }, + + /** + * @method getNextEnabledSibling + * @description Finds the menu item's next enabled sibling. + * @return YAHOO.widget.MenuItem + */ + getNextEnabledSibling: function() { + + if(this.parent instanceof Menu) { + + var nGroupIndex = this.groupIndex; + + /** + * Finds the next item in an array. + * @private + * @param {p_aArray} Array to search. + * @param {p_nStartIndex} Number indicating the index to + * start searching the array. + * @return {Object} + */ + var getNextArrayItem = function(p_aArray, p_nStartIndex) { + + return p_aArray[p_nStartIndex] || + getNextArrayItem(p_aArray, (p_nStartIndex+1)); + + }; + + + var aItemGroups = this.parent.getItemGroups(); + var oNextItem; + + + if(this.index < (aItemGroups[nGroupIndex].length - 1)) { + + oNextItem = getNextArrayItem( + aItemGroups[nGroupIndex], + (this.index+1) + ); + + } + else { + + var nNextGroupIndex; + + if(nGroupIndex < (aItemGroups.length - 1)) { + + nNextGroupIndex = nGroupIndex + 1; + + } + else { + + nNextGroupIndex = 0; + + } + + var aNextGroup = getNextArrayItem(aItemGroups, nNextGroupIndex); + + // Retrieve the first menu item in the next group + + oNextItem = getNextArrayItem(aNextGroup, 0); + + } + + return ( + oNextItem.cfg.getProperty("disabled") || + oNextItem.element.style.display == "none" + ) ? + oNextItem.getNextEnabledSibling() : oNextItem; + + } + + }, + + /** + * @method getPreviousEnabledSibling + * @description Finds the menu item's previous enabled sibling. + * @return {YAHOO.widget.MenuItem} + */ + getPreviousEnabledSibling: function() { + + if(this.parent instanceof Menu) { + + var nGroupIndex = this.groupIndex; + + /** + * Returns the previous item in an array + * @private + * @param {p_aArray} Array to search. + * @param {p_nStartIndex} Number indicating the index to + * start searching the array. + * @return {Object} + */ + var getPreviousArrayItem = function(p_aArray, p_nStartIndex) { + + return p_aArray[p_nStartIndex] || + getPreviousArrayItem(p_aArray, (p_nStartIndex-1)); + + }; + + /** + * Get the index of the first item in an array + * @private + * @param {p_aArray} Array to search. + * @param {p_nStartIndex} Number indicating the index to + * start searching the array. + * @return {Object} + */ + var getFirstItemIndex = function(p_aArray, p_nStartIndex) { + + return p_aArray[p_nStartIndex] ? + p_nStartIndex : + getFirstItemIndex(p_aArray, (p_nStartIndex+1)); + + }; + + var aItemGroups = this.parent.getItemGroups(); + var oPreviousItem; + + if( + this.index > getFirstItemIndex(aItemGroups[nGroupIndex], 0) + ) { + + oPreviousItem = + getPreviousArrayItem( + aItemGroups[nGroupIndex], + (this.index-1) + ); + + } + else { + + var nPreviousGroupIndex; + + if(nGroupIndex > getFirstItemIndex(aItemGroups, 0)) { + + nPreviousGroupIndex = nGroupIndex - 1; + + } + else { + + nPreviousGroupIndex = aItemGroups.length - 1; + + } + + var aPreviousGroup = + getPreviousArrayItem(aItemGroups, nPreviousGroupIndex); + + oPreviousItem = + getPreviousArrayItem( + aPreviousGroup, + (aPreviousGroup.length - 1) + ); + + } + + return ( + oPreviousItem.cfg.getProperty("disabled") || + oPreviousItem.element.style.display == "none" + ) ? + oPreviousItem.getPreviousEnabledSibling() : oPreviousItem; + + } + + }, + + /** + * @method focus + * @description Causes the menu item to receive the focus and fires the + * focus event. + */ + focus: function() { + + var oParent = this.parent; + var oAnchor = this._oAnchor; + var oActiveItem = oParent.activeItem; + + if( + !this.cfg.getProperty("disabled") && + oParent && + oParent.cfg.getProperty("visible") && + this.element.style.display != "none" + ) { + + if(oActiveItem) { + + oActiveItem.blur(); + + } + + try { + + oAnchor.focus(); + + } + catch(e) { + + } + + this.focusEvent.fire(); + + } + + }, + + /** + * @method blur + * @description Causes the menu item to lose focus and fires the + * onblur event. + */ + blur: function() { + + var oParent = this.parent; + + if( + !this.cfg.getProperty("disabled") && + oParent && + Dom.getStyle(oParent.element, "visibility") == "visible" + ) { + + this._oAnchor.blur(); + + this.blurEvent.fire(); + + } + + }, + + /** + * @method destroy + * @description Removes the menu item's
- Object + * specifying a Menu instance.
- Object literal specifying the + * menu to be created. Format:
{ id: [menu id], itemdata: + * [array of values for + * items] }
.- String specifying the id attribute + * of the
<div>
element of the menu.- + * Object specifying the
<div>
element of the + * menu.<li>
element + * from its parent<ul>
element. + */ + destroy: function() { + + var oEl = this.element; + + if(oEl) { + + // Remove CustomEvent listeners + + this.mouseOverEvent.unsubscribeAll(); + this.mouseOutEvent.unsubscribeAll(); + this.mouseDownEvent.unsubscribeAll(); + this.mouseUpEvent.unsubscribeAll(); + this.clickEvent.unsubscribeAll(); + this.keyPressEvent.unsubscribeAll(); + this.keyDownEvent.unsubscribeAll(); + this.keyUpEvent.unsubscribeAll(); + this.focusEvent.unsubscribeAll(); + this.blurEvent.unsubscribeAll(); + this.cfg.configChangedEvent.unsubscribeAll(); + + // Remove the element from the parent node + + var oParentNode = oEl.parentNode; + + if(oParentNode) { + + oParentNode.removeChild(oEl); + + this.destroyEvent.fire(); + + } + + this.destroyEvent.unsubscribeAll(); + + } + + }, + + /** + * @method toString + * @description Returns a string representing the menu item. + * @return {String} + */ + toString: function() { + + return ("MenuItem: " + this.cfg.getProperty("text")); + + } + +}; + +})(); + +/** +* Creates an item for a menu module. +* +* @param {String} p_oObject String specifying the text of the menu module item. +* @param {HTMLLIElement} p_oObject Object specifying the +*<li>
element of the menu module item. +* @param {HTMLOptGroupElement} p_oObject Object specifying +* the<optgroup>
element of the menu module item. +* @param {HTMLOptionElement} p_oObject Object specifying the +*<option>
element of the menu module item. +* @param {Object} p_oConfig Optional. Object literal specifying the +* configuration for the menu module item. See configuration class documentation +* for more details. +* @class MenuModuleItem +* @constructor +* @deprecated As of version 0.12, all MenuModuleItem functionality has been +* implemented directly in YAHOO.widget.MenuItem, making YAHOO.widget.MenuItem +* the base class for all menu items. +*/ +YAHOO.widget.MenuModuleItem = YAHOO.widget.MenuItem; + +/** +* Creates a list of options or commands which are made visible in response to +* an HTML element's "contextmenu" event ("mousedown" for Opera). +* +* @param {String} p_oElement String specifying the id attribute of the +*<div>
element of the context menu. +* @param {String} p_oElement String specifying the id attribute of the +*<select>
element to be used as the data source for the +* context menu. +* @param {HTMLDivElement} p_oElement Object specifying the +*<div>
element of the context menu. +* @param {HTMLSelectElement} p_oElement Object specifying +* the<select>
element to be used as the data source for +* the context menu. +* @param {Object} p_oConfig Optional. Object literal specifying the +* configuration for the context menu. See configuration class documentation +* for more details. +* @class ContextMenu +* @constructor +* @extends YAHOO.widget.Menu +* @namespace YAHOO.widget +*/ +YAHOO.widget.ContextMenu = function(p_oElement, p_oConfig) { + + YAHOO.widget.ContextMenu.superclass.constructor.call( + this, + p_oElement, + p_oConfig + ); + +}; + +YAHOO.extend(YAHOO.widget.ContextMenu, YAHOO.widget.Menu, { + +// Private properties + +/** +* @property _oTrigger +* @description Object reference to the current value of the "trigger" +* configuration property. +* @default null +* @private +* @type String|HTMLElement|Array +*/ +_oTrigger: null, + +// Public properties + +/** +* @property contextEventTarget +* @description Object reference for the HTML element that was the target of the +* "contextmenu" DOM event ("mousedown" for Opera) that triggered the display of +* the context menu. +* @default null +* @type HTMLElement +*/ +contextEventTarget: null, + +/** +* @method init +* @description The ContextMenu class's initialization method. This method is +* automatically called by the constructor, and sets up all DOM references for +* pre-existing markup, and creates required markup if it is not already present. +* @param {String} p_oElement String specifying the id attribute of the +*<div>
element of the context menu. +* @param {String} p_oElement String specifying the id attribute of the +*<select>
element to be used as the data source for +* the context menu. +* @param {HTMLDivElement} p_oElement Object specifying the +*<div>
element of the context menu. +* @param {HTMLSelectElement} p_oElement Object specifying +* the<select>
element to be used as the data source for +* the context menu. +* @param {Object} p_oConfig Optional. Object literal specifying the +* configuration for the context menu. See configuration class documentation +* for more details. +*/ +init: function(p_oElement, p_oConfig) { + + if(!this.ITEM_TYPE) { + + this.ITEM_TYPE = YAHOO.widget.ContextMenuItem; + + } + + // Call the init of the superclass (YAHOO.widget.Menu) + + YAHOO.widget.ContextMenu.superclass.init.call(this, p_oElement); + + this.beforeInitEvent.fire(YAHOO.widget.ContextMenu); + + if(p_oConfig) { + + this.cfg.applyConfig(p_oConfig, true); + + } + + + this.initEvent.fire(YAHOO.widget.ContextMenu); + +}, + +// Private methods + +/** +* @method _removeEventHandlers +* @description Removes all of the DOM event handlers from the HTML element(s) +* whose "context menu" event ("click" for Opera) trigger the display of +* the context menu. +* @private +*/ +_removeEventHandlers: function() { + + var Event = YAHOO.util.Event; + var oTrigger = this._oTrigger; + var bOpera = (this.browser == "opera"); + + // Remove the event handlers from the trigger(s) + + Event.removeListener( + oTrigger, + (bOpera ? "mousedown" : "contextmenu"), + this._onTriggerContextMenu + ); + + if(bOpera) { + + Event.removeListener(oTrigger, "click", this._onTriggerClick); + + } + +}, + +// Private event handlers + +/** +* @method _onTriggerClick +* @description "click" event handler for the HTML element(s) identified as the +* "trigger" for the context menu. Used to cancel default behaviors in Opera. +* @private +* @param {Event} p_oEvent Object representing the DOM event object passed back +* by the event utility (YAHOO.util.Event). +* @param {YAHOO.widget.ContextMenu} p_oMenu Object representing the context +* menu that is handling the event. +*/ +_onTriggerClick: function(p_oEvent, p_oMenu) { + + if(p_oEvent.ctrlKey) { + + YAHOO.util.Event.stopEvent(p_oEvent); + + } + +}, + +/** +* @method _onTriggerContextMenu +* @description "contextmenu" event handler ("mousedown" for Opera) for the HTML +* element(s) that trigger the display of the context menu. +* @private +* @param {Event} p_oEvent Object representing the DOM event object passed back +* by the event utility (YAHOO.util.Event). +* @param {YAHOO.widget.ContextMenu} p_oMenu Object representing the context +* menu that is handling the event. +*/ +_onTriggerContextMenu: function(p_oEvent, p_oMenu) { + + // Hide any other ContextMenu instances that might be visible + + YAHOO.widget.MenuManager.hideVisible(); + + var Event = YAHOO.util.Event; + var oConfig = this.cfg; + + if(p_oEvent.type == "mousedown" && !p_oEvent.ctrlKey) { + + return; + + } + + this.contextEventTarget = Event.getTarget(p_oEvent); + + // Position and display the context menu + + var nX = Event.getPageX(p_oEvent); + var nY = Event.getPageY(p_oEvent); + + oConfig.applyConfig( { xy:[nX, nY], visible:true } ); + oConfig.fireQueue(); + + /* + Prevent the browser's default context menu from appearing and + stop the propagation of the "contextmenu" event so that + other ContextMenu instances are not displayed. + */ + + Event.stopEvent(p_oEvent); + +}, + +// Public methods + +/** +* @method toString +* @description Returns a string representing the context menu. +* @return {String} +*/ +toString: function() { + + return ("ContextMenu " + this.id); + +}, + +/** +* @method initDefaultConfig +* @description Initializes the class's configurable properties which can be +* changed using the context menu's Config object ("cfg"). +*/ +initDefaultConfig: function() { + + YAHOO.widget.ContextMenu.superclass.initDefaultConfig.call(this); + + /** + * @config trigger + * @description The HTML element(s) whose "contextmenu" event ("mousedown" + * for Opera) trigger the display of the context menu. Can be a string + * representing the id attribute of the HTML element, an object reference + * for the HTML element, or an array of strings or HTML element references. + * @default null + * @type String|HTMLElement|Array + */ + this.cfg.addProperty("trigger", { handler: this.configTrigger }); + +}, + +/** +* @method destroy +* @description Removes the context menu's<div>
element +* (and accompanying child nodes) from the document. +*/ +destroy: function() { + + // Remove the DOM event handlers from the current trigger(s) + + this._removeEventHandlers(); + + + // Continue with the superclass implementation of this method + + YAHOO.widget.ContextMenu.superclass.destroy.call(this); + +}, + +// Public event handlers for configuration properties + +/** +* @method configTrigger +* @description Event handler for when the value of the "trigger" configuration +* property changes. +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.ContextMenu} p_oMenu Object representing the context +* menu that fired the event. +*/ +configTrigger: function(p_sType, p_aArgs, p_oMenu) { + + var Event = YAHOO.util.Event; + var oTrigger = p_aArgs[0]; + + if(oTrigger) { + + /* + If there is a current "trigger" - remove the event handlers + from that element(s) before assigning new ones + */ + + if(this._oTrigger) { + + this._removeEventHandlers(); + + } + + this._oTrigger = oTrigger; + + /* + Listen for the "mousedown" event in Opera b/c it does not + support the "contextmenu" event + */ + + var bOpera = (this.browser == "opera"); + + Event.addListener( + oTrigger, + (bOpera ? "mousedown" : "contextmenu"), + this._onTriggerContextMenu, + this, + true + ); + + /* + Assign a "click" event handler to the trigger element(s) for + Opera to prevent default browser behaviors. + */ + + if(bOpera) { + + Event.addListener( + oTrigger, + "click", + this._onTriggerClick, + this, + true + ); + + } + + } + else { + + this._removeEventHandlers(); + + } + +} + +}); // END YAHOO.extend + +/** +* Creates an item for a context menu. +* +* @param {String} p_oObject String specifying the text of the context menu item. +* @param {HTMLLIElement} p_oObject Object specifying the +*<li>
element of the context menu item. +* @param {HTMLOptGroupElement} p_oObject Object +* specifying the<optgroup>
element of the context +* menu item. +* @param {HTMLOptionElement} p_oObject Object specifying +* the<option>
element of the context menu item. +* @param {Object} p_oConfig Optional. Object literal specifying the +* configuration for the context menu item. See configuration class +* documentation for more details. +* @class ContextMenuItem +* @constructor +* @extends YAHOO.widget.MenuItem +*/ +YAHOO.widget.ContextMenuItem = function(p_oObject, p_oConfig) { + + YAHOO.widget.ContextMenuItem.superclass.constructor.call( + this, + p_oObject, + p_oConfig + ); + +}; + +YAHOO.extend(YAHOO.widget.ContextMenuItem, YAHOO.widget.MenuItem, { + +/** +* @method init +* @description The ContextMenuItem class's initialization method. This method +* is automatically called by the constructor, and sets up all DOM references +* for pre-existing markup, and creates required markup if it is not +* already present. +* @param {String} p_oObject String specifying the text of the context menu item. +* @param {HTMLLIElement} p_oObject Object specifying the +*<li>
element of the context menu item. +* @param {HTMLOptGroupElement} p_oObject Object +* specifying the<optgroup>
element of the context +* menu item. +* @param {HTMLOptionElement} p_oObject Object specifying +* the<option>
element of the context menu item. +* @param {Object} p_oConfig Optional. Object literal specifying the +* configuration for the context menu item. See configuration class +* documentation for more details. +*/ +init: function(p_oObject, p_oConfig) { + + if(!this.SUBMENU_TYPE) { + + this.SUBMENU_TYPE = YAHOO.widget.ContextMenu; + + } + + /* + Call the init of the superclass (YAHOO.widget.MenuItem) + Note: We don't pass the user config in here yet + because we only want it executed once, at the lowest + subclass level. + */ + + YAHOO.widget.ContextMenuItem.superclass.init.call(this, p_oObject); + + var oConfig = this.cfg; + + if(p_oConfig) { + + oConfig.applyConfig(p_oConfig, true); + + } + + oConfig.fireQueue(); + +}, + +// Public methods + +/** +* @method toString +* @description Returns a string representing the context menu item. +* @return {String} +*/ +toString: function() { + + return ("MenuBarItem: " + this.cfg.getProperty("text")); + +} + +}); // END YAHOO.extend + +/** +* Horizontal collection of items, each of which can contain a submenu. +* +* @param {String} p_oElement String specifying the id attribute of the +*<div>
element of the menu bar. +* @param {String} p_oElement String specifying the id attribute of the +*<select>
element to be used as the data source for the +* menu bar. +* @param {HTMLDivElement} p_oElement Object specifying +* the<div>
element of the menu bar. +* @param {HTMLSelectElement} p_oElement Object +* specifying the<select>
element to be used as the data +* source for the menu bar. +* @param {Object} p_oConfig Optional. Object literal specifying the +* configuration for the menu bar. See configuration class documentation for +* more details. +* @class Menubar +* @constructor +* @extends YAHOO.widget.Menu +* @namespace YAHOO.widget +*/ +YAHOO.widget.MenuBar = function(p_oElement, p_oConfig) { + + YAHOO.widget.MenuBar.superclass.constructor.call( + this, + p_oElement, + p_oConfig + ); + +}; + +YAHOO.extend(YAHOO.widget.MenuBar, YAHOO.widget.Menu, { + +/** +* @method init +* @description The MenuBar class's initialization method. This method is +* automatically called by the constructor, and sets up all DOM references for +* pre-existing markup, and creates required markup if it is not already present. +* @param {String} p_oElement String specifying the id attribute of the +*<div>
element of the menu bar. +* @param {String} p_oElement String specifying the id attribute of the +*<select>
element to be used as the data source for the +* menu bar. +* @param {HTMLDivElement} p_oElement Object specifying +* the<div>
element of the menu bar. +* @param {HTMLSelectElement} p_oElement Object +* specifying the<select>
element to be used as the data +* source for the menu bar. +* @param {Object} p_oConfig Optional. Object literal specifying the +* configuration for the menu bar. See configuration class documentation for +* more details. +*/ +init: function(p_oElement, p_oConfig) { + + if(!this.ITEM_TYPE) { + + this.ITEM_TYPE = YAHOO.widget.MenuBarItem; + + } + + // Call the init of the superclass (YAHOO.widget.Menu) + + YAHOO.widget.MenuBar.superclass.init.call(this, p_oElement); + + this.beforeInitEvent.fire(YAHOO.widget.MenuBar); + + if(p_oConfig) { + + this.cfg.applyConfig(p_oConfig, true); + + } + + this.initEvent.fire(YAHOO.widget.MenuBar); + +}, + +// Constants + +/** +* @property CSS_CLASS_NAME +* @description String representing the CSS class(es) to be applied to the menu +* bar's<div>
element. +* @default "yuimenubar" +* @final +* @type String +*/ +CSS_CLASS_NAME: "yuimenubar", + +// Protected event handlers + +/** +* @method _onKeyDown +* @description "keydown" Custom Event handler for the menu bar. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.MenuBar} p_oMenuBar Object representing the menu bar +* that fired the event. +*/ +_onKeyDown: function(p_sType, p_aArgs, p_oMenuBar) { + + var Event = YAHOO.util.Event; + var oEvent = p_aArgs[0]; + var oItem = p_aArgs[1]; + var oItemCfg = oItem.cfg; + var oSubmenu; + + switch(oEvent.keyCode) { + + case 27: // Esc key + + if(this.cfg.getProperty("position") == "dynamic") { + + this.hide(); + + if(this.parent) { + + this.parent.focus(); + + } + + } + else if(this.activeItem) { + + oSubmenu = this.activeItem.cfg.getProperty("submenu"); + + if(oSubmenu && oSubmenu.cfg.getProperty("visible")) { + + oSubmenu.hide(); + this.activeItem.focus(); + + } + else { + + this.activeItem.cfg.setProperty("selected", false); + this.activeItem.blur(); + + } + + } + + + Event.preventDefault(oEvent); + + break; + + case 37: // Left arrow + case 39: // Right arrow + + if( + oItem == this.activeItem && + !oItemCfg.getProperty("selected") + ) { + + oItemCfg.setProperty("selected", true); + + } + else { + + var oNextItem = (oEvent.keyCode == 37) ? + oItem.getPreviousEnabledSibling() : + oItem.getNextEnabledSibling(); + + if(oNextItem) { + + this.clearActiveItem(); + + oNextItem.cfg.setProperty("selected", true); + + if(this.cfg.getProperty("autosubmenudisplay")) { + + oSubmenu = oNextItem.cfg.getProperty("submenu"); + + if(oSubmenu) { + + oSubmenu.show(); + oSubmenu.activeItem.blur(); + oSubmenu.activeItem = null; + + } + + } + + oNextItem.focus(); + + } + + } + + Event.preventDefault(oEvent); + + break; + + case 40: // Down arrow + + if(this.activeItem != oItem) { + + this.clearActiveItem(); + + oItemCfg.setProperty("selected", true); + oItem.focus(); + + } + + oSubmenu = oItemCfg.getProperty("submenu"); + + if(oSubmenu) { + + if(oSubmenu.cfg.getProperty("visible")) { + + oSubmenu.setInitialSelection(); + oSubmenu.setInitialFocus(); + + } + else { + + oSubmenu.show(); + + } + + } + + Event.preventDefault(oEvent); + + break; + + } + +}, + +/** +* @method _onClick +* @description "click" event handler for the menu bar. +* @protected +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.MenuBar} p_oMenuBar Object representing the menu bar +* that fired the event. +*/ +_onClick: function(p_sType, p_aArgs, p_oMenuBar) { + + YAHOO.widget.MenuBar.superclass._onClick.call( + this, + p_sType, + p_aArgs, + p_oMenuBar + ); + + var oItem = p_aArgs[1]; + + if(oItem) { + + var Event = YAHOO.util.Event; + var Dom = YAHOO.util.Dom; + + var oEvent = p_aArgs[0]; + var oTarget = Event.getTarget(oEvent); + + var oActiveItem = this.activeItem; + var oConfig = this.cfg; + + // Hide any other submenus that might be visible + + if(oActiveItem && oActiveItem != oItem) { + + this.clearActiveItem(); + + } + + + // Select and focus the current item + + oItem.cfg.setProperty("selected", true); + oItem.focus(); + + + // Show the submenu for the item + + var oSubmenu = oItem.cfg.getProperty("submenu"); + + if(oSubmenu && oTarget != oItem.submenuIndicator) { + + if(oSubmenu.cfg.getProperty("visible")) { + + oSubmenu.hide(); + + } + else { + + oSubmenu.show(); + + } + + } + + } + +}, + +// Public methods + +/** +* @method toString +* @description Returns a string representing the menu bar. +* @return {String} +*/ +toString: function() { + + return ("MenuBar " + this.id); + +}, + +/** +* @description Initializes the class's configurable properties which can be +* changed using the menu bar's Config object ("cfg"). +* @method initDefaultConfig +*/ +initDefaultConfig: function() { + + YAHOO.widget.MenuBar.superclass.initDefaultConfig.call(this); + + var oConfig = this.cfg; + + // Add configuration properties + + /* + Set the default value for the "position" configuration property + to "static" by re-adding the property. + */ + + /** + * @config position + * @description String indicating how a menu bar should be positioned on the + * screen. Possible values are "static" and "dynamic." Static menu bars + * are visible by default and reside in the normal flow of the document + * (CSS position: static). Dynamic menu bars are hidden by default, reside + * out of the normal flow of the document (CSS position: absolute), and can + * overlay other elements on the screen. + * @default static + * @type String + */ + oConfig.addProperty( + "position", + { + value: "static", + handler: this.configPosition, + validator: this._checkPosition, + supercedes: ["visible"] + } + ); + + /* + Set the default value for the "submenualignment" configuration property + to ["tl","bl"] by re-adding the property. + */ + + /** + * @config submenualignment + * @description Array defining how submenus should be aligned to their + * parent menu bar item. The format is: [itemCorner, submenuCorner]. + * @default ["tl","bl"] + * @type Array + */ + oConfig.addProperty("submenualignment", { value: ["tl","bl"] } ); + + /* + Change the default value for the "autosubmenudisplay" configuration + property to "false" by re-adding the property. + */ + + /** + * @config autosubmenudisplay + * @description Boolean indicating if submenus are automatically made + * visible when the user mouses over the menu bar's items. + * @default false + * @type Boolean + */ + oConfig.addProperty( + "autosubmenudisplay", + { value: false, validator: oConfig.checkBoolean } + ); + +} + +}); // END YAHOO.extend + +/** +* Creates an item for a menu bar. +* +* @param {String} p_oObject String specifying the text of the menu bar item. +* @param {HTMLLIElement} p_oObject Object specifying the +*<li>
element of the menu bar item. +* @param {HTMLOptGroupElement} p_oObject Object +* specifying the<optgroup>
element of the menu bar item. +* @param {HTMLOptionElement} p_oObject Object specifying +* the<option>
element of the menu bar item. +* @param {Object} p_oConfig Optional. Object literal specifying the +* configuration for the menu bar item. See configuration class documentation +* for more details. +* @class MenuBarItem +* @constructor +* @extends YAHOO.widget.MenuItem +*/ +YAHOO.widget.MenuBarItem = function(p_oObject, p_oConfig) { + + YAHOO.widget.MenuBarItem.superclass.constructor.call( + this, + p_oObject, + p_oConfig + ); + +}; + +YAHOO.extend(YAHOO.widget.MenuBarItem, YAHOO.widget.MenuItem, { + +/** +* @method init +* @description The MenuBarItem class's initialization method. This method is +* automatically called by the constructor, and sets up all DOM references for +* pre-existing markup, and creates required markup if it is not already present. +* @param {String} p_oObject String specifying the text of the menu bar item. +* @param {HTMLLIElement} p_oObject Object specifying the +*<li>
element of the menu bar item. +* @param {HTMLOptGroupElement} p_oObject Object +* specifying the<optgroup>
element of the menu bar item. +* @param {HTMLOptionElement} p_oObject Object specifying +* the<option>
element of the menu bar item. +* @param {Object} p_oConfig Optional. Object literal specifying the +* configuration for the menu bar item. See configuration class documentation +* for more details. +*/ +init: function(p_oObject, p_oConfig) { + + if(!this.SUBMENU_TYPE) { + + this.SUBMENU_TYPE = YAHOO.widget.Menu; + + } + + /* + Call the init of the superclass (YAHOO.widget.MenuItem) + Note: We don't pass the user config in here yet + because we only want it executed once, at the lowest + subclass level. + */ + + YAHOO.widget.MenuBarItem.superclass.init.call(this, p_oObject); + + var oConfig = this.cfg; + + if(p_oConfig) { + + oConfig.applyConfig(p_oConfig, true); + + } + + oConfig.fireQueue(); + +}, + +// Constants + +/** +* @property CSS_CLASS_NAME +* @description String representing the CSS class(es) to be applied to the +*<li>
element of the menu bar item. +* @default "yuimenubaritem" +* @final +* @type String +*/ +CSS_CLASS_NAME: "yuimenubaritem", + +/** +* @property SUBMENU_INDICATOR_IMAGE_PATH +* @description String representing the path to the image to be used for the +* menu bar item's submenu arrow indicator. +* @default "nt/ic/ut/alt1/menuarodwn8_nrm_1.gif" +* @final +* @type String +*/ +SUBMENU_INDICATOR_IMAGE_PATH: "nt/ic/ut/alt1/menuarodwn8_nrm_1.gif", + +/** +* @property SELECTED_SUBMENU_INDICATOR_IMAGE_PATH +* @description String representing the path to the image to be used for the +* submenu arrow indicator when the menu bar item is selected. +* @default "nt/ic/ut/alt1/menuarodwn8_hov_1.gif" +* @final +* @type String +*/ +SELECTED_SUBMENU_INDICATOR_IMAGE_PATH: "nt/ic/ut/alt1/menuarodwn8_hov_1.gif", + +/** +* @property DISABLED_SUBMENU_INDICATOR_IMAGE_PATH +* @description String representing the path to the image to be used for the +* submenu arrow indicator when the menu bar item is disabled. +* @default "nt/ic/ut/alt1/menuarodwn8_dim_1.gif" +* @final +* @type String +*/ +DISABLED_SUBMENU_INDICATOR_IMAGE_PATH: "nt/ic/ut/alt1/menuarodwn8_dim_1.gif", + +// Public methods + +/** +* @method toString +* @description Returns a string representing the menu bar item. +* @return {String} +*/ +toString: function() { + + return ("MenuBarItem: " + this.cfg.getProperty("text")); + +} + +}); // END YAHOO.extend + diff --git a/frontend/beta/js/YUI/slider.js b/frontend/beta/js/YUI/slider.js new file mode 100644 index 0000000..8d3cd62 --- a/dev/null +++ b/frontend/beta/js/YUI/slider.js @@ -0,0 +1,1113 @@ +/* +Copyright (c) 2006, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 0.12.0 +*/ + +/** + * The Slider component is a UI control that enables the user to adjust + * values in a finite range along one or two axes. Typically, the Slider + * control is used in a web application as a rich, visual replacement + * for an input box that takes a number as input. The Slider control can + * also easily accommodate a second dimension, providing x,y output for + * a selection point chosen from a rectangular region. + * + * @module slider + * @title Slider Widget + * @namespace YAHOO.widget + * @requires yahoo,dom,dragdrop,event + * @optional animation + */ + +/** + * A DragDrop implementation that can be used as a background for a + * slider. It takes a reference to the thumb instance + * so it can delegate some of the events to it. The goal is to make the + * thumb jump to the location on the background when the background is + * clicked. + * + * @class Slider + * @extends YAHOO.util.DragDrop + * @constructor + * @param {String} id The id of the element linked to this instance + * @param {String} sGroup The group of related DragDrop items + * @param {String} sType The type of slider (horiz, vert, region) + */ +YAHOO.widget.Slider = function(sElementId, sGroup, oThumb, sType) { + if (sElementId) { + + /** + * The type of the slider (horiz, vert, region) + * @property type + * @type string + */ + this.type = sType; + + this.init(sElementId, sGroup, true); + + //this.removeInvalidHandleType("A"); + + + var self = this; + + /** + * Event the fires when the value of the control changes. If + * the control is animated the event will fire every point + * along the way. + * @event change + * @param {int} new + * @param {int} firstOffset the number of pixels the thumb has moved + * from its start position. Normal horizontal and vertical sliders will only + * have the firstOffset. Regions will have both, the first is the horizontal + * offset, the second the vertical. + * @param {int} secondOffset the y offset for region sliders + */ + this.createEvent("change", this); + + /** + * Event that fires at the end of a slider thumb move. + * @event slideStart + */ + this.createEvent("slideStart", this); + + /** + * Event that fires at the end of a slider thumb move + * @event slideEnd + */ + this.createEvent("slideEnd", this); + + /** + * A YAHOO.widget.SliderThumb instance that we will use to + * reposition the thumb when the background is clicked + * @property thumb + * @type YAHOO.widget.SliderThumb + */ + this.thumb = oThumb; + + // add handler for the handle onchange event + oThumb.onChange = function() { + self.handleThumbChange(); + }; + + /** + * Overrides the isTarget property in YAHOO.util.DragDrop + * @property isTarget + * @private + */ + this.isTarget = false; + + /** + * Flag that determines if the thumb will animate when moved + * @property animate + * @type boolean + */ + this.animate = YAHOO.widget.Slider.ANIM_AVAIL; + + /** + * Set to false to disable a background click thumb move + * @property backgroundEnabled + * @type boolean + */ + this.backgroundEnabled = true; + + /** + * Adjustment factor for tick animation, the more ticks, the + * faster the animation (by default) + * @property tickPause + * @type int + */ + this.tickPause = 40; + + /** + * Enables the arrow, home and end keys, defaults to true. + * @property enableKeys + * @type boolean + */ + this.enableKeys = true; + + /** + * Specifies the number of pixels the arrow keys will move the slider. + * Default is 25. + * @property keyIncrement + * @type int + */ + this.keyIncrement = 20; + + /** + * moveComplete is set to true when the slider has moved to its final + * destination. For animated slider, this value can be checked in + * the onChange handler to make it possible to execute logic only + * when the move is complete rather than at all points along the way. + * + * @property moveComplete + * @type Boolean + */ + this.moveComplete = true; + + /** + * If animation is configured, specifies the length of the animation + * in seconds. + * @property animationDuration + * @type int + * @default 0.2 + */ + this.animationDuration = 0.2; + + if (oThumb._isHoriz && oThumb.xTicks && oThumb.xTicks.length) { + this.tickPause = Math.round(360 / oThumb.xTicks.length); + } else if (oThumb.yTicks && oThumb.yTicks.length) { + this.tickPause = Math.round(360 / oThumb.yTicks.length); + } + + + // delegate thumb methods + oThumb.onMouseDown = function () { return self.focus(); }; + //oThumb.b4MouseDown = function () { return self.b4MouseDown(); }; + // oThumb.lock = function() { self.lock(); }; + // oThumb.unlock = function() { self.unlock(); }; + oThumb.onMouseUp = function() { self.thumbMouseUp(); }; + oThumb.onDrag = function() { self.fireEvents(); }; + oThumb.onAvailable = function() { return self.setStartSliderState(); }; + } +}; + +/** + * Factory method for creating a horizontal slider + * @method YAHOO.widget.Slider.getHorizSlider + * @static + * @param {String} sBGElId the id of the slider's background element + * @param {String} sHandleElId the id of the thumb element + * @param {int} iLeft the number of pixels the element can move left + * @param {int} iRight the number of pixels the element can move right + * @param {int} iTickSize optional parameter for specifying that the element + * should move a certain number pixels at a time. + * @return {Slider} a horizontal slider control + */ +YAHOO.widget.Slider.getHorizSlider = + function (sBGElId, sHandleElId, iLeft, iRight, iTickSize) { + return new YAHOO.widget.Slider(sBGElId, sBGElId, + new YAHOO.widget.SliderThumb(sHandleElId, sBGElId, + iLeft, iRight, 0, 0, iTickSize), "horiz"); +}; + +/** + * Factory method for creating a vertical slider + * @method YAHOO.widget.Slider.getVertSlider + * @static + * @param {String} sBGElId the id of the slider's background element + * @param {String} sHandleElId the id of the thumb element + * @param {int} iUp the number of pixels the element can move up + * @param {int} iDown the number of pixels the element can move down + * @param {int} iTickSize optional parameter for specifying that the element + * should move a certain number pixels at a time. + * @return {Slider} a vertical slider control + */ +YAHOO.widget.Slider.getVertSlider = + function (sBGElId, sHandleElId, iUp, iDown, iTickSize) { + return new YAHOO.widget.Slider(sBGElId, sBGElId, + new YAHOO.widget.SliderThumb(sHandleElId, sBGElId, 0, 0, + iUp, iDown, iTickSize), "vert"); +}; + +/** + * Factory method for creating a slider region like the one in the color + * picker example + * @method YAHOO.widget.Slider.getSliderRegion + * @static + * @param {String} sBGElId the id of the slider's background element + * @param {String} sHandleElId the id of the thumb element + * @param {int} iLeft the number of pixels the element can move left + * @param {int} iRight the number of pixels the element can move right + * @param {int} iUp the number of pixels the element can move up + * @param {int} iDown the number of pixels the element can move down + * @param {int} iTickSize optional parameter for specifying that the element + * should move a certain number pixels at a time. + * @return {Slider} a slider region control + */ +YAHOO.widget.Slider.getSliderRegion = + function (sBGElId, sHandleElId, iLeft, iRight, iUp, iDown, iTickSize) { + return new YAHOO.widget.Slider(sBGElId, sBGElId, + new YAHOO.widget.SliderThumb(sHandleElId, sBGElId, iLeft, iRight, + iUp, iDown, iTickSize), "region"); +}; + +/** + * By default, animation is available if the animation library is detected. + * @property YAHOO.widget.Slider.ANIM_AVAIL + * @static + * @type boolean + */ +YAHOO.widget.Slider.ANIM_AVAIL = true; + +YAHOO.extend(YAHOO.widget.Slider, YAHOO.util.DragDrop, { + + onAvailable: function() { + var Event = YAHOO.util.Event; + Event.on(this.id, "keydown", this.handleKeyDown, this, true); + Event.on(this.id, "keypress", this.handleKeyPress, this, true); + }, + + handleKeyPress: function(e) { + if (this.enableKeys) { + var Event = YAHOO.util.Event; + var kc = Event.getCharCode(e); + switch (kc) { + case 0x25: // left + case 0x26: // up + case 0x27: // right + case 0x28: // down + case 0x24: // home + case 0x23: // end + Event.preventDefault(e); + break; + default: + } + } + }, + + handleKeyDown: function(e) { + if (this.enableKeys) { + var Event = YAHOO.util.Event; + + var kc = Event.getCharCode(e), t=this.thumb; + var h=this.getXValue(),v=this.getYValue(); + + var horiz = false; + var changeValue = true; + switch (kc) { + + // left + case 0x25: h -= this.keyIncrement; break; + + // up + case 0x26: v -= this.keyIncrement; break; + + // right + case 0x27: h += this.keyIncrement; break; + + // down + case 0x28: v += this.keyIncrement; break; + + // home + case 0x24: h = t.leftConstraint; + v = t.topConstraint; + break; + + // end + case 0x23: h = t.rightConstraint; + v = t.bottomConstraint; + break; + + default: changeValue = false; + } + + if (changeValue) { + if (t._isRegion) { + this.setRegionValue(h, v, true); + } else { + var newVal = (t._isHoriz) ? h : v; + this.setValue(newVal, true); + } + Event.stopEvent(e); + } + + } + }, + + /** + * Initialization that sets up the value offsets once the elements are ready + * @method setSliderStartState + */ + setStartSliderState: function() { + + + this.setThumbCenterPoint(); + + /** + * The basline position of the background element, used + * to determine if the background has moved since the last + * operation. + * @property baselinePos + * @type [int, int] + */ + this.baselinePos = YAHOO.util.Dom.getXY(this.getEl()); + + this.thumb.startOffset = this.thumb.getOffsetFromParent(this.baselinePos); + + if (this.thumb._isRegion) { + if (this.deferredSetRegionValue) { + this.setRegionValue.apply(this, this.deferredSetRegionValue, true); + this.deferredSetRegionValue = null; + } else { + this.setRegionValue(0, 0, true); + } + } else { + if (this.deferredSetValue) { + this.setValue.apply(this, this.deferredSetValue, true); + this.deferredSetValue = null; + } else { + this.setValue(0, true, true); + } + } + }, + + /** + * When the thumb is available, we cache the centerpoint of the element so + * we can position the element correctly when the background is clicked + * @method setThumbCenterPoint + */ + setThumbCenterPoint: function() { + + var el = this.thumb.getEl(); + + if (el) { + /** + * The center of the slider element is stored so we can position + * place it in the correct position when the background is clicked + * @property thumbCenterPoint + * @type {"x": int, "y": int} + */ + this.thumbCenterPoint = { + x: parseInt(el.offsetWidth/2, 10), + y: parseInt(el.offsetHeight/2, 10) + }; + } + + }, + + /** + * Locks the slider, overrides YAHOO.util.DragDrop + * @method lock + */ + lock: function() { + this.thumb.lock(); + this.locked = true; + }, + + /** + * Unlocks the slider, overrides YAHOO.util.DragDrop + * @method unlock + */ + unlock: function() { + this.thumb.unlock(); + this.locked = false; + }, + + /** + * Handles mouseup event on the slider background + * @method thumbMouseUp + * @private + */ + thumbMouseUp: function() { + if (!this.isLocked() && !this.moveComplete) { + this.endMove(); + } + + }, + + /** + * Returns a reference to this slider's thumb + * @method getThumb + * @return {SliderThumb} this slider's thumb + */ + getThumb: function() { + return this.thumb; + }, + + /** + * Try to focus the element when clicked so we can add + * accessibility features + * @method focus + * @private + */ + focus: function() { + + // Focus the background element if possible + var el = this.getEl(); + + if (el.focus) { + try { + el.focus(); + } catch(e) { + // Prevent permission denied unhandled exception in FF that can + // happen when setting focus while another element is handling + // the blur. @TODO this is still writing to the error log + // (unhandled error) in FF1.5 with strict error checking on. + } + } + + this.verifyOffset(); + + if (this.isLocked()) { + return false; + } else { + this.onSlideStart(); + return true; + } + }, + + /** + * Event that fires when the value of the slider has changed + * @method onChange + * @param {int} firstOffset the number of pixels the thumb has moved + * from its start position. Normal horizontal and vertical sliders will only + * have the firstOffset. Regions will have both, the first is the horizontal + * offset, the second the vertical. + * @param {int} secondOffset the y offset for region sliders + * @deprecated use instance.subscribe("change") instead + */ + onChange: function (firstOffset, secondOffset) { + /* override me */ + }, + + /** + * Event that fires when the at the beginning of the slider thumb move + * @method onSlideStart + * @deprecated use instance.subscribe("slideStart") instead + */ + onSlideStart: function () { + /* override me */ + }, + + /** + * Event that fires at the end of a slider thumb move + * @method onSliderEnd + * @deprecated use instance.subscribe("slideEnd") instead + */ + onSlideEnd: function () { + /* override me */ + }, + + /** + * Returns the slider's thumb offset from the start position + * @method getValue + * @return {int} the current value + */ + getValue: function () { + return this.thumb.getValue(); + }, + + /** + * Returns the slider's thumb X offset from the start position + * @method getXValue + * @return {int} the current horizontal offset + */ + getXValue: function () { + return this.thumb.getXValue(); + }, + + /** + * Returns the slider's thumb Y offset from the start position + * @method getYValue + * @return {int} the current vertical offset + */ + getYValue: function () { + return this.thumb.getYValue(); + }, + + /** + * Internal handler for the slider thumb's onChange event + * @method handleThumbChange + * @private + */ + handleThumbChange: function () { + var t = this.thumb; + if (t._isRegion) { + t.onChange(t.getXValue(), t.getYValue()); + this.fireEvent("change", { x: t.getXValue(), y: t.getYValue() } ); + } else { + t.onChange(t.getValue()); + this.fireEvent("change", t.getValue()); + } + + }, + + /** + * Provides a way to set the value of the slider in code. + * @method setValue + * @param {int} newOffset the number of pixels the thumb should be + * positioned away from the initial start point + * @param {boolean} skipAnim set to true to disable the animation + * for this move action (but not others). + * @param {boolean} force ignore the locked setting and set value anyway + * @return {boolean} true if the move was performed, false if it failed + */ + setValue: function(newOffset, skipAnim, force) { + + if (!this.thumb.available) { + this.deferredSetValue = arguments; + return false; + } + + if (this.isLocked() && !force) { + return false; + } + + if ( isNaN(newOffset) ) { + return false; + } + + var t = this.thumb; + var newX, newY; + this.verifyOffset(); + if (t._isRegion) { + return false; + } else if (t._isHoriz) { + this.onSlideStart(); + // this.fireEvent("slideStart"); + newX = t.initPageX + newOffset + this.thumbCenterPoint.x; + this.moveThumb(newX, t.initPageY, skipAnim); + } else { + this.onSlideStart(); + // this.fireEvent("slideStart"); + newY = t.initPageY + newOffset + this.thumbCenterPoint.y; + this.moveThumb(t.initPageX, newY, skipAnim); + } + + return true; + }, + + /** + * Provides a way to set the value of the region slider in code. + * @method setRegionValue + * @param {int} newOffset the number of pixels the thumb should be + * positioned away from the initial start point (x axis for region) + * @param {int} newOffset2 the number of pixels the thumb should be + * positioned away from the initial start point (y axis for region) + * @param {boolean} skipAnim set to true to disable the animation + * for this move action (but not others). + * @param {boolean} force ignore the locked setting and set value anyway + * @return {boolean} true if the move was performed, false if it failed + */ + setRegionValue: function(newOffset, newOffset2, skipAnim) { + + if (!this.thumb.available) { + this.deferredSetRegionValue = arguments; + return false; + } + + if (this.isLocked() && !force) { + return false; + } + + if ( isNaN(newOffset) ) { + return false; + } + + var t = this.thumb; + if (t._isRegion) { + this.onSlideStart(); + var newX = t.initPageX + newOffset + this.thumbCenterPoint.x; + var newY = t.initPageY + newOffset2 + this.thumbCenterPoint.y; + this.moveThumb(newX, newY, skipAnim); + return true; + } + + return false; + + }, + + /** + * Checks the background position element position. If it has moved from the + * baseline position, the constraints for the thumb are reset + * @method verifyOffset + * @return {boolean} True if the offset is the same as the baseline. + */ + verifyOffset: function() { + + var newPos = YAHOO.util.Dom.getXY(this.getEl()); + + if (newPos[0] != this.baselinePos[0] || newPos[1] != this.baselinePos[1]) { + this.thumb.resetConstraints(); + this.baselinePos = newPos; + return false; + } + + return true; + }, + + /** + * Move the associated slider moved to a timeout to try to get around the + * mousedown stealing moz does when I move the slider element between the + * cursor and the background during the mouseup event + * @method moveThumb + * @param {int} x the X coordinate of the click + * @param {int} y the Y coordinate of the click + * @param {boolean} skipAnim don't animate if the move happend onDrag + * @private + */ + moveThumb: function(x, y, skipAnim) { + + + var t = this.thumb; + var self = this; + + if (!t.available) { + return; + } + + + // this.verifyOffset(); + + t.setDelta(this.thumbCenterPoint.x, this.thumbCenterPoint.y); + + var _p = t.getTargetCoord(x, y); + var p = [_p.x, _p.y]; + + this.fireEvent("slideStart"); + + if (this.animate && YAHOO.widget.Slider.ANIM_AVAIL && t._graduated && !skipAnim) { + // this.thumb._animating = true; + this.lock(); + + setTimeout( function() { self.moveOneTick(p); }, this.tickPause ); + + } else if (this.animate && YAHOO.widget.Slider.ANIM_AVAIL && !skipAnim) { + + // this.thumb._animating = true; + this.lock(); + + var oAnim = new YAHOO.util.Motion( + t.id, { points: { to: p } }, + this.animationDuration, + YAHOO.util.Easing.easeOut ); + + oAnim.onComplete.subscribe( function() { self.endMove(); } ); + oAnim.animate(); + } else { + t.setDragElPos(x, y); + // this.fireEvents(); + this.endMove(); + } + }, + + /** + * Move the slider one tick mark towards its final coordinate. Used + * for the animation when tick marks are defined + * @method moveOneTick + * @param {int[]} the destination coordinate + * @private + */ + moveOneTick: function(finalCoord) { + + var t = this.thumb; + var curCoord = YAHOO.util.Dom.getXY(t.getEl()); + var tmp; + + // var thresh = Math.min(t.tickSize + (Math.floor(t.tickSize/2)), 10); + // var thresh = 10; + // var thresh = t.tickSize + (Math.floor(t.tickSize/2)); + + var nextCoord = null; + + if (t._isRegion) { + nextCoord = this._getNextX(curCoord, finalCoord); + var tmpX = (nextCoord) ? nextCoord[0] : curCoord[0]; + nextCoord = this._getNextY([tmpX, curCoord[1]], finalCoord); + + } else if (t._isHoriz) { + nextCoord = this._getNextX(curCoord, finalCoord); + } else { + nextCoord = this._getNextY(curCoord, finalCoord); + } + + + if (nextCoord) { + + // move to the next coord + // YAHOO.util.Dom.setXY(t.getEl(), nextCoord); + + // var el = t.getEl(); + // YAHOO.util.Dom.setStyle(el, "left", (nextCoord[0] + this.thumb.deltaSetXY[0]) + "px"); + // YAHOO.util.Dom.setStyle(el, "top", (nextCoord[1] + this.thumb.deltaSetXY[1]) + "px"); + + this.thumb.alignElWithMouse(t.getEl(), nextCoord[0], nextCoord[1]); + + // check if we are in the final position, if not make a recursive call + if (!(nextCoord[0] == finalCoord[0] && nextCoord[1] == finalCoord[1])) { + var self = this; + setTimeout(function() { self.moveOneTick(finalCoord); }, + this.tickPause); + } else { + this.endMove(); + } + } else { + this.endMove(); + } + + //this.tickPause = Math.round(this.tickPause/2); + }, + + /** + * Returns the next X tick value based on the current coord and the target coord. + * @method _getNextX + * @private + */ + _getNextX: function(curCoord, finalCoord) { + var t = this.thumb; + var thresh; + var tmp = []; + var nextCoord = null; + if (curCoord[0] > finalCoord[0]) { + thresh = t.tickSize - this.thumbCenterPoint.x; + tmp = t.getTargetCoord( curCoord[0] - thresh, curCoord[1] ); + nextCoord = [tmp.x, tmp.y]; + } else if (curCoord[0] < finalCoord[0]) { + thresh = t.tickSize + this.thumbCenterPoint.x; + tmp = t.getTargetCoord( curCoord[0] + thresh, curCoord[1] ); + nextCoord = [tmp.x, tmp.y]; + } else { + // equal, do nothing + } + + return nextCoord; + }, + + /** + * Returns the next Y tick value based on the current coord and the target coord. + * @method _getNextY + * @private + */ + _getNextY: function(curCoord, finalCoord) { + var t = this.thumb; + var thresh; + var tmp = []; + var nextCoord = null; + + if (curCoord[1] > finalCoord[1]) { + thresh = t.tickSize - this.thumbCenterPoint.y; + tmp = t.getTargetCoord( curCoord[0], curCoord[1] - thresh ); + nextCoord = [tmp.x, tmp.y]; + } else if (curCoord[1] < finalCoord[1]) { + thresh = t.tickSize + this.thumbCenterPoint.y; + tmp = t.getTargetCoord( curCoord[0], curCoord[1] + thresh ); + nextCoord = [tmp.x, tmp.y]; + } else { + // equal, do nothing + } + + return nextCoord; + }, + + /** + * Resets the constraints before moving the thumb. + * @method b4MouseDown + * @private + */ + b4MouseDown: function(e) { + this.thumb.autoOffset(); + this.thumb.resetConstraints(); + }, + + /** + * Handles the mousedown event for the slider background + * @method onMouseDown + * @private + */ + onMouseDown: function(e) { + // this.resetConstraints(true); + // this.thumb.resetConstraints(true); + + if (! this.isLocked() && this.backgroundEnabled) { + var x = YAHOO.util.Event.getPageX(e); + var y = YAHOO.util.Event.getPageY(e); + + this.focus(); + this.moveThumb(x, y); + } + + }, + + /** + * Handles the onDrag event for the slider background + * @method onDrag + * @private + */ + onDrag: function(e) { + if (! this.isLocked()) { + var x = YAHOO.util.Event.getPageX(e); + var y = YAHOO.util.Event.getPageY(e); + this.moveThumb(x, y, true); + } + }, + + /** + * Fired when the slider movement ends + * @method endMove + * @private + */ + endMove: function () { + // this._animating = false; + this.unlock(); + this.moveComplete = true; + this.fireEvents(); + }, + + /** + * Fires the change event if the value has been changed. Ignored if we are in + * the middle of an animation as the event will fire when the animation is + * complete + * @method fireEvents + * @private + */ + fireEvents: function () { + + var t = this.thumb; + + t.cachePosition(); + + if (! this.isLocked()) { + if (t._isRegion) { + var newX = t.getXValue(); + var newY = t.getYValue(); + + if (newX != this.previousX || newY != this.previousY) { + this.onChange(newX, newY); + this.fireEvent("change", { x: newX, y: newY }); + } + + this.previousX = newX; + this.previousY = newY; + + } else { + var newVal = t.getValue(); + if (newVal != this.previousVal) { + this.onChange( newVal ); + this.fireEvent("change", newVal); + } + this.previousVal = newVal; + } + + if (this.moveComplete) { + this.onSlideEnd(); + this.fireEvent("slideEnd"); + this.moveComplete = false; + } + + } + }, + + /** + * Slider toString + * @method toString + * @return {string} string representation of the instance + */ + toString: function () { + return ("Slider (" + this.type +") " + this.id); + } + +}); + +YAHOO.augment(YAHOO.widget.Slider, YAHOO.util.EventProvider); + +/** + * A drag and drop implementation to be used as the thumb of a slider. + * @class SliderThumb + * @extends YAHOO.util.DD + * @constructor + * @param {String} id the id of the slider html element + * @param {String} sGroup the group of related DragDrop items + * @param {int} iLeft the number of pixels the element can move left + * @param {int} iRight the number of pixels the element can move right + * @param {int} iUp the number of pixels the element can move up + * @param {int} iDown the number of pixels the element can move down + * @param {int} iTickSize optional parameter for specifying that the element + * should move a certain number pixels at a time. + */ +YAHOO.widget.SliderThumb = function(id, sGroup, iLeft, iRight, iUp, iDown, iTickSize) { + + if (id) { + this.init(id, sGroup); + + /** + * The id of the thumbs parent HTML element (the slider background + * element). + * @property parentElId + * @type string + */ + this.parentElId = sGroup; + } + + //this.removeInvalidHandleType("A"); + + + /** + * Overrides the isTarget property in YAHOO.util.DragDrop + * @property isTarget + * @private + */ + this.isTarget = false; + + /** + * The tick size for this slider + * @property tickSize + * @type int + * @private + */ + this.tickSize = iTickSize; + + /** + * Informs the drag and drop util that the offsets should remain when + * resetting the constraints. This preserves the slider value when + * the constraints are reset + * @property maintainOffset + * @type boolean + * @private + */ + this.maintainOffset = true; + + this.initSlider(iLeft, iRight, iUp, iDown, iTickSize); + + /** + * Turns off the autoscroll feature in drag and drop + * @property scroll + * @private + */ + this.scroll = false; + +}; + +YAHOO.extend(YAHOO.widget.SliderThumb, YAHOO.util.DD, { + + /** + * The (X and Y) difference between the thumb location and its parent + * (the slider background) when the control is instantiated. + * @property startOffset + * @type [int, int] + */ + startOffset: null, + + /** + * Flag used to figure out if this is a horizontal or vertical slider + * @property _isHoriz + * @type boolean + * @private + */ + _isHoriz: false, + + /** + * Cache the last value so we can check for change + * @property _prevVal + * @type int + * @private + */ + _prevVal: 0, + + /** + * The slider is _graduated if there is a tick interval defined + * @property _graduated + * @type boolean + * @private + */ + _graduated: false, + + /** + * Returns the difference between the location of the thumb and its parent. + * @method getOffsetFromParent + * @param {[int, int]} parentPos Optionally accepts the position of the parent + * @type [int, int] + */ + getOffsetFromParent: function(parentPos) { + var myPos = YAHOO.util.Dom.getXY(this.getEl()); + var ppos = parentPos || YAHOO.util.Dom.getXY(this.parentElId); + + return [ (myPos[0] - ppos[0]), (myPos[1] - ppos[1]) ]; + }, + + /** + * Set up the slider, must be called in the constructor of all subclasses + * @method initSlider + * @param {int} iLeft the number of pixels the element can move left + * @param {int} iRight the number of pixels the element can move right + * @param {int} iUp the number of pixels the element can move up + * @param {int} iDown the number of pixels the element can move down + * @param {int} iTickSize the width of the tick interval. + */ + initSlider: function (iLeft, iRight, iUp, iDown, iTickSize) { + + this.setXConstraint(iLeft, iRight, iTickSize); + this.setYConstraint(iUp, iDown, iTickSize); + + if (iTickSize && iTickSize > 1) { + this._graduated = true; + } + + this._isHoriz = (iLeft || iRight); + this._isVert = (iUp || iDown); + this._isRegion = (this._isHoriz && this._isVert); + + }, + + /** + * Clear's the slider's ticks + * @method clearTicks + */ + clearTicks: function () { + YAHOO.widget.SliderThumb.superclass.clearTicks.call(this); + this._graduated = false; + }, + + /** + * Gets the current offset from the element's start position in + * pixels. + * @method getValue + * @return {int} the number of pixels (positive or negative) the + * slider has moved from the start position. + */ + getValue: function () { + if (!this.available) { return 0; } + var val = (this._isHoriz) ? this.getXValue() : this.getYValue(); + return val; + }, + + /** + * Gets the current X offset from the element's start position in + * pixels. + * @method getXValue + * @return {int} the number of pixels (positive or negative) the + * slider has moved horizontally from the start position. + */ + getXValue: function () { + if (!this.available) { return 0; } + var newOffset = this.getOffsetFromParent(); + return (newOffset[0] - this.startOffset[0]); + }, + + /** + * Gets the current Y offset from the element's start position in + * pixels. + * @method getYValue + * @return {int} the number of pixels (positive or negative) the + * slider has moved vertically from the start position. + */ + getYValue: function () { + if (!this.available) { return 0; } + var newOffset = this.getOffsetFromParent(); + return (newOffset[1] - this.startOffset[1]); + }, + + /** + * Thumb toString + * @method toString + * @return {string} string representation of the instance + */ + toString: function () { + return "SliderThumb " + this.id; + }, + + /** + * The onchange event for the handle/thumb is delegated to the YAHOO.widget.Slider + * instance it belongs to. + * @method onChange + * @private + */ + onChange: function (x, y) { + } + +}); + +if ("undefined" == typeof YAHOO.util.Anim) { + YAHOO.widget.Slider.ANIM_AVAIL = false; +} + diff --git a/frontend/beta/js/YUI/tabview.js b/frontend/beta/js/YUI/tabview.js new file mode 100644 index 0000000..34a09bb --- a/dev/null +++ b/frontend/beta/js/YUI/tabview.js @@ -0,0 +1,1950 @@ +/* +Copyright (c) 2006, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 0.12.0 +*/ +(function() { + + YAHOO.util.Lang = { + isArray: function(val) { // frames lose type, so test constructor string + if (val.constructor && val.constructor.toString().indexOf('Array') > -1) { + return true; + } else { + return YAHOO.util.Lang.isObject(val) && val.constructor == Array; + } + }, + + isBoolean: function(val) { + return typeof val == 'boolean'; + }, + + isFunction: function(val) { + return typeof val == 'function'; + }, + + isNull: function(val) { + return val === null; + }, + + isNumber: function(val) { + return !isNaN(val); + }, + + isObject: function(val) { + return typeof val == 'object' || YAHOO.util.Lang.isFunction(val); + }, + + isString: function(val) { + return typeof val == 'string'; + }, + + isUndefined: function(val) { + return typeof val == 'undefined'; + } + }; +})();/** + * Provides Attribute configurations. + * @namespace YAHOO.util + * @class Attribute + * @constructor + * @param hash {Object} The intial Attribute. + * @param {YAHOO.util.AttributeProvider} The owner of the Attribute instance. + */ + +YAHOO.util.Attribute = function(hash, owner) { + if (owner) { + this.owner = owner; + this.configure(hash, true); + } +}; + +YAHOO.util.Attribute.prototype = { + /** + * The name of the attribute. + * @property name + * @type String + */ + name: undefined, + + /** + * The value of the attribute. + * @property value + * @type String + */ + value: null, + + /** + * The owner of the attribute. + * @property owner + * @type YAHOO.util.AttributeProvider + */ + owner: null, + + /** + * Whether or not the attribute is read only. + * @property readOnly + * @type Boolean + */ + readOnly: false, + + /** + * Whether or not the attribute can only be written once. + * @property writeOnce + * @type Boolean + */ + writeOnce: false, + + /** + * The attribute's initial configuration. + * @private + * @property _initialConfig + * @type Object + */ + _initialConfig: null, + + /** + * Whether or not the attribute's value has been set. + * @private + * @property _written + * @type Boolean + */ + _written: false, + + /** + * The method to use when setting the attribute's value. + * The method recieves the new value as the only argument. + * @property method + * @type Function + */ + method: null, + + /** + * The validator to use when setting the attribute's value. + * @property validator + * @type Function + * @return Boolean + */ + validator: null, + + /** + * Retrieves the current value of the attribute. + * @method getValue + * @return {any} The current value of the attribute. + */ + getValue: function() { + return this.value; + }, + + /** + * Sets the value of the attribute and fires beforeChange and change events. + * @method setValue + * @param {Any} value The value to apply to the attribute. + * @param {Boolean} silent If true the change events will not be fired. + * @return {Boolean} Whether or not the value was set. + */ + setValue: function(value, silent) { + var beforeRetVal; + var owner = this.owner; + var name = this.name; + + var event = { + type: name, + prevValue: this.getValue(), + newValue: value + }; + + if (this.readOnly || ( this.writeOnce && this._written) ) { + return false; // write not allowed + } + + if (this.validator && !this.validator.call(owner, value) ) { + return false; // invalid value + } + + if (!silent) { + beforeRetVal = owner.fireBeforeChangeEvent(event); + if (beforeRetVal === false) { + YAHOO.log('setValue ' + name + + 'cancelled by beforeChange event', 'info', 'Attribute'); + return false; + } + } + + if (this.method) { + this.method.call(owner, value); + } + + this.value = value; + this._written = true; + + event.type = name; + + if (!silent) { + this.owner.fireChangeEvent(event); + } + + return true; + }, + + /** + * Allows for configuring the Attribute's properties. + * @method configure + * @param {Object} map A key-value map of Attribute properties. + * @param {Boolean} init Whether or not this should become the initial config. + */ + configure: function(map, init) { + map = map || {}; + this._written = false; // reset writeOnce + this._initialConfig = this._initialConfig || {}; + + for (var key in map) { + if ( key && map.hasOwnProperty(key) ) { + this[key] = map[key]; + if (init) { + this._initialConfig[key] = map[key]; + } + } + } + }, + + /** + * Resets the value to the initial config value. + * @method resetValue + * @return {Boolean} Whether or not the value was set. + */ + resetValue: function() { + return this.setValue(this._initialConfig.value); + }, + + /** + * Resets the attribute config to the initial config state. + * @method resetConfig + */ + resetConfig: function() { + this.configure(this._initialConfig); + }, + + /** + * Resets the value to the current value. + * Useful when values may have gotten out of sync with actual properties. + * @method refresh + * @return {Boolean} Whether or not the value was set. + */ + refresh: function(silent) { + this.setValue(this.value, silent); + } +};(function() { + var Lang = YAHOO.util.Lang; + + /* + Copyright (c) 2006, Yahoo! Inc. All rights reserved. + Code licensed under the BSD License: + http://developer.yahoo.net/yui/license.txt + */ + + /** + * Provides and manages YAHOO.util.Attribute instances + * @namespace YAHOO.util + * @class AttributeProvider + * @uses YAHOO.util.EventProvider + */ + YAHOO.util.AttributeProvider = function() {}; + + YAHOO.util.AttributeProvider.prototype = { + + /** + * A key-value map of Attribute configurations + * @property _configs + * @protected (may be used by subclasses and augmentors) + * @private + * @type {Object} + */ + _configs: null, + /** + * Returns the current value of the attribute. + * @method get + * @param {String} key The attribute whose value will be returned. + */ + get: function(key){ + var configs = this._configs || {}; + var config = configs[key]; + + if (!config) { + YAHOO.log(key + ' not found', 'error', 'AttributeProvider'); + return undefined; + } + + return config.value; + }, + + /** + * Sets the value of a config. + * @method set + * @param {String} key The name of the attribute + * @param {Any} value The value to apply to the attribute + * @param {Boolean} silent Whether or not to suppress change events + * @return {Boolean} Whether or not the value was set. + */ + set: function(key, value, silent){ + var configs = this._configs || {}; + var config = configs[key]; + + if (!config) { + YAHOO.log('set failed: ' + key + ' not found', + 'error', 'AttributeProvider'); + return false; + } + + return config.setValue(value, silent); + }, + + /** + * Returns an array of attribute names. + * @method getAttributeKeys + * @return {Array} An array of attribute names. + */ + getAttributeKeys: function(){ + var configs = this._configs; + var keys = []; + var config; + for (var key in configs) { + config = configs[key]; + if ( configs.hasOwnProperty(key) && + !Lang.isUndefined(config) ) { + keys[keys.length] = key; + } + } + + return keys; + }, + + /** + * Sets multiple attribute values. + * @method setAttributes + * @param {Object} map A key-value map of attributes + * @param {Boolean} silent Whether or not to suppress change events + */ + setAttributes: function(map, silent){ + for (var key in map) { + if ( map.hasOwnProperty(key) ) { + this.set(key, map[key], silent); + } + } + }, + + /** + * Resets the specified attribute's value to its initial value. + * @method resetValue + * @param {String} key The name of the attribute + * @param {Boolean} silent Whether or not to suppress change events + * @return {Boolean} Whether or not the value was set + */ + resetValue: function(key, silent){ + var configs = this._configs || {}; + if (configs[key]) { + this.set(key, configs[key]._initialConfig.value, silent); + return true; + } + return false; + }, + + /** + * Sets the attribute's value to its current value. + * @method refresh + * @param {String | Array} key The attribute(s) to refresh + * @param {Boolean} silent Whether or not to suppress change events + */ + refresh: function(key, silent){ + var configs = this._configs; + + key = ( ( Lang.isString(key) ) ? [key] : key ) || + this.getAttributeKeys(); + + for (var i = 0, len = key.length; i < len; ++i) { + if ( // only set if there is a value and not null + configs[key[i]] && + ! Lang.isUndefined(configs[key[i]].value) && + ! Lang.isNull(configs[key[i]].value) ) { + configs[key[i]].refresh(silent); + } + } + }, + + /** + * Adds an Attribute to the AttributeProvider instance. + * @method register + * @param {String} key The attribute's name + * @param {Object} map A key-value map containing the + * attribute's properties. + */ + register: function(key, map) { + this._configs = this._configs || {}; + + if (this._configs[key]) { // dont override + return false; + } + + map.name = key; + this._configs[key] = new YAHOO.util.Attribute(map, this); + return true; + }, + + /** + * Returns the attribute's properties. + * @method getAttributeConfig + * @param {String} key The attribute's name + * @private + * @return {object} A key-value map containing all of the + * attribute's properties. + */ + getAttributeConfig: function(key) { + var configs = this._configs || {}; + var config = configs[key] || {}; + var map = {}; // returning a copy to prevent overrides + + for (key in config) { + if ( config.hasOwnProperty(key) ) { + map[key] = config[key]; + } + } + + return map; + }, + + /** + * Sets or updates an Attribute instance's properties. + * @method configureAttribute + * @param {String} key The attribute's name. + * @param {Object} map A key-value map of attribute properties + * @param {Boolean} init Whether or not this should become the intial config. + */ + configureAttribute: function(key, map, init) { + var configs = this._configs || {}; + + if (!configs[key]) { + YAHOO.log('unable to configure, ' + key + ' not found', + 'error', 'AttributeProvider'); + return false; + } + + configs[key].configure(map, init); + }, + + /** + * Resets an attribute to its intial configuration. + * @method resetAttributeConfig + * @param {String} key The attribute's name. + * @private + */ + resetAttributeConfig: function(key){ + var configs = this._configs || {}; + configs[key].resetConfig(); + }, + + /** + * Fires the attribute's beforeChange event. + * @method fireBeforeChangeEvent + * @param {String} key The attribute's name. + * @param {Obj} e The event object to pass to handlers. + */ + fireBeforeChangeEvent: function(e) { + var type = 'before'; + type += e.type.charAt(0).toUpperCase() + e.type.substr(1) + 'Change'; + e.type = type; + return this.fireEvent(e.type, e); + }, + + /** + * Fires the attribute's change event. + * @method fireChangeEvent + * @param {String} key The attribute's name. + * @param {Obj} e The event object to pass to the handlers. + */ + fireChangeEvent: function(e) { + e.type += 'Change'; + return this.fireEvent(e.type, e); + } + }; + + YAHOO.augment(YAHOO.util.AttributeProvider, YAHOO.util.EventProvider); +})();(function() { +// internal shorthand +var Dom = YAHOO.util.Dom, + Lang = YAHOO.util.Lang, + EventPublisher = YAHOO.util.EventPublisher, + AttributeProvider = YAHOO.util.AttributeProvider; + +/** + * Element provides an interface to an HTMLElement's attributes and common + * methods. Other commonly used attributes are added as well. + * @namespace YAHOO.util + * @class Element + * @uses YAHOO.util.AttributeProvider + * @constructor + * @param el {HTMLElement | String} The html element that + * represents the Element. + * @param {Object} map A key-value map of initial config names and values + */ +YAHOO.util.Element = function(el, map) { + if (arguments.length) { + this.init(el, map); + } +}; + +YAHOO.util.Element.prototype = { + /** + * Dom events supported by the Element instance. + * @property DOM_EVENTS + * @type Object + */ + DOM_EVENTS: null, + + /** + * Wrapper for HTMLElement method. + * @method appendChild + * @param {Boolean} deep Whether or not to do a deep clone + */ + appendChild: function(child) { + child = child.get ? child.get('element') : child; + this.get('element').appendChild(child); + }, + + /** + * Wrapper for HTMLElement method. + * @method getElementsByTagName + * @param {String} tag The tagName to collect + */ + getElementsByTagName: function(tag) { + return this.get('element').getElementsByTagName(tag); + }, + + /** + * Wrapper for HTMLElement method. + * @method hasChildNodes + * @return {Boolean} Whether or not the element has childNodes + */ + hasChildNodes: function() { + return this.get('element').hasChildNodes(); + }, + + /** + * Wrapper for HTMLElement method. + * @method insertBefore + * @param {HTMLElement} element The HTMLElement to insert + * @param {HTMLElement} before The HTMLElement to insert + * the element before. + */ + insertBefore: function(element, before) { + element = element.get ? element.get('element') : element; + before = (before && before.get) ? before.get('element') : before; + + this.get('element').insertBefore(element, before); + }, + + /** + * Wrapper for HTMLElement method. + * @method removeChild + * @param {HTMLElement} child The HTMLElement to remove + */ + removeChild: function(child) { + child = child.get ? child.get('element') : child; + this.get('element').removeChild(child); + return true; + }, + + /** + * Wrapper for HTMLElement method. + * @method replaceChild + * @param {HTMLElement} newNode The HTMLElement to insert + * @param {HTMLElement} oldNode The HTMLElement to replace + */ + replaceChild: function(newNode, oldNode) { + newNode = newNode.get ? newNode.get('element') : newNode; + oldNode = oldNode.get ? oldNode.get('element') : oldNode; + return this.get('element').replaceChild(newNode, oldNode); + }, + + + /** + * Registers Element specific attributes. + * @method initAttributes + * @param {Object} map A key-value map of initial attribute configs + */ + initAttributes: function(map) { + map = map || {}; + var element = Dom.get(map.element) || null; + + /** + * The HTMLElement the Element instance refers to. + * @config element + * @type HTMLElement + */ + this.register('element', { + value: element, + readOnly: true + }); + }, + + /** + * Adds a listener for the given event. These may be DOM or + * customEvent listeners. Any event that is fired via fireEvent + * can be listened for. All handlers receive an event object. + * @method addListener + * @param {String} type The name of the event to listen for + * @param {Function} fn The handler to call when the event fires + * @param {Any} obj A variable to pass to the handler + * @param {Object} scope The object to use for the scope of the handler + */ + addListener: function(type, fn, obj, scope) { + var el = this.get('element'); + var scope = scope || this; + + el = this.get('id') || el; + + if (!this._events[type]) { // create on the fly + if ( this.DOM_EVENTS[type] ) { + YAHOO.util.Event.addListener(el, type, function(e) { + if (e.srcElement && !e.target) { // supplement IE with target + e.target = e.srcElement; + } + this.fireEvent(type, e); + }, obj, scope); + } + + this.createEvent(type, this); + this._events[type] = true; + } + + this.subscribe.apply(this, arguments); // notify via customEvent + }, + + + /** + * Alias for addListener + * @method on + * @param {String} type The name of the event to listen for + * @param {Function} fn The function call when the event fires + * @param {Any} obj A variable to pass to the handler + * @param {Object} scope The object to use for the scope of the handler + */ + on: function() { this.addListener.apply(this, arguments); }, + + + /** + * Remove an event listener + * @method removeListener + * @param {String} type The name of the event to listen for + * @param {Function} fn The function call when the event fires + */ + removeListener: function(type, fn) { + this.unsubscribe.apply(this, arguments); + }, + + /** + * Wrapper for Dom method. + * @method addClass + * @param {String} className The className to add + */ + addClass: function(className) { + Dom.addClass(this.get('element'), className); + }, + + /** + * Wrapper for Dom method. + * @method getElementsByClassName + * @param {String} className The className to collect + * @param {String} tag (optional) The tag to use in + * conjunction with class name + * @return {Array} Array of HTMLElements + */ + getElementsByClassName: function(className, tag) { + return Dom.getElementsByClassName(className, tag, + this.get('element') ); + }, + + /** + * Wrapper for Dom method. + * @method hasClass + * @param {String} className The className to add + * @return {Boolean} Whether or not the element has the class name + */ + hasClass: function(className) { + return Dom.hasClass(this.get('element'), className); + }, + + /** + * Wrapper for Dom method. + * @method removeClass + * @param {String} className The className to remove + */ + removeClass: function(className) { + return Dom.removeClass(this.get('element'), className); + }, + + /** + * Wrapper for Dom method. + * @method replaceClass + * @param {String} oldClassName The className to replace + * @param {String} newClassName The className to add + */ + replaceClass: function(oldClassName, newClassName) { + return Dom.replaceClass(this.get('element'), + oldClassName, newClassName); + }, + + /** + * Wrapper for Dom method. + * @method setStyle + * @param {String} property The style property to set + * @param {String} value The value to apply to the style property + */ + setStyle: function(property, value) { + return Dom.setStyle(this.get('element'), property, value); + }, + + /** + * Wrapper for Dom method. + * @method getStyle + * @param {String} property The style property to retrieve + * @return {String} The current value of the property + */ + getStyle: function(property) { + return Dom.getStyle(this.get('element'), property); + }, + + /** + * Apply any queued set calls. + * @method fireQueue + */ + fireQueue: function() { + var queue = this._queue; + for (var i = 0, len = queue.length; i < len; ++i) { + this[queue[i][0]].apply(this, queue[i][1]); + } + }, + + /** + * Appends the HTMLElement into either the supplied parentNode. + * @method appendTo + * @param {HTMLElement | Element} parentNode The node to append to + * @param {HTMLElement | Element} before An optional node to insert before + */ + appendTo: function(parent, before) { + parent = (parent.get) ? parent.get('element') : Dom.get(parent); + + before = (before && before.get) ? + before.get('element') : Dom.get(before); + var element = this.get('element'); + + var newAddition = !Dom.inDocument(element); + + if (!element) { + YAHOO.log('appendTo failed: element not available', + 'error', 'Element'); + return false; + } + + if (!parent) { + YAHOO.log('appendTo failed: parent not available', + 'error', 'Element'); + return false; + } + + if (element.parent != parent) { + if (before) { + parent.insertBefore(element, before); + } else { + parent.appendChild(element); + } + } + + YAHOO.log(element + 'appended to ' + parent); + + if (!newAddition) { + return false; // note return; no refresh if in document + } + + // if a new addition, refresh HTMLElement any applied attributes + var keys = this.getAttributeKeys(); + + for (var key in keys) { // only refresh HTMLElement attributes + if ( !Lang.isUndefined(element[key]) ) { + this.refresh(key); + } + } + }, + + get: function(key) { + var configs = this._configs || {}; + var el = configs.element; // avoid loop due to 'element' + if (el && !configs[key] && !Lang.isUndefined(el.value[key]) ) { + return el.value[key]; + } + + return AttributeProvider.prototype.get.call(this, key); + }, + + set: function(key, value, silent) { + var el = this.get('element'); + if (!el) { + this._queue[key] = ['set', arguments]; + return false; + } + + // set it on the element if not a property + if ( !this._configs[key] && !Lang.isUndefined(el[key]) ) { + _registerHTMLAttr(this, key); + } + + return AttributeProvider.prototype.set.apply(this, arguments); + }, + + register: function(key) { // protect html attributes + var configs = this._configs || {}; + var element = this.get('element') || null; + + if ( element && !Lang.isUndefined(element[key]) ) { + YAHOO.log(key + ' is reserved for ' + element, + 'error', 'Element'); + return false; + } + + return AttributeProvider.prototype.register.apply(this, arguments); + }, + + configureAttribute: function(property, map, init) { // protect html attributes + if (!this._configs[property] && this._configs.element && + !Lang.isUndefined(this._configs.element[property]) ) { + _registerHTMLAttr(this, property, map); + return false; + } + + return AttributeProvider.prototype.configure.apply(this, arguments); + }, + + getAttributeKeys: function() { + var el = this.get('element'); + var keys = AttributeProvider.prototype.getAttributeKeys.call(this); + + //add any unconfigured element keys + for (var key in el) { + if (!this._configs[key]) { + keys[key] = keys[key] || el[key]; + } + } + + return keys; + }, + + init: function(el, attr) { + this._queue = this._queue || []; + this._events = this._events || {}; + this._configs = this._configs || {}; + attr = attr || {}; + attr.element = attr.element || el || null; + + this.DOM_EVENTS = { + 'click': true, + 'keydown': true, + 'keypress': true, + 'keyup': true, + 'mousedown': true, + 'mousemove': true, + 'mouseout': true, + 'mouseover': true, + 'mouseup': true + }; + + var readyHandler = function() { + this.initAttributes(attr); + + this.setAttributes(attr, true); + this.fireQueue(); + this.fireEvent('contentReady', { + type: 'contentReady', + target: attr.element + }); + }; + + if ( Lang.isString(el) ) { + _registerHTMLAttr(this, 'id', { value: el }); + YAHOO.util.Event.onAvailable(el, function() { + attr.element = Dom.get(el); + this.fireEvent('available', { + type: 'available', + target: attr.element + }); + }, this, true); + + YAHOO.util.Event.onContentReady(el, function() { + readyHandler.call(this); + }, this, true); + } else { + readyHandler.call(this); + } + } +}; + +/** + * Sets the value of the property and fires beforeChange and change events. + * @private + * @method _registerHTMLAttr + * @param {YAHOO.util.Element} element The Element instance to + * register the config to. + * @param {String} key The name of the config to register + * @param {Object} map A key-value map of the config's params + */ +var _registerHTMLAttr = function(self, key, map) { + var el = self.get('element'); + map = map || {}; + map.name = key; + map.method = map.method || function(value) { + el[key] = value; + }; + map.value = map.value || el[key]; + self._configs[key] = new YAHOO.util.Attribute(map, self); +}; + +/** + * Fires when the Element's HTMLElement can be retrieved by Id. + *See: Element.addListener
+ *Event fields:
+ *<String> type
available
+ *<HTMLElement> + * target
the HTMLElement bound to this Element instance
+ *Usage:
+ * @event available + */ + +/** + * Fires when the Element's HTMLElement subtree is rendered. + *
+ *var handler = function(e) {var target = e.target};
+ * myTabs.addListener('available', handler);See: Element.addListener
+ *Event fields:
+ *<String> type
contentReady
+ *<HTMLElement> + * target
the HTMLElement bound to this Element instance
+ *Usage:
+ * @event contentReady + */ + +YAHOO.augment(YAHOO.util.Element, AttributeProvider); +})();(function() { + var Dom = YAHOO.util.Dom, + Event = YAHOO.util.Event, + Lang = YAHOO.util.Lang; + + /** + * A representation of a Tab's label and content. + * @namespace YAHOO.widget + * @class Tab + * @extends YAHOO.util.Element + * @constructor + * @param element {HTMLElement | String} (optional) The html element that + * represents the TabView. An element will be created if none provided. + * @param {Object} properties A key map of initial properties + */ + Tab = function(el, attr) { + attr = attr || {}; + if (arguments.length == 1 && !Lang.isString(el) && !el.nodeName) { + attr = el; + el = attr.element; + } + + if (!el && !attr.element) { + el = _createTabElement.call(this, attr); + } + + this.loadHandler = { + success: function(o) { + this.set('content', o.responseText); + }, + failure: function(o) { + YAHOO.log('loading failed: ' + o.statusText, + 'error', 'Tab'); + } + }; + + Tab.superclass.constructor.call(this, el, attr); + + this.DOM_EVENTS = {}; // delegating to tabView + }; + + YAHOO.extend(Tab, YAHOO.util.Element); + var proto = Tab.prototype; + + /** + * The default tag name for a Tab's inner element. + * @property LABEL_INNER_TAGNAME + * @type String + * @default "em" + */ + proto.LABEL_TAGNAME = 'em'; + + /** + * The class name applied to active tabs. + * @property ACTIVE_CLASSNAME + * @type String + * @default "on" + */ + proto.ACTIVE_CLASSNAME = 'selected'; + + /** + * The class name applied to disabled tabs. + * @property DISABLED_CLASSNAME + * @type String + * @default "disabled" + */ + proto.DISABLED_CLASSNAME = 'disabled'; + + /** + * The class name applied to dynamic tabs while loading. + * @property LOADING_CLASSNAME + * @type String + * @default "disabled" + */ + proto.LOADING_CLASSNAME = 'loading'; + + /** + * Provides a reference to the connection request object when data is + * loaded dynamically. + * @property dataConnection + * @type Object + */ + proto.dataConnection = null; + + /** + * Object containing success and failure callbacks for loading data. + * @property loadHandler + * @type object + */ + proto.loadHandler = null; + + /** + * Provides a readable name for the tab. + * @method toString + * @return String + */ + proto.toString = function() { + var el = this.get('element'); + var id = el.id || el.tagName; + return "Tab " + id; + }; + + /** + * Registers TabView specific properties. + * @method initAttributes + * @param {Object} attr Hash of initial attributes + */ + proto.initAttributes = function(attr) { + attr = attr || {}; + Tab.superclass.initAttributes.call(this, attr); + + var el = this.get('element'); + + /** + * The event that triggers the tab's activation. + * @config activationEvent + * @type String + */ + this.register('activationEvent', { + value: attr.activationEvent || 'click' + }); + + /** + * The element that contains the tab's label. + * @config labelEl + * @type HTMLElement + */ + this.register('labelEl', { + value: attr.labelEl || _getlabelEl.call(this), + method: function(value) { + var current = this.get('labelEl'); + + if (current) { + if (current == value) { + return false; // already set + } + + this.replaceChild(value, current); + } else if (el.firstChild) { // ensure label is firstChild by default + this.insertBefore(value, el.firstChild); + } else { + this.appendChild(value); + } + } + }); + + /** + * The tab's label text (or innerHTML). + * @config label + * @type String + */ + this.register('label', { + value: attr.label || _getLabel.call(this), + method: function(value) { + var labelEl = this.get('labelEl'); + if (!labelEl) { // create if needed + this.set('labelEl', _createlabelEl.call(this)); + } + + _setLabel.call(this, value); + } + }); + + /** + * The HTMLElement that contains the tab's content. + * @config contentEl + * @type HTMLElement + */ + this.register('contentEl', { // TODO: apply className? + value: attr.contentEl || document.createElement('div'), + method: function(value) { + var current = this.get('contentEl'); + + if (current) { + if (current == value) { + return false; // already set + } + this.replaceChild(value, current); + } + } + }); + + /** + * The tab's content. + * @config content + * @type String + */ + this.register('content', { + value: attr.content, // TODO: what about existing? + method: function(value) { + this.get('contentEl').innerHTML = value; + } + }); + + var _dataLoaded = false; + + /** + * The tab's data source, used for loading content dynamically. + * @config dataSrc + * @type String + */ + this.register('dataSrc', { + value: attr.dataSrc + }); + + /** + * Whether or not content should be reloaded for every view. + * @config cacheData + * @type Boolean + * @default false + */ + this.register('cacheData', { + value: attr.cacheData || false, + validator: Lang.isBoolean + }); + + /** + * The method to use for the data request. + * @config loadMethod + * @type String + * @default "GET" + */ + this.register('loadMethod', { + value: attr.loadMethod || 'GET', + validator: Lang.isString + }); + + /** + * Whether or not any data has been loaded from the server. + * @config dataLoaded + * @type Boolean + */ + this.register('dataLoaded', { + value: false, + validator: Lang.isBoolean, + writeOnce: true + }); + + /** + * Number if milliseconds before aborting and calling failure handler. + * @config dataTimeout + * @type Number + * @default null + */ + this.register('dataTimeout', { + value: attr.dataTimeout || null, + validator: Lang.isNumber + }); + + /** + * Whether or not the tab is currently active. + * If a dataSrc is set for the tab, the content will be loaded from + * the given source. + * @config active + * @type Boolean + */ + this.register('active', { + value: attr.active || this.hasClass(this.ACTIVE_CLASSNAME), + method: function(value) { + if (value === true) { + this.addClass(this.ACTIVE_CLASSNAME); + this.set('title', 'active'); + } else { + this.removeClass(this.ACTIVE_CLASSNAME); + this.set('title', ''); + } + }, + validator: function(value) { + return Lang.isBoolean(value) && !this.get('disabled') ; + } + }); + + /** + * Whether or not the tab is disabled. + * @config disabled + * @type Boolean + */ + this.register('disabled', { + value: attr.disabled || this.hasClass(this.DISABLED_CLASSNAME), + method: function(value) { + if (value === true) { + Dom.addClass(this.get('element'), this.DISABLED_CLASSNAME); + } else { + Dom.removeClass(this.get('element'), this.DISABLED_CLASSNAME); + } + }, + validator: Lang.isBoolean + }); + + /** + * The href of the tab's anchor element. + * @config href + * @type String + * @default '#' + */ + this.register('href', { + value: attr.href || '#', + method: function(value) { + this.getElementsByTagName('a')[0].href = value; + }, + validator: Lang.isString + }); + + /** + * The Whether or not the tab's content is visible. + * @config contentVisible + * @type Boolean + * @default false + */ + this.register('contentVisible', { + value: attr.contentVisible, + method: function(value) { + if (value == true) { + this.get('contentEl').style.display = 'block'; + + if ( this.get('dataSrc') ) { + // load dynamic content unless already loaded and caching + if ( !this.get('dataLoaded') || !this.get('cacheData') ) { + _dataConnect.call(this); + } + } + } else { + this.get('contentEl').style.display = 'none'; + } + }, + validator: Lang.isBoolean + }); + }; + + var _createTabElement = function(attr) { + var el = document.createElement('li'); + var a = document.createElement('a'); + + a.href = attr.href || '#'; + + el.appendChild(a); + + var label = attr.label || null; + var labelEl = attr.labelEl || null; + + if (labelEl) { // user supplied labelEl + if (!label) { // user supplied label + label = _getLabel.call(this, labelEl); + } + } else { + labelEl = _createlabelEl.call(this); + } + + a.appendChild(labelEl); + + return el; + }; + + var _getlabelEl = function() { + return this.getElementsByTagName(this.LABEL_TAGNAME)[0]; + }; + + var _createlabelEl = function() { + var el = document.createElement(this.LABEL_TAGNAME); + return el; + }; + + var _setLabel = function(label) { + var el = this.get('labelEl'); + el.innerHTML = label; + }; + + var _getLabel = function() { + var label, + el = this.get('labelEl'); + + if (!el) { + return undefined; + } + + return el.innerHTML; + }; + + var _dataConnect = function() { + if (!YAHOO.util.Connect) { + YAHOO.log('YAHOO.util.Connect dependency not met', + 'error', 'Tab'); + return false; + } + + Dom.addClass(this.get('contentEl').parentNode, this.LOADING_CLASSNAME); + + this.dataConnection = YAHOO.util.Connect.asyncRequest( + this.get('loadMethod'), + this.get('dataSrc'), + { + success: function(o) { + this.loadHandler.success.call(this, o); + this.set('dataLoaded', true); + this.dataConnection = null; + Dom.removeClass(this.get('contentEl').parentNode, + this.LOADING_CLASSNAME); + }, + failure: function(o) { + this.loadHandler.failure.call(this, o); + this.dataConnection = null; + Dom.removeClass(this.get('contentEl').parentNode, + this.LOADING_CLASSNAME); + }, + scope: this, + timeout: this.get('dataTimeout') + } + ); + }; + + YAHOO.widget.Tab = Tab; + + /** + * Fires before the active state is changed. + *
+ *var handler = function(e) {var target = e.target};
+ * myTabs.addListener('contentReady', handler);See: Element.addListener
+ *If handler returns false, the change will be cancelled, and the value will not + * be set.
+ *Event fields:
+ *
+ *<String> type
beforeActiveChange
+ *<Boolean> + * prevValue
the current value
+ *<Boolean> + * newValue
the new valueUsage:
+ * @event beforeActiveChange + */ + + /** + * Fires after the active state is changed. + *
+ *var handler = function(e) {var previous = e.prevValue};
+ * myTabs.addListener('beforeActiveChange', handler);See: Element.addListener
+ *Event fields:
+ *
+ *<String> type
activeChange
+ *<Boolean> + * prevValue
the previous value
+ *<Boolean> + * newValue
the updated valueUsage:
+ * @event activeChange + */ + + /** + * Fires before the tab label is changed. + *
+ *var handler = function(e) {var previous = e.prevValue};
+ * myTabs.addListener('activeChange', handler);See: Element.addListener
+ *If handler returns false, the change will be cancelled, and the value will not + * be set.
+ *Event fields:
+ *
+ *<String> type
beforeLabelChange
+ *<String> + * prevValue
the current value
+ *<String> + * newValue
the new valueUsage:
+ * @event beforeLabelChange + */ + + /** + * Fires after the tab label is changed. + *
+ *var handler = function(e) {var previous = e.prevValue};
+ * myTabs.addListener('beforeLabelChange', handler);See: Element.addListener
+ *Event fields:
+ *
+ *<String> type
labelChange
+ *<String> + * prevValue
the previous value
+ *<String> + * newValue
the updated valueUsage:
+ * @event labelChange + */ + + /** + * Fires before the tab content is changed. + *
+ *var handler = function(e) {var previous = e.prevValue};
+ * myTabs.addListener('labelChange', handler);See: Element.addListener
+ *If handler returns false, the change will be cancelled, and the value will not + * be set.
+ *Event fields:
+ *
+ *<String> type
beforeContentChange
+ *<String> + * prevValue
the current value
+ *<String> + * newValue
the new valueUsage:
+ * @event beforeContentChange + */ + + /** + * Fires after the tab content is changed. + *
+ *var handler = function(e) {var previous = e.prevValue};
+ * myTabs.addListener('beforeContentChange', handler);See: Element.addListener
+ *Event fields:
+ *
+ *<String> type
contentChange
+ *<String> + * prevValue
the previous value
+ *<Boolean> + * newValue
the updated valueUsage:
+ * @event contentChange + */ +})();(function() { + + /** + * The tabview module provides a widget for managing content bound to tabs. + * @module tabview + * + */ + /** + * A widget to control tabbed views. + * @namespace YAHOO.widget + * @class TabView + * @extends YAHOO.util.Element + * @constructor + * @param {HTMLElement | String | Object} el(optional) The html + * element that represents the TabView, or the attribute object to use. + * An element will be created if none provided. + * @param {Object} attr (optional) A key map of the tabView's + * initial attributes. Ignored if first arg is attributes object. + */ + YAHOO.widget.TabView = function(el, attr) { + attr = attr || {}; + if (arguments.length == 1 && !Lang.isString(el) && !el.nodeName) { + attr = el; // treat first arg as attr object + el = attr.element || null; + } + + if (!el && !attr.element) { // create if we dont have one + el = _createTabViewElement.call(this, attr); + } + YAHOO.widget.TabView.superclass.constructor.call(this, el, attr); + }; + + YAHOO.extend(YAHOO.widget.TabView, YAHOO.util.Element); + + var proto = YAHOO.widget.TabView.prototype; + var Dom = YAHOO.util.Dom; + var Lang = YAHOO.util.Lang; + var Event = YAHOO.util.Event; + var Tab = YAHOO.widget.Tab; + + + /** + * The className to add when building from scratch. + * @property CLASSNAME + * @default "navset" + */ + proto.CLASSNAME = 'yui-navset'; + + /** + * The className of the HTMLElement containing the TabView's tab elements + * to look for when building from existing markup, or to add when building + * from scratch. + * All childNodes of the tab container are treated as Tabs when building + * from existing markup. + * @property TAB_PARENT_CLASSNAME + * @default "nav" + */ + proto.TAB_PARENT_CLASSNAME = 'yui-nav'; + + /** + * The className of the HTMLElement containing the TabView's label elements + * to look for when building from existing markup, or to add when building + * from scratch. + * All childNodes of the content container are treated as content elements when + * building from existing markup. + * @property CONTENT_PARENT_CLASSNAME + * @default "nav-content" + */ + proto.CONTENT_PARENT_CLASSNAME = 'yui-content'; + + proto._tabParent = null; + proto._contentParent = null; + + /** + * Adds a Tab to the TabView instance. + * If no index is specified, the tab is added to the end of the tab list. + * @method addTab + * @param {YAHOO.widget.Tab} tab A Tab instance to add. + * @param {Integer} index The position to add the tab. + * @return void + */ + proto.addTab = function(tab, index) { + var tabs = this.get('tabs'); + if (!tabs) { // not ready yet + this._queue[this._queue.length] = ['addTab', arguments]; + return false; + } + + index = (index === undefined) ? tabs.length : index; + + var before = this.getTab(index); + + var self = this; + var el = this.get('element'); + var tabParent = this._tabParent; + var contentParent = this._contentParent; + + var tabElement = tab.get('element'); + var contentEl = tab.get('contentEl'); + + if ( before ) { + tabParent.insertBefore(tabElement, before.get('element')); + } else { + tabParent.appendChild(tabElement); + } + + if ( contentEl && !Dom.isAncestor(contentParent, contentEl) ) { + contentParent.appendChild(contentEl); + } + + if ( !tab.get('active') ) { + tab.set('contentVisible', false, true); /* hide if not active */ + } else { + this.set('activeTab', tab, true); + + } + + var activate = function(e) { + YAHOO.util.Event.preventDefault(e); + self.set('activeTab', this); + }; + + tab.addListener( tab.get('activationEvent'), activate); + + tab.addListener('activationEventChange', function(e) { + if (e.prevValue != e.newValue) { + tab.removeListener(e.prevValue, activate); + tab.addListener(e.newValue, activate); + } + }); + + tabs.splice(index, 0, tab); + }; + + /** + * Routes childNode events. + * @method DOMEventHandler + * @param {event} e The Dom event that is being handled. + * @return void + */ + proto.DOMEventHandler = function(e) { + var el = this.get('element'); + var target = YAHOO.util.Event.getTarget(e); + var tabParent = this._tabParent; + + if (Dom.isAncestor(tabParent, target) ) { + var tabEl; + var tab = null; + var contentEl; + var tabs = this.get('tabs'); + + for (var i = 0, len = tabs.length; i < len; i++) { + tabEl = tabs[i].get('element'); + contentEl = tabs[i].get('contentEl'); + + if ( target == tabEl || Dom.isAncestor(tabEl, target) ) { + tab = tabs[i]; + break; // note break + } + } + + if (tab) { + tab.fireEvent(e.type, e); + } + } + }; + + /** + * Returns the Tab instance at the specified index. + * @method getTab + * @param {Integer} index The position of the Tab. + * @return YAHOO.widget.Tab + */ + proto.getTab = function(index) { + return this.get('tabs')[index]; + }; + + /** + * Returns the index of given tab. + * @method getTabIndex + * @param {YAHOO.widget.Tab} tab The tab whose index will be returned. + * @return int + */ + proto.getTabIndex = function(tab) { + var index = null; + var tabs = this.get('tabs'); + for (var i = 0, len = tabs.length; i < len; ++i) { + if (tab == tabs[i]) { + index = i; + break; + } + } + + return index; + }; + + /** + * Removes the specified Tab from the TabView. + * @method removeTab + * @param {YAHOO.widget.Tab} item The Tab instance to be removed. + * @return void + */ + proto.removeTab = function(tab) { + var tabCount = this.get('tabs').length; + + var index = this.getTabIndex(tab); + var nextIndex = index + 1; + if ( tab == this.get('activeTab') ) { // select next tab + if (tabCount > 1) { + if (index + 1 == tabCount) { + this.set('activeIndex', index - 1); + } else { + this.set('activeIndex', index + 1); + } + } + } + + this._tabParent.removeChild( tab.get('element') ); + this._contentParent.removeChild( tab.get('contentEl') ); + this._configs.tabs.value.splice(index, 1); + + }; + + /** + * Provides a readable name for the TabView instance. + * @method toString + * @return String + */ + proto.toString = function() { + var name = this.get('id') || this.get('tagName'); + return "TabView " + name; + }; + + /** + * The transiton to use when switching between tabs. + * @method contentTransition + */ + proto.contentTransition = function(newTab, oldTab) { + newTab.set('contentVisible', true); + oldTab.set('contentVisible', false); + }; + + /** + * Registers TabView specific properties. + * @method initAttributes + * @param {Object} attr Hash of initial attributes + */ + proto.initAttributes = function(attr) { + YAHOO.widget.TabView.superclass.initAttributes.call(this, attr); + + if (!attr.orientation) { + attr.orientation = 'top'; + } + + var el = this.get('element'); + + /** + * The Tabs belonging to the TabView instance. + * @config tabs + * @type Array + */ + this.register('tabs', { + value: [], + readOnly: true + }); + + /** + * The container of the tabView's label elements. + * @property _tabParent + * @private + * @type HTMLElement + */ + this._tabParent = + this.getElementsByClassName(this.TAB_PARENT_CLASSNAME, + 'ul' )[0] || _createTabParent.call(this); + + /** + * The container of the tabView's content elements. + * @property _contentParent + * @type HTMLElement + * @private + */ + this._contentParent = + this.getElementsByClassName(this.CONTENT_PARENT_CLASSNAME, + 'div')[0] || _createContentParent.call(this); + + /** + * How the Tabs should be oriented relative to the TabView. + * @config orientation + * @type String + * @default "top" + */ + this.register('orientation', { + value: attr.orientation, + method: function(value) { + var current = this.get('orientation'); + this.addClass('yui-navset-' + value); + + if (current != value) { + this.removeClass('yui-navset-' + current); + } + + switch(value) { + case 'bottom': + this.appendChild(this._tabParent); + break; + } + } + }); + + /** + * The index of the tab currently active. + * @config activeIndex + * @type Int + */ + this.register('activeIndex', { + value: attr.activeIndex, + method: function(value) { + this.set('activeTab', this.getTab(value)); + }, + validator: function(value) { + return !this.getTab(value).get('disabled'); // cannot activate if disabled + } + }); + + /** + * The tab currently active. + * @config activeTab + * @type YAHOO.widget.Tab + */ + this.register('activeTab', { + value: attr.activeTab, + method: function(tab) { + var activeTab = this.get('activeTab'); + + if (tab) { + tab.set('active', true); + } + + if (activeTab && activeTab != tab) { + activeTab.set('active', false); + } + + if (activeTab && tab != activeTab) { // no transition if only 1 + this.contentTransition(tab, activeTab); + } else if (tab) { + tab.set('contentVisible', true); + } + }, + validator: function(value) { + return !value.get('disabled'); // cannot activate if disabled + } + }); + + if ( this._tabParent ) { + _initTabs.call(this); + } + + for (var type in this.DOM_EVENTS) { + if ( this.DOM_EVENTS.hasOwnProperty(type) ) { + this.addListener.call(this, type, this.DOMEventHandler); + } + } + }; + + /** + * Creates Tab instances from a collection of HTMLElements. + * @method createTabs + * @private + * @param {Array|HTMLCollection} elements The elements to use for Tabs. + * @return void + */ + var _initTabs = function() { + var tab, + attr, + contentEl; + + var el = this.get('element'); + var tabs = _getChildNodes(this._tabParent); + var contentElements = _getChildNodes(this._contentParent); + + for (var i = 0, len = tabs.length; i < len; ++i) { + attr = {}; + + if (contentElements[i]) { + attr.contentEl = contentElements[i]; + } + + tab = new YAHOO.widget.Tab(tabs[i], attr); + this.addTab(tab); + + if (tab.hasClass(tab.ACTIVE_CLASSNAME) ) { + this._configs.activeTab.value = tab; // dont invoke method + } + } + }; + + var _createTabViewElement = function(attr) { + var el = document.createElement('div'); + + if ( this.CLASSNAME ) { + el.className = this.CLASSNAME; + } + + return el; + }; + + var _createTabParent = function(attr) { + var el = document.createElement('ul'); + + if ( this.TAB_PARENT_CLASSNAME ) { + el.className = this.TAB_PARENT_CLASSNAME; + } + + this.get('element').appendChild(el); + + return el; + }; + + var _createContentParent = function(attr) { + var el = document.createElement('div'); + + if ( this.CONTENT_PARENT_CLASSNAME ) { + el.className = this.CONTENT_PARENT_CLASSNAME; + } + + this.get('element').appendChild(el); + + return el; + }; + + var _getChildNodes = function(el) { + var nodes = []; + var childNodes = el.childNodes; + + for (var i = 0, len = childNodes.length; i < len; ++i) { + if (childNodes[i].nodeType == 1) { + nodes[nodes.length] = childNodes[i]; + } + } + + return nodes; + }; + +/** + * Fires before the activeTab is changed. + *
+ *var handler = function(e) {var previous = e.prevValue};
+ * myTabs.addListener('contentChange', handler);See: Element.addListener
+ *If handler returns false, the change will be cancelled, and the value will not + * be set.
+ *Event fields:
+ *
+ *<String> type
beforeActiveTabChange
+ *<YAHOO.widget.Tab> + * prevValue
the currently active tab
+ *<YAHOO.widget.Tab> + * newValue
the tab to be made activeUsage:
+ * @event beforeActiveTabChange + */ + +/** + * Fires after the activeTab is changed. + *
+ *var handler = function(e) {var previous = e.prevValue};
+ * myTabs.addListener('beforeActiveTabChange', handler);See: Element.addListener
+ *Event fields:
+ *
+ *<String> type
activeTabChange
+ *<YAHOO.widget.Tab> + * prevValue
the formerly active tab
+ *<YAHOO.widget.Tab> + * newValue
the new active tabUsage:
+ * @event activeTabChange + */ + +/** + * Fires before the orientation is changed. + *
+ *var handler = function(e) {var previous = e.prevValue};
+ * myTabs.addListener('activeTabChange', handler);See: Element.addListener
+ *If handler returns false, the change will be cancelled, and the value will not + * be set.
+ *Event fields:
+ *
+ *<String> type
beforeOrientationChange
+ *<String> + * prevValue
the current orientation
+ *<String> + * newValue
the new orientation to be appliedUsage:
+ * @event beforeOrientationChange + */ + +/** + * Fires after the orientation is changed. + *
+ *var handler = function(e) {var previous = e.prevValue};
+ * myTabs.addListener('beforeOrientationChange', handler);See: Element.addListener
+ *Event fields:
+ *
+ *<String> type
orientationChange
+ *<String> + * prevValue
the former orientation
+ *<String> + * newValue
the new orientationUsage:
+ * @event orientationChange + */ +})(); \ No newline at end of file diff --git a/frontend/beta/js/YUI/treeview.js b/frontend/beta/js/YUI/treeview.js new file mode 100644 index 0000000..ea6b6ef --- a/dev/null +++ b/frontend/beta/js/YUI/treeview.js @@ -0,0 +1,2182 @@ +/* +Copyright (c) 2006, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 0.12.0 +*/ + +/** + * The treeview widget is a generic tree building tool. + * @module treeview + * @title TreeView Widget + * @requires yahoo + * @optional animation + * @namespace YAHOO.widget + */ + +/** + * Contains the tree view state data and the root node. + * + * @class TreeView + * @constructor + * @param {string|HTMLElement} id The id of the element, or the element + * itself that the tree will be inserted into. + */ +YAHOO.widget.TreeView = function(id) { + if (id) { this.init(id); } +}; + +YAHOO.widget.TreeView.prototype = { + + /** + * The id of tree container element + * @property id + * @type String + */ + id: null, + + /** + * The host element for this tree + * @property _el + * @private + */ + _el: null, + + /** + * Flat collection of all nodes in this tree + * @property _nodes + * @type Node[] + * @private + */ + _nodes: null, + + /** + * We lock the tree control while waiting for the dynamic loader to return + * @property locked + * @type boolean + */ + locked: false, + + /** + * The animation to use for expanding children, if any + * @property _expandAnim + * @type string + * @private + */ + _expandAnim: null, + + /** + * The animation to use for collapsing children, if any + * @property _collapseAnim + * @type string + * @private + */ + _collapseAnim: null, + + /** + * The current number of animations that are executing + * @property _animCount + * @type int + * @private + */ + _animCount: 0, + + /** + * The maximum number of animations to run at one time. + * @property maxAnim + * @type int + */ + maxAnim: 2, + + /** + * Sets up the animation for expanding children + * @method setExpandAnim + * @param {string} type the type of animation (acceptable values defined + * in YAHOO.widget.TVAnim) + */ + setExpandAnim: function(type) { + if (YAHOO.widget.TVAnim.isValid(type)) { + this._expandAnim = type; + } + }, + + /** + * Sets up the animation for collapsing children + * @method setCollapseAnim + * @param {string} the type of animation (acceptable values defined in + * YAHOO.widget.TVAnim) + */ + setCollapseAnim: function(type) { + if (YAHOO.widget.TVAnim.isValid(type)) { + this._collapseAnim = type; + } + }, + + /** + * Perform the expand animation if configured, or just show the + * element if not configured or too many animations are in progress + * @method animateExpand + * @param el {HTMLElement} the element to animate + * @param node {YAHOO.util.Node} the node that was expanded + * @return {boolean} true if animation could be invoked, false otherwise + */ + animateExpand: function(el, node) { + + if (this._expandAnim && this._animCount < this.maxAnim) { + // this.locked = true; + var tree = this; + var a = YAHOO.widget.TVAnim.getAnim(this._expandAnim, el, + function() { tree.expandComplete(node); }); + if (a) { + ++this._animCount; + this.fireEvent("animStart", { + "node": node, + "type": "expand" + }); + a.animate(); + } + + return true; + } + + return false; + }, + + /** + * Perform the collapse animation if configured, or just show the + * element if not configured or too many animations are in progress + * @method animateCollapse + * @param el {HTMLElement} the element to animate + * @param node {YAHOO.util.Node} the node that was expanded + * @return {boolean} true if animation could be invoked, false otherwise + */ + animateCollapse: function(el, node) { + + if (this._collapseAnim && this._animCount < this.maxAnim) { + // this.locked = true; + var tree = this; + var a = YAHOO.widget.TVAnim.getAnim(this._collapseAnim, el, + function() { tree.collapseComplete(node); }); + if (a) { + ++this._animCount; + this.fireEvent("animStart", { + "node": node, + "type": "collapse" + }); + a.animate(); + } + + return true; + } + + return false; + }, + + /** + * Function executed when the expand animation completes + * @method expandComplete + */ + expandComplete: function(node) { + --this._animCount; + this.fireEvent("animComplete", { + "node": node, + "type": "expand" + }); + // this.locked = false; + }, + + /** + * Function executed when the collapse animation completes + * @method collapseComplete + */ + collapseComplete: function(node) { + --this._animCount; + this.fireEvent("animComplete", { + "node": node, + "type": "collapse" + }); + // this.locked = false; + }, + + /** + * Initializes the tree + * @method init + * @parm {string|HTMLElement} id the id of the element that will hold the tree + * @private + */ + init: function(id) { + + this.id = id; + + if ("string" !== typeof id) { + this._el = id; + this.id = this.generateId(id); + } + + /** + * When animation is enabled, this event fires when the animation + * starts + * @event animStart + * @type CustomEvent + * @param {YAHOO.widget.Node} node the node that is expanding/collapsing + * @parm {String} type the type of animation ("expand" or "collapse") + */ + this.createEvent("animStart", this); + + /** + * When animation is enabled, this event fires when the animation + * completes + * @event animComplete + * @type CustomEvent + * @param {YAHOO.widget.Node} node the node that is expanding/collapsing + * @parm {String} type the type of animation ("expand" or "collapse") + */ + this.createEvent("animComplete", this); + + /** + * Fires when a node is going to be expanded. Return false to stop + * the expand. + * @event collapse + * @type CustomEvent + * @param {YAHOO.widget.Node} node the node that is expanding/collapsing + */ + this.createEvent("collapse", this); + + /** + * Fires when a node is going to be collapsed. Return false to stop + * the collapse. + * @event expand + * @type CustomEvent + * @param {YAHOO.widget.Node} node the node that is expanding/collapsing + */ + this.createEvent("expand", this); + + this._nodes = []; + + // store a global reference + YAHOO.widget.TreeView.trees[this.id] = this; + + // Set up the root node + this.root = new YAHOO.widget.RootNode(this); + + + }, + + /** + * Renders the tree boilerplate and visible nodes + * @method draw + */ + draw: function() { + var html = this.root.getHtml(); + this.getEl().innerHTML = html; + this.firstDraw = false; + }, + + /** + * Returns the tree's host element + * @method getEl + * @return {HTMLElement} the host element + */ + getEl: function() { + if (! this._el) { + this._el = document.getElementById(this.id); + } + return this._el; + }, + + /** + * Nodes register themselves with the tree instance when they are created. + * @method regNode + * @param node {Node} the node to register + * @private + */ + regNode: function(node) { + this._nodes[node.index] = node; + }, + + /** + * Returns the root node of this tree + * @method getRoot + * @return {Node} the root node + */ + getRoot: function() { + return this.root; + }, + + /** + * Configures this tree to dynamically load all child data + * @method setDynamicLoad + * @param {function} fnDataLoader the function that will be called to get the data + * @param iconMode {int} configures the icon that is displayed when a dynamic + * load node is expanded the first time without children. By default, the + * "collapse" icon will be used. If set to 1, the leaf node icon will be + * displayed. + */ + setDynamicLoad: function(fnDataLoader, iconMode) { + this.root.setDynamicLoad(fnDataLoader, iconMode); + }, + + /** + * Expands all child nodes. Note: this conflicts with the "multiExpand" + * node property. If expand all is called in a tree with nodes that + * do not allow multiple siblings to be displayed, only the last sibling + * will be expanded. + * @method expandAll + */ + expandAll: function() { + if (!this.locked) { + this.root.expandAll(); + } + }, + + /** + * Collapses all expanded child nodes in the entire tree. + * @method collapseAll + */ + collapseAll: function() { + if (!this.locked) { + this.root.collapseAll(); + } + }, + + /** + * Returns a node in the tree that has the specified index (this index + * is created internally, so this function probably will only be used + * in html generated for a given node.) + * @method getNodeByIndex + * @param {int} nodeIndex the index of the node wanted + * @return {Node} the node with index=nodeIndex, null if no match + */ + getNodeByIndex: function(nodeIndex) { + var n = this._nodes[nodeIndex]; + return (n) ? n : null; + }, + + /** + * Returns a node that has a matching property and value in the data + * object that was passed into its constructor. + * @method getNodeByProperty + * @param {object} property the property to search (usually a string) + * @param {object} value the value we want to find (usuall an int or string) + * @return {Node} the matching node, null if no match + */ + getNodeByProperty: function(property, value) { + for (var i in this._nodes) { + var n = this._nodes[i]; + if (n.data && value == n.data[property]) { + return n; + } + } + + return null; + }, + + /** + * Returns a collection of nodes that have a matching property + * and value in the data object that was passed into its constructor. + * @method getNodesByProperty + * @param {object} property the property to search (usually a string) + * @param {object} value the value we want to find (usuall an int or string) + * @return {Array} the matching collection of nodes, null if no match + */ + getNodesByProperty: function(property, value) { + var values = []; + for (var i in this._nodes) { + var n = this._nodes[i]; + if (n.data && value == n.data[property]) { + values.push(n); + } + } + + return (values.length) ? values : null; + }, + + /** + * Removes the node and its children, and optionally refreshes the + * branch of the tree that was affected. + * @method removeNode + * @param {Node} The node to remove + * @param {boolean} autoRefresh automatically refreshes branch if true + * @return {boolean} False is there was a problem, true otherwise. + */ + removeNode: function(node, autoRefresh) { + + // Don't delete the root node + if (node.isRoot()) { + return false; + } + + // Get the branch that we may need to refresh + var p = node.parent; + if (p.parent) { + p = p.parent; + } + + // Delete the node and its children + this._deleteNode(node); + + // Refresh the parent of the parent + if (autoRefresh && p && p.childrenRendered) { + p.refresh(); + } + + return true; + }, + + /** + * Deletes this nodes child collection, recursively. Also collapses + * the node, and resets the dynamic load flag. The primary use for + * this method is to purge a node and allow it to fetch its data + * dynamically again. + * @method removeChildren + * @param {Node} node the node to purge + */ + removeChildren: function(node) { + while (node.children.length) { + this._deleteNode(node.children[0]); + } + + node.childrenRendered = false; + node.dynamicLoadComplete = false; + if (node.expanded) { + node.collapse(); + } else { + node.updateIcon(); + } + }, + + /** + * Deletes the node and recurses children + * @method _deleteNode + * @private + */ + _deleteNode: function(node) { + // Remove all the child nodes first + this.removeChildren(node); + + // Remove the node from the tree + this.popNode(node); + }, + + /** + * Removes the node from the tree, preserving the child collection + * to make it possible to insert the branch into another part of the + * tree, or another tree. + * @method popNode + * @param {Node} the node to remove + */ + popNode: function(node) { + var p = node.parent; + + // Update the parent's collection of children + var a = []; + + for (var i=0, len=p.children.length;i
+ *var handler = function(e) {var previous = e.prevValue};
+ * myTabs.addListener('orientationChange', handler);'; + } + + var f = document.createElement("div"); + var s = f.style; + s.position = "absolute"; + s.top = "-1000px"; + s.left = "-1000px"; + f.innerHTML = sb.join(""); + + document.body.appendChild(f); + + YAHOO.widget.TreeView.removeHandler(window, + "load", YAHOO.widget.TreeView.preload); + +}; + +YAHOO.widget.TreeView.addHandler(window, + "load", YAHOO.widget.TreeView.preload); + +/** + * The base class for all tree nodes. The node's presentation and behavior in + * response to mouse events is handled in Node subclasses. + * @namespace YAHOO.widget + * @class Node + * @param oData {object} a string or object containing the data that will + * be used to render this node + * @param oParent {Node} this node's parent node + * @param expanded {boolean} the initial expanded/collapsed state + * @constructor + */ +YAHOO.widget.Node = function(oData, oParent, expanded) { + if (oData) { this.init(oData, oParent, expanded); } +}; + +YAHOO.widget.Node.prototype = { + + /** + * The index for this instance obtained from global counter in YAHOO.widget.TreeView. + * @property index + * @type int + */ + index: 0, + + /** + * This node's child node collection. + * @property children + * @type Node[] + */ + children: null, + + /** + * Tree instance this node is part of + * @property tree + * @type TreeView + */ + tree: null, + + /** + * The data linked to this node. This can be any object or primitive + * value, and the data can be used in getNodeHtml(). + * @property data + * @type object + */ + data: null, + + /** + * Parent node + * @property parent + * @type Node + */ + parent: null, + + /** + * The depth of this node. We start at -1 for the root node. + * @property depth + * @type int + */ + depth: -1, + + /** + * The href for the node's label. If one is not specified, the href will + * be set so that it toggles the node. + * @property href + * @type string + */ + href: null, + + /** + * The label href target, defaults to current window + * @property target + * @type string + */ + target: "_self", + + /** + * The node's expanded/collapsed state + * @property expanded + * @type boolean + */ + expanded: false, + + /** + * Can multiple children be expanded at once? + * @property multiExpand + * @type boolean + */ + multiExpand: true, + + /** + * Should we render children for a collapsed node? It is possible that the + * implementer will want to render the hidden data... @todo verify that we + * need this, and implement it if we do. + * @property renderHidden + * @type boolean + */ + renderHidden: false, + + /** + * This flag is set to true when the html is generated for this node's + * children, and set to false when new children are added. + * @property childrenRendered + * @type boolean + */ + childrenRendered: false, + + /** + * Dynamically loaded nodes only fetch the data the first time they are + * expanded. This flag is set to true once the data has been fetched. + * @property dynamicLoadComplete + * @type boolean + */ + dynamicLoadComplete: false, + + /** + * This node's previous sibling + * @property previousSibling + * @type Node + */ + previousSibling: null, + + /** + * This node's next sibling + * @property nextSibling + * @type Node + */ + nextSibling: null, + + /** + * We can set the node up to call an external method to get the child + * data dynamically. + * @property _dynLoad + * @type boolean + * @private + */ + _dynLoad: false, + + /** + * Function to execute when we need to get this node's child data. + * @property dataLoader + * @type function + */ + dataLoader: null, + + /** + * This is true for dynamically loading nodes while waiting for the + * callback to return. + * @property isLoading + * @type boolean + */ + isLoading: false, + + /** + * The toggle/branch icon will not show if this is set to false. This + * could be useful if the implementer wants to have the child contain + * extra info about the parent, rather than an actual node. + * @property hasIcon + * @type boolean + */ + hasIcon: true, + + /** + * Used to configure what happens when a dynamic load node is expanded + * and we discover that it does not have children. By default, it is + * treated as if it still could have children (plus/minus icon). Set + * iconMode to have it display like a leaf node instead. + * @property iconMode + * @type int + */ + iconMode: 0, + + /** + * The node type + * @property _type + * @private + */ + _type: "Node", + + /* + spacerPath: "http://us.i1.yimg.com/us.yimg.com/i/space.gif", + expandedText: "Expanded", + collapsedText: "Collapsed", + loadingText: "Loading", + */ + + /** + * Initializes this node, gets some of the properties from the parent + * @method init + * @param oData {object} a string or object containing the data that will + * be used to render this node + * @param oParent {Node} this node's parent node + * @param expanded {boolean} the initial expanded/collapsed state + */ + init: function(oData, oParent, expanded) { + + this.data = oData; + this.children = []; + this.index = YAHOO.widget.TreeView.nodeCount; + ++YAHOO.widget.TreeView.nodeCount; + this.expanded = expanded; + + /** + * The parentChange event is fired when a parent element is applied + * to the node. This is useful if you need to apply tree-level + * properties to a tree that need to happen if a node is moved from + * one tre to another. + * + * @event parentChange + * @type CustomEvent + */ + this.createEvent("parentChange", this); + + // oParent should never be null except when we create the root node. + if (oParent) { + oParent.appendChild(this); + } + }, + + /** + * Certain properties for the node cannot be set until the parent + * is known. This is called after the node is inserted into a tree. + * the parent is also applied to this node's children in order to + * make it possible to move a branch from one tree to another. + * @method applyParent + * @param {Node} parentNode this node's parent node + * @return {boolean} true if the application was successful + */ + applyParent: function(parentNode) { + if (!parentNode) { + return false; + } + + this.tree = parentNode.tree; + this.parent = parentNode; + this.depth = parentNode.depth + 1; + + if (!this.href) { + this.href = "javascript:" + this.getToggleLink(); + } + + if (! this.multiExpand) { + this.multiExpand = parentNode.multiExpand; + } + + this.tree.regNode(this); + parentNode.childrenRendered = false; + + // cascade update existing children + for (var i=0, len=this.children.length;i 0 || + (checkForLazyLoad && this.isDynamic() && !this.dynamicLoadComplete) ); + }, + + /** + * Expands if node is collapsed, collapses otherwise. + * @method toggle + */ + toggle: function() { + if (!this.tree.locked && ( this.hasChildren(true) || this.isDynamic()) ) { + if (this.expanded) { this.collapse(); } else { this.expand(); } + } + }, + + /** + * Returns the markup for this node and its children. + * @method getHtml + * @return {string} the markup for this node and its expanded children. + */ + getHtml: function() { + + this.childrenRendered = false; + + var sb = []; + sb[sb.length] = ' '; + sb[sb.length] = this.getNodeHtml(); + sb[sb.length] = this.getChildrenHtml(); + sb[sb.length] = ''; + return sb.join(""); + }, + + /** + * Called when first rendering the tree. We always build the div that will + * contain this nodes children, but we don't render the children themselves + * unless this node is expanded. + * @method getChildrenHtml + * @return {string} the children container div html and any expanded children + * @private + */ + getChildrenHtml: function() { + + var sb = []; + sb[sb.length] = ' '; + + return sb.join(""); + }, + + /** + * Generates the markup for the child nodes. This is not done until the node + * is expanded. + * @method renderChildren + * @return {string} the html for this node's children + * @private + */ + renderChildren: function() { + + + var node = this; + + if (this.isDynamic() && !this.dynamicLoadComplete) { + this.isLoading = true; + this.tree.locked = true; + + if (this.dataLoader) { + + setTimeout( + function() { + node.dataLoader(node, + function() { + node.loadComplete(); + }); + }, 10); + + } else if (this.tree.root.dataLoader) { + + setTimeout( + function() { + node.tree.root.dataLoader(node, + function() { + node.loadComplete(); + }); + }, 10); + + } else { + return "Error: data loader not found or not specified."; + } + + return ""; + + } else { + return this.completeRender(); + } + }, + + /** + * Called when we know we have all the child data. + * @method completeRender + * @return {string} children html + */ + completeRender: function() { + var sb = []; + + for (var i=0; i < this.children.length; ++i) { + // this.children[i].childrenRendered = false; + sb[sb.length] = this.children[i].getHtml(); + } + + this.childrenRendered = true; + + return sb.join(""); + }, + + /** + * Load complete is the callback function we pass to the data provider + * in dynamic load situations. + * @method loadComplete + */ + loadComplete: function() { + this.getChildrenEl().innerHTML = this.completeRender(); + this.dynamicLoadComplete = true; + this.isLoading = false; + this.expand(); + this.tree.locked = false; + }, + + /** + * Returns this node's ancestor at the specified depth. + * @method getAncestor + * @param {int} depth the depth of the ancestor. + * @return {Node} the ancestor + */ + getAncestor: function(depth) { + if (depth >= this.depth || depth < 0) { + return null; + } + + var p = this.parent; + + while (p.depth > depth) { + p = p.parent; + } + + return p; + }, + + /** + * Returns the css class for the spacer at the specified depth for + * this node. If this node's ancestor at the specified depth + * has a next sibling the presentation is different than if it + * does not have a next sibling + * @method getDepthStyle + * @param {int} depth the depth of the ancestor. + * @return {string} the css class for the spacer + */ + getDepthStyle: function(depth) { + return (this.getAncestor(depth).nextSibling) ? + "ygtvdepthcell" : "ygtvblankdepthcell"; + }, + + /** + * Get the markup for the node. This is designed to be overrided so that we can + * support different types of nodes. + * @method getNodeHtml + * @return {string} The HTML that will render this node. + */ + getNodeHtml: function() { + return ""; + }, + + /** + * Regenerates the html for this node and its children. To be used when the + * node is expanded and new children have been added. + * @method refresh + */ + refresh: function() { + // this.loadComplete(); + this.getChildrenEl().innerHTML = this.completeRender(); + + if (this.hasIcon) { + var el = this.getToggleEl(); + if (el) { + el.className = this.getStyle(); + } + } + }, + + /** + * Node toString + * @method toString + * @return {string} string representation of the node + */ + toString: function() { + return "Node (" + this.index + ")"; + } + +}; + +YAHOO.augment(YAHOO.widget.Node, YAHOO.util.EventProvider); + +/** + * A custom YAHOO.widget.Node that handles the unique nature of + * the virtual, presentationless root node. + * @namespace YAHOO.widget + * @class RootNode + * @extends YAHOO.widget.Node + * @param oTree {YAHOO.widget.TreeView} The tree instance this node belongs to + * @constructor + */ +YAHOO.widget.RootNode = function(oTree) { + // Initialize the node with null params. The root node is a + // special case where the node has no presentation. So we have + // to alter the standard properties a bit. + this.init(null, null, true); + + /* + * For the root node, we get the tree reference from as a param + * to the constructor instead of from the parent element. + */ + this.tree = oTree; +}; + +YAHOO.extend(YAHOO.widget.RootNode, YAHOO.widget.Node, { + + // overrides YAHOO.widget.Node + getNodeHtml: function() { + return ""; + }, + + toString: function() { + return "RootNode"; + }, + + loadComplete: function() { + this.tree.draw(); + } + +}); +/** + * The default node presentation. The first parameter should be + * either a string that will be used as the node's label, or an object + * that has a string propery called label. By default, the clicking the + * label will toggle the expanded/collapsed state of the node. By + * changing the href property of the instance, this behavior can be + * changed so that the label will go to the specified href. + * @namespace YAHOO.widget + * @class TextNode + * @extends YAHOO.widget.Node + * @constructor + * @param oData {object} a string or object containing the data that will + * be used to render this node + * @param oParent {YAHOO.widget.Node} this node's parent node + * @param expanded {boolean} the initial expanded/collapsed state + */ +YAHOO.widget.TextNode = function(oData, oParent, expanded) { + + if (oData) { + this.init(oData, oParent, expanded); + this.setUpLabel(oData); + } + +}; + +YAHOO.extend(YAHOO.widget.TextNode, YAHOO.widget.Node, { + + /** + * The CSS class for the label href. Defaults to ygtvlabel, but can be + * overridden to provide a custom presentation for a specific node. + * @property labelStyle + * @type string + */ + labelStyle: "ygtvlabel", + + /** + * The derived element id of the label for this node + * @property labelElId + * @type string + */ + labelElId: null, + + /** + * The text for the label. It is assumed that the oData parameter will + * either be a string that will be used as the label, or an object that + * has a property called "label" that we will use. + * @property label + * @type string + */ + label: null, + + textNodeParentChange: function() { + + /** + * Custom event that is fired when the text node label is clicked. The + * custom event is defined on the tree instance, so there is a single + * event that handles all nodes in the tree. The node clicked is + * provided as an argument + * + * @event labelClick + * @for YAHOO.widget.TreeView + * @param {YAHOO.widget.Node} node the node clicked + */ + if (this.tree && !this.tree.hasEvent("labelClick")) { + this.tree.createEvent("labelClick", this.tree); + } + + }, + + /** + * Sets up the node label + * @method setUpLabel + * @param oData string containing the label, or an object with a label property + */ + setUpLabel: function(oData) { + + // set up the custom event on the tree + this.textNodeParentChange(); + this.subscribe("parentChange", this.textNodeParentChange); + + if (typeof oData == "string") { + oData = { label: oData }; + } + this.label = oData.label; + + // update the link + if (oData.href) { + this.href = oData.href; + } + + // set the target + if (oData.target) { + this.target = oData.target; + } + + if (oData.style) { + this.labelStyle = oData.style; + } + + this.labelElId = "ygtvlabelel" + this.index; + }, + + /** + * Returns the label element + * @for YAHOO.widget.TextNode + * @method getLabelEl + * @return {object} the element + */ + getLabelEl: function() { + return document.getElementById(this.labelElId); + }, + + // overrides YAHOO.widget.Node + getNodeHtml: function() { + var sb = []; + + sb[sb.length] = ''; + sb[sb.length] = '
'; + + return sb.join(""); + }, + + /** + * Executed when the label is clicked. Fires the labelClick custom event. + * @method onLabelClick + * @param me {Node} this node + * @scope the anchor tag clicked + * @return false to cancel the anchor click + */ + onLabelClick: function(me) { + return me.tree.fireEvent("labelClick", me); + //return true; + }, + + toString: function() { + return "TextNode (" + this.index + ") " + this.label; + } + +}); +/** + * A menu-specific implementation that differs from TextNode in that only + * one sibling can be expanded at a time. + * @namespace YAHOO.widget + * @class MenuNode + * @extends YAHOO.widget.TextNode + * @param oData {object} a string or object containing the data that will + * be used to render this node + * @param oParent {YAHOO.widget.Node} this node's parent node + * @param expanded {boolean} the initial expanded/collapsed state + * @constructor + */ +YAHOO.widget.MenuNode = function(oData, oParent, expanded) { + if (oData) { + this.init(oData, oParent, expanded); + this.setUpLabel(oData); + } + + /* + * Menus usually allow only one branch to be open at a time. + */ + this.multiExpand = false; + + +}; + +YAHOO.extend(YAHOO.widget.MenuNode, YAHOO.widget.TextNode, { + + toString: function() { + return "MenuNode (" + this.index + ") " + this.label; + } + +}); +/** + * This implementation takes either a string or object for the + * oData argument. If is it a string, we will use it for the display + * of this node (and it can contain any html code). If the parameter + * is an object, we look for a parameter called "html" that will be + * used for this node's display. + * @namespace YAHOO.widget + * @class HTMLNode + * @extends YAHOO.widget.Node + * @constructor + * @param oData {object} a string or object containing the data that will + * be used to render this node + * @param oParent {YAHOO.widget.Node} this node's parent node + * @param expanded {boolean} the initial expanded/collapsed state + * @param hasIcon {boolean} specifies whether or not leaf nodes should + * have an icon + */ +YAHOO.widget.HTMLNode = function(oData, oParent, expanded, hasIcon) { + if (oData) { + this.init(oData, oParent, expanded); + this.initContent(oData, hasIcon); + } +}; + +YAHOO.extend(YAHOO.widget.HTMLNode, YAHOO.widget.Node, { + + /** + * The CSS class for the html content container. Defaults to ygtvhtml, but + * can be overridden to provide a custom presentation for a specific node. + * @property contentStyle + * @type string + */ + contentStyle: "ygtvhtml", + + /** + * The generated id that will contain the data passed in by the implementer. + * @property contentElId + * @type string + */ + contentElId: null, + + /** + * The HTML content to use for this node's display + * @property content + * @type string + */ + content: null, + + /** + * Sets up the node label + * @property initContent + * @param {object} An html string or object containing an html property + * @param {boolean} hasIcon determines if the node will be rendered with an + * icon or not + */ + initContent: function(oData, hasIcon) { + if (typeof oData == "string") { + oData = { html: oData }; + } + + this.html = oData.html; + this.contentElId = "ygtvcontentel" + this.index; + this.hasIcon = hasIcon; + + }, + + /** + * Returns the outer html element for this node's content + * @method getContentEl + * @return {HTMLElement} the element + */ + getContentEl: function() { + return document.getElementById(this.contentElId); + }, + + // overrides YAHOO.widget.Node + getNodeHtml: function() { + var sb = []; + + sb[sb.length] = ''; + + for (var i=0;i '; + sb[sb.length] = ''; + sb[sb.length] = ' '; + } + + var getNode = 'YAHOO.widget.TreeView.getNode(\'' + + this.tree.id + '\',' + this.index + ')'; + + sb[sb.length] = ' '; + + /* + sb[sb.length] = ' '; + sb[sb.length] = ''; + */ + + sb[sb.length] = ' '; + + sb[sb.length] = '
'; + sb[sb.length] = ''; + sb[sb.length] = this.label; + sb[sb.length] = ''; + sb[sb.length] = ' '; + sb[sb.length] = ''; + sb[sb.length] = '
'; + + return sb.join(""); + }, + + toString: function() { + return "HTMLNode (" + this.index + ")"; + } + +}); +/** + * A static factory class for tree view expand/collapse animations + * @class TVAnim + * @static + */ +YAHOO.widget.TVAnim = function() { + return { + /** + * Constant for the fade in animation + * @property FADE_IN + * @type string + * @static + */ + FADE_IN: "TVFadeIn", + + /** + * Constant for the fade out animation + * @property FADE_OUT + * @type string + * @static + */ + FADE_OUT: "TVFadeOut", + + /** + * Returns a ygAnim instance of the given type + * @method getAnim + * @param type {string} the type of animation + * @param el {HTMLElement} the element to element (probably the children div) + * @param callback {function} function to invoke when the animation is done. + * @return {YAHOO.util.Animation} the animation instance + * @static + */ + getAnim: function(type, el, callback) { + if (YAHOO.widget[type]) { + return new YAHOO.widget[type](el, callback); + } else { + return null; + } + }, + + /** + * Returns true if the specified animation class is available + * @method isValid + * @param type {string} the type of animation + * @return {boolean} true if valid, false if not + * @static + */ + isValid: function(type) { + return (YAHOO.widget[type]); + } + }; +} (); + +/** + * A 1/2 second fade-in animation. + * @class TVFadeIn + * @constructor + * @param el {HTMLElement} the element to animate + * @param callback {function} function to invoke when the animation is finished + */ +YAHOO.widget.TVFadeIn = function(el, callback) { + /** + * The element to animate + * @property el + * @type HTMLElement + */ + this.el = el; + + /** + * the callback to invoke when the animation is complete + * @property callback + * @type function + */ + this.callback = callback; + +}; + +YAHOO.widget.TVFadeIn.prototype = { + /** + * Performs the animation + * @method animate + */ + animate: function() { + var tvanim = this; + + var s = this.el.style; + s.opacity = 0.1; + s.filter = "alpha(opacity=10)"; + s.display = ""; + + var dur = 0.4; + var a = new YAHOO.util.Anim(this.el, {opacity: {from: 0.1, to: 1, unit:""}}, dur); + a.onComplete.subscribe( function() { tvanim.onComplete(); } ); + a.animate(); + }, + + /** + * Clean up and invoke callback + * @method onComplete + */ + onComplete: function() { + this.callback(); + }, + + /** + * toString + * @method toString + * @return {string} the string representation of the instance + */ + toString: function() { + return "TVFadeIn"; + } +}; + +/** + * A 1/2 second fade out animation. + * @class TVFadeOut + * @constructor + * @param el {HTMLElement} the element to animate + * @param callback {Function} function to invoke when the animation is finished + */ +YAHOO.widget.TVFadeOut = function(el, callback) { + /** + * The element to animate + * @property el + * @type HTMLElement + */ + this.el = el; + + /** + * the callback to invoke when the animation is complete + * @property callback + * @type function + */ + this.callback = callback; + +}; + +YAHOO.widget.TVFadeOut.prototype = { + /** + * Performs the animation + * @method animate + */ + animate: function() { + var tvanim = this; + var dur = 0.4; + var a = new YAHOO.util.Anim(this.el, {opacity: {from: 1, to: 0.1, unit:""}}, dur); + a.onComplete.subscribe( function() { tvanim.onComplete(); } ); + a.animate(); + }, + + /** + * Clean up and invoke callback + * @method onComplete + */ + onComplete: function() { + var s = this.el.style; + s.display = "none"; + // s.opacity = 1; + s.filter = "alpha(opacity=100)"; + this.callback(); + }, + + /** + * toString + * @method toString + * @return {string} the string representation of the instance + */ + toString: function() { + return "TVFadeOut"; + } +}; + diff --git a/frontend/beta/js/YUI/yahoo.js b/frontend/beta/js/YUI/yahoo.js new file mode 100644 index 0000000..8a44a91 --- a/dev/null +++ b/frontend/beta/js/YUI/yahoo.js @@ -0,0 +1,145 @@ +/* +Copyright (c) 2006, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 0.12.0 +*/ + +/** + * The YAHOO object is the single global object used by YUI Library. It + * contains utility function for setting up namespaces, inheritance, and + * logging. YAHOO.util, YAHOO.widget, and YAHOO.example are namespaces + * created automatically for and used by the library. + * @module yahoo + * @title YAHOO Global + */ + +/** + * The YAHOO global namespace object + * @class YAHOO + * @static + */ +if (typeof YAHOO == "undefined") { + var YAHOO = {}; +} + +/** + * Returns the namespace specified and creates it if it doesn't exist + *'; + + for (var i=0;i '; + sb[sb.length] = ''; + } + + if (this.hasIcon) { + sb[sb.length] = ' '; + } + + sb[sb.length] = ' '; + sb[sb.length] = this.html; + sb[sb.length] = ' '; + sb[sb.length] = '+ * YAHOO.namespace("property.package"); + * YAHOO.namespace("YAHOO.property.package"); + *+ * Either of the above would create YAHOO.property, then + * YAHOO.property.package + * + * Be careful when naming packages. Reserved words may work in some browsers + * and not others. For instance, the following will fail in Safari: + *+ * YAHOO.namespace("really.long.nested.namespace"); + *+ * This fails because "long" is a future reserved word in ECMAScript + * + * @method namespace + * @static + * @param {String*} arguments 1-n namespaces to create + * @return {Object} A reference to the last namespace object created + */ +YAHOO.namespace = function() { + var a=arguments, o=null, i, j, d; + for (i=0; i