Chapter 1
Introduction to web development
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 1 Objectives Applied 1. Run JavaScript applications that are on the Internet, your computer, or a local server by loading their HTML documents into your browser. 2. Use a text editor or IDE like Aptana Studio 3 to edit HTML, CSS, and JavaScript files. 3. If you’re using an IDE like Aptana Studio 3 that lets you run applications from it, run an application from the IDE.
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 2 Objectives (continued) Knowledge 1. Describe the components of a web application. 2. Describe HTTP requests and responses. 3. Distinguish between the way a web server processes static web pages and dynamic web pages. 4. Describe the use of JavaScript and jQuery. 5. Describe the use of HTML and CSS. 6. Distinguish between the HTML div and span elements and the HTML5 semantic elements. 7. Describe the use of these HTML attributes: id, class, title, for, and name.
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 3 Objectives (continued) 8. Describe the coding for these types of CSS selectors: type, id, and class. 9. Describe the components of a CSS rule set. 10. Describe the components of a URL. 11. Describe the issue of cross-browser compatibility as it relates to the development of web pages and JavaScript applications. 12. In general terms, describe the two workarounds for using the HTML5 semantic elements with old browsers.
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 4 The components of a web application
`
Computer
The Internet
Web Server Tablet
Smart Phone
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 5 Terms • client • web server • network • intranet • local area network (LAN) • Internet • wide area network (WAN) • Internet Service Provider (ISP)
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 6 A static web page at http://www.modulemedia.com/ourwork/index.html
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 7 How a web server processes a static web page
Terms • Hypertext Markup Language (HTML) • static web page • HTTP request • HTTP response • rendering a page
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 8 A dynamic web page at amazon.com
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 9 How a web server processes a dynamic web page
Terms • dynamic web page • application server • database server • round trip
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 10 A web page with image swaps and rollovers
Image Image rollover swap
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 11 How JavaScript fits into this architecture
Terms • scripting language • JavaScript engine • jQuery • client-side processing • server-side processing
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 12 Some of the uses of JavaScript and jQuery • Data validation • Image swaps and rollovers • Accordions • Carousels • Slide shows • Collapsible panels • Tabs
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 13 An HTML file (index.html) in a browser after CSS has been applied to it
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 14 The code for the HTML file named index.html
Please join our email list
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 16 The code for the CSS file named email_list.css
body { font-family: Arial, Helvetica, sans-serif; background-color: white; margin: 0 auto; width: 650px; border: 3px solid blue; } h1 { color: blue; } section { padding: 0 2em 1em; }
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 17 The CSS file named email_list.css (continued)
label { float: left; width: 11em; text-align: right; } input { margin-left: 1em; margin-bottom: .5em; } span { color: red; }
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 18 The web page in a browser with JavaScript used for data validation
The HTML script element for the JavaScript file
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 19 The code for the JavaScript file (email_list.js) var $ = function (id) { return document.getElementById(id); } var joinList = function () { var emailAddress1 = $("email_address1").value; var emailAddress2 = $("email_address2").value; var isValid = true;
if (emailAddress1 == "") { $("email_address1_error").firstChild.nodeValue = "This field is required."; isValid = false; } else { $("email_address1_error").firstChild.nodeValue = ""; }
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 20 The JavaScript file (continued) if (emailAddress1 !== emailAddress2) { $("email_address2_error").firstChild.nodeValue = "This entry must equal first entry."; isValid = false; } else { $("email_address2_error").firstChild.nodeValue = ""; }
if ($("first_name").value == "") { $("first_name_error").firstChild.nodeValue = "This field is required."; isValid = false; } else { $("first_name_error").firstChild.nodeValue = ""; }
if (isValid) { $("email_form").submit(); } } window.onload = function () { $("join_list").onclick = joinList; $("email_address").focus(); }
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 21 The primary HTML5 semantic elements
header section article nav aside figure footer
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 22 A page that’s structured with HTML5 elements
San Joaquin Valley Town Hall
Welcome to San Joaquin Valley Town Hall. We have some fascinating speakers for you this season!
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 23 The HTML in a web browser
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 24 The JavaScript shiv that tells older browsers about the HTML5 elements
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 25 Terms • HTML5 semantics • semantic elements • JavaScript shiv • JavaScript shim
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 26 HTML div elements for a JavaScript application jQuery FAQs
What is jQuery?
Why is jQuery becoming so popular?
Which is harder to learn: jQuery or JavaScript?
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 27 HTML span elements for a JavaScript application *
*
*
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 28 The basic HTML attributes id class title for name
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 29 HTML that uses these attributes
San Joaquin Valley Town Hall
Welcome to San Joaquin Valley Town Hall.
Please enter your e-mail address to subscribe to our newsletter.
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 30 The HTML in a web browser with a tooltip displayed for the text box
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 31 Two ways to provide styles Use an external style sheet by coding a link element in the head section Embed the styles in the head section The sequence in which styles are applied • Styles from an external style sheet • Embedded styles
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 32 A head element that includes two style sheets
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 33 How to specify the medium for a style sheet
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 34 HTML that can be selected by type, id, or class
The Speaker Lineup
October 19: Jeffrey Toobin
November 16: Andrew Ross Sorkin
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 35 CSS rule sets that select by type, id, and class Type selectors body { font-family: Arial, Helvetica, sans-serif; width: 400px; margin: 1em auto; } section { border: 2px solid black; padding: 1em; } p { margin: .25em 0 .25em 3em; } ID selectors #first_heading { margin: 0 1em .25em; } Class selectors .blue { color: blue; } .right { text-align: right; }
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 36 The HTML elements in a browser
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 37 The CSS file for a typical application in this book
/* The CSS workaround for HTML5 semantic elements */ article, aside, figure, footer, header, nav, section { display: block; } body { font-family: Arial, Helvetica, sans-serif; background-color: white; margin: 0 auto; width: 650px; border: 3px solid blue; } h1 { color: blue; } section { padding: 0 2em 1em; }
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 38 The CSS file for a typical application (continued) label { float: left; width: 11em; text-align: right; } input { margin-left: 1em; margin-bottom: .5em; } span { color: red; }
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 39 Terms • rule set • rule • property name • value
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 40 The web page at c:/jquery/book_apps/ch01/email_list.html
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 41 Four ways to run an HTML page that’s on your own server or computer • Use the FileOpen command or the FileOpen File. • Find the file in the Windows Explorer and double-click on it. • Use the features of your text editor or IDE. • Click on a link in the current web page to load the next web page.
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 42 Two ways to run an HTML page on the Internet • Enter the URL of a web page into the browser’s address bar. • Click on a link in the current web page to load the next web page.
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 43 The components of an HTTP URL on the Internet
http://www.modulemedia.com/ourwork/index.html protocol domain name path filename
What happens if you omit parts of a URL • If you omit the protocol, http:// will be used. • If you omit the filename, the default document name for the web server will be used. • The default document name is typically index.html, default.htm, or some variation.
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 44 The HTML5 ratings of current browsers Perfect score is 500 Browser Release HTML5 Test Rating Chrome 22 437 Opera 12 385 Firefox 15 346 Safari 6 376 IE 9 138 The web site for these ratings http://www.html5test.com
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 45 Guidelines for cross-browser compatibility • Test your web pages on all of the major browsers, including older versions. • Use the HTML5 and CSS3 features that are supported by all of the modern browsers. • Use the workarounds so HTML5 pages will run on the older browsers too.
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 46 The workarounds for using HTML5 semantics The JavaScript shiv The CSS rule set article, aside, figure, figcaption, footer, header, nav, section { display: block; }
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 47 How to test your web pages in older browsers • One of the problems in cross-browser testing is that you can’t install all of the old browsers on one system. • The solution is to use programs or web sites that offer this type of testing.
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 48 The last dialog box for creating an Aptana project
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 49 How to create a project • Use the FileNewWeb Project command to display the New Web Project dialog box. • In the New Web Project dialog box: Enter a name for the project. Uncheck the Use Default Location box. Click the Browse button. Select the top-level folder for the project. Read the warning message. Click the Finish button. The folder that contains the folders for all of the book applications c:\murach\jquery\book_apps
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 50 Aptana with the App Explorer shown and a JavaScript file in the second tab
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 51 How to open a file within an Aptana project • Use the drop-down list in the App Explorer to select the project. • Locate the file in the App Explorer and double-click on it. How to open a file that isn’t in an Aptana project • Use the Project Explorer to locate the file, and double-click on it. • Use the FileOpen File command. How to close one or more files in Aptana • To close one file, click on the X in the tab for the file. • To close all of the files except one, right click on the tab you don’t want to close and select Close Others. • To close all of the files, right click on any tab and select Close All.
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 52 Aptana’s Themes dialog box
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 53 How to apply a new theme for Aptana • Use the WindowPreferences command to open the Preferences dialog box. • Click on Aptana Studio, and then click on Themes to display the Themes dialog box. • Choose a theme from the drop-down list.
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 54 Aptana with an auto-completion list for a JavaScript entry
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 55 To run a web page, click on Aptana’s Run button
Run button
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 56 To rerun a web page in a browser, clicking on the Reload button
Reload button
Murach's JavaScript and jQuery, C1 © 2012, Mike Murach & Associates, Inc. Slide 57