home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / res / samples / dexparamdialog.xul < prev    next >
Extensible Markup Language  |  2001-02-14  |  8KB  |  228 lines

  1. <?xml version="1.0"?>
  2. <!DOCTYPE window>
  3. <!-- DO NOT LOCALIZE: this file is source documentation; not part of the build -->
  4. <!-- dialog containing a control requiring initial setup, expecting
  5.      initial settings to be passed in as parameters -->
  6. <xul:window
  7.     xmlns:html="http://www.w3.org/1999/xhtml"
  8.     xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  9.     onload = "SetFromParams()"
  10.     title = "Things to do"
  11.     height = "200" width = "300">
  12.  
  13.   <html:script>
  14.     <![CDATA[
  15.     var debug = true;
  16.     // Initialize controls from parameters sent through the URL
  17.     function SetFromURL() {
  18.       // dump a bunch of diagnostics
  19.       if (debug) {
  20.         dump("In SetFromURL...\n");
  21.         dump("param string is '" + location.search + "', length " +
  22.             location.search.length + "\n");
  23.         var debugSetting = GetNamedParam(location.search.substring(1,location.search.length), "remind");
  24.         if (debugSetting) {
  25.           dump("'remind' parameter = '" + debugSetting + "'\n");
  26.         } else
  27.           dump("'remind' setting not found\n");
  28.         if (document.getElementById("remind"))
  29.           dump("found 'remind' element in document\n");
  30.         else
  31.           dump("'remind' element missing from document\n");
  32.         dump("Finishing SetFromURL...\n");
  33.       }
  34.  
  35.       // set checkbox from "remind=xxx" name=value pair
  36.       var params = location.search.substring(1, location.search.length);
  37.       var setting = GetNamedParam(params, "remind");
  38.       if (setting)
  39.         setting = setting.toLowerCase() == "true";
  40.       else
  41.         setting = false;
  42.       var checkbox = document.getElementById("remind");
  43.       if (checkbox)
  44.         checkbox.checked = setting;
  45.  
  46.       // set prompt text from "prompt=xxx" name=value pair
  47.       var setting = GetNamedParam(params, "prompt");
  48.       control = document.getElementById("prompt");
  49.       if (control && setting) {
  50.         control = control.firstChild;
  51.         if (control && control.nodeType == 3) // TEXT_NODE
  52.           control.data = setting;
  53.       }
  54.     }
  55.  
  56.     // Initialize controls from parameters sent through openDialog
  57.     function SetFromParams() {
  58.       // dump a bunch of diagnostics
  59.       if (debug) {
  60.         var debugSetting;
  61.         var debugControl;
  62.         dump("In SetFromParams...\n");
  63.         if (window.arguments) {
  64.           dump("arguments exist\n");
  65.           if (window.arguments[0]) {
  66.             dump("  arguments[0] exists\n");
  67.             if (window.arguments[0].remind) {
  68.               dump("  arguments[0].remind exists\n");
  69.               debugSetting = window.arguments[0].remind;
  70.               dump("  it's " + debugSetting +
  71.                 ", type " + typeof debugSetting + "\n");
  72.             } else
  73.               dump("arguments[0].remind does not exist\n");
  74.             if (window.arguments[0].prompt) {
  75.               dump("  arguments[0].prompt exists\n");
  76.               debugSetting = window.arguments[0].prompt;
  77.               dump("  it's " + debugSetting +
  78.                 ", type " + typeof debugSetting + "\n");
  79.             } else
  80.               dump("arguments[0].prompt does not exist (or it's just false)\n");
  81.           } else
  82.             dump("arguments[0] does not exist\n");
  83.         } else
  84.           dump("no arguments\n");
  85.         debugControl = document.getElementById("remind");
  86.         if (debugControl)
  87.           dump("found 'remind' element in document "+
  88.             typeof debugControl+"\n");
  89.         else
  90.           dump("'remind' element missing from document\n");
  91.         debugControl = document.getElementById("prompt");
  92.         if (debugControl) {
  93.           dump("found 'prompt' element in document "+
  94.             typeof debugControl+"\n");
  95.           debugControl = debugControl.firstChild;
  96.           if (debugControl) {
  97.             dump("found prompt's first child. type " + debugControl.nodeName + "\n");
  98.           } else
  99.             dump("couldn't find prompt's first child\n");
  100.         } else
  101.           dump("'prompt' element missing from document\n");
  102.         dump("Finishing SetFromParams...\n");
  103.       }
  104.  
  105.       // look in arguments[0] for an object with interesting properties and values
  106.       // set checkbox from its value, if present
  107.       if (window.arguments && window.arguments[0]) {
  108.         var setting;
  109.         var control;
  110.         // set checkbox from the value of argment[0]'s "value" property
  111.         setting = window.arguments[0].remind;
  112.         if (setting) { // (exists and true)
  113.           control = document.getElementById("remind");
  114.           if (control)
  115.             control.checked = setting;
  116.         }
  117.         // set prompt from the value of argment[0]'s "prompt" property
  118.         setting = window.arguments[0].prompt;
  119.         if (setting) {
  120.           if (typeof setting == "string") {
  121.             control = document.getElementById("prompt");
  122.             if (control) {
  123.               control = control.firstChild;
  124.               if (control && control.nodeType == 3) // TEXT_NODE
  125.                 control.data = setting;
  126.             }
  127.           }
  128.         }
  129.       }
  130.     }
  131.  
  132.     // OK button handler
  133.     // return the setting of the "remind" checkbox in two equivalent ways
  134.     // and then close the window (disabled for now, since that crashes)
  135.     function DoOK() {
  136.       var checkbox = document.getElementById("remind");
  137.       if (checkbox) {
  138.  
  139.         // attach a property to ourselves, which can be queried from outside
  140.         window.returnArguments = checkbox.checked;
  141.  
  142.         // additionally, if we were given an openDialog parameter, set its value
  143.         if (window.arguments && window.arguments[0])
  144.           window.arguments[0].remind = checkbox.checked;
  145.       }
  146. //    var toolkitCore = GetToolkitCore();
  147. //    if (toolkitCore)
  148. //      toolkitCore.CloseWindow(window);
  149.       window.close();
  150.     }
  151.  
  152.     function GetToolkitCore() {
  153.       var toolkitCore = XPAppCoresManager.Find("ToolkitCore");
  154.       if (!toolkitCore) {
  155.         toolkitCore = new ToolkitCore();
  156.         if (toolkitCore)
  157.           toolkitCore.Init("ToolkitCore");
  158.       }
  159.       return toolkitCore;
  160.     }
  161.  
  162.     // params is a list of name=value parameters separated by semicolons
  163.     // or ampersands. To pass parameters containing either character,
  164.     // string together parameters escape()d separately, separated by ;.
  165.     // this function returns the value of the named pair, or null
  166.     // if it found nothing.
  167.     function GetNamedParam(params, name) {
  168.       if (debug)
  169.         dump("GetNamedParam looking for '" + name + "' in '" + params + "'\n");
  170.       var re = new RegExp(name+" *=([^&;]+)");
  171.       var match = re(params);
  172.       if (match) {
  173.         if (debug)
  174.           dump("  matched regexp. found '" + match[1] + "'\n");
  175.         return unescape(match[1]);
  176.       }
  177.       return null;
  178.     }
  179.  
  180.     function DumpWindow() {
  181.       dump("**********************************************\n");
  182.       for (prop in window)
  183.         dump(prop + "\n");
  184.       dump("----------------------------------------------\n");
  185.     }
  186.     ]]>
  187.   </html:script>
  188.  
  189.   <html:table>
  190.     <html:tr>
  191.       <html:td html:id="prompt">Give me your money</html:td>
  192.     </html:tr>
  193.     <html:tr>
  194.       <html:td>
  195.         <!-- note the html namespace on the id attribute, which
  196.              seems at this time to be required by getAttribute() -->
  197.         <html:input type="checkbox" html:id="remind"/>Remind me
  198.       </html:td>
  199.     </html:tr>
  200.     <html:tr>
  201.       <html:td>
  202.         <html:button onclick="DoOK()">OK</html:button>
  203.       </html:td>
  204.     </html:tr>
  205.     <html:tr>
  206.       <html:td>
  207.         <html:button onclick="SetFromURL()">Startup from URL</html:button>
  208.       </html:td>
  209.     </html:tr>
  210.     <html:tr>
  211.       <html:td>
  212.         <html:button onclick="SetFromParams()">Startup from Params</html:button>
  213.       </html:td>
  214.     </html:tr>
  215.     <html:tr>
  216.       <html:td>
  217.         <html:button onclick="sizeToContent()">Size To Content</html:button>
  218.       </html:td>
  219.     </html:tr>
  220.     <html:tr>
  221.       <html:td>
  222.         <html:button onclick="DumpWindow()">Dump Window</html:button>
  223.       </html:td>
  224.     </html:tr>
  225.   </html:table>
  226.  
  227. </xul:window>
  228.