PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/ParametricNavigation/googleParametricInclude.txt

http://parametric.googlecode.com/
Plain Text | 703 lines | 614 code | 89 blank | 0 comment | 0 complexity | 3601a6b8bc3e995adab91ed58ad1fde0 MD5 | raw file
  1<!-- Meta Tag Cluster code start -->
  2 <script language='javascript'>
  3
  4
  5// This javascript file is used to setup the meta data cluster view
  6
  7// The host that the search resides on
  8var mTGSAHost = "SOMEHOST.com";
  9var originalURL;
 10
 11var seperator = ".";
 12
 13// The name of the id where the meta data clusters are going to be placed
 14var idName = "";
 15
 16// Whether or not we are going to show the number of hits beside each item
 17// By default, displaying the hit count is turned off.
 18var mTShowNumbers = 0;
 19
 20// Hashes used for various things such as whether to display or combine fields
 21// and sorting information.
 22var mTDisplayHash;
 23var mTCombineHash;
 24var mTSortHash;
 25var mTDisplayNameHash;
 26
 27var mTArray;
 28
 29// The header to display above the parametric navigation
 30var mTHeader = "Parametric Navigation";
 31
 32// How mata data values do we display for each meta data item before we show the more link and hide the rest
 33var mTMaxDisplay = 5;
 34
 35var mTExpandName = "expand...";
 36var mTCollapseName = "collapse...";
 37
 38// The label for the all display for each meta data bucket
 39var mTAllName = "all";
 40var mTAllLocation = "list"; // Value of list indicates in the list and a value of
 41                         // header indicates in the header
 42
 43// Create a request object
 44var mTHTTP = mTCreateRequestObject();
 45
 46// Set the title name
 47mTSetHeader('Parametric Navigation');
 48
 49// Set the host name
 50mTSetHost('gsa41.enterprisedemo-google.com');
 51
 52// Add the fields that need to be displayed. The format is
 53// mTAddField(metaTagName, metaTagDelimiter);
 54mTAddField('keywords', ',');
 55mTSetDisplayName('keywords', 'Keywords');
 56mTAddField('techcluster','+');
 57mTSetDisplayName('techcluster', 'Tech Cluster');
 58mTAddField('author', '+');
 59mTSetDisplayName('author', 'Author');
 60
 61// Set the label and placement for the all link
 62mTSetAllPlacement('ALL', 'list');
 63
 64// Set the maximum number of parametric fields to display before
 65// we display the expand link
 66mTSetMaxDisplay(5);
 67
 68// Set the name for the expand and collapse links
 69mTSetExpandName("more...");
 70mTSetCollapseName("less...");
 71
 72// Sort specific fields
 73// Valid values are 'alpha asc', 'alpha desc', 'hits asc', and 'hits desc'
 74mTSort('keywords', 'alpha asc');
 75mTSort('techcluster', 'hits desc');
 76
 77// Setup any fields that need to be combined.  The format is
 78// mTCombineField(formField, toField);
 79mTCombineField('creationdate', 'createdate');
 80
 81
 82// Create the Request Object that we will use to make AJAX calls.
 83function mTCreateRequestObject()
 84{
 85
 86  var ro;
 87  var browser = navigator.appName;
 88
 89  if(browser == "Microsoft Internet Explorer")
 90  {
 91    ro = new ActiveXObject("Microsoft.XMLHTTP");
 92  } else
 93  {
 94    ro = new XMLHttpRequest();
 95  }
 96
 97  return ro;
 98}
 99
100// This function allows the user to select the meta data tags that they want to
101// display.
102function mTAddField(metaTagName, metaTagDelimiter)
103{
104  if (!mTDisplayHash)
105  {
106    mTDisplayHash = new Array();
107  }
108  mTDisplayHash[metaTagName] = metaTagDelimiter;
109}
110
111// This function allows the user to change the display name of the meta tags
112// that they are displaying.
113function mTSetDisplayName(metaTagName, metaTagDisplayName)
114{
115  if (!mTDisplayNameHash)
116  {
117    mTDisplayNameHash = new Array();
118  }
119  mTDisplayNameHash[metaTagName] = metaTagDisplayName;
120}
121
122// This function allows the user to set the header displayed above the
123// parametric navigation
124function mTSetHeader(headerName)
125{
126  mTHeader = headerName;
127}
128
129// This function allows the user to set the placement and text of the all link
130function mTSetAllPlacement(allName, allLocation)
131{
132  mTAllName = allName;
133  mTAllLocation = allLocation.toLowerCase();
134}
135
136// This function allows the user to tell parametric to show or hide the numbers
137function mTSetShowNumbers(show)
138{
139  mTShowNumbers = show;
140}
141
142// This function allows the user to set name of the value to display for the
143// expand... link.
144function mTSetExpandName(expandName)
145{
146  mTExpandName = expandName;
147}
148
149// This function allows the user to set name of the value to display for the
150// collapse... link.
151function mTSetCollapseName(collapseName)
152{
153  mTCollapseName = collapseName;
154}
155
156// This function allows the user to set the maximum number of items to be
157// displayed for each meta tag.
158function mTSetMaxDisplay(maxDisplay)
159{
160  mTMaxDisplay = maxDisplay;
161}
162
163
164// This function allows the user to set the host to send the parametric query
165// to.
166function mTSetHost(hostName)
167{
168  mTGSAHost = hostName;
169}
170
171// This function allows the user to set how the parametric results for a
172// specific metaTag are sorted.
173// A sortBy value of 'alpha asc' indicates alphabetical sorting in ascending order.
174// A sortBy value of 'alpha desc' indicates alphabetical sorting in descending order.
175// A sortBy value of 'hits asc' indicates sorting on hits in ascending order.
176// A sortBy value of 'hits asc' indicates sorting on hits in descending order.
177function mTSort(metaTagName, sortBy)
178{
179  if (!mTSortHash)
180  {
181    mTSortHash = new Array();
182  }
183  mTSortHash[metaTagName] = sortBy;
184}
185
186// This function allows the user to select the meta data tags that they want to
187// display.
188function mTCombineField(mTNameS, mTNameE)
189{
190  if (!mTCombineHash)
191  {
192    mTCombineHash = new Array();
193  }
194  mTCombineHash[mTNameS] = mTNameE;
195}
196
197// This function is called when the page is loaded.  This kicks off the calls
198// to get all the meta tag values.
199function mTLoad(id, mTURL)
200{
201  idName = id;
202  var partialFields = "";
203
204  originalURL = "http://" + mTGSAHost + "/search?" + mTURL;
205
206  // Modify the URL to get the appropriate XML output
207  var url = "http://" + mTGSAHost + "/search?" + mTURL + "&amp;num=100";
208  url = url.replace(/&amp;proxystylesheet=.*?&amp;/, "&amp;");
209  // alert("in mtLoad about to post " + url);
210
211  // This must be a get or it will not work with firefox.  For IE it can be
212  // either and it will work.
213  mTHTTP.open('get', url);
214  mTHTTP.setRequestHeader("Content-Length", url.length);
215  mTHTTP.onreadystatechange = mTHandleResponse;
216  mTHTTP.send(null);
217}
218
219function mTHandleResponse()
220{
221  if(mTHTTP.readyState == 4)
222  {
223    if (mTHTTP.status == 200)
224    {      // perfect!
225
226      var response = mTHTTP.responseXML;
227
228      // Parse the results and build the appropriate list of meta tags
229      // and thier count.
230      mTParse(idName, response);
231
232    } else
233    {
234      // there was a problem with the request,
235      // for example the response may be a 404 (Not Found)
236      // or 500 (Internal Server Error) response codes
237      alert("HTTP ERROR STATUS: " + mTHTTP.status);
238      var responseText = mTHTTP.responseText;
239      alert(responseText);
240    }
241  }
242}
243
244function trim(str)
245{
246  return str.replace(/\s+/g, " ").replace(/^\s*|\s*$/g,"");
247}
248
249function mTParse(idName, response)
250{
251
252  var metaTagName;
253  var metaTagValue;
254  var metaTagDelimiter;
255  var displayTagName = false;
256  var mTResult = "";
257
258  // Go through each meta tag in the XML response.
259  var metaTags = response.getElementsByTagName('MT');
260
261  // Only display parametric information if there is parametric information to
262  // display
263  if (metaTags.length &gt; 0)
264  {
265    for(var i=0;i &lt; metaTags.length;i++)
266    {
267      metaTagName = "";
268      metaTagValue = "";
269      metaTagDelimiter = "";
270
271      // Get the meta tag name and modify it if necessary.
272      metaTagName = metaTags[i].attributes.getNamedItem("N").value;
273      metaTagName = metaTagName.toLowerCase();
274      metaTagName = mTDoCombination(metaTagName);
275      // alert("metaTagName = " + metaTagName);
276
277      // Get the meta tag value and modify it if necessary.
278      metaTagValue = metaTags[i].attributes.getNamedItem("V").value;
279      metaTagValue = trim(metaTagValue);
280      // alert("metaTagValue = " + metaTagValue);
281
282      displayTagName = false;
283      if (metaTagValue != "")
284      {
285        // Find out if the meta tag name matches one that we are suppossed to
286        // allow
287        if (mTDisplayHash)
288        {
289          // Here we check the current tag name against the list of valid tag names
290          displayTagName  = false;
291          for (var mT in mTDisplayHash)
292          {
293            if (mT.toLowerCase() == metaTagName.toLowerCase())
294            {
295              displayTagName = true;
296              metaTagDelimiter = mTDisplayHash[mT];
297            }
298          }
299        } else
300        {
301          displayTagName = true;
302        }
303
304        // If this occurs, then figure out the delimiter
305        if (displayTagName == true)
306        {
307
308          if (!mTArray)
309          {
310            mTArray = new Array();
311          }
312
313          // Do we have a delimiter?  If so, we have to see if we have to split
314          // this value and do this mulitple times.
315          if (metaTagDelimiter != "")
316          {
317            var newMTValues;
318            newMTValues = metaTagValue.split(metaTagDelimiter);
319            for(var j=0;j &lt; newMTValues.length;j++)
320            {
321              if (newMTValues[j] != "")
322              {
323                // Call a function here which will generate the hash with the
324                // correct value.
325                mTArray  = mTDoHash(mTArray, metaTagName, newMTValues[j]);
326              }
327            }
328          } else
329          {
330            // Call a function here which will generate the hash with the
331            // correct value.
332            mTArray  = mTDoHash(mTArray, metaTagName, metaTagValue);
333          }
334        }
335      }
336    }
337  }
338
339  // Output the results to the page
340  mTOutputParametric(idName);
341}
342
343function mTDoHash(mTArray, mTName, mTValue)
344{
345  var lcMTName = mTName.toLowerCase();
346  var lcMTValue = trim(mTValue.toLowerCase());
347  if (mTArray[lcMTName])
348  {
349    // We have an array for this meta tag.  Now let's see if we have a
350    // dimension for it's value
351    if (isNaN(mTArray[lcMTName][lcMTValue]))
352    {
353      mTArray[lcMTName][lcMTValue] = 1;
354    } else
355    {
356      var tmpVal = mTArray[lcMTName][lcMTValue];
357      tmpVal++;
358      mTArray[lcMTName][lcMTValue] = tmpVal;
359    }
360  } else
361  {
362    mTArray[lcMTName] = new Array();
363    mTArray[lcMTName][lcMTValue] = 1;
364  }
365  return mTArray;
366}
367
368function mTDoCombination(mTName)
369{
370  var lcMTName = mTName.toLowerCase();
371  if (mTCombineHash)
372  {
373    if (mTCombineHash[lcMTName])
374    {
375      return mTCombineHash[lcMTName];
376    }
377  }
378  return mTName;
379}
380
381function mTPosSwitch(mTParametricArr, arrPos1, arrPos2)
382{
383  var tmpArr = new Array();
384  tmpArr[0] = mTParametricArr[arrPos1][0];
385  tmpArr[1] = mTParametricArr[arrPos1][1];
386  mTParametricArr[arrPos1][0] = mTParametricArr[arrPos2][0];
387  mTParametricArr[arrPos1][1] = mTParametricArr[arrPos2][1];
388  mTParametricArr[arrPos2][0] = tmpArr[0];
389  mTParametricArr[arrPos2][1] = tmpArr[1];
390  return mTParametricArr;
391}
392
393function hidediv(pass)
394{
395  var divs = document.getElementsByTagName('div');
396  for(i=0;i &lt; divs.length;i++)
397  {
398    //if they are 'see' divs
399    if(divs[i].id.match(pass))
400    {
401      if (document.getElementById) // DOM3 = IE5, NS6
402      {
403        divs[i].style.display="none";// show/hide
404      } else
405      {
406        if (document.layers) // Netscape 4
407        {
408          document.layers[divs[i]].display = 'none';
409        } else // IE 4
410        {
411          document.all.hideShow.divs[i].display = 'none';
412        }
413      }
414    }
415  }
416}
417
418function showdiv(pass)
419{
420  var divs = document.getElementsByTagName('div');
421  for(i=0;i &lt; divs.length;i++)
422  {
423    if(divs[i].id.match(pass))
424    {
425      if (document.getElementById)
426      {
427        divs[i].style.display="block";
428      } else if (document.layers) // Netscape 4
429      {
430        document.layers[divs[i]].display = 'visible';
431      } else // IE 4
432      {
433        document.all.hideShow.divs[i].display = 'block';
434      }
435    }
436  }
437}
438
439
440function mTOutputParametric(idName)
441{
442  var mTResult = "";
443
444  if (mTArray)
445  {
446    mTResult = "&lt;html&gt;&lt;body&gt;&lt;br/&gt;&lt;h3&gt;" + mTHeader + "&lt;/h3&gt;&lt;font size=\"-1\"&gt;";
447    for (var i in mTArray)
448    {
449
450      var baseURL = originalURL + "&amp;partialfields=" + i + ":";
451
452      if ((mTDisplayNameHash != null) &amp;&amp; (mTDisplayNameHash[i]))
453      {
454        mTResult += "&lt;b&gt;" + mTDisplayNameHash[i] + "&lt;/b&gt;";
455      } else
456      {
457        mTResult += "&lt;b&gt;" + i + "&lt;/b&gt;";
458      }
459      if (mTAllLocation == "header")
460      {
461        mTResult += "(&lt;a href=\"javascript:void(0);\" onClick=\"setCookie('" + i + "', '');var newURL=addPartialFieldsToURL('" + originalURL + "');document.location.href=newURL;\"&gt;" + mTAllName + "&lt;/a&gt;)&lt;br/&gt;";
462      } else if (mTAllLocation == "list")
463      {
464        mTResult += "&lt;br/&gt;&lt;a href=\"javascript:void(0);\" onClick=\"setCookie('" + i + "', '');var newURL=addPartialFieldsToURL('" + originalURL + "');document.location.href=newURL;\"&gt;" + mTAllName + "&lt;/a&gt;&lt;br/&gt;";
465      }
466
467      // Stuff the values for this meta tag in an array
468      var mTParametricArr = new Array();
469      var mTParametricCnt = 0;
470      for (var j in mTArray[i])
471      {
472        if (trim(j).length &gt; 0)
473        {
474          mTParametricArr[mTParametricCnt] = new Array();
475          mTParametricArr[mTParametricCnt][0] = j;
476          mTParametricArr[mTParametricCnt][1] = mTArray[i][j];
477          mTParametricCnt++;
478        }
479      }
480
481      // Now we need to sort if this field is one of the ones we need to sort
482      var sortBy = 0;
483      var sortOrder = "";
484      if (mTSortHash)
485      {
486        if (mTSortHash[i])
487        {
488          var tmpArr = mTSortHash[i].split(/ /);
489          if (tmpArr[0].toLowerCase() == "hits")
490          {
491            sortBy = 1;
492          }
493          if (tmpArr[1].toLowerCase() == "asc")
494          {
495            sortOrder = "a";
496          } else if (tmpArr[1].toLowerCase() == "desc")
497          {
498            sortOrder = "d";
499          }
500        }
501      }
502
503      // We are just using a simple bubble sort here, because the number of
504      // values in the array doesn't warrant anything more powerful such as a
505      // quick sort.
506      if (sortOrder != "")
507      {
508        for (var j=0; j &lt; mTParametricArr.length; j++)
509        {
510          for (var k=0; k &lt; mTParametricArr.length; k++)
511          {
512            if (sortOrder == "a")
513            {
514              if (mTParametricArr[j][sortBy] &lt; mTParametricArr[k][sortBy])
515              {
516                mtParametricArr = mTPosSwitch(mTParametricArr, j, k);
517              }
518            } else if (sortOrder == "d")
519            {
520              if (mTParametricArr[j][sortBy] &gt; mTParametricArr[k][sortBy])
521              {
522                mtParametricArr = mTPosSwitch(mTParametricArr, j, k);
523              }
524            }
525          }
526        }
527      }
528
529
530      // Let's figure out if this has been selected.
531      var selectedValue = unescape(getCookie(i));
532      // alert("selectedValue = '" + selectedValue + "'");
533
534      // Now print out the information.
535      for (var j=0; j &lt; mTParametricArr.length; j++)
536      {
537        var linkURL = baseURL;
538
539        // At this point, we have to determine if there is an ampersand in the
540        // value.  If there is, we have to split based upon it, and search
541        // multiple partial fields.  If not, then we just append the value.
542        if (mTParametricArr[j][0].indexOf("&amp;") &gt; 0)
543        {
544          var tmpPartialFields = mTParametricArr[j][0].split("&amp;");
545          for(var k=0; k &lt; tmpPartialFields.length; k++)
546          {
547            if (k == 0)
548            {
549              linkURL += trim(tmpPartialFields[k]);
550            } else
551            {
552              linkURL += seperator + i + ":" + trim(tmpPartialFields[k]);
553            }
554          }
555        } else
556        {
557          linkURL += mTParametricArr[j][0];
558        }
559
560        if (j == mTMaxDisplay)
561        {
562          mTResult += "&lt;div id=\"" + i + "_expand\"&gt;&lt;a href=\"javascript:void(0)\" onClick=\"hidediv('" + i + "_expand');showdiv('" + i + "_collapse');\">" + mTExpandName + "&lt;/a&gt;&lt;/div&gt;";
563          mTResult += "&lt;div id=\"" + i + "_collapse\" style=\"display:none\"&gt;";
564        }
565        if ((selectedValue != null) &amp;&amp; (selectedValue == mTParametricArr[j][0]))
566        {
567          mTResult += "&lt;b&gt;&lt;font color='red'&gt;" + mTParametricArr[j][0] + "&lt;/font&gt;&lt;/b&gt;";
568        } else
569        {
570          mTResult += "&lt;a href=\"javascript:void(0)\" onClick=\"setCookie('" + i + "', '" + mTParametricArr[j][0] + "');var newURL=addPartialFieldsToURL('" + linkURL + "');document.location.href=newURL;\"&gt;" + mTParametricArr[j][0] + "&lt;/a&gt;";
571        }
572        if (mTShowNumbers)
573        {
574          mTResult += " (" + mTParametricArr[j][1] + ")";
575        }
576        mTResult += "<br/>";
577      }
578      if (mTParametricArr.length &gt; mTMaxDisplay)
579      {
580        mTResult += "&lt;a href=\"javascript:void(0)\" onClick=\"hidediv('" + i + "_collapse');showdiv('" + i + "_expand');\"&gt;" + mTCollapseName + "&lt;/a&gt;&lt;/div&gt;";
581      }
582
583      mTResult += "&lt;br/&gt;&lt;br/&gt;";
584    }
585    mTResult += "&lt;/font&gt;&lt;/body&gt;&lt;/html&gt;";
586  } else
587  {
588    mTResult += "<html><body></body></html>";
589  }
590
591  // Output the results to the page
592  document.getElementById(idName).innerHTML = mTResult;
593}
594
595function setCookie (name, value, expires, path, domain, secure)
596{
597  // alert("setting cookie '" + name + "' to value '" + value + "'");
598  document.cookie = name + "=" + escape(value) +
599                    ((expires) ? "; expires=" + expires : "") +
600                    ((path) ? "; path=" + path : "") +
601                    ((domain) ? "; domain=" + domain : "") +
602                    ((secure) ? "; secure" : "");
603}
604
605function getCookie(name)
606{
607  // alert("getting cookie '" + name + "'");
608  var nameEQ = name + "=";
609  var ca = document.cookie.split(';');
610  for(var i=0;i &lt; ca.length;i++)
611  {
612    var c = ca[i];
613    while (c.charAt(0)==' ') c = c.substring(1,c.length);
614    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
615  }
616  return null;
617}
618
619function replaceAll(str, replaceFrom, replaceWith )
620{
621  var returnString = str;
622  while(returnString.match(replaceFrom) != null)
623  {
624    returnString = returnString.replace(replaceFrom, replaceWith);
625  }
626  return returnString;
627}
628
629function removePartialFieldsFromURL(URL)
630{
631  var newURL = URL;
632  // Get rid of any partialfields that occur in the middle of the URL
633  if (newURL.match(/&amp;partialfields=.*?&amp;/) != null)
634  {
635    while (newURL.match(/&amp;partialfields=.*?&amp;/) != null)
636    {
637      newURL = newURL.replace(/&amp;partialfields=.*?&amp;/, "&amp;");
638    }
639  }
640  // Get rid of partialfields that occurs at the end of the URL
641  newURL = newURL.replace(/&amp;partialfields=.*/, "");
642
643  return newURL;
644}
645
646function addPartialFieldsToURL(URL)
647{
648  var newURL = removePartialFieldsFromURL(URL);
649  var ca = document.cookie.split(';');
650
651  var pfCount = 0;
652  for(var i=0;i &lt; ca.length;i++)
653  {
654    var c = trim(ca[i]);
655    // Don't allow for cookies that start with two underscores or that are one
656    // character.
657    if (c.match(/^__/) == null)
658    {
659      var cookieName = c;
660      cookieName = cookieName.replace(/\=.*$/, "");
661      if (cookieName.length &gt; 1)
662      {
663        var cookieValue = unescape(getCookie(cookieName));
664        if ((cookieValue != null) &amp;&amp; (cookieValue != ""))
665        {
666          if (pfCount == 0)
667          {
668            newURL += "&amp;partialfields=";
669          } else
670          {
671            newURL += seperator;
672          }
673
674          if (cookieValue.indexOf("&amp;") > 0)
675          {
676            var tmpPartialFields = cookieValue.split("&amp;");
677            for(var k=0; k &lt; tmpPartialFields.length; k++)
678            {
679              if (k == 0)
680              {
681                newURL += escape(cookieName + ":" + escape(trim(tmpPartialFields[k])));
682              } else
683              {
684                newURL += seperator + escape(cookieName + ":" + escape(trim(tmpPartialFields[k])));
685              }
686            }
687          } else
688          {
689            newURL += escape(cookieName + ":" + escape(trim(cookieValue)));
690          }
691          pfCount++;
692        }
693      }
694    }
695  }
696  // alert("newURL = " + newURL);
697
698  return newURL;
699}
700
701
702</script>
703<!-- Meta Tag Cluster code end -->