adding parameter passing examples

This commit is contained in:
danm%netscape.com 1999-05-17 19:21:35 +00:00
Родитель 0a1f41b7dc
Коммит 12a6b27bef
4 изменённых файлов: 329 добавлений и 6 удалений

Просмотреть файл

@ -26,10 +26,12 @@ include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk
EXPORT_RESOURCE_SAMPLES = \
$(srcdir)/dexsimplemaster.xul \
$(srcdir)/dexsimpledialog.xul \
$(srcdir)/dexanimmaster.xul \
$(srcdir)/dexanimdialog.xul \
$(srcdir)/dexparammaster.xul \
$(srcdir)/dexparamdialog.xul \
$(srcdir)/dexsimplemaster.xul \
$(srcdir)/dexsimpledialog.xul \
$(NULL)
install::

Просмотреть файл

@ -0,0 +1,221 @@
<?xml version="1.0"?>
<?xml-stylesheet href="xul.css" type="text/css"?>
<!DOCTYPE window>
<!-- dialog containing a control requiring initial setup -->
<xul:window
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload = "SetFromParams()"
title = "Things to do"
height = "200" width = "300">
<html:script>
<![CDATA[
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");
}
]]>
</html:script>
<html:table>
<html:tr>
<html:td html:id="prompt">Give me your money</html:td>
</html:tr>
<html:tr>
<html:td>
<!-- note the html namespace on the id attribute, which
seems at this time to be required by getAttribute() -->
<html:input type="checkbox" html:id="remind"/>Remind me
</html:td>
</html:tr>
<html:tr>
<html:td>
<html:button onclick="DoOK()">OK</html:button>
</html:td>
</html:tr>
<html:tr>
<html:td>
<html:button onclick="SetFromURL()">Startup from URL</html:button>
</html:td>
</html:tr>
<html:tr>
<html:td>
<html:button onclick="SetFromParams()">Startup from Params</html:button>
</html:td>
</html:tr>
<html:tr>
<html:td>
<html:button onclick="DumpWindow()">Dump Window</html:button>
</html:td>
</html:tr>
</html:table>
</xul:window>

Просмотреть файл

@ -0,0 +1,96 @@
<?xml version="1.0"?>
<?xml-stylesheet href="xul.css" type="text/css"?>
<!DOCTYPE window>
<!-- Simple sample interface for bringing up a nonmodal dialog -->
<xul:window
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:xul ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title = "Dialog creation sample">
<html:script>
<![CDATA[
var dialogWindow = null;
// show a nonmodal dialog, sending parameters as part of the URL
function MakeURLDialog() {
var newWin = window.open("resource://res/samples/dexparamdialog.xul?remind=true;prompt=Give me your money and convertible bonds", "New");
return newWin;
}
// show a nonmodal dialog, sending parameters as part of the function call
function MakeParamDialog() {
var newWin = window.openDialog("resource://res/samples/dexparamdialog.xul",
"New", "chrome", {remind:true, prompt:"Give me your money and convertible bonds"});
return newWin;
}
// show a modal dialog (requires toolkit core for now)
function ModalDialog() {
var toolkitCore = GetToolkitCore();
if (toolkitCore)
toolkitCore.ShowModalDialog("resource://res/samples/dexparamdialog.xul",
window);
}
// find and load the toolkit core
function GetToolkitCore() {
var toolkitCore = XPAppCoresManager.Find("ToolkitCore");
if (!toolkitCore) {
toolkitCore = new ToolkitCore();
if (toolkitCore)
toolkitCore.Init("ToolkitCore");
}
return toolkitCore;
}
// dump the contents of a JS object
function Regurgitate(what, explain) {
dump("***regurgitating " + explain + ": " + what + "\n");
for (prop in what) {
dump(" property '" + prop + "' = '" + what[prop] + "'\n");
var subarg = what[prop];
dump(" length "+subarg.length+"\n");
for (subprop in subarg)
dump(" subarg property '"+subprop+"' = '"+subarg[subprop]+"'\n");
}
dump("regurgitated.\n");
}
// just list the properties of a JS object
function ListProperties(what) {
dump("**********************************************\n");
for (prop in what)
dump(prop + "\n");
dump("----------------------------------------------\n");
}
// display a bunch of possibly interesting properties of the last
// dialog window we saw
function DumpLastDialog() {
ListProperties(dialogWindow);
Regurgitate(dialogWindow.arguments, "sent arguments");
Regurgitate(dialogWindow.returnArguments, "returned arguments");
}
]]>
</html:script>
<xul:toolbox>
<xul:toolbar>
<!-- insert the next line should the bug where buttons don't show up
without an image specified ever return -->
<!-- src="resource:/res/toolbar/TB_Stop.gif" align="bottom" -->
<xul:titledbutton
value="URL Dialog" onclick="dialogWindow=MakeURLDialog()"
style="background-color:rgb(192,192,192);"/>
<xul:titledbutton
value="Param Dialog" onclick="dialogWindow=MakeParamDialog()"
style="background-color:rgb(192,192,192);"/>
<xul:titledbutton
value="Modal Dialog" onclick="ModalDialog()"
style="background-color:rgb(192,192,192);"/>
<xul:titledbutton
value="Dump Window" onclick="DumpLastDialog()"
style="background-color:rgb(192,192,192);"/>
</xul:toolbar>
</xul:toolbox>
</xul:window>

Просмотреть файл

@ -22,13 +22,17 @@ DIRS=sampleimages
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) dexsimplemaster.xul $(DIST)\bin\res\samples
$(MAKE_INSTALL) dexsimpledialog.xul $(DIST)\bin\res\samples
$(MAKE_INSTALL) dexanimmaster.xul $(DIST)\bin\res\samples
$(MAKE_INSTALL) dexanimdialog.xul $(DIST)\bin\res\samples
$(MAKE_INSTALL) dexparammaster.xul $(DIST)\bin\res\samples
$(MAKE_INSTALL) dexparamdialog.xul $(DIST)\bin\res\samples
$(MAKE_INSTALL) dexsimplemaster.xul $(DIST)\bin\res\samples
$(MAKE_INSTALL) dexsimpledialog.xul $(DIST)\bin\res\samples
clobber::
rm -f $(DIST)\res\samples\dexsimplemaster.xul
rm -f $(DIST)\res\samples\dexsimpledialog.xul
rm -f $(DIST)\res\samples\dexanimmaster.xul
rm -f $(DIST)\res\samples\dexanimdialog.xul
rm -f $(DIST)\res\samples\dexparammaster.xul
rm -f $(DIST)\res\samples\dexparamdialog.xul
rm -f $(DIST)\res\samples\dexsimplemaster.xul
rm -f $(DIST)\res\samples\dexsimpledialog.xul