15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 2 ✦ Window and Frame Objects (Chapter 16)<br />

returned by the showModelessWindow() method. The variable gets used to invoke<br />

the init() function inside the modeless dialog box, but also as conditions in an if<br />

construction surrounding the generation of the dialog box. The reason this is<br />

needed is to prevent multiple instances of the dialog box being created (the button<br />

is still alive while the modeless window is showing). The dialog box won’t be created<br />

again as long as there is a value in prefsDlog, and the dialog box window has not<br />

been closed (picking up the window.closed property of the dialog box window).<br />

The showModelessDialog() method’s second parameter is a reference to the<br />

function in the main window that updates the main document. As you see in a<br />

moment, that function is invoked from the dialog box when the user clicks the OK<br />

or Apply buttons.<br />

Listing 16-41: Main Page for showModelessDialog()<br />

<br />

<br />

window.setModelessDialog() Method<br />

<br />

var currPrefs = new Array()<br />

var prefsDlog<br />

function getPrefsData() {<br />

if (!prefsDlog || prefsDlog.closed) {<br />

prefsDlog = showModelessDialog(“lst16-42.htm”, setPrefs,<br />

“dialogWidth:400px; dialogHeight:300px”)<br />

prefsDlog.init(currPrefs)<br />

}<br />

}<br />

function setPrefs(prefs) {<br />

if (prefs[“bgColor”]) {<br />

document.body.style.backgroundColor = prefs[“bgColor”]<br />

currPrefs[“bgColor”] = prefs[“bgColor”]<br />

}<br />

if (prefs[“textColor”]) {<br />

document.body.style.color = prefs[“textColor”]<br />

currPrefs[“textColor”] = prefs[“textColor”]<br />

}<br />

if (prefs[“h1Size”]) {<br />

document.all.welcomeHeader.style.fontSize = prefs[“h1Size”]<br />

currPrefs[“h1Size”] = prefs[“h1Size”]<br />

}<br />

if (prefs[“name”]) {<br />

document.all.firstName.innerText = prefs[“name”]<br />

currPrefs[“name”] = prefs[“name”]<br />

}<br />

}<br />

function init() {<br />

document.all.firstName.innerText = “friend”<br />

}<br />

<br />

Continued<br />

183<br />

windowObject.showModalDialog()

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!