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 / EdInsSrc.js < prev    next >
Text File  |  2003-06-08  |  3KB  |  96 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Netscape Public License
  6.  * Version 1.1 (the "License"); you may not use this file except in
  7.  * compliance with the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/NPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is 
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *    Akkana Peck (akkana@netscape.com)
  24.  *    Charles Manske (cmanske@netscape.com)
  25.  *
  26.  *
  27.  * Alternatively, the contents of this file may be used under the terms of
  28.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  29.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  30.  * in which case the provisions of the GPL or the LGPL are applicable instead
  31.  * of those above. If you wish to allow use of your version of this file only
  32.  * under the terms of either the GPL or the LGPL, and not to allow others to
  33.  * use your version of this file under the terms of the NPL, indicate your
  34.  * decision by deleting the provisions above and replace them with the notice
  35.  * and other provisions required by the GPL or the LGPL. If you do not delete
  36.  * the provisions above, a recipient may use your version of this file under
  37.  * the terms of any one of the NPL, the GPL or the LGPL.
  38.  *
  39.  * ***** END LICENSE BLOCK ***** */
  40.  
  41. /* Insert Source HTML dialog */
  42.  
  43. function Startup()
  44. {
  45.   var editor = GetCurrentEditor();
  46.   if (!editor)
  47.   {
  48.     window.close();
  49.     return;
  50.   }
  51.  
  52.   var okButton = document.documentElement.getButton("accept");
  53.   if (okButton)
  54.   {
  55.     okButton.removeAttribute("default");
  56.     okButton.setAttribute("label",GetString("Insert"));
  57.     okButton.setAttribute("accesskey",GetString("InsertAccessKey"));
  58.   }
  59.   // Create dialog object to store controls for easy access
  60.   gDialog.srcInput = document.getElementById("srcInput");
  61.  
  62.   var selection;
  63.   try {
  64.     selection = editor.outputToString("text/html", 35); // OutputWrap+OutputFormatted+OutputSelectionOnly
  65.   } catch (e) {}
  66.   if (selection)
  67.   {
  68.     selection = (selection.replace(/<body[^>]*>/,"")).replace(/<\/body>/,"");
  69.     if (selection)
  70.       gDialog.srcInput.value = selection;
  71.   }
  72.   // Set initial focus
  73.   gDialog.srcInput.focus();
  74.   // Note: We can't set the caret location in a multiline textbox
  75.   SetWindowLocation();
  76. }
  77.  
  78. function onAccept()
  79. {
  80.   if (gDialog.srcInput.value)
  81.   {
  82.     try {
  83.       GetCurrentEditor().insertHTML(gDialog.srcInput.value);
  84.     } catch (e) {}
  85.   }
  86.   else
  87.   {
  88.     dump("Null value -- not inserting in HTML Source dialog\n");
  89.     return false;
  90.   }
  91.   SaveWindowLocation();
  92.  
  93.   return true;
  94. }
  95.  
  96.