home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-macos9-1.3.1.sea.bin / Mozilla1.3.1 / Chrome / comm.jar / content / editor / EditorSaveAsCharset.js < prev    next >
Text File  |  2003-06-08  |  4KB  |  155 lines

  1. /* 
  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.  * 
  20.  * Contributor(s): 
  21.  * Frank Tang  ftang@netscape.com
  22.  * J.M  Betak  jbetak@netscape.com
  23.  * Neil Rashbrook <neil@parkwaycc.co.uk>
  24.  */
  25.  
  26.  
  27. var gCharset="";
  28. var gTitleWasEdited = false;
  29. var gCharsetWasChanged = false;
  30. var gInsertNewContentType = false;
  31. var gContenttypeElement;
  32. var gInitDone = false;
  33.  
  34. //Cancel() is in EdDialogCommon.js
  35.  
  36. function Startup()
  37. {
  38.   var editor = GetCurrentEditor();
  39.   if (!editor)
  40.   {
  41.     window.close();
  42.     return;
  43.   }
  44.  
  45.   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  46.   observerService.notifyObservers(null, "charsetmenu-selected", "other");
  47.  
  48.   gDialog.TitleInput    = document.getElementById("TitleInput");
  49.   gDialog.charsetTree   = document.getElementById('CharsetTree'); 
  50.   gDialog.exportToText  = document.getElementById('ExportToText');
  51.  
  52.   gContenttypeElement = GetHTTPEquivMetaElement("content-type");
  53.   if (!gContenttypeElement && (editor.contentsMIMEType != 'text/plain')) 
  54.   {
  55.     gContenttypeElement = CreateHTTPEquivMetaElement("content-type");
  56.     if (!gContenttypeElement ) 
  57.     {
  58.       window.close();
  59.       return;
  60.     }
  61.     gInsertNewContentType = true;
  62.   }
  63.  
  64.   try {
  65.     gCharset = editor.documentCharacterSet;
  66.   } catch (e) {}
  67.  
  68.   InitDialog();
  69.  
  70.   // Use the same text as the messagebox for getting title by regular "Save"
  71.   document.getElementById("EnterTitleLabel").setAttribute("value",GetString("NeedDocTitle"));
  72.   // This is an <HTML> element so it wraps -- append a child textnode
  73.   var helpTextParent = document.getElementById("TitleHelp");
  74.   var helpText = document.createTextNode(GetString("DocTitleHelp"));
  75.   if (helpTextParent)
  76.     helpTextParent.appendChild(helpText);
  77.   
  78.   // SET FOCUS TO FIRST CONTROL
  79.   SetTextboxFocus(gDialog.TitleInput);
  80.   
  81.   gInitDone = true;
  82.   
  83.   SetWindowLocation();
  84. }
  85.  
  86.   
  87. function InitDialog() 
  88. {
  89.   gDialog.TitleInput.value = GetDocumentTitle();
  90.  
  91.   var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
  92.   var index = gDialog.charsetTree.builderView.getIndexOfResource(RDF.GetResource(gCharset));
  93.   if (index >= 0) {
  94.     var treeBox = gDialog.charsetTree.treeBoxObject;
  95.     treeBox.selection.select(index);
  96.     treeBox.ensureRowIsVisible(index);
  97.   }
  98. }
  99.  
  100.  
  101. function onAccept()
  102. {
  103.   var editor = GetCurrentEditor();
  104.   editor.beginTransaction();
  105.  
  106.   if(gCharsetWasChanged) 
  107.   {
  108.      try {
  109.        SetMetaElementContent(gContenttypeElement, "text/html; charset=" + gCharset, gInsertNewContentType, true);     
  110.       editor.documentCharacterSet = gCharset;
  111.     } catch (e) {}
  112.   }
  113.  
  114.   editor.endTransaction();
  115.  
  116.   if(gTitleWasEdited) 
  117.     SetDocumentTitle(TrimString(gDialog.TitleInput.value));
  118.  
  119.   window.opener.ok = true;
  120.   window.opener.exportToText = gDialog.exportToText.checked;
  121.   SaveWindowLocation();
  122.   return true;
  123. }
  124.  
  125.  
  126. function readRDFString(aDS,aRes,aProp) 
  127. {
  128.   var n = aDS.GetTarget(aRes, aProp, true);
  129.   if (n)
  130.     return n.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  131.   else
  132.     return "";
  133. }
  134.  
  135.       
  136. function SelectCharset()
  137. {
  138.   if(gInitDone) 
  139.   {
  140.     try 
  141.     {
  142.       gCharset = gDialog.charsetTree.builderView.getResourceAtIndex(gDialog.charsetTree.currentIndex).Value;
  143.       if (gCharset)
  144.         gCharsetWasChanged = true;
  145.     }
  146.     catch(e) {}
  147.   }
  148. }
  149.  
  150.  
  151. function TitleChanged()
  152. {
  153.   gTitleWasEdited = true; 
  154. }
  155.