home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / comm.jar / content / editor / EdInsSrc.js < prev    next >
Encoding:
JavaScript  |  2001-03-21  |  1.9 KB  |  65 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is mozilla.org code.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation.  Portions created by Netscape are
  17.  * Copyright (C) 1998 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  */
  22.  
  23. /* Insert Source HTML dialog */
  24. var srcInput;
  25.  
  26. // dialog initialization code
  27. function Startup()
  28. {
  29.   if (!InitEditorShell())
  30.     return;
  31.   doSetOKCancel(onOK, onCancel);
  32.   var okButton = document.getElementById("ok");
  33.   if (okButton)
  34.   {
  35.     okButton.removeAttribute("default");
  36.     okButton.setAttribute("label",GetString("Insert"));
  37.   }
  38.   // Create dialog object to store controls for easy access
  39.   srcInput = document.getElementById("srcInput");
  40.  
  41.   var selection = editorShell.GetContentsAs("text/html", 35);
  42.   selection = (selection.replace(/<body[^>]*>/,"")).replace(/<\/body>/,"");
  43.   if (selection != "")
  44.     srcInput.value = selection;
  45.  
  46.   // Set initial focus
  47.   srcInput.focus();
  48.   // Note: We can't set the caret location in a multiline textbox
  49.   SetWindowLocation();
  50. }
  51.  
  52. function onOK()
  53. {
  54.   if (srcInput.value != "")
  55.     editorShell.InsertSource(srcInput.value);
  56.   else {
  57.     dump("Null value -- not inserting in HTML Source dialog\n");
  58.     return false;
  59.   }
  60.   SaveWindowLocation();
  61.  
  62.   return true;
  63. }
  64.  
  65.