suggest.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. // This file contains javascript associated with a autosuggest control
  2. function smc_AutoSuggest(oOptions)
  3. {
  4. this.opt = oOptions;
  5. // Store the handle to the text box.
  6. this.oTextHandle = document.getElementById(this.opt.sControlId);
  7. this.oRealTextHandle = null;
  8. this.oSuggestDivHandle = null;
  9. this.sLastSearch = '';
  10. this.sLastDirtySearch = '';
  11. this.oSelectedDiv = null;
  12. this.aCache = [];
  13. this.aDisplayData = [];
  14. this.sRetrieveURL = 'sRetrieveURL' in this.opt ? this.opt.sRetrieveURL : '%scripturl%action=suggest;suggest_type=%suggest_type%;search=%search%;%sessionVar%=%sessionID%;xml;time=%time%';
  15. // How many objects can we show at once?
  16. this.iMaxDisplayQuantity = 'iMaxDisplayQuantity' in this.opt ? this.opt.iMaxDisplayQuantity : 15;
  17. // How many characters shall we start searching on?
  18. this.iMinimumSearchChars = 'iMinimumSearchChars' in this.opt ? this.opt.iMinimumSearchChars : 3;
  19. // Should selected items be added to a list?
  20. this.bItemList = 'bItemList' in this.opt ? this.opt.bItemList : false;
  21. // Are there any items that should be added in advance?
  22. this.aListItems = 'aListItems' in this.opt ? this.opt.aListItems : [];
  23. this.sItemTemplate = 'sItemTemplate' in this.opt ? this.opt.sItemTemplate : '<input type="hidden" name="%post_name%[]" value="%item_id%"><a href="%item_href%" class="extern" onclick="window.open(this.href, \'_blank\'); return false;">%item_name%</a>&nbsp;<span class="generic_icons del_small" title="%delete_text%" onclick="return %self%.deleteAddedItem(%item_id%);"></span>';
  24. this.sTextDeleteItem = 'sTextDeleteItem' in this.opt ? this.opt.sTextDeleteItem : '';
  25. this.oCallback = {};
  26. this.bDoAutoAdd = false;
  27. this.iItemCount = 0;
  28. this.oHideTimer = null;
  29. this.bPositionComplete = false;
  30. // Just make sure the page is loaded before calling the init.
  31. addLoadEvent(this.opt.sSelf + '.init();');
  32. }
  33. smc_AutoSuggest.prototype.init = function()
  34. {
  35. if (!window.XMLHttpRequest)
  36. return false;
  37. // Create a div that'll contain the results later on.
  38. this.oSuggestDivHandle = document.createElement('div');
  39. this.oSuggestDivHandle.className = 'auto_suggest_div';
  40. document.body.appendChild(this.oSuggestDivHandle);
  41. // Create a backup text input.
  42. this.oRealTextHandle = document.createElement('input');
  43. this.oRealTextHandle.type = 'hidden';
  44. this.oRealTextHandle.name = this.oTextHandle.name;
  45. this.oRealTextHandle.value = this.oTextHandle.value;
  46. this.oTextHandle.form.appendChild(this.oRealTextHandle);
  47. // Disable autocomplete in any browser by obfuscating the name.
  48. this.oTextHandle.name = 'dummy_' + Math.floor(Math.random() * 1000000);
  49. this.oTextHandle.autocomplete = 'off';
  50. this.oTextHandle.instanceRef = this;
  51. var fOnKeyDown = function (oEvent) {
  52. return this.instanceRef.handleKey(oEvent);
  53. };
  54. is_opera ? this.oTextHandle.onkeypress = fOnKeyDown : this.oTextHandle.onkeydown = fOnKeyDown;
  55. this.oTextHandle.onkeyup = function (oEvent) {
  56. return this.instanceRef.autoSuggestUpdate(oEvent);
  57. };
  58. this.oTextHandle.onchange = function (oEvent) {
  59. return this.instanceRef.autoSuggestUpdate(oEvent);
  60. };
  61. this.oTextHandle.onblur = function (oEvent) {
  62. return this.instanceRef.autoSuggestHide(oEvent);
  63. };
  64. this.oTextHandle.onfocus = function (oEvent) {
  65. return this.instanceRef.autoSuggestUpdate(oEvent);
  66. };
  67. if (this.bItemList)
  68. {
  69. if ('sItemListContainerId' in this.opt)
  70. this.oItemList = document.getElementById(this.opt.sItemListContainerId);
  71. else
  72. {
  73. this.oItemList = document.createElement('div');
  74. this.oTextHandle.parentNode.insertBefore(this.oItemList, this.oTextHandle.nextSibling);
  75. }
  76. }
  77. if (this.aListItems.length > 0)
  78. for (var i = 0, n = this.aListItems.length; i < n; i++)
  79. this.addItemLink(this.aListItems[i].sItemId, this.aListItems[i].sItemName);
  80. return true;
  81. }
  82. // Was it an enter key - if so assume they are trying to select something.
  83. smc_AutoSuggest.prototype.handleKey = function(oEvent)
  84. {
  85. // Grab the event object, one way or the other
  86. if (!oEvent)
  87. oEvent = window.event;
  88. // Get the keycode of the key that was pressed.
  89. var iKeyPress = 0;
  90. if ('keyCode' in oEvent)
  91. iKeyPress = oEvent.keyCode;
  92. else if ('which' in oEvent)
  93. iKeyPress = oEvent.which;
  94. switch (iKeyPress)
  95. {
  96. // Tab.
  97. case 9:
  98. if (this.aDisplayData.length > 0)
  99. {
  100. if (this.oSelectedDiv != null)
  101. this.itemClicked(this.oSelectedDiv);
  102. else
  103. this.handleSubmit();
  104. }
  105. // Continue to the next control.
  106. return true;
  107. break;
  108. // Enter.
  109. case 13:
  110. if (this.aDisplayData.length > 0 && this.oSelectedDiv != null)
  111. {
  112. this.itemClicked(this.oSelectedDiv);
  113. // Do our best to stop it submitting the form!
  114. return false;
  115. }
  116. else
  117. return true;
  118. break;
  119. // Up/Down arrow?
  120. case 38:
  121. case 40:
  122. if (this.aDisplayData.length && this.oSuggestDivHandle.style.visibility != 'hidden')
  123. {
  124. // Loop through the display data trying to find our entry.
  125. var bPrevHandle = false;
  126. var oToHighlight = null;
  127. for (var i = 0; i < this.aDisplayData.length; i++)
  128. {
  129. // If we're going up and yet the top one was already selected don't go around.
  130. if (this.oSelectedDiv != null && this.oSelectedDiv == this.aDisplayData[i] && i == 0 && iKeyPress == 38)
  131. {
  132. oToHighlight = this.oSelectedDiv;
  133. break;
  134. }
  135. // If nothing is selected and we are going down then we select the first one.
  136. if (this.oSelectedDiv == null && iKeyPress == 40)
  137. {
  138. oToHighlight = this.aDisplayData[i];
  139. break;
  140. }
  141. // If the previous handle was the actual previously selected one and we're hitting down then this is the one we want.
  142. if (bPrevHandle != false && bPrevHandle == this.oSelectedDiv && iKeyPress == 40)
  143. {
  144. oToHighlight = this.aDisplayData[i];
  145. break;
  146. }
  147. // If we're going up and this is the previously selected one then we want the one before, if there was one.
  148. if (bPrevHandle != false && this.aDisplayData[i] == this.oSelectedDiv && iKeyPress == 38)
  149. {
  150. oToHighlight = bPrevHandle;
  151. break;
  152. }
  153. // Make the previous handle this!
  154. bPrevHandle = this.aDisplayData[i];
  155. }
  156. // If we don't have one to highlight by now then it must be the last one that we're after.
  157. if (oToHighlight == null)
  158. oToHighlight = bPrevHandle;
  159. // Remove any old highlighting.
  160. if (this.oSelectedDiv != null)
  161. this.itemMouseOut(this.oSelectedDiv);
  162. // Mark what the selected div now is.
  163. this.oSelectedDiv = oToHighlight;
  164. this.itemMouseOver(this.oSelectedDiv);
  165. }
  166. break;
  167. }
  168. return true;
  169. }
  170. // Functions for integration.
  171. smc_AutoSuggest.prototype.registerCallback = function(sCallbackType, sCallback)
  172. {
  173. switch (sCallbackType)
  174. {
  175. case 'onBeforeAddItem':
  176. this.oCallback.onBeforeAddItem = sCallback;
  177. break;
  178. case 'onAfterAddItem':
  179. this.oCallback.onAfterAddItem = sCallback;
  180. break;
  181. case 'onAfterDeleteItem':
  182. this.oCallback.onAfterDeleteItem = sCallback;
  183. break;
  184. case 'onBeforeUpdate':
  185. this.oCallback.onBeforeUpdate = sCallback;
  186. break;
  187. }
  188. }
  189. // User hit submit?
  190. smc_AutoSuggest.prototype.handleSubmit = function()
  191. {
  192. var bReturnValue = true;
  193. var oFoundEntry = null;
  194. // Do we have something that matches the current text?
  195. for (var i = 0; i < this.aCache.length; i++)
  196. {
  197. if (this.sLastSearch.toLowerCase() == this.aCache[i].sItemName.toLowerCase().substr(0, this.sLastSearch.length))
  198. {
  199. // Exact match?
  200. if (this.sLastSearch.length == this.aCache[i].sItemName.length)
  201. {
  202. // This is the one!
  203. oFoundEntry = {
  204. sItemId: this.aCache[i].sItemId,
  205. sItemName: this.aCache[i].sItemName
  206. };
  207. break;
  208. }
  209. // Not an exact match, but it'll do for now.
  210. else
  211. {
  212. // If we have two matches don't find anything.
  213. if (oFoundEntry != null)
  214. bReturnValue = false;
  215. else
  216. oFoundEntry = {
  217. sItemId: this.aCache[i].sItemId,
  218. sItemName: this.aCache[i].sItemName
  219. };
  220. }
  221. }
  222. }
  223. if (oFoundEntry == null || bReturnValue == false)
  224. return bReturnValue;
  225. else
  226. {
  227. this.addItemLink(oFoundEntry.sItemId, oFoundEntry.sItemName, true);
  228. return false;
  229. }
  230. }
  231. // Positions the box correctly on the window.
  232. smc_AutoSuggest.prototype.positionDiv = function()
  233. {
  234. // Only do it once.
  235. if (this.bPositionComplete)
  236. return true;
  237. this.bPositionComplete = true;
  238. // Put the div under the text box.
  239. var aParentPos = smf_itemPos(this.oTextHandle);
  240. this.oSuggestDivHandle.style.left = aParentPos[0] + 'px';
  241. this.oSuggestDivHandle.style.top = (aParentPos[1] + this.oTextHandle.offsetHeight) + 'px';
  242. this.oSuggestDivHandle.style.width = this.oTextHandle.style.width;
  243. return true;
  244. }
  245. // Do something after clicking an item.
  246. smc_AutoSuggest.prototype.itemClicked = function(oCurElement)
  247. {
  248. // Is there a div that we are populating?
  249. if (this.bItemList)
  250. this.addItemLink(oCurElement.sItemId, oCurElement.innerHTML);
  251. // Otherwise clear things down.
  252. else
  253. this.oTextHandle.value = oCurElement.innerHTML.php_unhtmlspecialchars();
  254. this.oRealTextHandle.value = this.oTextHandle.value;
  255. this.autoSuggestActualHide();
  256. this.oSelectedDiv = null;
  257. }
  258. // Remove the last searched for name from the search box.
  259. smc_AutoSuggest.prototype.removeLastSearchString = function ()
  260. {
  261. // Remove the text we searched for from the div.
  262. var sTempText = this.oTextHandle.value.toLowerCase();
  263. var iStartString = sTempText.indexOf(this.sLastSearch.toLowerCase());
  264. // Just attempt to remove the bits we just searched for.
  265. if (iStartString != -1)
  266. {
  267. while (iStartString > 0)
  268. {
  269. if (sTempText.charAt(iStartString - 1) == '"' || sTempText.charAt(iStartString - 1) == ',' || sTempText.charAt(iStartString - 1) == ' ')
  270. {
  271. iStartString--;
  272. if (sTempText.charAt(iStartString - 1) == ',')
  273. break;
  274. }
  275. else
  276. break;
  277. }
  278. // Now remove anything from iStartString upwards.
  279. this.oTextHandle.value = this.oTextHandle.value.substr(0, iStartString);
  280. }
  281. // Just take it all.
  282. else
  283. this.oTextHandle.value = '';
  284. }
  285. // Add a result if not already done.
  286. smc_AutoSuggest.prototype.addItemLink = function (sItemId, sItemName, bFromSubmit)
  287. {
  288. // Increase the internal item count.
  289. this.iItemCount ++;
  290. // If there's a callback then call it.
  291. if ('oCallback' in this && 'onBeforeAddItem' in this.oCallback && typeof(this.oCallback.onBeforeAddItem) == 'string')
  292. {
  293. // If it returns false the item must not be added.
  294. if (!eval(this.oCallback.onBeforeAddItem + '(' + this.opt.sSelf + ', \'' + sItemId + '\');'))
  295. return;
  296. }
  297. var oNewDiv = document.createElement('div');
  298. oNewDiv.id = 'suggest_' + this.opt.sSuggestId + '_' + sItemId;
  299. setInnerHTML(oNewDiv, this.sItemTemplate.replace(/%post_name%/g, this.opt.sPostName).replace(/%item_id%/g, sItemId).replace(/%item_href%/g, smf_prepareScriptUrl(smf_scripturl) + this.opt.sURLMask.replace(/%item_id%/g, sItemId)).replace(/%item_name%/g, sItemName).replace(/%images_url%/g, smf_images_url).replace(/%self%/g, this.opt.sSelf).replace(/%delete_text%/g, this.sTextDeleteItem));
  300. this.oItemList.appendChild(oNewDiv);
  301. // If there's a registered callback, call it.
  302. if ('oCallback' in this && 'onAfterAddItem' in this.oCallback && typeof(this.oCallback.onAfterAddItem) == 'string')
  303. eval(this.oCallback.onAfterAddItem + '(' + this.opt.sSelf + ', \'' + oNewDiv.id + '\', ' + this.iItemCount + ');');
  304. // Clear the div a bit.
  305. this.removeLastSearchString();
  306. // If we came from a submit, and there's still more to go, turn on auto add for all the other things.
  307. this.bDoAutoAdd = this.oTextHandle.value != '' && bFromSubmit;
  308. // Update the fellow..
  309. this.autoSuggestUpdate();
  310. }
  311. // Delete an item that has been added, if at all?
  312. smc_AutoSuggest.prototype.deleteAddedItem = function (sItemId)
  313. {
  314. var oDiv = document.getElementById('suggest_' + this.opt.sSuggestId + '_' + sItemId);
  315. // Remove the div if it exists.
  316. if (typeof(oDiv) == 'object' && oDiv != null)
  317. {
  318. oDiv.parentNode.removeChild(document.getElementById('suggest_' + this.opt.sSuggestId + '_' + sItemId));
  319. // Decrease the internal item count.
  320. this.iItemCount --;
  321. // If there's a registered callback, call it.
  322. if ('oCallback' in this && 'onAfterDeleteItem' in this.oCallback && typeof(this.oCallback.onAfterDeleteItem) == 'string')
  323. eval(this.oCallback.onAfterDeleteItem + '(' + this.opt.sSelf + ', ' + this.iItemCount + ');');
  324. }
  325. return false;
  326. }
  327. // Hide the box.
  328. smc_AutoSuggest.prototype.autoSuggestHide = function ()
  329. {
  330. // Delay to allow events to propogate through....
  331. this.oHideTimer = setTimeout(this.opt.sSelf + '.autoSuggestActualHide();', 250);
  332. }
  333. // Do the actual hiding after a timeout.
  334. smc_AutoSuggest.prototype.autoSuggestActualHide = function()
  335. {
  336. this.oSuggestDivHandle.style.display = 'none';
  337. this.oSuggestDivHandle.style.visibility = 'hidden';
  338. this.oSelectedDiv = null;
  339. }
  340. // Show the box.
  341. smc_AutoSuggest.prototype.autoSuggestShow = function()
  342. {
  343. if (this.oHideTimer)
  344. {
  345. clearTimeout(this.oHideTimer);
  346. this.oHideTimer = false;
  347. }
  348. this.positionDiv();
  349. this.oSuggestDivHandle.style.visibility = 'visible';
  350. this.oSuggestDivHandle.style.display = '';
  351. }
  352. // Populate the actual div.
  353. smc_AutoSuggest.prototype.populateDiv = function(aResults)
  354. {
  355. // Cannot have any children yet.
  356. while (this.oSuggestDivHandle.childNodes.length > 0)
  357. {
  358. // Tidy up the events etc too.
  359. this.oSuggestDivHandle.childNodes[0].onmouseover = null;
  360. this.oSuggestDivHandle.childNodes[0].onmouseout = null;
  361. this.oSuggestDivHandle.childNodes[0].onclick = null;
  362. this.oSuggestDivHandle.removeChild(this.oSuggestDivHandle.childNodes[0]);
  363. }
  364. // Something to display?
  365. if (typeof(aResults) == 'undefined')
  366. {
  367. this.aDisplayData = [];
  368. return false;
  369. }
  370. var aNewDisplayData = [];
  371. for (var i = 0; i < (aResults.length > this.iMaxDisplayQuantity ? this.iMaxDisplayQuantity : aResults.length); i++)
  372. {
  373. // Create the sub element
  374. var oNewDivHandle = document.createElement('div');
  375. oNewDivHandle.sItemId = aResults[i].sItemId;
  376. oNewDivHandle.className = 'auto_suggest_item';
  377. oNewDivHandle.innerHTML = aResults[i].sItemName;
  378. //oNewDivHandle.style.width = this.oTextHandle.style.width;
  379. this.oSuggestDivHandle.appendChild(oNewDivHandle);
  380. // Attach some events to it so we can do stuff.
  381. oNewDivHandle.instanceRef = this;
  382. oNewDivHandle.onmouseover = function (oEvent)
  383. {
  384. this.instanceRef.itemMouseOver(this);
  385. }
  386. oNewDivHandle.onmouseout = function (oEvent)
  387. {
  388. this.instanceRef.itemMouseOut(this);
  389. }
  390. oNewDivHandle.onclick = function (oEvent)
  391. {
  392. this.instanceRef.itemClicked(this);
  393. }
  394. aNewDisplayData[i] = oNewDivHandle;
  395. }
  396. this.aDisplayData = aNewDisplayData;
  397. return true;
  398. }
  399. // Refocus the element.
  400. smc_AutoSuggest.prototype.itemMouseOver = function (oCurElement)
  401. {
  402. this.oSelectedDiv = oCurElement;
  403. oCurElement.className = 'auto_suggest_item_hover';
  404. }
  405. // Onfocus the element
  406. smc_AutoSuggest.prototype.itemMouseOut = function (oCurElement)
  407. {
  408. oCurElement.className = 'auto_suggest_item';
  409. }
  410. smc_AutoSuggest.prototype.onSuggestionReceived = function (oXMLDoc)
  411. {
  412. var sQuoteText = '';
  413. var aItems = oXMLDoc.getElementsByTagName('item');
  414. this.aCache = [];
  415. for (var i = 0; i < aItems.length; i++)
  416. {
  417. this.aCache[i] = {
  418. sItemId: aItems[i].getAttribute('id'),
  419. sItemName: aItems[i].childNodes[0].nodeValue
  420. };
  421. // If we're doing auto add and we find the exact person, then add them!
  422. if (this.bDoAutoAdd && this.sLastSearch == this.aCache[i].sItemName)
  423. {
  424. var oReturnValue = {
  425. sItemId: this.aCache[i].sItemId,
  426. sItemName: this.aCache[i].sItemName
  427. };
  428. this.aCache = [];
  429. return this.addItemLink(oReturnValue.sItemId, oReturnValue.sItemName, true);
  430. }
  431. }
  432. // Check we don't try to keep auto updating!
  433. this.bDoAutoAdd = false;
  434. // Populate the div.
  435. this.populateDiv(this.aCache);
  436. // Make sure we can see it - if we can.
  437. if (aItems.length == 0)
  438. this.autoSuggestHide();
  439. else
  440. this.autoSuggestShow();
  441. return true;
  442. }
  443. // Get a new suggestion.
  444. smc_AutoSuggest.prototype.autoSuggestUpdate = function ()
  445. {
  446. // If there's a callback then call it.
  447. if ('onBeforeUpdate' in this.oCallback && typeof(this.oCallback.onBeforeUpdate) == 'string')
  448. {
  449. // If it returns false the item must not be added.
  450. if (!eval(this.oCallback.onBeforeUpdate + '(' + this.opt.sSelf + ');'))
  451. return false;
  452. }
  453. this.oRealTextHandle.value = this.oTextHandle.value;
  454. if (isEmptyText(this.oTextHandle))
  455. {
  456. this.aCache = [];
  457. this.populateDiv();
  458. this.autoSuggestHide();
  459. return true;
  460. }
  461. // Nothing changed?
  462. if (this.oTextHandle.value == this.sLastDirtySearch)
  463. return true;
  464. this.sLastDirtySearch = this.oTextHandle.value;
  465. // We're only actually interested in the last string.
  466. var sSearchString = this.oTextHandle.value.replace(/^("[^"]+",[ ]*)+/, '').replace(/^([^,]+,[ ]*)+/, '');
  467. if (sSearchString.substr(0, 1) == '"')
  468. sSearchString = sSearchString.substr(1);
  469. // Stop replication ASAP.
  470. var sRealLastSearch = this.sLastSearch;
  471. this.sLastSearch = sSearchString;
  472. // Either nothing or we've completed a sentance.
  473. if (sSearchString == '' || sSearchString.substr(sSearchString.length - 1) == '"')
  474. {
  475. this.populateDiv();
  476. return true;
  477. }
  478. // Nothing?
  479. if (sRealLastSearch == sSearchString)
  480. return true;
  481. // Too small?
  482. else if (sSearchString.length < this.iMinimumSearchChars)
  483. {
  484. this.aCache = [];
  485. this.autoSuggestHide();
  486. return true;
  487. }
  488. else if (sSearchString.substr(0, sRealLastSearch.length) == sRealLastSearch)
  489. {
  490. // Instead of hitting the server again, just narrow down the results...
  491. var aNewCache = [];
  492. var j = 0;
  493. var sLowercaseSearch = sSearchString.toLowerCase();
  494. for (var k = 0; k < this.aCache.length; k++)
  495. {
  496. if (this.aCache[k].sItemName.substr(0, sSearchString.length).toLowerCase() == sLowercaseSearch)
  497. aNewCache[j++] = this.aCache[k];
  498. }
  499. this.aCache = [];
  500. if (aNewCache.length != 0)
  501. {
  502. this.aCache = aNewCache;
  503. // Repopulate.
  504. this.populateDiv(this.aCache);
  505. // Check it can be seen.
  506. this.autoSuggestShow();
  507. return true;
  508. }
  509. }
  510. // Clean the text handle.
  511. sSearchString = sSearchString.php_to8bit().php_urlencode();
  512. // Get the document.
  513. sendXMLDocument.call(this, this.sRetrieveURL.replace(/%scripturl%/g, smf_prepareScriptUrl(smf_scripturl)).replace(/%suggest_type%/g, this.opt.sSearchType).replace(/%search%/g, sSearchString).replace(/%sessionVar%/g, this.opt.sSessionVar).replace(/%sessionID%/g, this.opt.sSessionId).replace(/%time%/g, new Date().getTime()), '', this.onSuggestionReceived);
  514. return true;
  515. }