home *** CD-ROM | disk | FTP | other *** search
/ CyberMycha Extra 2002 March / CMYCHA200203_EXTRA_broken.iso / Przegladarki / NetscapeSetupB.exe / bin / chrome / help.jar / content / help / help.js < prev    next >
Text File  |  2002-06-23  |  15KB  |  460 lines

  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  * 
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  * 
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  * 
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  * Contributor(s): 
  20.  *    Original author: oeschger@netscape.com 
  21.  *    amended by: Peter Wilson (added sidebar tabs) */
  22.  
  23. //-------- global variables
  24. var helpBrowser;
  25. var helpWindow;
  26. var helpSearchPanel;
  27. var emptySearch;
  28. var emptySearchText
  29. var emptySearchLink
  30. var helpTocPanel;
  31. var helpIndexPanel;
  32. var helpGlossaryPanel;
  33.  
  34. // Namespaces
  35. const NC = "http://home.netscape.com/NC-rdf#";
  36. const SN = "rdf:http://www.w3.org/1999/02/22-rdf-syntax-ns#";
  37. const XML = "http://www.w3.org/XML/1998/namespace#"
  38. const MAX_LEVEL = 40; // maximum depth of recursion in search datasources.
  39.  
  40. // Resources
  41. var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
  42. var RDF_ROOT = RDF.GetResource("urn:root");
  43. var NC_PANELLIST = RDF.GetResource(NC + "panellist");
  44. var NC_PANELID = RDF.GetResource(NC + "panelid");
  45. var NC_EMPTY_SEARCH_TEXT = RDF.GetResource(NC + "emptysearchtext");
  46. var NC_EMPTY_SEARCH_LINK = RDF.GetResource(NC + "emptysearchlink");
  47. var NC_DATASOURCES = RDF.GetResource(NC + "datasources");
  48. var NC_SUBHEADINGS = RDF.GetResource(NC + "subheadings");
  49. var NC_NAME = RDF.GetResource(NC + "name");
  50. var NC_CHILD = RDF.GetResource(NC + "child");
  51. var NC_LINK = RDF.GetResource(NC + "link");
  52. var NC_TITLE = RDF.GetResource(NC + "title");
  53. var NC_BASE = RDF.GetResource(NC + "base"); 
  54. var NC_DEFAULTTOPIC = RDF.GetResource(NC + "defaulttopic"); 
  55.  
  56. var RDFCUtils = Components.classes["@mozilla.org/rdf/container-utils;1"].getService().
  57.    QueryInterface(Components.interfaces.nsIRDFContainerUtils);
  58. var RDFContainer = Components.classes["@mozilla.org/rdf/container;1"].getService(Components.interfaces.nsIRDFContainer);
  59. var CONSOLE_SERVICE = Components.classes['@mozilla.org/consoleservice;1'].getService(Components.interfaces.nsIConsoleService);
  60.             
  61. var urnID = 0;
  62. var RE;
  63.  
  64. var helpFileURI;
  65. var helpFileDS;
  66. // Set from nc:base attribute on help rdf file. It may be used for prefix reduction on all links within
  67. // the current help set.
  68. var helpBaseURI;
  69.  
  70. const defaultHelpFile = "chrome://help/locale/mozillahelp.rdf";
  71. // Set from nc:defaulttopic. It is used when the requested uri has no topic specified. 
  72. var defaultTopic = "welcome"; 
  73. var searchDatasources = "rdf:null";
  74. var searchDS = null;
  75.  
  76. const NSRESULT_RDF_SYNTAX_ERROR = 0x804e03f7; 
  77.  
  78. // This function is called by dialogs/windows that want to display context-sensitive help
  79. // These dialogs/windows should include the script chrome://help/content/contextHelp.js
  80. function displayTopic(topic) {
  81.   if (!topic)
  82.     topic = defaultTopic;
  83.   var uri = getLink(topic);
  84.   if (!uri) // Topic not found - revert to default.
  85.       uri = getLink(defaultTopic); 
  86.   loadURI(uri);
  87. }
  88.  
  89. // Initialize the Help window
  90. function init() {
  91.   //cache panel references.
  92.   helpWindow = document.getElementById("help");
  93.   helpSearchPanel = document.getElementById("help-search-panel");
  94.   helpTocPanel = document.getElementById("help-toc-tree");
  95.   helpIndexPanel = document.getElementById("help-index-tree");
  96.   helpGlossaryPanel = document.getElementById("help-glossary-tree");
  97.   helpBrowser = document.getElementById("help-content");
  98.  
  99.   var URI = normalizeURI(decodeURIComponent(window.location.search));
  100.   helpFileURI = URI.helpFileURI;
  101.   var helpTopic = URI.topic;
  102.   helpBaseURI = helpFileURI.substring(0, helpFileURI.lastIndexOf("/")+1); // trailing "/" included.
  103.  
  104.   loadHelpRDF();
  105.  
  106.   displayTopic(helpTopic);  
  107.  
  108.   // move to right end of screen
  109.   var width = document.documentElement.getAttribute("width");
  110.   var height = document.documentElement.getAttribute("height");
  111.   window.moveTo(screen.availWidth-width, (screen.availHeight-height)/2);
  112.  
  113.   var sessionHistory =  Components.classes["@mozilla.org/browser/shistory;1"]
  114.                   .createInstance(Components.interfaces.nsISHistory);
  115.  
  116.   getWebNavigation().sessionHistory = sessionHistory;
  117.   window.XULBrowserWindow = new nsHelpStatusHandler();
  118.   // hook up UI through progress listener
  119.   var interfaceRequestor = helpBrowser.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
  120.   var webProgress = interfaceRequestor.getInterface(Components.interfaces.nsIWebProgress);
  121.   webProgress.addProgressListener(window.XULBrowserWindow, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
  122. }
  123.  
  124. function normalizeURI(uri) {
  125.   // uri in format [uri of help rdf file][?initial topic]
  126.   // if the whole uri or help file uri is omitted then the default help is assumed.
  127.   // unpack uri
  128.   var URI = {};
  129.   URI.helpFileURI = defaultHelpFile;
  130.   URI.topic = null;
  131.   // Case: No help uri at all.
  132.   if (uri) {
  133.     // remove leading ?
  134.     if (uri.substr(0,1) == "?") 
  135.       uri = uri.substr(1);
  136.     var i = uri.indexOf("?");
  137.     // Case: Full uri with topic.
  138.     if ( i != -1) {
  139.         URI.helpFileURI = uri.substr(0,i);
  140.         URI.topic = uri.substr(i+1);
  141.     }
  142.     else {
  143.       // Case: uri with no topic.
  144.       if (uri.substr(0,7) == "chrome:") 
  145.         URI.helpFileURI = uri;
  146.       else {
  147.         // Case: uri with topic only.
  148.         URI.topic = uri;
  149.       }  
  150.     }
  151.   }  
  152.   URI.uri = URI.helpFileURI + ((URI.topic)? "?" + URI.topic : "");
  153.   return URI;
  154. }
  155.  
  156. function loadHelpRDF() {
  157.   if (!helpFileDS) {
  158.     try {
  159.       helpFileDS = RDF.GetDataSourceBlocking(helpFileURI);
  160.     }
  161.     catch (e if (e.result == NSRESULT_RDF_SYNTAX_ERROR)) {
  162.       log("Help file: " + helpFileURI + " contains a syntax error.");
  163.     }
  164.     catch (e) {
  165.       log("Help file: " + helpFileURI + " was not found.");
  166.     }
  167.     try {
  168.       helpWindow.setAttribute("title", getAttribute(helpFileDS, RDF_ROOT, NC_TITLE, ""));
  169.       helpBaseURI = getAttribute(helpFileDS, RDF_ROOT, NC_BASE, helpBaseURI);
  170.       defaultTopic = getAttribute(helpFileDS, RDF_ROOT, NC_DEFAULTTOPIC, "welcome");
  171.  
  172.       var panelDefs = helpFileDS.GetTarget(RDF_ROOT, NC_PANELLIST, true);      
  173.       RDFContainer.Init(helpFileDS, panelDefs);
  174.       var iterator = RDFContainer.GetElements();
  175.         while (iterator.hasMoreElements()) {
  176.         var panelDef = iterator.getNext();
  177.         var panelID = getAttribute(helpFileDS, panelDef, NC_PANELID, null);        
  178.  
  179.         var datasources = getAttribute(helpFileDS, panelDef, NC_DATASOURCES, "rdf:none");
  180.         datasources = normalizeLinks(helpBaseURI, datasources);
  181.         // cache additional datsources to augment search datasources.
  182.         if (panelID == "search") {
  183.            emptySearchText = getAttribute(helpFileDS, panelDef, NC_EMPTY_SEARCH_TEXT, null) || "No search items found." ;        
  184.            emptySearchLink = getAttribute(helpFileDS, panelDef, NC_EMPTY_SEARCH_LINK, null) || "about:blank";        
  185.           searchDatasources = datasources;
  186.           datasources = "rdf:null"; // but don't try to display them yet!
  187.         }  
  188.  
  189.         // cache toc datasources for use by ID lookup.
  190.         var tree = document.getElementById("help-" + panelID + "-tree");
  191.         tree.setAttribute("datasources", datasources);
  192.         //if (panelID == "toc") {
  193.           if (tree.database) {
  194.             loadDatabases(tree.database, datasources);
  195.             tree.builder.rebuild();
  196.           }
  197.         //}
  198.       }  
  199.     }
  200.     catch (e) {
  201.       log(e + "");      
  202.     }
  203.   }
  204. }
  205. function loadDatabases(compositeDatabase, datasources) {
  206.   var ds = datasources.split(/\s+/);
  207.   for (var i=0; i < ds.length; ++i) {
  208.     if (ds[i] == "rdf:null" || ds[i] == "")
  209.       continue;
  210.     try {  
  211.       // we need blocking here to ensure the database is loaded so getLink(topic) works.
  212.       var datasource = RDF.GetDataSourceBlocking(ds[i]);
  213.       if (datasource)  
  214.         compositeDatabase.AddDataSource(datasource);
  215.     }
  216.     catch (e) {
  217.       log("Datasource: " + ds[i] + " was not found.");
  218.     }
  219.   }
  220. }
  221.  
  222. // prepend helpBaseURI to list of space separated links if the don't start with "chrome:"
  223. function normalizeLinks(helpBaseURI, links) {
  224.   if (!helpBaseURI)
  225.     return links;
  226.   var ls = links.split(/\s+/);
  227.   if (ls.length == 0)
  228.     return links;
  229.   for (var i=0; i < ls.length; ++i) {
  230.     if (ls[i] == "")
  231.       continue;
  232.     if (ls[i].substr(0,7) != "chrome:" && ls[i].substr(0,4) != "rdf:") 
  233.       ls[i] = helpBaseURI + ls[i];
  234.   }
  235.   return ls.join(" ");  
  236. }
  237.  
  238. function getLink(ID) {
  239.   if (!ID)
  240.     return null;
  241.   // Note resources are stored in fileURL#ID format.
  242.   // We have one possible source for an ID for each datasource in the composite datasource.
  243.   // The first ID which matches is returned.
  244.   var tocTree = document.getElementById("help-toc-tree");
  245.     tocDS = tocTree.database;
  246.     if (tocDS == null)
  247.       return null;
  248.     var tocDatasources = tocTree.getAttribute("datasources");
  249.   var ds = tocDatasources.split(/\s+/);
  250.   for (var i=0; i < ds.length; ++i) {
  251.     if (ds[i] == "rdf:null" || ds[i] == "")
  252.       continue;
  253.     try {
  254.       var rdfID = ds[i] + "#" + ID;
  255.       var resource = RDF.GetResource(rdfID);
  256.       if (resource) {
  257.         var link = tocDS.GetTarget(resource, NC_LINK, true);
  258.         if (link) {
  259.           link = link.QueryInterface(Components.interfaces.nsIRDFLiteral);
  260.           if (link) 
  261.             return link.Value;
  262.           else  
  263.             return null;
  264.         }  
  265.       }
  266.     }
  267.     catch (e) { log(rdfID + " " + e);}
  268.   }
  269.   return null;
  270. }
  271.  
  272. // Called by contextHelp.js to determine if this window is displaying the requested help file.
  273. function getHelpFileURI() {
  274.   return helpFileURI;
  275. }
  276.  
  277.  
  278. function getWebNavigation()
  279. {
  280.   return helpBrowser.webNavigation;
  281. }
  282.  
  283. function loadURI(uri)
  284. {
  285.   if (uri.substr(0,7) != "chrome:")
  286.     uri = helpBaseURI + uri;
  287.   const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
  288.   getWebNavigation().loadURI(uri, nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
  289. }
  290.  
  291. function goBack()
  292. {
  293.   var webNavigation = getWebNavigation();
  294.   if (webNavigation.canGoBack)
  295.     webNavigation.goBack();
  296. }
  297.  
  298. function goForward()
  299. {
  300.   var webNavigation = getWebNavigation();
  301.   if (webNavigation.canGoForward)
  302.     webNavigation.goForward();
  303. }
  304.  
  305. function goHome() {
  306.   // load "Welcome" page
  307.   displayTopic(defaultTopic);
  308. }
  309.  
  310. function print()
  311. {
  312.   try {
  313.     _content.print();
  314.   } catch (e) {
  315.   }
  316. }
  317.  
  318. function createBackMenu(event)
  319. {
  320.   return FillHistoryMenu(event.target, "back");
  321. }
  322.  
  323. function createForwardMenu(event)
  324. {
  325.   return FillHistoryMenu(event.target, "forward");
  326. }
  327.  
  328. function gotoHistoryIndex(aEvent)
  329. {
  330.   var index = aEvent.target.getAttribute("index");
  331.   if (!index)
  332.     return false;
  333.   try {
  334.     getWebNavigation().gotoIndex(index);
  335.   }
  336.   catch(ex) {
  337.     return false;
  338.   }
  339.   return true;
  340. }
  341.  
  342. function BrowserBack()
  343. {
  344.   try {
  345.     getWebNavigation().goBack();
  346.   }
  347.   catch(ex) {
  348.   }
  349.   UpdateBackForwardButtons();
  350. }
  351.  
  352. function BrowserForward()
  353. {
  354.   try {
  355.     getWebNavigation().goForward();
  356.   }
  357.   catch(ex) {
  358.   }
  359.   UpdateBackForwardButtons();
  360. }
  361.  
  362. function nsHelpStatusHandler()
  363. {
  364. }
  365.  
  366. nsHelpStatusHandler.prototype =
  367. {
  368.   onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus) {},
  369.   onProgressChange : function(aWebProgress, aRequest, aCurSelfProgress,
  370.                               aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) {},
  371.   onSecurityChange : function(aWebProgress, aRequest, state) {},
  372.   onLocationChange : function(aWebProgress, aRequest, aLocation)
  373.   {
  374.     UpdateBackForwardButtons();
  375.   },
  376.   QueryInterface : function(aIID)
  377.   {
  378.     if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
  379.       aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
  380.       aIID.equals(Components.interfaces.nsIXULBrowserWindow) ||
  381.       aIID.equals(Components.interfaces.nsISupports))
  382.       return this;
  383.     throw Components.results.NS_NOINTERFACE;
  384.   },
  385.   setJSStatus : function(status) {},
  386.   setJSDefaultStatus : function(status) {},
  387.   setOverLink : function(link) {}
  388. }
  389.  
  390. function UpdateBackForwardButtons()
  391. {
  392.   var backBroadcaster = document.getElementById("canGoBack");
  393.   var forwardBroadcaster = document.getElementById("canGoForward");
  394.   var webNavigation = getWebNavigation();
  395.  
  396.   // Avoid setting attributes on broadcasters if the value hasn't changed!
  397.   // Remember, guys, setting attributes on elements is expensive!  They
  398.   // get inherited into anonymous content, broadcast to other widgets, etc.!
  399.   // Don't do it if the value hasn't changed! - dwh
  400.  
  401.   var backDisabled = (backBroadcaster.getAttribute("disabled") == "true");
  402.   var forwardDisabled = (forwardBroadcaster.getAttribute("disabled") == "true");
  403.  
  404.   if (backDisabled == webNavigation.canGoBack)
  405.     backBroadcaster.setAttribute("disabled", !backDisabled);
  406.   
  407.   if (forwardDisabled == webNavigation.canGoForward)
  408.     forwardBroadcaster.setAttribute("disabled", !forwardDisabled);
  409. }
  410.  
  411. function find(again)
  412. {
  413.   var focusedWindow = document.commandDispatcher.focusedWindow;
  414.   if (!focusedWindow || focusedWindow == window)
  415.     focusedWindow = window._content;
  416.   if (again)
  417.     findAgainInPage(helpBrowser, window._content, focusedWindow);
  418.   else
  419.     findInPage(helpBrowser, window._content, focusedWindow)
  420. }
  421.  
  422. function getMarkupDocumentViewer()
  423. {
  424.   return helpBrowser.markupDocumentViewer;
  425. }
  426.  
  427. function BrowserReload()
  428. {
  429.   const reloadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
  430.   return BrowserReloadWithFlags(reloadFlags);
  431. }
  432.  
  433. function BrowserReloadWithFlags(reloadFlags)
  434. {
  435.    try {
  436.      /* Need to get SessionHistory from docshell so that
  437.       * reload on framed pages will work right. This 
  438.       * method should not be used for the context menu item "Reload frame".
  439.       * "Reload frame" should directly call into docshell as it does right now
  440.       */
  441.      var sh = getWebNavigation().sessionHistory;
  442.      var webNav = sh.QueryInterface(Components.interfaces.nsIWebNavigation);      
  443.      webNav.reload(reloadFlags);
  444.    }
  445.    catch(ex) {
  446.    }
  447.  }
  448.  
  449.  // doc=null for regular page info, doc=owner document for frame info 
  450.  
  451. function BrowsemfS) {
  452.  , 
  453. {
  454.   return helpBrowsoad(y-Cv-Id("helpP" should direc.Boemen4
  455.       */Uyrn helpBrorm() sh = getWebNaviga_
  456. function finCs}
  457.  should directly call into docshell ashouw..ctly cal   .cal   .cal   .ieNcindex-tree")(wocswsemMee")(wocswioytARowner documeeturtons();
  458. ptySearchTexurn@t(fnntloadner gnd(again)
  459. {
  460.   var focusedWindow = document.commandDi_pemehould dirs=}.ner doc.AtonsFs.ieloakndDi_pemeho