• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

1.3. nav.html

The brains of the application lie in the header file named nav.html. In fact, the only other place you'll see JavaScript is in the results pages manufactured on the fly. Let's have a glimpse at the code. Example 1.1 leads the way.

Example 1.1. Source Code for nav.html

1  <HTML>
     2  <HEAD>
     3  <TITLE>Search Nav Page</TITLE>
     4  
     5  <SCRIPT LANGUAGE="JavaScript1.1" SRC="records.js"></SCRIPT>
     6  <SCRIPT LANGUAGE="JavaScript1.1">
     7  <!--
     8  
     9  var SEARCHANY  = 1;
    10  var SEARCHALL  = 2;
    11  var SEARCHURL  = 4;
    12  var searchType = "";
    13  var showMatches    = 10;
    14  var currentMatch  = 0;
    15  var copyArray    = new Array();
    16  var docObj  = parent.frames[1].document;
    17  
    18  function validate(entry) {  
    19    if (entry.charAt(0) == "+") {
    20     entry = entry.substring(1,entry.length);
    21     searchType = SEARCHALL;
    22     }
    23    else if (entry.substring(0,4) == "url:") {
    24     entry = entry.substring(5,entry.length);
    25     searchType = SEARCHURL;
    26     }
    27    else { searchType = SEARCHANY; }
    28    while (entry.charAt(0) == " ") {       
    29     entry = entry.substring(1,entry.length);
    30     document.forms[0].query.value = entry;
    31     } 
    32    while (entry.charAt(entry.length - 1) == " ") {
    33     entry = entry.substring(0,entry.length - 1);
    34     document.forms[0].query.value = entry;
    35     }
    36    if (entry.length < 3) {
    37     alert("You cannot search strings that small. Elaborate a little.");
    38     document.forms[0].query.focus();
    39     return;
    40     }
    41    convertString(entry);
    42    }
    43  
    44  function convertString(reentry) {
    45    var searchArray = reentry.split(" ");
    46    if (searchType == (SEARCHALL)) { requireAll(searchArray); }
    47    else { allowAny(searchArray); }
    48    }
    49  
    50  function allowAny(t) {
    51    var findings = new Array(0);
    52    for (i = 0; i < profiles.length; i++) {
    53      var compareElement  = profiles[i].toUpperCase();  
    54      if(searchType == SEARCHANY) { 
    55        var refineElement = compareElement.substring(0, 
    56          compareElement.indexOf('|HTTP')); 
    57        }
    58      else { 
    59        var refineElement = 
    60          compareElement.substring(compareElement.indexOf('|HTTP'), 
    61          compareElement.length); 
    62        }
    63      for (j = 0; j < t.length; j++) {
    64        var compareString = t[j].toUpperCase();
    65        if (refineElement.indexOf(compareString) != -1) {
    66          findings[findings.length] = profiles[i];
    67          break;
    68          }
    69        }
    70      }
    71    verifyManage(findings);
    72    }
    73  
    74  function requireAll(t) {
    75    var findings = new Array();
    76    for (i = 0; i < profiles.length; i++) {  
    77      var allConfirmation = true;    
    78      var allString     = profiles[i].toUpperCase();
    79      var refineAllString = allString.substring(0, 
    80        allString.indexOf('|HTTP'));
    81      for (j = 0; j < t.length; j++) { 
    82        var allElement = t[j].toUpperCase();
    83        if (refineAllString.indexOf(allElement) == -1) { 
    84          allConfirmation = false;
    85          continue; 
    86          }  
    87        }
    88      if (allConfirmation) {
    89        findings[findings.length] = profiles[i];
    90        }
    91      }
    92    verifyManage(findings);
    93    }
    94  
    95  function verifyManage(resultSet) {
    96    if (resultSet.length == 0) { noMatch(); }
    97    else {
    98      copyArray = resultSet.sort();
    99      formatResults(copyArray, currentMatch, showMatches);
   100      }   
   101    }
   102  
   103  function noMatch() {
   104    docObj.open();
   105    docObj.writeln('<HTML><HEAD><TITLE>Search Results</TITLE></HEAD>' + 
   106      '<BODY BGCOLOR=WHITE TEXT=BLACK>' + 
   107      '<TABLE WIDTH=90% BORDER=0 ALIGN=CENTER><TR><TD VALIGN=TOP>' +       
   108  '<FONT FACE=Arial><B><DL>' + 
   109      '<HR NOSHADE WIDTH=100%>"' + document.forms[0].query.value + 
   110      '" returned no results.<HR NOSHADE WIDTH=100%>' + 
   111      '</TD></TR></TABLE></BODY></HTML>');
   112    docObj.close();
   113    document.forms[0].query.select();
   114    }
   115  
   116  function formatResults(results, reference, offset) {
   117    var currentRecord = (results.length < reference + offset ? 
   118      results.length : reference + offset);
   119    docObj.open();
   120    docObj.writeln('<HTML><HEAD><TITLE>Search Results</TITLE>\n</HEAD>' + 
   121      '<BODY BGCOLOR=WHITE TEXT=BLACK>' + 
   122      '<TABLE WIDTH=90% BORDER=0 ALIGN=CENTER CELLPADDING=3><TR><TD>' + 
   123      '<HR NOSHADE WIDTH=100%></TD></TR><TR><TD VALIGN=TOP>' + 
   124      '<FONT FACE=Arial><B>Search Query: <I>' + 
   125      parent.frames[0].document.forms[0].query.value + '</I><BR>\n' + 
   126      'Search Results: <I>' + (reference + 1) + ' - ' + 
   127      currentRecord + ' of ' + results.length + '</I><BR><BR></FONT>' + 
   128      '<FONT FACE=Arial SIZE=-1><B>' + 
   129      '\n\n<!-- Begin result set //-->\n\n\t<DL>');  
   130    if (searchType == SEARCHURL) {
   131      for (var i = reference; i < currentRecord; i++) {
   132        var divide = results[i].split('|'); 
   133        docObj.writeln('\t<DT>' + '<A HREF="' + divide[2] + '">' + 
   134          divide[2] + '</A>\t<DD><I>' + divide[1] + '</I><P>\n\n');
   135        }
   136      }
   137    else {
   138      for (var i = reference; i < currentRecord; i++) {
   139        var divide = results[i].split('|');   
   140        docObj.writeln('\n\n\t<DT>' + '<A HREF="' + divide[2] + '">' + 
   141          divide[0] + '</A>' + '\t<DD>' + '<I>' + divide[1] + '</I><P>');
   142        }
   143      }
   144    docObj.writeln('\n\t</DL>\n\n<!-- End result set //-->\n\n');
   145    prevNextResults(results.length, reference, offset);      
   146    docObj.writeln('<HR NOSHADE WIDTH=100%>' + 
   147      '</TD>\n</TR>\n</TABLE>\n</BODY>\n</HTML>');
   148    docObj.close();
   149    document.forms[0].query.select();
   150    }
   151  
   152  function prevNextResults(ceiling, reference, offset) {
   153    docObj.writeln('<CENTER><FORM>');
   154    if(reference > 0) {
   155      docObj.writeln('<INPUT TYPE=BUTTON VALUE="Prev ' + offset + 
   156      ' Results" ' + 
   157   'onClick="parent.frames[0].formatResults(parent.frames[0].copyArray, ' + 
   158        (reference - offset) + ', ' + offset + ')">');
   159      }
   160    if(reference >= 0 && reference + offset < ceiling) {
   161      var trueTop = ((ceiling - (offset + reference) < offset) ? 
   162        ceiling - (reference + offset) : offset);
   163      var howMany = (trueTop > 1 ? "s" : "");
   164      docObj.writeln('<INPUT TYPE=BUTTON VALUE="Next ' + trueTop + 
   165        ' Result' + howMany + '" ' + 
   166   'onClick="parent.frames[0].formatResults(parent.frames[0].copyArray, ' + 
   167        (reference + offset) + ', ' + offset + ')">');
   168      }
   169    docObj.writeln('</CENTER>');
   170    }
   171  
   172  //-->
   173  </SCRIPT>
   174  </HEAD>
   175  <BODY BGCOLOR="WHITE">
   176  <TABLE WIDTH="95%" BORDER="0" ALIGN="CENTER">
   177  <TR>
   178    <TD VALIGN=MIDDLE>
   179    <FONT FACE="Arial">
   180    <B>Client-Side Search Engine</B>
   181    </TD>
   182  
   183    <TD VALIGN=ABSMIDDLE>
   184    <FORM NAME="search" 
   185      onsubmit="validate(document.forms[0].query.value); return false;">
   186    <INPUT TYPE=TEXT NAME="query" SIZE="33">
   187    <INPUT TYPE=HIDDEN NAME="standin" VALUE="">
   188    </FORM>
   189    </TD>
   190  
   191    <TD VALIGN=ABSMIDDLE>
   192    <FONT FACE="Arial">
   193    <B><A HREF="main.html" TARGET="main">Help</A></B>
   194    </TD>
   195  </TR>
   196  </TABLE>
   197  </BODY>
   198  </HTML>

					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint