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 / communicator / pref / pref-scripts.js < prev    next >
Text File  |  2003-06-08  |  8KB  |  183 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  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 Mozilla.org Code.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Doron Rosenberg.
  18.  * Portions created by the Initial Developer are Copyright (C) 2001
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Jonas J°rgensen <jonasj@jonasj.dk>
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. const pref = Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPref);
  39.  
  40. // need it globally, but can only set it in startup()
  41. var data;
  42.  
  43. function changeDisabledState(state){
  44.   //Set the states of the groupbox children state based on the "javascript enabled" checkbox value
  45.   document.getElementById("allowScripts").disabled = state;
  46.   document.getElementById("allowWindowMoveResize").disabled = state;
  47.   document.getElementById("allowImageSrcChange").disabled = state;
  48.   document.getElementById("allowDocumentCookieSet").disabled = state;
  49.   document.getElementById("allowDocumentCookieGet").disabled = state;
  50.   document.getElementById("allowWindowStatusChange").disabled = state;
  51.   document.getElementById("allowWindowFlip").disabled = state;
  52.   document.getElementById("allowHideStatusBar").disabled = state;
  53. }
  54.  
  55. function javascriptEnabledChange(){
  56.   // if javascriptAllowMailNews is overlayed (mailnews is installed), then if javascriptAllowMailnews 
  57.   // and javascriptAllowNavigator are unchecked, we disable the tree items. 
  58.   // If javascriptAllowMailNews is not available, we only take javascriptAllowNavigator in consideration
  59.  
  60.   if (document.getElementById('javascriptAllowMailNews')){
  61.     if (!document.getElementById('javascriptAllowNavigator').checked && !document.getElementById('javascriptAllowMailNews').checked)
  62.       changeDisabledState(true);
  63.     else changeDisabledState(false);
  64.   } else {
  65.     changeDisabledState(!document.getElementById('javascriptAllowNavigator').checked);
  66.   }
  67. }
  68.  
  69. function getPrefValueForCheckbox(prefName){
  70.   var prefValue = false;
  71.  
  72.   try {
  73.     prefValue = pref.GetBoolPref(prefName);
  74.   }
  75.   catch(e) {}
  76.  
  77.   // the prefs are stored in terms of disabling,
  78.   // but we want our value in terms of enabling.
  79.   // so let's invert the prefValue.
  80.   return !prefValue;
  81. }
  82.  
  83. function Startup(){
  84.  
  85.   data = parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-scripts.xul"];
  86.  
  87.   //If scriptData does not exist, then it is the first time the panel was shown and we default to false 
  88.   if (!("scriptData" in data)){
  89.     var changedList = ["allowWindowMoveResizeChanged",
  90.                        "allowWindowStatusChangeChanged",
  91.                        "allowWindowFlipChanged",
  92.                        "allowDocumentCookieSetChanged",
  93.                        "allowDocumentCookieGetChanged",
  94.                        "allowImageSrcChangeChanged",
  95.                        "allowHideStatusBarChanged"];
  96.  
  97.     data.scriptData = [];
  98.     for(var run = 0; run < changedList.length; run++ ){
  99.       data.scriptData[ changedList[run] ] = [];
  100.       data.scriptData[ changedList[run] ].value = false;
  101.     }
  102.  
  103.     document.getElementById("allowWindowMoveResize").checked =  getPrefValueForCheckbox("dom.disable_window_move_resize");
  104.     document.getElementById("allowWindowFlip").checked = getPrefValueForCheckbox("dom.disable_window_flip");
  105.     document.getElementById("allowWindowStatusChange").checked = getPrefValueForCheckbox("dom.disable_window_status_change");
  106.     document.getElementById("allowImageSrcChange").checked = getPrefValueForCheckbox("dom.disable_image_src_set");
  107.     document.getElementById("allowDocumentCookieGet").checked = getPrefValueForCheckbox("dom.disable_cookie_get");
  108.     document.getElementById("allowDocumentCookieSet").checked = getPrefValueForCheckbox("dom.disable_cookie_set");
  109.     document.getElementById("allowHideStatusBar").checked = getPrefValueForCheckbox("dom.disable_window_open_feature.status");
  110.  
  111.     //If we don't have a checkbox under groupbox pluginPreferences, we should hide it
  112.     var pluginGroup = document.getElementById("pluginPreferences")
  113.     var children = pluginGroup.childNodes;
  114.     if (!children || children.length <= 1)    // 1 for the caption
  115.       pluginGroup.setAttribute("hidden", "true");
  116.   }
  117.  
  118.   javascriptEnabledChange();
  119.  
  120.   document.getElementById("AllowList").addEventListener("CheckboxStateChange", onCheckboxCheck, false);
  121.  
  122.   parent.hPrefWindow.registerOKCallbackFunc(doOnOk);
  123. }
  124.  
  125. function doOnOk(){
  126.  
  127.   //If a user makes a change to this panel, goes to another panel, and returns to this panel to 
  128.   //make another change, then we cannot use data[elementName].  This is because data[elementName] 
  129.   //contains the original xul change and we would loose the new change. Thus we track all changes
  130.   //by using getElementById.
  131.  
  132.   //The nested functions are needed because doOnOk cannot access anything outside of its scope
  133.   //when it is called 
  134.   function getCheckboxValue(name){
  135.     if ("onCheckboxCheck" in window)
  136.       return document.getElementById(name).checked;
  137.  
  138.     return data[name].checked;
  139.   }
  140.  
  141.   var data = parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-scripts.xul"];
  142.  
  143.   if (data.scriptData["allowWindowMoveResizeChanged"].value){
  144.     parent.hPrefWindow.setPref("bool", "dom.disable_window_move_resize",
  145.       !getCheckboxValue('allowWindowMoveResize'));
  146.   }
  147.  
  148.   if (data.scriptData["allowWindowStatusChangeChanged"].value){
  149.     parent.hPrefWindow.setPref("bool", "dom.disable_window_status_change",
  150.       !getCheckboxValue("allowWindowStatusChange"));
  151.   }
  152.  
  153.   if (data.scriptData["allowWindowFlipChanged"].value){
  154.     parent.hPrefWindow.setPref("bool", "dom.disable_window_flip",
  155.       !getCheckboxValue("allowWindowFlip"));
  156.   }
  157.  
  158.   if (data.scriptData["allowDocumentCookieSetChanged"].value){
  159.     parent.hPrefWindow.setPref("bool", "dom.disable_cookie_set",
  160.       !getCheckboxValue("allowDocumentCookieSet"));
  161.   }
  162.  
  163.   if (data.scriptData["allowDocumentCookieGetChanged"].value){
  164.     parent.hPrefWindow.setPref("bool", "dom.disable_cookie_get",
  165.       !getCheckboxValue("allowDocumentCookieGet"));
  166.   } 
  167.  
  168.   if (data.scriptData["allowImageSrcChangeChanged"].value){
  169.     parent.hPrefWindow.setPref("bool", "dom.disable_image_src_set",
  170.       !getCheckboxValue("allowImageSrcChange"));
  171.   }
  172.  
  173.   if (data.scriptData["allowHideStatusBarChanged"].value) {
  174.     parent.hPrefWindow.setPref("bool", "dom.disable_window_open_feature.status",
  175.       !getCheckboxValue("allowHideStatusBar"));
  176.   }
  177. }
  178.  
  179. function onCheckboxCheck(event)
  180. {
  181.   data.scriptData[event.target.id+"Changed"].value = !data.scriptData[event.target.id+"Changed"].value;
  182. }
  183.