home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / comm.jar / content / editor / EdPageProps.js < prev    next >
Encoding:
JavaScript  |  2001-08-02  |  4.6 KB  |  167 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.  */
  22.  
  23. var newTitle = "";
  24. var author = "";
  25. var description = "";
  26. var authorElement;
  27. var descriptionElement;
  28. var insertNewAuthor = false;
  29. var insertNewDescription = false;
  30. var titleWasEdited = false;
  31. var authorWasEdited = false;
  32. var descWasEdited = false;
  33. var dialog;
  34.  
  35. //Cancel() is in EdDialogCommon.js
  36. // dialog initialization code
  37. function Startup()
  38. {
  39.   if (!InitEditorShell())
  40.     return;
  41.  
  42.   dialog = new Object;
  43.   if (!dialog)
  44.   {
  45.     dump("Failed to create dialog object!!!\n");
  46.     window.close();
  47.     return;
  48.   }
  49.   dialog.PageLocation     = document.getElementById("PageLocation");
  50.   dialog.TitleInput       = document.getElementById("TitleInput");
  51.   dialog.AuthorInput      = document.getElementById("AuthorInput");
  52.   dialog.DescriptionInput = document.getElementById("DescriptionInput");
  53.   doSetOKCancel(onOK, onCancel);
  54.   
  55.   // Default string for new page is set from DTD string in XUL,
  56.   //   so set only if not new doc URL
  57.   var location = editorShell.editorDocument.location;
  58.   var lastmodString = GetString("Unknown");
  59.  
  60.   if (location != "about:blank")
  61.   {
  62.     dialog.PageLocation.setAttribute("value", editorShell.editorDocument.location);
  63.  
  64.     // Get last-modified file date+time
  65.     // TODO: Convert this to local time?
  66.     var lastmod = editorShell.editorDocument.lastModified;  // get string of last modified date
  67.     var lastmoddate = Date.parse(lastmod);                  // convert modified string to date
  68.     if(lastmoddate != 0)                                    // unknown date (or January 1, 1970 GMT)
  69.       lastmodString = lastmoddate;
  70.  
  71.   }
  72.   document.getElementById("PageModDate").setAttribute("value", lastmodString);
  73.  
  74.   authorElement = GetMetaElement("author");
  75.   if (!authorElement)
  76.   {
  77.     authorElement = CreateMetaElement("author");
  78.     if (!authorElement)
  79.     {
  80.       window.close();
  81.       return;
  82.     }
  83.     insertNewAuthor = true;
  84.   }
  85.  
  86.   descriptionElement = GetMetaElement("description");
  87.   if (!descriptionElement)
  88.   {
  89.     descriptionElement = CreateMetaElement("description");
  90.     if (!descriptionElement)
  91.       window.close();
  92.  
  93.     insertNewDescription = true;
  94.   }
  95.   
  96.   InitDialog();
  97.  
  98.   SetTextboxFocus(dialog.TitleInput);
  99.  
  100.   SetWindowLocation();
  101. }
  102.  
  103. function InitDialog()
  104. {
  105.   dialog.TitleInput.value = editorShell.GetDocumentTitle();
  106.   var author = authorElement.getAttribute("content").trimString();
  107.   if (author.length == 0)
  108.   {
  109.     // Fill in with value from editor prefs
  110.     var prefs = GetPrefs();
  111.     if (prefs) 
  112.       author = prefs.CopyCharPref("editor.author");
  113.   }
  114.   dialog.AuthorInput.value = author;
  115.   dialog.DescriptionInput.value = descriptionElement.getAttribute("content");
  116. }
  117.  
  118. function TextboxChanged(ID)
  119. {
  120.   switch(ID)
  121.   {
  122.     case "TitleInput":
  123.       titleWasEdited = true;
  124.       break;
  125.     case "AuthorInput":
  126.       authorWasEdited = true;
  127.       break;
  128.     case "DescriptionInput":
  129.       descWasEdited = true;
  130.       break;
  131.   }
  132. }
  133.  
  134. function ValidateData()
  135. {
  136.   newTitle = dialog.TitleInput.value.trimString();
  137.   author = dialog.AuthorInput.value.trimString();
  138.   description = dialog.DescriptionInput.value.trimString();
  139.   return true;
  140. }
  141.  
  142. function onOK()
  143. {
  144.   if (ValidateData())
  145.   {
  146.     editorShell.BeginBatchChanges();
  147.     if (titleWasEdited)
  148.     {
  149.       // Set title contents even if string is empty
  150.       //  because TITLE is a required HTML element
  151.       editorShell.SetDocumentTitle(newTitle);
  152.     }
  153.     
  154.     if (authorWasEdited)
  155.       SetMetaElementContent(authorElement, author, insertNewAuthor);
  156.     if (descWasEdited)
  157.       SetMetaElementContent(descriptionElement, description, insertNewDescription);
  158.  
  159.     editorShell.EndBatchChanges();
  160.  
  161.     SaveWindowLocation();
  162.     return true; // do close the window
  163.   }
  164.   return false;
  165. }
  166.  
  167.