PageRenderTime 272ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://struts2yuiplugin.googlecode.com/
JavaScript | 2908 lines | 1343 code | 279 blank | 1286 comment | 372 complexity | 4c9f18b74e0a2ac25136d6e9e77ad62b MD5 | raw file

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

  1. /*
  2. Copyright (c) 2009, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.net/yui/license.txt
  5. version: 2.7.0
  6. */
  7. /////////////////////////////////////////////////////////////////////////////
  8. //
  9. // YAHOO.widget.DataSource Backwards Compatibility
  10. //
  11. /////////////////////////////////////////////////////////////////////////////
  12. YAHOO.widget.DS_JSArray = YAHOO.util.LocalDataSource;
  13. YAHOO.widget.DS_JSFunction = YAHOO.util.FunctionDataSource;
  14. YAHOO.widget.DS_XHR = function(sScriptURI, aSchema, oConfigs) {
  15. var DS = new YAHOO.util.XHRDataSource(sScriptURI, oConfigs);
  16. DS._aDeprecatedSchema = aSchema;
  17. return DS;
  18. };
  19. YAHOO.widget.DS_ScriptNode = function(sScriptURI, aSchema, oConfigs) {
  20. var DS = new YAHOO.util.ScriptNodeDataSource(sScriptURI, oConfigs);
  21. DS._aDeprecatedSchema = aSchema;
  22. return DS;
  23. };
  24. YAHOO.widget.DS_XHR.TYPE_JSON = YAHOO.util.DataSourceBase.TYPE_JSON;
  25. YAHOO.widget.DS_XHR.TYPE_XML = YAHOO.util.DataSourceBase.TYPE_XML;
  26. YAHOO.widget.DS_XHR.TYPE_FLAT = YAHOO.util.DataSourceBase.TYPE_TEXT;
  27. // TODO: widget.DS_ScriptNode.scriptCallbackParam
  28. /**
  29. * The AutoComplete control provides the front-end logic for text-entry suggestion and
  30. * completion functionality.
  31. *
  32. * @module autocomplete
  33. * @requires yahoo, dom, event, datasource
  34. * @optional animation
  35. * @namespace YAHOO.widget
  36. * @title AutoComplete Widget
  37. */
  38. /****************************************************************************/
  39. /****************************************************************************/
  40. /****************************************************************************/
  41. /**
  42. * The AutoComplete class provides the customizable functionality of a plug-and-play DHTML
  43. * auto completion widget. Some key features:
  44. * <ul>
  45. * <li>Navigate with up/down arrow keys and/or mouse to pick a selection</li>
  46. * <li>The drop down container can "roll down" or "fly out" via configurable
  47. * animation</li>
  48. * <li>UI look-and-feel customizable through CSS, including container
  49. * attributes, borders, position, fonts, etc</li>
  50. * </ul>
  51. *
  52. * @class AutoComplete
  53. * @constructor
  54. * @param elInput {HTMLElement} DOM element reference of an input field.
  55. * @param elInput {String} String ID of an input field.
  56. * @param elContainer {HTMLElement} DOM element reference of an existing DIV.
  57. * @param elContainer {String} String ID of an existing DIV.
  58. * @param oDataSource {YAHOO.widget.DataSource} DataSource instance.
  59. * @param oConfigs {Object} (optional) Object literal of configuration params.
  60. */
  61. YAHOO.widget.AutoComplete = function(elInput,elContainer,oDataSource,oConfigs) {
  62. if(elInput && elContainer && oDataSource) {
  63. // Validate DataSource
  64. if(oDataSource instanceof YAHOO.util.DataSourceBase) {
  65. this.dataSource = oDataSource;
  66. }
  67. else {
  68. YAHOO.log("Could not instantiate AutoComplete due to an invalid DataSource", "error", this.toString());
  69. return;
  70. }
  71. // YAHOO.widget.DataSource schema backwards compatibility
  72. // Converted deprecated schema into supported schema
  73. // First assume key data is held in position 0 of results array
  74. this.key = 0;
  75. var schema = oDataSource.responseSchema;
  76. // An old school schema has been defined in the deprecated DataSource constructor
  77. if(oDataSource._aDeprecatedSchema) {
  78. var aDeprecatedSchema = oDataSource._aDeprecatedSchema;
  79. if(YAHOO.lang.isArray(aDeprecatedSchema)) {
  80. if((oDataSource.responseType === YAHOO.util.DataSourceBase.TYPE_JSON) ||
  81. (oDataSource.responseType === YAHOO.util.DataSourceBase.TYPE_UNKNOWN)) { // Used to default to unknown
  82. // Store the resultsList
  83. schema.resultsList = aDeprecatedSchema[0];
  84. // Store the key
  85. this.key = aDeprecatedSchema[1];
  86. // Only resultsList and key are defined, so grab all the data
  87. schema.fields = (aDeprecatedSchema.length < 3) ? null : aDeprecatedSchema.slice(1);
  88. }
  89. else if(oDataSource.responseType === YAHOO.util.DataSourceBase.TYPE_XML) {
  90. schema.resultNode = aDeprecatedSchema[0];
  91. this.key = aDeprecatedSchema[1];
  92. schema.fields = aDeprecatedSchema.slice(1);
  93. }
  94. else if(oDataSource.responseType === YAHOO.util.DataSourceBase.TYPE_TEXT) {
  95. schema.recordDelim = aDeprecatedSchema[0];
  96. schema.fieldDelim = aDeprecatedSchema[1];
  97. }
  98. oDataSource.responseSchema = schema;
  99. }
  100. }
  101. // Validate input element
  102. if(YAHOO.util.Dom.inDocument(elInput)) {
  103. if(YAHOO.lang.isString(elInput)) {
  104. this._sName = "instance" + YAHOO.widget.AutoComplete._nIndex + " " + elInput;
  105. this._elTextbox = document.getElementById(elInput);
  106. }
  107. else {
  108. this._sName = (elInput.id) ?
  109. "instance" + YAHOO.widget.AutoComplete._nIndex + " " + elInput.id:
  110. "instance" + YAHOO.widget.AutoComplete._nIndex;
  111. this._elTextbox = elInput;
  112. }
  113. YAHOO.util.Dom.addClass(this._elTextbox, "yui-ac-input");
  114. }
  115. else {
  116. YAHOO.log("Could not instantiate AutoComplete due to an invalid input element", "error", this.toString());
  117. return;
  118. }
  119. // Validate container element
  120. if(YAHOO.util.Dom.inDocument(elContainer)) {
  121. if(YAHOO.lang.isString(elContainer)) {
  122. this._elContainer = document.getElementById(elContainer);
  123. }
  124. else {
  125. this._elContainer = elContainer;
  126. }
  127. if(this._elContainer.style.display == "none") {
  128. YAHOO.log("The container may not display properly if display is set to \"none\" in CSS", "warn", this.toString());
  129. }
  130. // For skinning
  131. var elParent = this._elContainer.parentNode;
  132. var elTag = elParent.tagName.toLowerCase();
  133. if(elTag == "div") {
  134. YAHOO.util.Dom.addClass(elParent, "yui-ac");
  135. }
  136. else {
  137. YAHOO.log("Could not find the wrapper element for skinning", "warn", this.toString());
  138. }
  139. }
  140. else {
  141. YAHOO.log("Could not instantiate AutoComplete due to an invalid container element", "error", this.toString());
  142. return;
  143. }
  144. // Default applyLocalFilter setting is to enable for local sources
  145. if(this.dataSource.dataType === YAHOO.util.DataSourceBase.TYPE_LOCAL) {
  146. this.applyLocalFilter = true;
  147. }
  148. // Set any config params passed in to override defaults
  149. if(oConfigs && (oConfigs.constructor == Object)) {
  150. for(var sConfig in oConfigs) {
  151. if(sConfig) {
  152. this[sConfig] = oConfigs[sConfig];
  153. }
  154. }
  155. }
  156. // Initialization sequence
  157. this._initContainerEl();
  158. this._initProps();
  159. this._initListEl();
  160. this._initContainerHelperEls();
  161. // Set up events
  162. var oSelf = this;
  163. var elTextbox = this._elTextbox;
  164. // Dom events
  165. YAHOO.util.Event.addListener(elTextbox,"keyup",oSelf._onTextboxKeyUp,oSelf);
  166. YAHOO.util.Event.addListener(elTextbox,"keydown",oSelf._onTextboxKeyDown,oSelf);
  167. YAHOO.util.Event.addListener(elTextbox,"focus",oSelf._onTextboxFocus,oSelf);
  168. YAHOO.util.Event.addListener(elTextbox,"blur",oSelf._onTextboxBlur,oSelf);
  169. YAHOO.util.Event.addListener(elContainer,"mouseover",oSelf._onContainerMouseover,oSelf);
  170. YAHOO.util.Event.addListener(elContainer,"mouseout",oSelf._onContainerMouseout,oSelf);
  171. YAHOO.util.Event.addListener(elContainer,"click",oSelf._onContainerClick,oSelf);
  172. YAHOO.util.Event.addListener(elContainer,"scroll",oSelf._onContainerScroll,oSelf);
  173. YAHOO.util.Event.addListener(elContainer,"resize",oSelf._onContainerResize,oSelf);
  174. YAHOO.util.Event.addListener(elTextbox,"keypress",oSelf._onTextboxKeyPress,oSelf);
  175. YAHOO.util.Event.addListener(window,"unload",oSelf._onWindowUnload,oSelf);
  176. // Custom events
  177. this.textboxFocusEvent = new YAHOO.util.CustomEvent("textboxFocus", this);
  178. this.textboxKeyEvent = new YAHOO.util.CustomEvent("textboxKey", this);
  179. this.dataRequestEvent = new YAHOO.util.CustomEvent("dataRequest", this);
  180. this.dataReturnEvent = new YAHOO.util.CustomEvent("dataReturn", this);
  181. this.dataErrorEvent = new YAHOO.util.CustomEvent("dataError", this);
  182. this.containerPopulateEvent = new YAHOO.util.CustomEvent("containerPopulate", this);
  183. this.containerExpandEvent = new YAHOO.util.CustomEvent("containerExpand", this);
  184. this.typeAheadEvent = new YAHOO.util.CustomEvent("typeAhead", this);
  185. this.itemMouseOverEvent = new YAHOO.util.CustomEvent("itemMouseOver", this);
  186. this.itemMouseOutEvent = new YAHOO.util.CustomEvent("itemMouseOut", this);
  187. this.itemArrowToEvent = new YAHOO.util.CustomEvent("itemArrowTo", this);
  188. this.itemArrowFromEvent = new YAHOO.util.CustomEvent("itemArrowFrom", this);
  189. this.itemSelectEvent = new YAHOO.util.CustomEvent("itemSelect", this);
  190. this.unmatchedItemSelectEvent = new YAHOO.util.CustomEvent("unmatchedItemSelect", this);
  191. this.selectionEnforceEvent = new YAHOO.util.CustomEvent("selectionEnforce", this);
  192. this.containerCollapseEvent = new YAHOO.util.CustomEvent("containerCollapse", this);
  193. this.textboxBlurEvent = new YAHOO.util.CustomEvent("textboxBlur", this);
  194. this.textboxChangeEvent = new YAHOO.util.CustomEvent("textboxChange", this);
  195. // Finish up
  196. elTextbox.setAttribute("autocomplete","off");
  197. YAHOO.widget.AutoComplete._nIndex++;
  198. YAHOO.log("AutoComplete initialized","info",this.toString());
  199. }
  200. // Required arguments were not found
  201. else {
  202. YAHOO.log("Could not instantiate AutoComplete due invalid arguments", "error", this.toString());
  203. }
  204. };
  205. /////////////////////////////////////////////////////////////////////////////
  206. //
  207. // Public member variables
  208. //
  209. /////////////////////////////////////////////////////////////////////////////
  210. /**
  211. * The DataSource object that encapsulates the data used for auto completion.
  212. * This object should be an inherited object from YAHOO.widget.DataSource.
  213. *
  214. * @property dataSource
  215. * @type YAHOO.widget.DataSource
  216. */
  217. YAHOO.widget.AutoComplete.prototype.dataSource = null;
  218. /**
  219. * By default, results from local DataSources will pass through the filterResults
  220. * method to apply a client-side matching algorithm.
  221. *
  222. * @property applyLocalFilter
  223. * @type Boolean
  224. * @default true for local arrays and json, otherwise false
  225. */
  226. YAHOO.widget.AutoComplete.prototype.applyLocalFilter = null;
  227. /**
  228. * When applyLocalFilter is true, the local filtering algorthim can have case sensitivity
  229. * enabled.
  230. *
  231. * @property queryMatchCase
  232. * @type Boolean
  233. * @default false
  234. */
  235. YAHOO.widget.AutoComplete.prototype.queryMatchCase = false;
  236. /**
  237. * When applyLocalFilter is true, results can be locally filtered to return
  238. * matching strings that "contain" the query string rather than simply "start with"
  239. * the query string.
  240. *
  241. * @property queryMatchContains
  242. * @type Boolean
  243. * @default false
  244. */
  245. YAHOO.widget.AutoComplete.prototype.queryMatchContains = false;
  246. /**
  247. * Enables query subset matching. When the DataSource's cache is enabled and queryMatchSubset is
  248. * true, substrings of queries will return matching cached results. For
  249. * instance, if the first query is for "abc" susequent queries that start with
  250. * "abc", like "abcd", will be queried against the cache, and not the live data
  251. * source. Recommended only for DataSources that return comprehensive results
  252. * for queries with very few characters.
  253. *
  254. * @property queryMatchSubset
  255. * @type Boolean
  256. * @default false
  257. *
  258. */
  259. YAHOO.widget.AutoComplete.prototype.queryMatchSubset = false;
  260. /**
  261. * Number of characters that must be entered before querying for results. A negative value
  262. * effectively turns off the widget. A value of 0 allows queries of null or empty string
  263. * values.
  264. *
  265. * @property minQueryLength
  266. * @type Number
  267. * @default 1
  268. */
  269. YAHOO.widget.AutoComplete.prototype.minQueryLength = 1;
  270. /**
  271. * Maximum number of results to display in results container.
  272. *
  273. * @property maxResultsDisplayed
  274. * @type Number
  275. * @default 10
  276. */
  277. YAHOO.widget.AutoComplete.prototype.maxResultsDisplayed = 10;
  278. /**
  279. * Number of seconds to delay before submitting a query request. If a query
  280. * request is received before a previous one has completed its delay, the
  281. * previous request is cancelled and the new request is set to the delay. If
  282. * typeAhead is also enabled, this value must always be less than the typeAheadDelay
  283. * in order to avoid certain race conditions.
  284. *
  285. * @property queryDelay
  286. * @type Number
  287. * @default 0.2
  288. */
  289. YAHOO.widget.AutoComplete.prototype.queryDelay = 0.2;
  290. /**
  291. * If typeAhead is true, number of seconds to delay before updating input with
  292. * typeAhead value. In order to prevent certain race conditions, this value must
  293. * always be greater than the queryDelay.
  294. *
  295. * @property typeAheadDelay
  296. * @type Number
  297. * @default 0.5
  298. */
  299. YAHOO.widget.AutoComplete.prototype.typeAheadDelay = 0.5;
  300. /**
  301. * When IME usage is detected, AutoComplete will switch to querying the input
  302. * value at the given interval rather than per key event.
  303. *
  304. * @property queryInterval
  305. * @type Number
  306. * @default 500
  307. */
  308. YAHOO.widget.AutoComplete.prototype.queryInterval = 500;
  309. /**
  310. * Class name of a highlighted item within results container.
  311. *
  312. * @property highlightClassName
  313. * @type String
  314. * @default "yui-ac-highlight"
  315. */
  316. YAHOO.widget.AutoComplete.prototype.highlightClassName = "yui-ac-highlight";
  317. /**
  318. * Class name of a pre-highlighted item within results container.
  319. *
  320. * @property prehighlightClassName
  321. * @type String
  322. */
  323. YAHOO.widget.AutoComplete.prototype.prehighlightClassName = null;
  324. /**
  325. * Query delimiter. A single character separator for multiple delimited
  326. * selections. Multiple delimiter characteres may be defined as an array of
  327. * strings. A null value or empty string indicates that query results cannot
  328. * be delimited. This feature is not recommended if you need forceSelection to
  329. * be true.
  330. *
  331. * @property delimChar
  332. * @type String | String[]
  333. */
  334. YAHOO.widget.AutoComplete.prototype.delimChar = null;
  335. /**
  336. * Whether or not the first item in results container should be automatically highlighted
  337. * on expand.
  338. *
  339. * @property autoHighlight
  340. * @type Boolean
  341. * @default true
  342. */
  343. YAHOO.widget.AutoComplete.prototype.autoHighlight = true;
  344. /**
  345. * If autohighlight is enabled, whether or not the input field should be automatically updated
  346. * with the first query result as the user types, auto-selecting the substring portion
  347. * of the first result that the user has not yet typed.
  348. *
  349. * @property typeAhead
  350. * @type Boolean
  351. * @default false
  352. */
  353. YAHOO.widget.AutoComplete.prototype.typeAhead = false;
  354. /**
  355. * Whether or not to animate the expansion/collapse of the results container in the
  356. * horizontal direction.
  357. *
  358. * @property animHoriz
  359. * @type Boolean
  360. * @default false
  361. */
  362. YAHOO.widget.AutoComplete.prototype.animHoriz = false;
  363. /**
  364. * Whether or not to animate the expansion/collapse of the results container in the
  365. * vertical direction.
  366. *
  367. * @property animVert
  368. * @type Boolean
  369. * @default true
  370. */
  371. YAHOO.widget.AutoComplete.prototype.animVert = true;
  372. /**
  373. * Speed of container expand/collapse animation, in seconds..
  374. *
  375. * @property animSpeed
  376. * @type Number
  377. * @default 0.3
  378. */
  379. YAHOO.widget.AutoComplete.prototype.animSpeed = 0.3;
  380. /**
  381. * Whether or not to force the user's selection to match one of the query
  382. * results. Enabling this feature essentially transforms the input field into a
  383. * &lt;select&gt; field. This feature is not recommended with delimiter character(s)
  384. * defined.
  385. *
  386. * @property forceSelection
  387. * @type Boolean
  388. * @default false
  389. */
  390. YAHOO.widget.AutoComplete.prototype.forceSelection = false;
  391. /**
  392. * Whether or not to allow browsers to cache user-typed input in the input
  393. * field. Disabling this feature will prevent the widget from setting the
  394. * autocomplete="off" on the input field. When autocomplete="off"
  395. * and users click the back button after form submission, user-typed input can
  396. * be prefilled by the browser from its cache. This caching of user input may
  397. * not be desired for sensitive data, such as credit card numbers, in which
  398. * case, implementers should consider setting allowBrowserAutocomplete to false.
  399. *
  400. * @property allowBrowserAutocomplete
  401. * @type Boolean
  402. * @default true
  403. */
  404. YAHOO.widget.AutoComplete.prototype.allowBrowserAutocomplete = true;
  405. /**
  406. * Enabling this feature prevents the toggling of the container to a collapsed state.
  407. * Setting to true does not automatically trigger the opening of the container.
  408. * Implementers are advised to pre-load the container with an explicit "sendQuery()" call.
  409. *
  410. * @property alwaysShowContainer
  411. * @type Boolean
  412. * @default false
  413. */
  414. YAHOO.widget.AutoComplete.prototype.alwaysShowContainer = false;
  415. /**
  416. * Whether or not to use an iFrame to layer over Windows form elements in
  417. * IE. Set to true only when the results container will be on top of a
  418. * &lt;select&gt; field in IE and thus exposed to the IE z-index bug (i.e.,
  419. * 5.5 < IE < 7).
  420. *
  421. * @property useIFrame
  422. * @type Boolean
  423. * @default false
  424. */
  425. YAHOO.widget.AutoComplete.prototype.useIFrame = false;
  426. /**
  427. * Whether or not the results container should have a shadow.
  428. *
  429. * @property useShadow
  430. * @type Boolean
  431. * @default false
  432. */
  433. YAHOO.widget.AutoComplete.prototype.useShadow = false;
  434. /**
  435. * Whether or not the input field should be updated with selections.
  436. *
  437. * @property suppressInputUpdate
  438. * @type Boolean
  439. * @default false
  440. */
  441. YAHOO.widget.AutoComplete.prototype.suppressInputUpdate = false;
  442. /**
  443. * For backward compatibility to pre-2.6.0 formatResults() signatures, setting
  444. * resultsTypeList to true will take each object literal result returned by
  445. * DataSource and flatten into an array.
  446. *
  447. * @property resultTypeList
  448. * @type Boolean
  449. * @default true
  450. */
  451. YAHOO.widget.AutoComplete.prototype.resultTypeList = true;
  452. /**
  453. * For XHR DataSources, AutoComplete will automatically insert a "?" between the server URI and
  454. * the "query" param/value pair. To prevent this behavior, implementers should
  455. * set this value to false. To more fully customize the query syntax, implementers
  456. * should override the generateRequest() method.
  457. *
  458. * @property queryQuestionMark
  459. * @type Boolean
  460. * @default true
  461. */
  462. YAHOO.widget.AutoComplete.prototype.queryQuestionMark = true;
  463. /////////////////////////////////////////////////////////////////////////////
  464. //
  465. // Public methods
  466. //
  467. /////////////////////////////////////////////////////////////////////////////
  468. /**
  469. * Public accessor to the unique name of the AutoComplete instance.
  470. *
  471. * @method toString
  472. * @return {String} Unique name of the AutoComplete instance.
  473. */
  474. YAHOO.widget.AutoComplete.prototype.toString = function() {
  475. return "AutoComplete " + this._sName;
  476. };
  477. /**
  478. * Returns DOM reference to input element.
  479. *
  480. * @method getInputEl
  481. * @return {HTMLELement} DOM reference to input element.
  482. */
  483. YAHOO.widget.AutoComplete.prototype.getInputEl = function() {
  484. return this._elTextbox;
  485. };
  486. /**
  487. * Returns DOM reference to container element.
  488. *
  489. * @method getContainerEl
  490. * @return {HTMLELement} DOM reference to container element.
  491. */
  492. YAHOO.widget.AutoComplete.prototype.getContainerEl = function() {
  493. return this._elContainer;
  494. };
  495. /**
  496. * Returns true if widget instance is currently focused.
  497. *
  498. * @method isFocused
  499. * @return {Boolean} Returns true if widget instance is currently focused.
  500. */
  501. YAHOO.widget.AutoComplete.prototype.isFocused = function() {
  502. return (this._bFocused === null) ? false : this._bFocused;
  503. };
  504. /**
  505. * Returns true if container is in an expanded state, false otherwise.
  506. *
  507. * @method isContainerOpen
  508. * @return {Boolean} Returns true if container is in an expanded state, false otherwise.
  509. */
  510. YAHOO.widget.AutoComplete.prototype.isContainerOpen = function() {
  511. return this._bContainerOpen;
  512. };
  513. /**
  514. * Public accessor to the &lt;ul&gt; element that displays query results within the results container.
  515. *
  516. * @method getListEl
  517. * @return {HTMLElement[]} Reference to &lt;ul&gt; element within the results container.
  518. */
  519. YAHOO.widget.AutoComplete.prototype.getListEl = function() {
  520. return this._elList;
  521. };
  522. /**
  523. * Public accessor to the matching string associated with a given &lt;li&gt; result.
  524. *
  525. * @method getListItemMatch
  526. * @param elListItem {HTMLElement} Reference to &lt;LI&gt; element.
  527. * @return {String} Matching string.
  528. */
  529. YAHOO.widget.AutoComplete.prototype.getListItemMatch = function(elListItem) {
  530. if(elListItem._sResultMatch) {
  531. return elListItem._sResultMatch;
  532. }
  533. else {
  534. return null;
  535. }
  536. };
  537. /**
  538. * Public accessor to the result data associated with a given &lt;li&gt; result.
  539. *
  540. * @method getListItemData
  541. * @param elListItem {HTMLElement} Reference to &lt;LI&gt; element.
  542. * @return {Object} Result data.
  543. */
  544. YAHOO.widget.AutoComplete.prototype.getListItemData = function(elListItem) {
  545. if(elListItem._oResultData) {
  546. return elListItem._oResultData;
  547. }
  548. else {
  549. return null;
  550. }
  551. };
  552. /**
  553. * Public accessor to the index of the associated with a given &lt;li&gt; result.
  554. *
  555. * @method getListItemIndex
  556. * @param elListItem {HTMLElement} Reference to &lt;LI&gt; element.
  557. * @return {Number} Index.
  558. */
  559. YAHOO.widget.AutoComplete.prototype.getListItemIndex = function(elListItem) {
  560. if(YAHOO.lang.isNumber(elListItem._nItemIndex)) {
  561. return elListItem._nItemIndex;
  562. }
  563. else {
  564. return null;
  565. }
  566. };
  567. /**
  568. * Sets HTML markup for the results container header. This markup will be
  569. * inserted within a &lt;div&gt; tag with a class of "yui-ac-hd".
  570. *
  571. * @method setHeader
  572. * @param sHeader {String} HTML markup for results container header.
  573. */
  574. YAHOO.widget.AutoComplete.prototype.setHeader = function(sHeader) {
  575. if(this._elHeader) {
  576. var elHeader = this._elHeader;
  577. if(sHeader) {
  578. elHeader.innerHTML = sHeader;
  579. elHeader.style.display = "block";
  580. }
  581. else {
  582. elHeader.innerHTML = "";
  583. elHeader.style.display = "none";
  584. }
  585. }
  586. };
  587. /**
  588. * Sets HTML markup for the results container footer. This markup will be
  589. * inserted within a &lt;div&gt; tag with a class of "yui-ac-ft".
  590. *
  591. * @method setFooter
  592. * @param sFooter {String} HTML markup for results container footer.
  593. */
  594. YAHOO.widget.AutoComplete.prototype.setFooter = function(sFooter) {
  595. if(this._elFooter) {
  596. var elFooter = this._elFooter;
  597. if(sFooter) {
  598. elFooter.innerHTML = sFooter;
  599. elFooter.style.display = "block";
  600. }
  601. else {
  602. elFooter.innerHTML = "";
  603. elFooter.style.display = "none";
  604. }
  605. }
  606. };
  607. /**
  608. * Sets HTML markup for the results container body. This markup will be
  609. * inserted within a &lt;div&gt; tag with a class of "yui-ac-bd".
  610. *
  611. * @method setBody
  612. * @param sBody {String} HTML markup for results container body.
  613. */
  614. YAHOO.widget.AutoComplete.prototype.setBody = function(sBody) {
  615. if(this._elBody) {
  616. var elBody = this._elBody;
  617. YAHOO.util.Event.purgeElement(elBody, true);
  618. if(sBody) {
  619. elBody.innerHTML = sBody;
  620. elBody.style.display = "block";
  621. }
  622. else {
  623. elBody.innerHTML = "";
  624. elBody.style.display = "none";
  625. }
  626. this._elList = null;
  627. }
  628. };
  629. /**
  630. * A function that converts an AutoComplete query into a request value which is then
  631. * passed to the DataSource's sendRequest method in order to retrieve data for
  632. * the query. By default, returns a String with the syntax: "query={query}"
  633. * Implementers can customize this method for custom request syntaxes.
  634. *
  635. * @method generateRequest
  636. * @param sQuery {String} Query string
  637. * @return {MIXED} Request
  638. */
  639. YAHOO.widget.AutoComplete.prototype.generateRequest = function(sQuery) {
  640. var dataType = this.dataSource.dataType;
  641. // Transform query string in to a request for remote data
  642. // By default, local data doesn't need a transformation, just passes along the query as is.
  643. if(dataType === YAHOO.util.DataSourceBase.TYPE_XHR) {
  644. // By default, XHR GET requests look like "{scriptURI}?{scriptQueryParam}={sQuery}&{scriptQueryAppend}"
  645. if(!this.dataSource.connMethodPost) {
  646. sQuery = (this.queryQuestionMark ? "?" : "") + (this.dataSource.scriptQueryParam || "query") + "=" + sQuery +
  647. (this.dataSource.scriptQueryAppend ? ("&" + this.dataSource.scriptQueryAppend) : "");
  648. }
  649. // By default, XHR POST bodies are sent to the {scriptURI} like "{scriptQueryParam}={sQuery}&{scriptQueryAppend}"
  650. else {
  651. sQuery = (this.dataSource.scriptQueryParam || "query") + "=" + sQuery +
  652. (this.dataSource.scriptQueryAppend ? ("&" + this.dataSource.scriptQueryAppend) : "");
  653. }
  654. }
  655. // By default, remote script node requests look like "{scriptURI}&{scriptCallbackParam}={callbackString}&{scriptQueryParam}={sQuery}&{scriptQueryAppend}"
  656. else if(dataType === YAHOO.util.DataSourceBase.TYPE_SCRIPTNODE) {
  657. sQuery = "&" + (this.dataSource.scriptQueryParam || "query") + "=" + sQuery +
  658. (this.dataSource.scriptQueryAppend ? ("&" + this.dataSource.scriptQueryAppend) : "");
  659. }
  660. return sQuery;
  661. };
  662. /**
  663. * Makes query request to the DataSource.
  664. *
  665. * @method sendQuery
  666. * @param sQuery {String} Query string.
  667. */
  668. YAHOO.widget.AutoComplete.prototype.sendQuery = function(sQuery) {
  669. // Reset focus for a new interaction
  670. this._bFocused = null;
  671. // Adjust programatically sent queries to look like they were input by user
  672. // when delimiters are enabled
  673. var newQuery = (this.delimChar) ? this._elTextbox.value + sQuery : sQuery;
  674. this._sendQuery(newQuery);
  675. };
  676. /**
  677. * Collapses container.
  678. *
  679. * @method collapseContainer
  680. */
  681. YAHOO.widget.AutoComplete.prototype.collapseContainer = function() {
  682. this._toggleContainer(false);
  683. };
  684. /**
  685. * Handles subset matching for when queryMatchSubset is enabled.
  686. *
  687. * @method getSubsetMatches
  688. * @param sQuery {String} Query string.
  689. * @return {Object} oParsedResponse or null.
  690. */
  691. YAHOO.widget.AutoComplete.prototype.getSubsetMatches = function(sQuery) {
  692. var subQuery, oCachedResponse, subRequest;
  693. // Loop through substrings of each cached element's query property...
  694. for(var i = sQuery.length; i >= this.minQueryLength ; i--) {
  695. subRequest = this.generateRequest(sQuery.substr(0,i));
  696. this.dataRequestEvent.fire(this, subQuery, subRequest);
  697. YAHOO.log("Searching for query subset \"" + subQuery + "\" in cache", "info", this.toString());
  698. // If a substring of the query is found in the cache
  699. oCachedResponse = this.dataSource.getCachedResponse(subRequest);
  700. if(oCachedResponse) {
  701. YAHOO.log("Found match for query subset \"" + subQuery + "\": " + YAHOO.lang.dump(oCachedResponse), "info", this.toString());
  702. return this.filterResults.apply(this.dataSource, [sQuery, oCachedResponse, oCachedResponse, {scope:this}]);
  703. }
  704. }
  705. YAHOO.log("Did not find subset match for query subset \"" + sQuery + "\"" , "info", this.toString());
  706. return null;
  707. };
  708. /**
  709. * Executed by DataSource (within DataSource scope via doBeforeParseData()) to
  710. * handle responseStripAfter cleanup.
  711. *
  712. * @method preparseRawResponse
  713. * @param sQuery {String} Query string.
  714. * @return {Object} oParsedResponse or null.
  715. */
  716. YAHOO.widget.AutoComplete.prototype.preparseRawResponse = function(oRequest, oFullResponse, oCallback) {
  717. var nEnd = ((this.responseStripAfter !== "") && (oFullResponse.indexOf)) ?
  718. oFullResponse.indexOf(this.responseStripAfter) : -1;
  719. if(nEnd != -1) {
  720. oFullResponse = oFullResponse.substring(0,nEnd);
  721. }
  722. return oFullResponse;
  723. };
  724. /**
  725. * Executed by DataSource (within DataSource scope via doBeforeCallback()) to
  726. * filter results through a simple client-side matching algorithm.
  727. *
  728. * @method filterResults
  729. * @param sQuery {String} Original request.
  730. * @param oFullResponse {Object} Full response object.
  731. * @param oParsedResponse {Object} Parsed response object.
  732. * @param oCallback {Object} Callback object.
  733. * @return {Object} Filtered response object.
  734. */
  735. YAHOO.widget.AutoComplete.prototype.filterResults = function(sQuery, oFullResponse, oParsedResponse, oCallback) {
  736. // If AC has passed a query string value back to itself, grab it
  737. if(oCallback && oCallback.argument && oCallback.argument.query) {
  738. sQuery = oCallback.argument.query;
  739. }
  740. // Only if a query string is available to match against
  741. if(sQuery && sQuery !== "") {
  742. // First make a copy of the oParseResponse
  743. oParsedResponse = YAHOO.widget.AutoComplete._cloneObject(oParsedResponse);
  744. var oAC = oCallback.scope,
  745. oDS = this,
  746. allResults = oParsedResponse.results, // the array of results
  747. filteredResults = [], // container for filtered results
  748. bMatchFound = false,
  749. bMatchCase = (oDS.queryMatchCase || oAC.queryMatchCase), // backward compat
  750. bMatchContains = (oDS.queryMatchContains || oAC.queryMatchContains); // backward compat
  751. // Loop through each result object...
  752. for(var i = allResults.length-1; i >= 0; i--) {
  753. var oResult = allResults[i];
  754. // Grab the data to match against from the result object...
  755. var sResult = null;
  756. // Result object is a simple string already
  757. if(YAHOO.lang.isString(oResult)) {
  758. sResult = oResult;
  759. }
  760. // Result object is an array of strings
  761. else if(YAHOO.lang.isArray(oResult)) {
  762. sResult = oResult[0];
  763. }
  764. // Result object is an object literal of strings
  765. else if(this.responseSchema.fields) {
  766. var key = this.responseSchema.fields[0].key || this.responseSchema.fields[0];
  767. sResult = oResult[key];
  768. }
  769. // Backwards compatibility
  770. else if(this.key) {
  771. sResult = oResult[this.key];
  772. }
  773. if(YAHOO.lang.isString(sResult)) {
  774. var sKeyIndex = (bMatchCase) ?
  775. sResult.indexOf(decodeURIComponent(sQuery)) :
  776. sResult.toLowerCase().indexOf(decodeURIComponent(sQuery).toLowerCase());
  777. // A STARTSWITH match is when the query is found at the beginning of the key string...
  778. if((!bMatchContains && (sKeyIndex === 0)) ||
  779. // A CONTAINS match is when the query is found anywhere within the key string...
  780. (bMatchContains && (sKeyIndex > -1))) {
  781. // Stash the match
  782. filteredResults.unshift(oResult);
  783. }
  784. }
  785. }
  786. oParsedResponse.results = filteredResults;
  787. YAHOO.log("Filtered " + filteredResults.length + " results against query \"" + sQuery + "\": " + YAHOO.lang.dump(filteredResults), "info", this.toString());
  788. }
  789. else {
  790. YAHOO.log("Did not filter results against query", "info", this.toString());
  791. }
  792. return oParsedResponse;
  793. };
  794. /**
  795. * Handles response for display. This is the callback function method passed to
  796. * YAHOO.util.DataSourceBase#sendRequest so results from the DataSource are
  797. * returned to the AutoComplete instance.
  798. *
  799. * @method handleResponse
  800. * @param sQuery {String} Original request.
  801. * @param oResponse {Object} Response object.
  802. * @param oPayload {MIXED} (optional) Additional argument(s)
  803. */
  804. YAHOO.widget.AutoComplete.prototype.handleResponse = function(sQuery, oResponse, oPayload) {
  805. if((this instanceof YAHOO.widget.AutoComplete) && this._sName) {
  806. this._populateList(sQuery, oResponse, oPayload);
  807. }
  808. };
  809. /**
  810. * Overridable method called before container is loaded with result data.
  811. *
  812. * @method doBeforeLoadData
  813. * @param sQuery {String} Original request.
  814. * @param oResponse {Object} Response object.
  815. * @param oPayload {MIXED} (optional) Additional argument(s)
  816. * @return {Boolean} Return true to continue loading data, false to cancel.
  817. */
  818. YAHOO.widget.AutoComplete.prototype.doBeforeLoadData = function(sQuery, oResponse, oPayload) {
  819. return true;
  820. };
  821. /**
  822. * Overridable method that returns HTML markup for one result to be populated
  823. * as innerHTML of an &lt;LI&gt; element.
  824. *
  825. * @method formatResult
  826. * @param oResultData {Object} Result data object.
  827. * @param sQuery {String} The corresponding query string.
  828. * @param sResultMatch {HTMLElement} The current query string.
  829. * @return {String} HTML markup of formatted result data.
  830. */
  831. YAHOO.widget.AutoComplete.prototype.formatResult = function(oResultData, sQuery, sResultMatch) {
  832. var sMarkup = (sResultMatch) ? sResultMatch : "";
  833. return sMarkup;
  834. };
  835. /**
  836. * Overridable method called before container expands allows implementers to access data
  837. * and DOM elements.
  838. *
  839. * @method doBeforeExpandContainer
  840. * @param elTextbox {HTMLElement} The text input box.
  841. * @param elContainer {HTMLElement} The container element.
  842. * @param sQuery {String} The query string.
  843. * @param aResults {Object[]} An array of query results.
  844. * @return {Boolean} Return true to continue expanding container, false to cancel the expand.
  845. */
  846. YAHOO.widget.AutoComplete.prototype.doBeforeExpandContainer = function(elTextbox, elContainer, sQuery, aResults) {
  847. return true;
  848. };
  849. /**
  850. * Nulls out the entire AutoComplete instance and related objects, removes attached
  851. * event listeners, and clears out DOM elements inside the container. After
  852. * calling this method, the instance reference should be expliclitly nulled by
  853. * implementer, as in myAutoComplete = null. Use with caution!
  854. *
  855. * @method destroy
  856. */
  857. YAHOO.widget.AutoComplete.prototype.destroy = function() {
  858. var instanceName = this.toString();
  859. var elInput = this._elTextbox;
  860. var elContainer = this._elContainer;
  861. // Unhook custom events
  862. this.textboxFocusEvent.unsubscribeAll();
  863. this.textboxKeyEvent.unsubscribeAll();
  864. this.dataRequestEvent.unsubscribeAll();
  865. this.dataReturnEvent.unsubscribeAll();
  866. this.dataErrorEvent.unsubscribeAll();
  867. this.containerPopulateEvent.unsubscribeAll();
  868. this.containerExpandEvent.unsubscribeAll();
  869. this.typeAheadEvent.unsubscribeAll();
  870. this.itemMouseOverEvent.unsubscribeAll();
  871. this.itemMouseOutEvent.unsubscribeAll();
  872. this.itemArrowToEvent.unsubscribeAll();
  873. this.itemArrowFromEvent.unsubscribeAll();
  874. this.itemSelectEvent.unsubscribeAll();
  875. this.unmatchedItemSelectEvent.unsubscribeAll();
  876. this.selectionEnforceEvent.unsubscribeAll();
  877. this.containerCollapseEvent.unsubscribeAll();
  878. this.textboxBlurEvent.unsubscribeAll();
  879. this.textboxChangeEvent.unsubscribeAll();
  880. // Unhook DOM events
  881. YAHOO.util.Event.purgeElement(elInput, true);
  882. YAHOO.util.Event.purgeElement(elContainer, true);
  883. // Remove DOM elements
  884. elContainer.innerHTML = "";
  885. // Null out objects
  886. for(var key in this) {
  887. if(YAHOO.lang.hasOwnProperty(this, key)) {
  888. this[key] = null;
  889. }
  890. }
  891. YAHOO.log("AutoComplete instance destroyed: " + instanceName);
  892. };
  893. /////////////////////////////////////////////////////////////////////////////
  894. //
  895. // Public events
  896. //
  897. /////////////////////////////////////////////////////////////////////////////
  898. /**
  899. * Fired when the input field receives focus.
  900. *
  901. * @event textboxFocusEvent
  902. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  903. */
  904. YAHOO.widget.AutoComplete.prototype.textboxFocusEvent = null;
  905. /**
  906. * Fired when the input field receives key input.
  907. *
  908. * @event textboxKeyEvent
  909. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  910. * @param nKeycode {Number} The keycode number.
  911. */
  912. YAHOO.widget.AutoComplete.prototype.textboxKeyEvent = null;
  913. /**
  914. * Fired when the AutoComplete instance makes a request to the DataSource.
  915. *
  916. * @event dataRequestEvent
  917. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  918. * @param sQuery {String} The query string.
  919. * @param oRequest {Object} The request.
  920. */
  921. YAHOO.widget.AutoComplete.prototype.dataRequestEvent = null;
  922. /**
  923. * Fired when the AutoComplete instance receives query results from the data
  924. * source.
  925. *
  926. * @event dataReturnEvent
  927. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  928. * @param sQuery {String} The query string.
  929. * @param aResults {Object[]} Results array.
  930. */
  931. YAHOO.widget.AutoComplete.prototype.dataReturnEvent = null;
  932. /**
  933. * Fired when the AutoComplete instance does not receive query results from the
  934. * DataSource due to an error.
  935. *
  936. * @event dataErrorEvent
  937. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  938. * @param sQuery {String} The query string.
  939. */
  940. YAHOO.widget.AutoComplete.prototype.dataErrorEvent = null;
  941. /**
  942. * Fired when the results container is populated.
  943. *
  944. * @event containerPopulateEvent
  945. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  946. */
  947. YAHOO.widget.AutoComplete.prototype.containerPopulateEvent = null;
  948. /**
  949. * Fired when the results container is expanded.
  950. *
  951. * @event containerExpandEvent
  952. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  953. */
  954. YAHOO.widget.AutoComplete.prototype.containerExpandEvent = null;
  955. /**
  956. * Fired when the input field has been prefilled by the type-ahead
  957. * feature.
  958. *
  959. * @event typeAheadEvent
  960. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  961. * @param sQuery {String} The query string.
  962. * @param sPrefill {String} The prefill string.
  963. */
  964. YAHOO.widget.AutoComplete.prototype.typeAheadEvent = null;
  965. /**
  966. * Fired when result item has been moused over.
  967. *
  968. * @event itemMouseOverEvent
  969. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  970. * @param elItem {HTMLElement} The &lt;li&gt element item moused to.
  971. */
  972. YAHOO.widget.AutoComplete.prototype.itemMouseOverEvent = null;
  973. /**
  974. * Fired when result item has been moused out.
  975. *
  976. * @event itemMouseOutEvent
  977. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  978. * @param elItem {HTMLElement} The &lt;li&gt; element item moused from.
  979. */
  980. YAHOO.widget.AutoComplete.prototype.itemMouseOutEvent = null;
  981. /**
  982. * Fired when result item has been arrowed to.
  983. *
  984. * @event itemArrowToEvent
  985. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  986. * @param elItem {HTMLElement} The &lt;li&gt; element item arrowed to.
  987. */
  988. YAHOO.widget.AutoComplete.prototype.itemArrowToEvent = null;
  989. /**
  990. * Fired when result item has been arrowed away from.
  991. *
  992. * @event itemArrowFromEvent
  993. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  994. * @param elItem {HTMLElement} The &lt;li&gt; element item arrowed from.
  995. */
  996. YAHOO.widget.AutoComplete.prototype.itemArrowFromEvent = null;
  997. /**
  998. * Fired when an item is selected via mouse click, ENTER key, or TAB key.
  999. *
  1000. * @event itemSelectEvent
  1001. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  1002. * @param elItem {HTMLElement} The selected &lt;li&gt; element item.
  1003. * @param oData {Object} The data returned for the item, either as an object,
  1004. * or mapped from the schema into an array.
  1005. */
  1006. YAHOO.widget.AutoComplete.prototype.itemSelectEvent = null;
  1007. /**
  1008. * Fired when a user selection does not match any of the displayed result items.
  1009. *
  1010. * @event unmatchedItemSelectEvent
  1011. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  1012. * @param sSelection {String} The selected string.
  1013. */
  1014. YAHOO.widget.AutoComplete.prototype.unmatchedItemSelectEvent = null;
  1015. /**
  1016. * Fired if forceSelection is enabled and the user's input has been cleared
  1017. * because it did not match one of the returned query results.
  1018. *
  1019. * @event selectionEnforceEvent
  1020. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  1021. * @param sClearedValue {String} The cleared value (including delimiters if applicable).
  1022. */
  1023. YAHOO.widget.AutoComplete.prototype.selectionEnforceEvent = null;
  1024. /**
  1025. * Fired when the results container is collapsed.
  1026. *
  1027. * @event containerCollapseEvent
  1028. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  1029. */
  1030. YAHOO.widget.AutoComplete.prototype.containerCollapseEvent = null;
  1031. /**
  1032. * Fired when the input field loses focus.
  1033. *
  1034. * @event textboxBlurEvent
  1035. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  1036. */
  1037. YAHOO.widget.AutoComplete.prototype.textboxBlurEvent = null;
  1038. /**
  1039. * Fired when the input field value has changed when it loses focus.
  1040. *
  1041. * @event textboxChangeEvent
  1042. * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
  1043. */
  1044. YAHOO.widget.AutoComplete.prototype.textboxChangeEvent = null;
  1045. /////////////////////////////////////////////////////////////////////////////
  1046. //
  1047. // Private member variables
  1048. //
  1049. /////////////////////////////////////////////////////////////////////////////
  1050. /**
  1051. * Internal class variable to index multiple AutoComplete instances.
  1052. *
  1053. * @property _nIndex
  1054. * @type Number
  1055. * @default 0
  1056. * @private
  1057. */
  1058. YAHOO.widget.AutoComplete._nIndex = 0;
  1059. /**
  1060. * Name of AutoComplete instance.
  1061. *
  1062. * @property _sName
  1063. * @type String
  1064. * @private
  1065. */
  1066. YAHOO.widget.AutoComplete.prototype._sName = null;
  1067. /**
  1068. * Text input field DOM element.
  1069. *
  1070. * @property _elTextbox
  1071. * @type HTMLElement
  1072. * @private
  1073. */
  1074. YAHOO.widget.AutoComplete.prototype._elTextbox = null;
  1075. /**
  1076. * Container DOM element.
  1077. *
  1078. * @property _elContainer
  1079. * @type HTMLElement
  1080. * @private
  1081. */
  1082. YAHOO.widget.AutoComplete.prototype._elContainer = null;
  1083. /**
  1084. * Reference to content element within container element.
  1085. *
  1086. * @property _elContent
  1087. * @type HTMLElement
  1088. * @private
  1089. */
  1090. YAHOO.widget.AutoComplete.prototype._elContent = null;
  1091. /**
  1092. * Reference to header element within content element.
  1093. *
  1094. * @property _elHeader
  1095. * @type HTMLElement
  1096. * @private
  1097. */
  1098. YAHOO.widget.AutoComplete.prototype._elHeader = null;
  1099. /**
  1100. * Reference to body element within content element.
  1101. *
  1102. * @property _elBody
  1103. * @type HTMLElement
  1104. * @private
  1105. */
  1106. YAHOO.widget.AutoComplete.prototype._elBody = null;
  1107. /**
  1108. * Reference to footer element within content element.
  1109. *
  1110. * @property _elFooter
  1111. * @type HTMLElement
  1112. * @private
  1113. */
  1114. YAHOO.widget.AutoComplete.prototype._elFooter = null;
  1115. /**
  1116. * Reference to shadow element within container element.
  1117. *
  1118. * @property _elShadow
  1119. * @type HTMLElement
  1120. * @private
  1121. */
  1122. YAHOO.widget.AutoComplete.prototype._elShadow = null;
  1123. /**
  1124. * Reference to iframe element within container element.
  1125. *
  1126. * @property _elIFrame
  1127. * @type HTMLElement
  1128. * @private
  1129. */
  1130. YAHOO.widget.AutoComplete.prototype._elIFrame = null;
  1131. /**
  1132. * Whether or not the input field is currently in focus. If query results come back
  1133. * but the user has already moved on, do not proceed with auto complete behavior.
  1134. *
  1135. * @property _bFocused
  1136. * @type Boolean
  1137. * @private
  1138. */
  1139. YAHOO.widget.AutoComplete.prototype._bFocused = null;
  1140. /**
  1141. * Animation instance for container expand/collapse.
  1142. *
  1143. * @property _oAnim
  1144. * @type Boolean
  1145. * @private
  1146. */
  1147. YAHOO.widget.AutoComplete.prototype._oAnim = null;
  1148. /**
  1149. * Whether or not the results container is currently open.
  1150. *
  1151. * @property _bContainerOpen
  1152. * @type Boolean
  1153. * @private
  1154. */
  1155. YAHOO.widget.AutoComplete.prototype._bContainerOpen = false;
  1156. /**
  1157. * Whether or not the mouse is currently over the results
  1158. * container. This is necessary in order to prevent clicks on container items
  1159. * from being text input field blur events.
  1160. *
  1161. * @property _bOverContainer
  1162. * @type Boolean
  1163. * @private
  1164. */
  1165. YAHOO.widget.AutoComplete.prototype._bOverContainer = false;
  1166. /**
  1167. * Internal reference to &lt;ul&gt; elements that contains query results within the
  1168. * results container.
  1169. *
  1170. * @property _elList
  1171. * @type HTMLElement
  1172. * @private
  1173. */
  1174. YAHOO.widget.AutoComplete.prototype._elList = null;
  1175. /*
  1176. * Array of &lt;li&gt; elements references that contain query results within the
  1177. * results container.
  1178. *
  1179. * @property _aListItemEls
  1180. * @type HTMLElement[]
  1181. * @private
  1182. */
  1183. //YAHOO.widget.AutoComplete.prototype._aListItemEls = null;
  1184. /**
  1185. * Number of &lt;li&gt; elements currently displayed in results container.
  1186. *
  1187. * @property _nDisplayedItems
  1188. * @type Number
  1189. * @private
  1190. */
  1191. YAHOO.widget.AutoComplete.prototype._nDisplayedItems = 0;
  1192. /*
  1193. * Internal count of &lt;li&gt; elements displayed and hidden in results container.
  1194. *
  1195. * @property _maxResultsDisplayed
  1196. * @type Number
  1197. * @private
  1198. */
  1199. //YAHOO.widget.AutoComplete.prototype._maxResultsDisplayed = 0;
  1200. /**
  1201. * Current query string
  1202. *
  1203. * @property _sCurQuery
  1204. * @type String
  1205. * @private
  1206. */
  1207. YAHOO.widget.AutoComplete.prototype._sCurQuery = null;
  1208. /**
  1209. * Selections from previous queries (for saving delimited queries).
  1210. *
  1211. * @property _sPastSelections
  1212. * @type String
  1213. * @default ""
  1214. * @private
  1215. */
  1216. YAHOO.widget.AutoComplete.prototype._sPastSelections = "";
  1217. /**
  1218. * Stores initial input value used to determine if textboxChangeEvent should be fired.
  1219. *
  1220. * @property _sInitInputValue
  1221. * @type String
  1222. * @private
  1223. */
  1224. YAHOO.widget.AutoComplete.prototype._sInitInputValue = null;
  1225. /**
  1226. * Pointer to the currently highlighted &lt;li&gt; element in the container.
  1227. *
  1228. * @property _elCurListItem
  1229. * @type HTMLElement
  1230. * @private
  1231. */
  1232. YAHOO.widget.AutoComplete.prototype._elCurListItem = null;
  1233. /**
  1234. * Whether or not an item has been selected since the container was populated
  1235. * with results. Reset to false by _populateList, and set to true when item is
  1236. * selected.
  1237. *
  1238. * @property _bItemSelected
  1239. * @type Boolean
  1240. * @private
  1241. */
  1242. YAHOO.widget.AutoComplete.prototype._bItemSelected = false;
  1243. /**
  1244. * Key code of the last key pressed in textbox.
  1245. *
  1246. * @property _nKeyCode
  1247. * @type Number
  1248. * @private
  1249. */
  1250. YAHOO.widget.AutoComplete.prototype._nKeyCode = null;
  1251. /**
  1252. * Delay timeout ID.
  1253. *
  1254. * @property _nDelayID
  1255. * @type Number
  1256. * @private
  1257. */
  1258. YAHOO.widget.AutoComplete.prototype._nDelayID = -1;
  1259. /**
  1260. * TypeAhead delay timeout ID.
  1261. *
  1262. * @property _nTypeAheadDelayID
  1263. * @type Number
  1264. * @private
  1265. */
  1266. YAHOO.widget.AutoComplete.prototype._nTypeAheadDelayID = -1;
  1267. /**
  1268. * Src to iFrame used when useIFrame = true. Supports implementations over SSL
  1269. * as well.
  1270. *
  1271. * @property _iFrameSrc
  1272. * @type String
  1273. * @private
  1274. */
  1275. YAHOO.widget.AutoComplete.prototype._iFrameSrc = "javascript:false;";
  1276. /**
  1277. * For users typing via certain IMEs, queries must be triggered by intervals,
  1278. * since key events yet supported across all browsers for all IMEs.
  1279. *
  1280. * @property _queryInterval
  1281. * @type Object
  1282. * @private
  1283. */
  1284. YAHOO.widget.AutoComplete.prototype._queryInterval = null;
  1285. /**
  1286. * Internal tracker to last known textbox value, used to determine whether or not
  1287. * to trigger a query via interval for certain IME users.
  1288. *
  1289. * @event _sLastTextboxValue
  1290. * @type String
  1291. * @private
  1292. */
  1293. YAHOO.widget.AutoComplete.prototype._sLastTextboxValue = null;
  1294. /////////////////////////////////////////////////////////////////////////////
  1295. //
  1296. // Private methods
  1297. //
  1298. /////////////////////////////////////////////////////////////////////////////
  1299. /**
  1300. * Updates and validates latest public config properties.
  1301. *
  1302. * @method __initProps
  1303. * @private
  1304. */
  1305. YAHOO.widget.AutoComplete.prototype._initProps = function() {
  1306. // Correct any invalid values
  1307. var minQueryLength = this.minQueryLength;
  1308. if(!YAHOO.lang.isNumber(minQueryLength)) {
  1309. this.minQueryLength = 1;
  1310. }
  1311. var maxResultsDisplayed = this.maxResultsDisplayed;
  1312. if(!YAHOO.lang.isNumber(maxResultsDisplayed) || (maxResultsDisplayed < 1)) {
  1313. this.maxResultsDisplayed = 10;
  1314. }
  1315. var queryDelay = this.queryDelay;
  1316. if(!YAHOO.lang.isNumber(queryDelay) || (queryDelay < 0)) {
  1317. this.queryDelay = 0.2;
  1318. }
  1319. var typeAheadDelay = this.typeAheadDelay;
  1320. if(!YAHOO.lang.isNumber(typeAheadDelay) || (typeAheadDelay < 0)) {
  1321. this.typeAheadDelay = 0.2;
  1322. }
  1323. var delimChar = this.delimChar;
  1324. if(YAHOO.lang.isString(delimChar) && (delimChar.length > 0)) {
  1325. this.delimChar = [delimChar];
  1326. }
  1327. else if(!YAHOO.lang.isArray(delimChar)) {
  1328. this.delimChar = null;
  1329. }
  1330. var animSpeed = this.animSpeed;
  1331. if((this.animHoriz || this.animVert) && YAHOO.util.Anim) {
  1332. if(!YAHOO.lang.isNumber(animSpeed) || (animSpeed < 0)) {
  1333. this.animSpeed = 0.3;
  1334. }
  1335. if(!this._oAnim ) {
  1336. this._oAnim = new YAHOO.util.Anim(this._elContent, {}, this.animSpeed);
  1337. }
  1338. else {
  1339. this._oAnim.duration = this.animSpeed;
  1340. }
  1341. }
  1342. if(this.forceSelection && delimChar) {
  1343. YAHOO.log("The forceSelection feature has been enabled with delimChar defined.","warn", this.toString());
  1344. }
  1345. };
  1346. /**
  1347. * Initializes the results container helpers if they are enabled and do
  1348. * not exist
  1349. *
  1350. * @method _initContainerHelperEls
  1351. * @private
  1352. */
  1353. YAHOO.widget.AutoComplete.prototype._initContainerHelperEls = function() {
  1354. if(this.useShadow && !this._elShadow) {
  1355. var elShadow = document.createElement("div");
  1356. elShadow.className = "yui-ac-shadow";
  1357. elShadow.style.width = 0;
  1358. elShadow.style.height = 0;
  1359. this._elShadow = this._elContainer.appendChild(elShadow);
  1360. }
  1361. if(this.useIFrame && !this._elIFrame) {
  1362. var elIFrame = document.createElement("iframe");
  1363. elIFrame.src = this._iFrameSrc;
  1364. elIFrame.fra

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