autocomplete-list.js revision f5738feb0b3d461c1398fc1cd8fc01b0de21d592
/**
* Traditional autocomplete dropdown list widget, just like Mom used to make.
*
* @module autocomplete
* @submodule autocomplete-list
* @class AutoCompleteList
* @extends Widget
* @uses AutoCompleteBase
* @uses WidgetPosition
* @uses WidgetPositionAlign
* @uses WidgetStack
* @constructor
* @param {Object} config Configuration object.
*/
YArray = Y.Array,
// keyCode constants.
// KEY_DOWN = 40,
// KEY_ENTER = 13,
// KEY_ESC = 27,
KEY_TAB = 9,
// KEY_UP = 38,
// String shorthand.
INPUT_NODE = 'inputNode',
VISIBLE = 'visible',
WIDTH = 'width',
], {
// -- Prototype Properties -------------------------------------------------
CONTENT_TEMPLATE: '<ul/>',
ITEM_TEMPLATE: '<li/>',
// -- Lifecycle Prototype Methods ------------------------------------------
initializer: function () {
this._events = [];
if (!this._inputNode) {
Y.error('No inputNode specified.');
}
if (!this.get('align.node')) {
}
}
},
destructor: function () {
this.unbindInput();
}
},
bindUI: function () {
this._bindInput();
this._bindList();
},
renderUI: function () {
// See http://www.w3.org/WAI/PF/aria/roles#combobox for ARIA details.
'aria-autocomplete': 'list',
role: 'combobox'
});
},
syncUI: function () {
this._syncResults();
this._syncVisibility();
},
// -- Public Prototype Methods ---------------------------------------------
/**
* Hides the list.
*
* @method hide
* @see show
* @chainable
*/
hide: function () {
},
/**
* Shows the list.
*
* @method show
* @see hide
* @chainable
*/
show: function () {
},
// -- Protected Prototype Methods ------------------------------------------
/**
* Appends the specified result <i>items</i> to the list inside a new item
* node.
*
* @method _add
* @param {Array|Node|HTMLElement|String} items Result item or array of
* result items.
* @protected
*/
var itemNodes = [];
}, this);
},
/**
* Binds <code>inputNode</code> events, in addition to those already bound
* by <code>AutoCompleteBase</code>'s public <code>bindInput()</code>
* method.
*
* @method _bindInput
* @protected
*/
_bindInput: function () {
var inputNode = this._inputNode;
// Call AutoCompleteBase's bind method first.
this.bindInput();
]);
},
/**
* Binds list events.
*
* @method _bindList
* @protected
*/
_bindList: function () {
]);
},
/**
* Clears the contents of the tray.
*
* @method _clear
* @protected
*/
_clear: function () {
},
/**
* Creates an item node with the specified <i>content</i>.
*
* @method _createItemNode
* @param {Node|HTMLElement|String} content
* @protected
* @returns {Node} Item node.
*/
_createItemNode: function (content) {
role: 'option'
},
/**
* Synchronizes the results displayed in the list with those in the
* <i>results</i> argument, or with the <code>results</code> attribute if an
* argument is not provided.
*
* @method _syncResults
* @param {Array} results (optional) Results.
* @protected
*/
_syncResults: function (results) {
if (!results) {
}
this._clear();
}
},
/**
* Synchronizes the visibility of the tray with the <i>visible</i> argument,
* or with the <code>visible</code> attribute if an argument is not
* provided.
*
* @method _syncVisibility
* @param {Boolean} visible (optional) Visibility.
* @protected
*/
_syncVisibility: function (visible) {
}
},
// -- Protected Event Handlers ---------------------------------------------
/**
* Handles <code>inputNode</code> <code>blur</code> events.
*
* @method _onInputBlur
* @param {EventTarget} e
* @protected
*/
_onInputBlur: function (e) {
// Hide the list on inputNode blur events, unless the mouse is currently
// over the list (which indicates that the user is probably interacting
// with it) or the tab key was pressed.
this._inputNode.focus();
} else {
this.hide();
}
},
/**
* Handles <code>inputNode</code> key events.
*
* @method _onInputKeyDown
* @param {EventTarget} e
* @protected
*/
_onInputKeyDown: function (e) {
this._lastInputKey = e.keyCode;
},
/**
* Handles <code>mouseenter</code> events.
*
* @method _afterMouseEnter
* @param {EventTarget} e
* @protected
*/
_afterMouseEnter: function () {
this._mouseOverList = true;
},
/**
* Handles <code>mouseleave</code> events.
*
* @method _afterMouseLeave
* @param {EventTarget} e
* @protected
*/
_afterMouseLeave: function () {
this._mouseOverList = false;
},
/**
* Handles <code>resultsChange</code> events.
*
* @method _afterResultsChange
* @param {EventFacade} e
* @protected
*/
_afterResultsChange: function (e) {
this._syncResults(e.newVal);
},
/**
* Handles <code>visibleChange</code> events.
*
* @method _afterVisibleChange
* @param {EventFacade} e
* @protected
*/
_afterVisibleChange: function (e) {
this._syncVisibility(!!e.newVal);
}
}, {
ATTRS: {
align: {
value: {
}
},
visible: {
value: false
}
},
});
Y.AutoCompleteList = List;
/**
* Alias for <a href="AutoCompleteList.html"><code>AutoCompleteList</code></a>.
* See that class for API docs.
*
* @class AutoComplete
*/
Y.AutoComplete = List;