home *** CD-ROM | disk | FTP | other *** search
-
- /* ******************* BEGIN HistoryNav Object ******************** */
-
- /* ======================================================================
- OBJECT: HistoryNav
-
- PROPERTIES: The following properties should be considered public, and
- can be set by the outside world.
- ---
- domain (string) : the domain name being accessed (e.g. "netobjects.com")
- firstLabel (string): the label that appears when the list is initialized
- name (string) : the name of the HTML select element
- size (integer) : the size of the HTML select element
- size == 1 --> drop-down list box
- size > 1 --> scrolling list box
-
- The following properties should be considered private, and
- should not be set by the outside world. The object uses
- these properties internally.
- ---
- lastLink (string) : the last URL accessed
- links (array) : an array of URL strings
- labels (array) : an array of labels that correspond to the URLs
- maxItems (integer): the total number of items allowed in the list;
- defaults to 25
- numItems (integer): the number of elements in the links and labels
- arrays
-
- METHODS: The following methods should be considered public, and
- can be called by the outside world.
- ---
- addLink : adds a URL and label to the links and labels arrays
- getOpenerURL : gets the URL of the opener window
- isDuplicateURL : determines if a given URL accessed already exists in the list
- render : writes out the HTML that defines the select element
- update : update the HTML select list with most recent links and labels
-
- The following methods should be considered private, and
- should not be set by the outside world. The object uses
- these methods internally.
- ---
- validateLocation : makes sure URL selected in opener window is valid
- before proceeding to add links to the list
-
- DESC: This object allows developers to create an HTML select form element
- that populates itself with a history of navigated pages. For any given
- host domain (e.g. www.netobjects.com, www.microsoft.com, etc.) the navigator will
- track all pages visited in the domain and present them in an HTML
- select list. The user may jump to history list items by selecting
- an item in the list.
-
- This object is generally for use on a small pop-up window of it's own.
- You should create the pop-up window from a form button or the onLoad
- method on another window. This navigator will then track the history of URL's navigated in this
- window that opened the navigator window, provided they are all in the
- target domain.
-
- NOTE: This object will work ONLY with pages of the same domain. If you
- attempt to access pages outside of the domain in which the navigator is
- launched, you will get a security violation.
-
- PLATFORMS: Netscape Navigator 3.01 or higher,
- Microsoft Internet Explorer 4.0 or higher
-
- USAGE: The following code shows an example of how to use the object in a
- typical scenario. See the individual method definitions for more
- information.
-
- // Example of how to call the navigator from an opener window. This
- // page will open a window that contains a navigator object
-
- function OpenNavWin( sourceFile, width, height ) {
- navWin = window.open(sourceFile,'NavWin','toolbar=0,width=' + width +
- ',height=' + height + ',directories=0,status=0,scrollbars=0' +
- ',resize=0,menubar=0');
- } // end OpenNavWin
-
- // Later in in the <BODY> of the page, launch the window like so:
- <FORM NAME="LaunchForm">
- <!-- Launch History.html, which contains the HistoryNav object, in a pop-up window -->
- <INPUT TYPE=button NAME="Launcher" VALUE="Launch History Navigator"
- onClick="OpenNavWin('histtest.html', 350, 175)">
- </FORM>
-
- /////////////////////////////////////////////////////////////////////
-
- // The pop-up window (e.g. 'History.html') should contain the following
- // code in the <BODY> in addition to the object definition, which should be placed in the
- // <HEAD> of the document.
-
- // Create the object. The select list will be named "hnav"
- // on the page. A size of 1 is specified, so it will render as a
- // drop-down list. Up to 20 items may be stored in the list.
- myHistory = new HistoryNav("www.netobjects.com", "hnav", 1, 20);
-
- // Render the initial HTML on the page
- myHistory.render();
-
- // Start the listener which listens for page changes
- HistoryListener("myHistory", myHistory);
-
- ====================================================================== */
- function com_netobjects_HistoryNav( obj ) {
-
- // "Public" Properties - can be modified by outside world
- this.domain = (obj.domain+"" != "undefined" && obj.domain != null) ? obj.domain.toUpperCase() : "";
- this.firstLabel = (obj.firstLabel+"" != "undefined" && obj.firstLabel != null ? obj.firstLabel : "There arcurrently no items in the histy navigator.");
- this.name = (obj.name+"" != "undefined" && obj.name != null) ? obj.name : "HistoryNav1";
- this.size = (obj.size+"" != "undefined" && obj.size != null) ? obj.size : 1;
- this.selectName = (obj.selectName+"" != "undefined" && obj.selectName != null ? obj.selectName : "");
-
- // "Private" Properties - should not be modified except by object methods
- this.labels = new Array();
- this.lastLink = "";
- this.links = new Array();
- this.maxItems = (obj.maxItems+"" != "undefined" && obj.maxItems != null) ? obj.maxItems : 25;
- this.numItems = 0;
-
- // "Public" Methods - can be called by outside world
- this.addLink = hnAddLink;
- this.getOpenerURL = hnGetOpenerURL;
- this.isDuplicateURL = hnIsDuplicateURL;
- this.render = hnRender;
- this.update = hnUpdate;
- this.historyListener = HistoryListener;
-
- // "Private" Methods - should not be called except by other methods
- this.refreshLinks = hnRefreshLinks;
- this.validateLocation = hnValidateLocation;
-
- // Initialize this.lastLink
- this.lastLink = this.getOpenerURL();
-
- /* ======================================================================
- FUNCTION: hnValidateLocation (HistoryNav method: validateLocation)
-
- INPUT: none.
-
- RETURNS: none.
-
- DESC: This function validates any locations discovered when the opener
- window's location changes. If the location is valid, the link
- and label are added to the lists of links.
- ====================================================================== */
- function hnValidateLocation() {
- var locn = this.getOpenerURL().toUpperCase();
- // Make sure the location is not empty and the domain is valid
- if (locn != "") {
- // Do not attempt to add link unless domains are the same
- if(locn.indexOf(this.domain) != -1)
- this.addLink();
- }
- else { // close history tracker if opener URL cannot be found (i.e. opener is closed)
- }
- } // end hnValidateLocation
-
-
- /* ======================================================================
- FUNCTION: hnAddLink (HistoryNav method: addLink)
-
- INPUT: none.
-
- RETURNS: none.
-
- DESC: This function adds a url and corresponding optional label to the
- links and labels arrays. It then calls update() to update the
- HTML select list.
- ====================================================================== */
- function hnAddLink() {
- var url = "";
- var label = "";
-
- url = this.getOpenerURL();
-
- if (url != this.lastLink && url != "") {
- // Set lastLink to the url just detected
- this.lastLink = url;
-
- // Only add link if it doesn't already exist in the history list
- label = window.opener.document.title;
- if (!this.isDuplicateURL(url)) {
- this.numItems++;
-
- // If the number of items exceeds max allowed, strip off the old URL
- if (this.numItems > this.maxItems)
- this.refreshLinks();
-
- this.links[this.numItems-1] = url;
- // Add the label. If no label was given, make the label the same as the link
- this.labels[this.numItems-1] = (label != null || label+"" != "undefined") ? label : url;
- // Update the options list
- this.update();
- } // end inner if
- } // end outer if
- } // end hnAddLink
-
-
- /* ======================================================================
- FUNCTION: hnRender (HistoryNav method: render)
-
- INPUT: none.
-
- RETURNS: none.
-
- DESC: This function writes out all necessary HTML to render the initial
- select list on the page. You should not call this function more
- than once per object.
- ====================================================================== */
- function hnRender() {
- document.writeln('<FORM NAME="' + this.selectName + '">');
- document.writeln('<SELECT NAME="' + this.selectName + '"' +
- 'onChange="window.opener.location.href = this.options[this.selectedIndex].value">');
- // Initialize options array up to maxItems.
- // This sets the width
- for (var i=0; i < this.maxItems; i++) {
- document.writeln('<OPTION>' + this.firstLabel);
- }
- document.writeln('</SELECT>');
- document.writeln('</FORM>');
-
- // Blank out all items but the first
- for (var j=this.maxItems-1; j > 0; j--) {
- document.forms[this.selectName].elements[this.selectName].options[j] = null;
- }
-
- this.update();
- } // end hnRender
-
-
- /* ======================================================================
- FUNCTION: hnUpdate (HistoryNav method: update)
-
- INPUT: none.
-
- RETURNS: none.
-
- DESC: This function uses the links and labels arrays to update the
- HTML select list on the form.
- ====================================================================== */
- function hnUpdate() {
- if (this.numItems > 0) {
- with (document.forms[this.selectName].elements[this.selectName]) {
- // Blank out all options
- for(var i=this.numItems-1; i >= 0; i--)
- options[i] = null;
- // Fill array with most recently trapped at top of list
- for (j=0; j < this.numItems; j++)
- options[j] = new Option((j + 1) + ") " + this.labels[j], this.links[j]);
- } // end with
-
- // Select the most recent entry
- document.forms[this.selectName].elements[this.selectName].options[this.numItems-1].selected = true;
- } // end if
- else
- document.forms[this.selectName].elements[this.selectName].options[0].selected = true;
- } // end hnUpdate
-
-
- /* ======================================================================
- FUNCTION: hnIsDuplicateURL (HistoryNav method: isDuplicateURL)
-
- INPUT: url (string) : the url to test
-
- RETURNS: true, if the url is a duplicate
- false, otherwise
-
- DESC: This function compares the url parameter to all links and labels
- stored. It returns true or false to indicate whether or not url
- is a duplicate of a link already stored.
- ====================================================================== */
- function hnIsDuplicateURL( url ) {
- var isDuplicate = false;
-
- for(i=0; i < this.numItems; i++)
- if (this.links[i].indexOf(url) != -1)
- isDuplicate = true;
-
- return isDuplicate;
- } // end hnIsDuplicateURL
-
-
- /* ======================================================================
- FUNCTION: hnGetOpenerURL (HistoryNav method: getOpenerURL)
-
- INPUT: none.
-
- RETURNS: the URL of the opener window, if the window is open;
- "", otherwise
-
- DESC: This function compares the url parameter to all links and labels
- stored. It returns true or false to indicate whether or not url
- is a duplicate of a link already stored.
- ====================================================================== */
- function hnGetOpenerURL() {
- var result = "";
- if (window.opener+"" != "undefined" && window.opener != null)
- result = window.opener.location.href+"";
-
- return result;
- } // end hnGetOpenerURL
-
-
- /* ======================================================================
- FUNCTION: hnRefreshLinks (HistoryNav method: refreshLinks)
-
- INPUT: none.
-
- RETURNS: none.
-
- DESC: This function refreshes the links and labels arrays by
- removing the oldest (first) link and label in each array,
- then moving the other links over one position. This method
- is used to keep the list from exceeding this.maxItems.
- ====================================================================== */
- function hnRefreshLinks() {
-
- for (var i=0; i < this.numItems; i++) {
- this.links[i] = this.links[i+1];
- this.labels[i] = this.labels[i+1];
- }
- this.numItems--;
-
- } // end hnRefreshLinks
-
- /* ======================================================================
- FUNCTION: HistoryListener (companion to the HistoryNav object)
-
- INPUT: objName (string) : a string representing the name of the HistoryNav
- object on the page
- histNavObj (object) : a HistoryNav object on the page
-
- RETURNS: none.
-
- DESC: This function starts a recursive setTimeout loop that calls histNavObj's
- "validateLocation" method to validate any change of location in the
- opener window. The parameter objName must be the EXACT name of the
- HistoryNav instance you created on the page (it is case-sensitive).
- The histNavObj parameter should contain the corresponding HistoryNav
- object itself.
- ====================================================================== */
- function HistoryListener() {
- // Start the recursive timer
- listenerTimer = setTimeout(this.name + ".historyListener()", 1000);
- // Check locations of pages that the listener "hears"
- this.validateLocation();
- } // end HistoryListener
- } // end HistoryNav constructor
-
- /* ******************** END HistoryNav Object ******************** */
-
-