home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 October / DPPCPRO1005.ISO / Download / Web Developer / webdeveloper.xpi / chrome / webdeveloper.jar / content / webdeveloper / resize.js < prev    next >
Encoding:
JavaScript  |  2005-03-21  |  4.8 KB  |  117 lines

  1. // Resizes the window to a custom size
  2. function webdeveloper_customWindowSize()
  3. {
  4.     window.openDialog("chrome://webdeveloper/content/dialogs/resize.xul", "webdeveloper-resize-dialog", "centerscreen,chrome,modal", window.outerWidth, window.outerHeight);
  5. }
  6.  
  7. // Displays the resize menu
  8. function webdeveloper_displayResizeMenu(menu, separatorName, tooltips)
  9. {
  10.     const resizeSeparator    = menu.getElementsByAttribute("id", separatorName)[0];
  11.     const preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  12.  
  13.     var description           = null;
  14.     var descriptionPreference = null;
  15.     var height                = null;
  16.     var heightPreference      = null;
  17.     var menuItem              = document.createElement("menuitem");
  18.     var resizeCount           = 0;
  19.     var windowHeight          = window.outerHeight;
  20.     var windowWidth           = window.outerWidth;
  21.     var width                 = null;
  22.     var widthPreference       = null;
  23.  
  24.     // If the resize count preference is set
  25.     if(preferencesService.prefHasUserValue("webdeveloper.resize.count"))
  26.     {
  27.         resizeCount = preferencesService.getIntPref("webdeveloper.resize.count");
  28.     }
  29.  
  30.     webdeveloper_removeGeneratedMenuItems(menu);
  31.  
  32.     // Loop through the possible resize options
  33.     for(var i = 1; i <= resizeCount; i++)
  34.     {
  35.         description = "webdeveloper.resize." + i + ".description";
  36.         height      = "webdeveloper.resize." + i + ".height";
  37.         width       = "webdeveloper.resize." + i + ".width";
  38.  
  39.         // If the description, width and height are set
  40.         if(preferencesService.prefHasUserValue(description) && preferencesService.prefHasUserValue(width) && preferencesService.prefHasUserValue(height))
  41.         {
  42.             descriptionPreference = preferencesService.getComplexValue(description, Components.interfaces.nsISupportsString).data.trim();
  43.  
  44.             // If the description is not blank
  45.             if(descriptionPreference != "")
  46.             {
  47.                 heightPreference = preferencesService.getIntPref(height);
  48.                 menuItem         = document.createElement("menuitem");
  49.                 widthPreference  = preferencesService.getIntPref(width);
  50.  
  51.                 // If the window values are set to this item's values
  52.                 if(windowWidth == widthPreference && windowHeight == heightPreference)
  53.                 {
  54.                     menuItem.setAttribute("checked", true);
  55.                 }
  56.  
  57.                 menuItem.setAttribute("class", "webdeveloper-generated-menu");
  58.                 menuItem.setAttribute("label", descriptionPreference);
  59.                 menuItem.setAttribute("oncommand", "webdeveloper_resizeWindow(" + widthPreference + ", " + heightPreference + ")");
  60.                 menuItem.setAttribute("type", "radio");
  61.  
  62.                 // If displaying tooltips
  63.                 if(tooltips)
  64.                 {
  65.                     menuItem.setAttribute("tooltiptext", descriptionPreference);
  66.                 }
  67.  
  68.                 menu.insertBefore(menuItem, resizeSeparator);
  69.             }
  70.         }
  71.     }
  72. }
  73.  
  74. // Displays the current window size
  75. function webdeveloper_displayWindowSize()
  76. {
  77.     const stringBundle = document.getElementById("webdeveloper-string-bundle");
  78.  
  79.     alert(stringBundle.getFormattedString("webdeveloper_displayWindowSize", [getBrowser().contentWindow.outerWidth, getBrowser().contentWindow.outerHeight, getBrowser().contentWindow.innerWidth, getBrowser().contentWindow.innerHeight]));
  80. }
  81.  
  82. // Displays the current window size in the title bar
  83. function webdeveloper_displayWindowSizeInTitle(element, applyStyle)
  84. {
  85.     const checked = element.getAttribute("checked");
  86.  
  87.     // If the menu is checked
  88.     if(checked)
  89.     {
  90.         getBrowser().contentDocument.title += " - " + window.outerWidth + "x" + window.outerHeight;
  91.         window.onresize                     = webdeveloper_updateWindowSizeInTitle;
  92.     }
  93.     else
  94.     {
  95.         const title = getBrowser().contentTitle;
  96.  
  97.         getBrowser().contentDocument.title = title.substring(0, title.lastIndexOf(" - "));
  98.         window.onresize                    = null;
  99.     }
  100.  
  101.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/empty.css", "webdeveloper-display-current-size-title", applyStyle);
  102. }
  103.  
  104. // Resizes the window to the given width and height
  105. function webdeveloper_resizeWindow(width, height)
  106. {
  107.     window.resizeTo(width, height);
  108. }
  109.  
  110. // Updates the window size in the title bar
  111. function webdeveloper_updateWindowSizeInTitle()
  112. {
  113.     const title = getBrowser().contentTitle;
  114.  
  115.     getBrowser().contentDocument.title = title.substring(0, title.lastIndexOf(" - ")) + " - " + window.outerWidth + "x" + window.outerHeight;
  116. }
  117.