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 / EdLabelProps.js < prev    next >
Text File  |  2003-06-08  |  4KB  |  151 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 Label 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 labelElement;
  38.  
  39. // dialog initialization code
  40.  
  41. function Startup()
  42. {
  43.   var editor = GetCurrentEditor();
  44.   if (!editor)
  45.   {
  46.     dump("Failed to get active editor!\n");
  47.     window.close();
  48.     return;
  49.   }
  50.  
  51.   gDialog.editText = document.getElementById("EditText");
  52.   gDialog.labelText = document.getElementById("LabelText");
  53.   gDialog.labelFor = document.getElementById("LabelFor");
  54.   gDialog.labelAccessKey = document.getElementById("LabelAccessKey");
  55.  
  56.   labelElement = window.arguments[0];
  57.  
  58.   // Make a copy to use for AdvancedEdit
  59.   globalElement = labelElement.cloneNode(false);
  60.  
  61.   InitDialog();
  62.  
  63.   try {
  64.     editor.selectElement(labelElement);
  65.     gDialog.labelText.value = GetSelectionAsText();
  66.   } catch (e) {}
  67.  
  68.   if (/</.test(labelElement.innerHTML))
  69.   {
  70.     gDialog.editText.checked = false;
  71.     gDialog.editText.disabled = false;
  72.     gDialog.labelText.disabled = true;
  73.     gDialog.editText.addEventListener("command", onEditText, false);
  74.     SetTextboxFocus(gDialog.labelFor);
  75.   }
  76.   else
  77.     SetTextboxFocus(gDialog.labelText);
  78.  
  79.   SetWindowLocation();
  80. }
  81.  
  82. function InitDialog()
  83. {
  84.   gDialog.labelFor.value = globalElement.getAttribute("for");
  85.   gDialog.labelAccessKey.value = globalElement.getAttribute("accesskey");
  86. }
  87.  
  88. function onEditText()
  89. {
  90.   gDialog.editText.removeEventListener("command", onEditText, false);
  91.   AlertWithTitle(GetString("Alert"), GetString("EditTextWarning"));
  92. }
  93.  
  94. function RemoveLabel()
  95. {
  96.   // RemoveTextProperty might work
  97.   // but only because the label was selected to get its text
  98.   RemoveElementKeepingChildren(labelElement);
  99.   SaveWindowLocation();
  100.   window.close();
  101. }
  102.  
  103. function ValidateData()
  104. {
  105.   if (gDialog.labelFor.value)
  106.     globalElement.setAttribute("for", gDialog.labelFor.value);
  107.   else
  108.     globalElement.removeAttribute("for");
  109.   if (gDialog.labelAccessKey.value)
  110.     globalElement.setAttribute("accesskey", gDialog.labelAccessKey.value);
  111.   else
  112.     globalElement.removeAttribute("accesskey");
  113.   return true;
  114. }
  115.  
  116. function onAccept()
  117. {
  118.   // All values are valid - copy to actual element in doc
  119.   ValidateData();
  120.  
  121.   var editor = GetCurrentEditor();
  122.  
  123.   editor.beginTransaction();
  124.  
  125.   try {
  126.     if (gDialog.editText.checked)
  127.     {
  128.       editor.setShouldTxnSetSelection(false);
  129.  
  130.       while (labelElement.firstChild)
  131.         editor.deleteNode(labelElement.firstChild);
  132.       if (gDialog.labelText.value) {
  133.         var textNode = editor.document.createTextNode(gDialog.labelText.value);
  134.         editor.insertNode(textNode, labelElement, 0);
  135.         editor.selectElement(labelElement);
  136.       }
  137.  
  138.       editor.setShouldTxnSetSelection(true);
  139.     }
  140.  
  141.     editor.cloneAttributes(labelElement, globalElement);
  142.   } catch(e) {}
  143.  
  144.   editor.endTransaction();
  145.  
  146.   SaveWindowLocation();
  147.  
  148.   return true;
  149. }
  150.  
  151.