1.  
  2. var jsonLoader = new BiJsonLoader();
  3. ...
  4. var jsonLoaded = function(e) {
  5. var resultSet = this.getData().ResultSet;
  6.  
  7. if (resultSet == undefined) {
  8. alert("Search returned no results");
  9. }
  10.  
  11. var item;
  12.  
  13. // BEGIN :: Scrolling event handler
  14. var prevScrollTop = win.getScrollTop();
  15.  
  16. var handleScrolling = function(e) {
  17. // Ignore horizontal scrolling
  18. var target = e.getTarget();
  19. var scrollLeft = target.getScrollLeft();
  20. if (scrollLeft > 0) {
  21. return;
  22. }
  23. var scrollTop = target.getScrollTop();
  24.  
  25. if (prevScrollTop < scrollTop) {
  26. if (!searching) {
  27. searchForward();
  28. }
  29. } else if (prevScrollTop > scrollTop) {
  30. ;
  31. } else if (scrollLeft == 0) {
  32. return;
  33. }
  34. prevScrollTop = scrollTop;
  35. }
  36. // END :: Scrolling event handler
  37. if (resultsList == undefined) { // Do this only on the FIRST search!
  38. about.setStyleProperty("display", "none");
  39. var array = new Array();
  40. array[0] = new Array();
  41. array[0][0] = undefined;
  42. array[0][1] = undefined;
  43. array[0][2] = undefined;
  44.  
  45. resultsList = new BiTree2();
  46. resultsList.setShowGridLines(true);
  47. resultsList.setShowHeaders(true);
  48. resultsList.setShowRowHeaders(false);
  49. resultsList.setColumnNames(["Title", "Summary", "Url"]);
  50. resultsList.setColumnCount(3);
  51. resultsList.setColumnWidths([200, 400, 400]);
  52. resultsList.setColumnOrders([0, 1, 2]);
  53. resultsList.setLocation(0, 75);
  54. resultsList.setSize(1000, 200);
  55. resultsList.setStyleProperty("width", "75%");
  56. resultsList.setStyleProperty("marginLeft", "5px");
  57. resultsList.addEventListener("scroll", handleScrolling);
  58.  
  59. win.add(resultsList);
  60. }
  61. lastPositionShown = resultSet.firstResultPosition + resultSet.totalResultsReturned;
  62. // Build the grid
  63. var len = resultSet.Result.length;
  64.  
  65. for (var i=0;i<len;i++) {
  66. var url = resultSet.Result[i].Url;
  67. // add a row with Title, Summary and url
  68. var dataObj = new Array();
  69. dataObj[0] = resultSet.Result[i].Title;
  70. dataObj[1] = resultSet.Result[i].Summary;
  71. dataObj[2] = url;
  72. item = new BiTree2Row(dataObj);
  73. resultsList.addRow(item);
  74. }
  75. resultsList.update();
  76. var firstResultPosition = resultSet.firstResultPosition > 0 ? 1 : 0;
  77. stat.setHtml("Results <b>" + firstResultPosition + "</b> to <b>" + lastPositionShown + "</b> of <b>" + resultSet.totalResultsAvailable + "</b>");
  78. searching = false;
  79. };
  80. var doSearch = function() {
  81. if (resultsList != undefined) {
  82. resultsList.setStyleProperty("display", "none");
  83. resultsList.dispose();
  84. resultsList = undefined;
  85. searching = true;
  86. }
  87. updatedSearchUrl = searchUrl + "&query=" + textField.getText() + "&results=" + results;
  88. uri.setHref(updatedSearchUrl);
  89. jsonLoader.setUri(uri);
  90. jsonLoader.load(uri);
  91. }
  92. ...
  93. // BEGIN :: Event listeners
  94. jsonLoader.addEventListener("load", jsonLoaded);
  95. submitQuoteBtn.addEventListener("action", doSearch);
  96. textField.addEventListener("action", doSearch);
  97. // END :: Event listeners
  98.  
  99.