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 / EdFormProps.js < prev    next >
Text File  |  2003-06-08  |  5KB  |  156 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Form Properties Dialog.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Neil Rashbrook.
  18.  * Portions created by the Initial Developer are Copyright (C) 2001
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s): Neil Rashbrook <neil@parkwaycc.co.uk>
  22.  *
  23.  * Alternatively, the contents of this file may be used under the terms of
  24.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  25.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26.  * in which case the provisions of the GPL or the LGPL are applicable instead
  27.  * of those above. If you wish to allow use of your version of this file only
  28.  * under the terms of either the GPL or the LGPL, and not to allow others to
  29.  * use your version of this file under the terms of the MPL, indicate your
  30.  * decision by deleting the provisions above and replace them with the notice
  31.  * and other provisions required by the GPL or the LGPL. If you do not delete
  32.  * the provisions above, a recipient may use your version of this file under
  33.  * the terms of any one of the MPL, the GPL or the LGPL.
  34.  *
  35.  * ***** END LICENSE BLOCK ***** */
  36.  
  37. var gForm;
  38. var insertNew;
  39. var formElement;
  40. var formActionWarning;
  41.  
  42. function Startup()
  43. {
  44.   var editor = GetCurrentEditor();
  45.   if (!editor)
  46.   {
  47.     window.close();
  48.     return;
  49.   }
  50.  
  51.   gForm = {
  52.     Name:     document.getElementById("FormName"),
  53.     Action:   document.getElementById("FormAction"),
  54.     Method:   document.getElementById("FormMethod"),
  55.     EncType:  document.getElementById("FormEncType"),
  56.     Target:   document.getElementById("FormTarget")
  57.   }
  58.   gDialog.MoreSection = document.getElementById("MoreSection");
  59.   gDialog.MoreFewerButton = document.getElementById("MoreFewerButton");
  60.   gDialog.RemoveForm = document.getElementById("RemoveForm")
  61.  
  62.   // Get a single selected form element
  63.   var tagName = "form";
  64.   formElement = editor.getSelectedElement(tagName);
  65.   if (!formElement)
  66.     formElement = editor.getElementOrParentByTagName(tagName, editor.selection.anchorNode);
  67.   if (!formElement)
  68.     formElement = editor.getElementOrParentByTagName(tagName, editor.selection.focusNode);
  69.  
  70.   if (formElement)
  71.   {
  72.     // We found an element and don't need to insert one
  73.     insertNew = false;
  74.     formActionWarning = formElement.hasAttribute("action");
  75.   }
  76.   else
  77.   {
  78.     insertNew = true;
  79.     formActionWarning = true;
  80.  
  81.     // We don't have an element selected,
  82.     //  so create one with default attributes
  83.  
  84.     formElement = editor.createElementWithDefaults(tagName);
  85.     if (!formElement)
  86.     {
  87.       dump("Failed to get selected element or create a new one!\n");
  88.       window.close();
  89.       return;
  90.     }
  91.     // Hide button removing existing form
  92.     gDialog.RemoveForm.hidden = true;
  93.   }
  94.  
  95.   // Make a copy to use for AdvancedEdit
  96.   globalElement = formElement.cloneNode(false);
  97.  
  98.   InitDialog();
  99.  
  100.   InitMoreFewer();
  101.  
  102.   SetTextboxFocus(gForm.Name);
  103.  
  104.   SetWindowLocation();
  105. }
  106.  
  107. function InitDialog()
  108. {
  109.   for (var attribute in gForm)
  110.     gForm[attribute].value = globalElement.getAttribute(attribute);
  111. }
  112.  
  113. function RemoveForm()
  114. {
  115.   RemoveElementKeepingChildren(formElement);
  116.   SaveWindowLocation();
  117.   window.close();
  118. }
  119.  
  120. function ValidateData()
  121. {
  122.   for (var attribute in gForm)
  123.   {
  124.     if (gForm[attribute].value)
  125.       globalElement.setAttribute(attribute, gForm[attribute].value);
  126.     else
  127.       globalElement.removeAttribute(attribute);
  128.   }
  129.   return true;
  130. }
  131.  
  132. function onAccept()
  133. {
  134.   if (formActionWarning && !gForm.Action.value)
  135.   {
  136.     AlertWithTitle(GetString("Alert"), GetString("NoFormAction"));
  137.     gForm.Action.focus();
  138.     formActionWarning = false;
  139.     return false;
  140.   }
  141.   // All values are valid - copy to actual element in doc or
  142.   //   element created to insert
  143.   ValidateData();
  144.  
  145.   var editor = GetCurrentEditor();
  146.  
  147.   editor.cloneAttributes(formElement, globalElement);
  148.  
  149.   if (insertNew)
  150.     InsertElementAroundSelection(formElement);
  151.  
  152.   SaveWindowLocation();
  153.  
  154.   return true;
  155. }
  156.