home *** CD-ROM | disk | FTP | other *** search
-
- /**
- * Communicator Shared Utility Library
- * for shared application glue for the Communicator suite of applications
- **/
-
- var goPrefWindow = 0;
-
- function getBrowserURL() {
-
- try {
- var prefs = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
- var url = prefs.getCharPref("browser.chromeURL");
- if (url)
- return url;
- } catch(e) {
- }
- return "chrome://navigator/content/navigator.xul";
- }
-
- function goPageSetup(domwin, printSettings)
- {
- try {
- if (printSettings == null) {
- alert("PrintSettings arg is null!");
- }
-
- // This code calls the printoptions service to bring up the printoptions
- // dialog. This will be an xp dialog if the platform did not override
- // the ShowPrintSetupDialog method.
- var printingPromptService = Components.classes["@mozilla.org/embedcomp/printingprompt-service;1"]
- .getService(Components.interfaces.nsIPrintingPromptService);
- printingPromptService.showPageSetup(domwin, printSettings, null);
- return true;
- } catch(e) {
- return false;
- }
- return true;
- }
-
- function goToggleToolbar( id, elementID )
- {
- var toolbar = document.getElementById( id );
- var element = document.getElementById( elementID );
- if ( toolbar )
- {
- var attribValue = toolbar.getAttribute("hidden") ;
-
- if ( attribValue == "true" )
- {
- toolbar.setAttribute("hidden", "false" );
- if ( element )
- element.setAttribute("checked","true")
- }
- else
- {
- toolbar.setAttribute("hidden", true );
- if ( element )
- element.setAttribute("checked","false")
- }
- document.persist(id, 'hidden');
- document.persist(elementID, 'checked');
- }
- }
-
-
- function goClickThrobber( urlPref )
- {
- var url;
- try {
- var pref = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
- url = pref.getComplexValue(urlPref, Components.interfaces.nsIPrefLocalizedString).data;
- }
-
- catch(e) {
- url = null;
- }
-
- if ( url )
- openTopWin(url);
- }
-
-
- //No longer needed. Rip this out since we are using openTopWin
- function goHelpMenu( url )
- {
- /* note that this chrome url should probably change to not have all of the navigator controls */
- /* also, do we want to limit the number of help windows that can be spawned? */
- window.openDialog( getBrowserURL(), "_blank", "chrome,all,dialog=no", url );
- }
-
- function getTopWin()
- {
- var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
- var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
- var topWindowOfType = windowManagerInterface.getMostRecentWindow( "navigator:browser" );
-
- if (topWindowOfType) {
- return topWindowOfType;
- }
- return null;
- }
-
- function openTopWin( url )
- {
- /* note that this chrome url should probably change to not have
- all of the navigator controls, but if we do this we need to have
- the option for chrome controls because goClickThrobber() needs to
- use this function with chrome controls */
- /* also, do we want to
- limit the number of help windows that can be spawned? */
- if ((url == null) || (url == "")) return null;
-
- // xlate the URL if necessary
- if (url.indexOf("urn:") == 0)
- {
- url = xlateURL(url); // does RDF urn expansion
- }
-
- // avoid loading "", since this loads a directory listing
- if (url == "") {
- url = "about:blank";
- }
-
- var topWindowOfType = getTopWin();
- if ( topWindowOfType )
- {
- topWindowOfType.focus();
- topWindowOfType.loadURI(url);
- return topWindowOfType;
- }
- return window.openDialog( getBrowserURL(), "_blank", "chrome,all,dialog=no", url );
- }
-
- // update menu items that rely on focus
- function goUpdateGlobalEditMenuItems()
- {
- goUpdateCommand('cmd_undo');
- goUpdateCommand('cmd_redo');
- goUpdateCommand('cmd_cut');
- goUpdateCommand('cmd_copy');
- goUpdateCommand('cmd_paste');
- goUpdateCommand('cmd_selectAll');
- goUpdateCommand('cmd_delete');
- }
-
- // update menu items that rely on the current selection
- function goUpdateSelectEditMenuItems()
- {
- goUpdateCommand('cmd_cut');
- goUpdateCommand('cmd_copy');
- goUpdateCommand('cmd_delete');
- goUpdateCommand('cmd_selectAll');
- }
-
- // update menu items that relate to undo/redo
- function goUpdateUndoEditMenuItems()
- {
- goUpdateCommand('cmd_undo');
- goUpdateCommand('cmd_redo');
- }
-
- // update menu items that depend on clipboard contents
- function goUpdatePasteMenuItems()
- {
- goUpdateCommand('cmd_paste');
- }
-
- // Gather all descendent text under given document node.
- function gatherTextUnder ( root )
- {
- var text = "";
- var node = root.firstChild;
- var depth = 1;
- while ( node && depth > 0 ) {
- // See if this node is text.
- if ( node.nodeName == "#text" ) {
- // Add this text to our collection.
- text += " " + node.data;
- } else if ( node.nodeType == Node.ELEMENT_NODE
- && node.localName.toUpperCase() == "IMG" ) {
- // If it has an alt= attribute, use that.
- var altText = node.getAttribute( "alt" );
- if ( altText && altText != "" ) {
- text = altText;
- break;
- }
- }
- // Find next node to test.
- // First, see if this node has children.
- if ( node.hasChildNodes() ) {
- // Go to first child.
- node = node.firstChild;
- depth++;
- } else {
- // No children, try next sibling.
- if ( node.nextSibling ) {
- node = node.nextSibling;
- } else {
- // Last resort is our next oldest uncle/aunt.
- node = node.parentNode.nextSibling;
- depth--;
- }
- }
- }
- // Strip leading whitespace.
- text = text.replace( /^\s+/, "" );
- // Strip trailing whitespace.
- text = text.replace( /\s+$/, "" );
- // Compress remaining whitespace.
- text = text.replace( /\s+/g, " " );
- return text;
- }
-