Commit 12f02196 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading

9780596004675

0 → 120000
+1 −0
Changes for 9780596004675: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
9780596004675
 No newline at end of file

README.md

0 → 100644
+15 −0
Changes for README.md: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
## Example files for the title:  
  
# JavaScript & DHTML Cookbook, by Danny Goodman
  
[![JavaScript & DHTML Cookbook, by Danny Goodman](http://akamaicovers.oreilly.com/images/9780596004675/cat.gif)](https://www.safaribooksonline.com/library/view/title/0596004672//)
  
The following applies to example files from material published by O’Reilly Media, Inc. Content from other publishers may include different rules of usage. Please refer to any additional usage rights explained in the actual example files or refer to the publisher’s website.
  
O'Reilly books are here to help you get your job done. In general, you may use the code in O'Reilly books in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from our books does not require permission. Answering a question by citing our books and quoting example code does not require permission. On the other hand, selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Incorporating a significant amount of example code from our books into your product's documentation does require permission.
  
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN.
  
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <permissions@oreilly.com>.
  
Please note that the examples are not production code and have not been carefully testing. They are provided "as-is" and come with no warranty of any kind.
+6 KiB

File added.

No diff preview for this file type.

+47 −0
Changes for jsdhtmlcb-examples/14-03a.txt: 47 added lines, 0 removed lines.
Original line number Diff line number Diff line
var isMac = (navigator.userAgent.indexOf("Mac") != -1);
var isIEMac = (isMac && navigator.appName == "Microsoft Internet Explorer");
var isSafari = (navigator.userAgent.indexOf("Safari") != -1);

// let page's onload handle first time out for IE/Mac and Safari
function fauxLoad(elemID) {
    if (isIEMac || isSafari) {
        setTimeout("adjustIFrameSize('" + elemID + "')", 1000);
    }
}

// invoked from iframe's onload event handler
function adjustIFrameSize(elemID) {
    var myIframe = document.getElementById(elemID);
    if (myIframe) {
    	// Safari needs timeout, so group them all together
        setTimeout("finishSizing('" + elemID + "')", 50);
    }
}

// size the iframe to its content (browser willing)
function finishSizing(elemID) {
    var myIframe = document.getElementById(elemID);
    if (myIframe.contentDocument && myIframe.contentDocument.body.offsetHeight) {
        // W3C DOM (NN6+/Mozilla/Safari) syntax; Safari needs timeout
        myIframe.style.height = myIframe.contentDocument.body.offsetHeight + "px";    
    } else if (myIframe.Document && myIframe.Document.body.scrollHeight) {
       // IE/Windows DOM syntax
        myIframe.style.height = myIframe.Document.body.scrollHeight + "px";
    } else if (myIframe.document && myIframe.document.body.offsetHeight) {
        // IE/Mac DOM syntax -- if only it worked :-(
       myIframe.style.height = myIframe.document.body.offsetHeight + "px";
    }
}

----------

<body onload = "fauxLoad('myFrame')">



<iframe id="myFrame" frameborder="0" vspace="0" hspace="0" marginwidth="0" 
marginheight="0" width="100%" src="http://www.dannyg.com/new.html" scrolling="no" 
style="overflow:visible" onload="adjustIFrameSize(this.id)"></iframe>


----------
+107 −0
Changes for jsdhtmlcb-examples/Example8_1.txt: 107 added lines, 0 removed lines.
Original line number Diff line number Diff line
// validates that the field value string has one or more characters in it
function isNotEmpty(elem) {
    var str = elem.value;
    if(str == null || str.length == 0) {
        alert("Please fill in the required field.")
        return false;
    } else {
        return true;
    }
}

// validates that the entry is a positive or negative number
function isNumber(elem) {
    var str = elem.value;
    var oneDecimal = false;
    var oneChar = 0;
    // make sure value hasn't cast to a number data type
    str = str.toString();
    for (var i = 0; i < str.length; i++) {
        oneChar = str.charAt(i).charCodeAt(0);
        // OK for minus sign as first character
        if (oneChar == 45) {
            if (i == 0) {
                continue;
            } else {
                alert("Only the first character may be a minus sign.");
                return false;
            }
        }
        // OK for one decimal point
        if (oneChar == 46) {
            if (!oneDecimal) {
                oneDecimal = true;
                continue;
            } else {
                alert("Only one decimal is allowed in a number.");
                return false;
            }
        }
        // characters outside of 0 through 9 not OK
        if (oneChar < 48 || oneChar > 57) {
            alert("Enter only numbers into the field.");
            return false;
        }
    }
    return true;
}
// validates that the entry is 16 characters long
function isLen16((elem) {
    var str = elem.value;
    if (str.length != 16) {
        alert("Entry does not contain the required 16 characters.");
        return false;
    } else {
        return true;
    }
}
// validates that the entry is formatted as an email address
function isEMailAddr(elem) {
    var str = elem.value;
    str = str.toLowerCase();
    if (str.indexOf("@") > 1) {
        var addr = str.substring(0, str.indexOf("@"));
        var domain = str.substring(str.indexOf("@") + 1, str.length);
        // at least one top level domain required
        if (domain.indexOf(".") == -1) {
            alert("Verify the domain portion of the email address.");
            return false;
        }
        // parse address portion first, character by character
        for (var i = 0; i < addr.length; i++) {
            oneChar = addr.charAt(i).charCodeAt(0);
            // dot or hyphen not allowed in first position; dot in last
            if ((i == 0 && (oneChar == 45 || oneChar == 46))  || 
                (i == addr.length - 1 && oneChar == 46)) {
                alert("Verify the user name portion of the email address.");
                return false;
            }
            // acceptable characters (- . _ 0-9 a-z)
            if (oneChar == 45 || oneChar == 46 || oneChar == 95 || 
                (oneChar > 47 && oneChar < 58) || (oneChar > 96 && oneChar < 123)) {
                continue;
            } else {
                alert("Verify the user name portion of the email address.");
                return false;
            }
        }
        for (i = 0; i < domain.length; i++) {
            oneChar = domain.charAt(i).charCodeAt(0);
            if ((i == 0 && (oneChar == 45 || oneChar == 46)) || 
                ((i == domain.length - 1  || i == domain.length - 2) && oneChar == 46)) {
                alert("Verify the domain portion of the email address.");
                return false;
            }
            if (oneChar == 45 || oneChar == 46 || oneChar == 95 || 
                (oneChar > 47 && oneChar < 58) || (oneChar > 96 && oneChar < 123)) {
                continue;
            } else {
                alert("Verify the domain portion of the email address.");
                return false;
            }
        }
        return true;
    }
    alert("The email address may not be formatted correctly. Please verify.");
    return false;
}
Loading