File: dexparamdialog.html

package info (click to toggle)
iceweasel 2.0.0.19-0etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 298,784 kB
  • ctags: 317,912
  • sloc: cpp: 1,796,902; ansic: 987,677; xml: 109,036; makefile: 47,777; asm: 35,201; perl: 26,983; sh: 20,879; cs: 6,232; java: 5,513; python: 3,249; pascal: 459; lex: 306; php: 244; csh: 132; objc: 97; yacc: 79; ada: 49; awk: 14; sql: 4; sed: 4
file content (215 lines) | stat: -rw-r--r-- 7,372 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<html><body>

<script language="javascript">
    var debug = true;
    // Initialize controls from parameters sent through the URL
    function SetFromURL() {
      // dump a bunch of diagnostics
      if (debug) {
        dump("In SetFromURL...\n");
        dump("param string is '" + location.search + "', length " +
            location.search.length + "\n");
        var debugSetting = GetNamedParam(location.search.substring(1,location.search.length), "remind");
        if (debugSetting) {
          dump("'remind' parameter = '" + debugSetting + "'\n");
        } else
          dump("'remind' setting not found\n");
        if (document.getElementById("remind"))
          dump("found 'remind' element in document\n");
        else
          dump("'remind' element missing from document\n");
        dump("Finishing SetFromURL...\n");
      }

      // set checkbox from "remind=xxx" name=value pair
      var params = location.search.substring(1, location.search.length);
      var setting = GetNamedParam(params, "remind");
      if (setting)
        setting = setting.toLowerCase() == "true";
      else
        setting = false;
      var checkbox = document.getElementById("remind");
      if (checkbox)
        checkbox.checked = setting;

      // set prompt text from "prompt=xxx" name=value pair
      var setting = GetNamedParam(params, "prompt");
      control = document.getElementById("prompt");
      if (control && setting) {
        control = control.firstChild;
        if (control && control.nodeType == 3) // TEXT_NODE
          control.data = setting;
      }
    }

    // Initialize controls from parameters sent through openDialog
    function SetFromParams() {
      // dump a bunch of diagnostics
      if (debug) {
        var debugSetting;
        var debugControl;
        dump("In SetFromParams...\n");
        if (window.arguments) {
          dump("arguments exist\n");
          if (window.arguments[0]) {
            dump("  arguments[0] exists\n");
            if (window.arguments[0].remind) {
              dump("  arguments[0].remind exists\n");
              debugSetting = window.arguments[0].remind;
              dump("  it's " + debugSetting +
                ", type " + typeof debugSetting + "\n");
            } else
              dump("arguments[0].remind does not exist\n");
            if (window.arguments[0].prompt) {
              dump("  arguments[0].prompt exists\n");
              debugSetting = window.arguments[0].prompt;
              dump("  it's " + debugSetting +
                ", type " + typeof debugSetting + "\n");
            } else
              dump("arguments[0].prompt does not exist (or it's just false)\n");
          } else
            dump("arguments[0] does not exist\n");
        } else
          dump("no arguments\n");
        debugControl = document.getElementById("remind");
        if (debugControl)
          dump("found 'remind' element in document "+
            typeof debugControl+"\n");
        else
          dump("'remind' element missing from document\n");
        debugControl = document.getElementById("prompt");
        if (debugControl) {
          dump("found 'prompt' element in document "+
            typeof debugControl+"\n");
          debugControl = debugControl.firstChild;
          if (debugControl) {
            dump("found prompt's first child. type " + debugControl.nodeName + "\n");
          } else
            dump("couldn't find prompt's first child\n");
        } else
          dump("'prompt' element missing from document\n");
        dump("Finishing SetFromParams...\n");
      }

      // look in arguments[0] for an object with interesting properties and values
      // set checkbox from its value, if present
      if (window.arguments && window.arguments[0]) {
        var setting;
        var control;
        // set checkbox from the value of argment[0]'s "value" property
        setting = window.arguments[0].remind;
        if (setting) { // (exists and true)
          control = document.getElementById("remind");
          if (control)
            control.checked = setting;
        }
        // set prompt from the value of argment[0]'s "prompt" property
        setting = window.arguments[0].prompt;
        if (setting) {
          if (typeof setting == "string") {
            control = document.getElementById("prompt");
            if (control) {
              control = control.firstChild;
              if (control && control.nodeType == 3) // TEXT_NODE
                control.data = setting;
            }
          }
        }
      }
    }

    // OK button handler
    // return the setting of the "remind" checkbox in two equivalent ways
    // and then close the window (disabled for now, since that crashes)
    function DoOK() {
      var checkbox = document.getElementById("remind");
      if (checkbox) {

        // attach a property to ourselves, which can be queried from outside
        window.returnArguments = checkbox.checked;

        // additionally, if we were given an openDialog parameter, set its value
        if (window.arguments && window.arguments[0])
          window.arguments[0].remind = checkbox.checked;
      }
//    var toolkitCore = GetToolkitCore();
//    if (toolkitCore)
//      toolkitCore.CloseWindow(window);
      window.close();
    }

    function GetToolkitCore() {
      var toolkitCore = XPAppCoresManager.Find("ToolkitCore");
      if (!toolkitCore) {
        toolkitCore = new ToolkitCore();
        if (toolkitCore)
          toolkitCore.Init("ToolkitCore");
      }
      return toolkitCore;
    }

    // params is a list of name=value parameters separated by semicolons
    // or ampersands. To pass parameters containing either character,
    // string together parameters escape()d separately, separated by ;.
    // this function returns the value of the named pair, or null
    // if it found nothing.
    function GetNamedParam(params, name) {
      if (debug)
        dump("GetNamedParam looking for '" + name + "' in '" + params + "'\n");
      var re = new RegExp(name+" *=([^&;]+)");
      var match = re(params);
      if (match) {
        if (debug)
          dump("  matched regexp. found '" + match[1] + "'\n");
        return unescape(match[1]);
      }
      return null;
    }

    function DumpWindow() {
      dump("**********************************************\n");
      for (prop in window)
        dump(prop + "\n");
      dump("----------------------------------------------\n");
    }
  </script>

  <table>
    <tr>
      <td id="prompt">Give me your money</td>
    </tr>
    <tr>
      <td>
        <!-- note the html namespace on the id attribute, which
             seems at this time to be required by getAttribute() -->
        <input type="checkbox" id="remind"/>Remind me
      </td>
    </tr>
    <tr>
      <td>
        <button onclick="DoOK()">OK</button>
      </td>
    </tr>
    <tr>
      <td>
        <button onclick="SetFromURL()">Startup from URL</button>
      </td>
    </tr>
    <tr>
      <td>
        <button onclick="SetFromParams()">Startup from Params</button>
      </td>
    </tr>
    <tr>
      <td>
        <button onclick="DumpWindow()">Dump Window</button>
      </td>
    </tr>
    <tr>
      <td>
        <button onclick="alert('Hello world!')">Show Alert</button>
      </td>
    </tr>
  </table>

</body></html>