Date post: | 10-Jul-2015 |
Category: |
Internet |
Upload: | joe-devlin |
View: | 210 times |
Download: | 1 times |
Beginning JavascriptToday’s Event hosts
•St. Patrick’s Church - Tacoma
•Knights of Columbus Tacoma Council 809
•Moderator: Joe Devlin
10/25/2014 1parish.saintpats.org kofc809.org
A word from our hosts•St. Patrick’s Church – Tacoma
o The pastoral council has generously offered us this location for today, as part of the churches community outreach.
o Founded in 1892
o Aligned with St. Patrick’s Catholic School
o Reference: The Bible
o Working on the Engaged Church model“Growing an Engaged Church” by Albert Winseman, Gallup Press, ISBN 978-1-59562-014-9
o Promoting personal development with Strengths Finder.“Strengths Finder” by Tom Rath, Gallup Press, ISBN 978-1-59562-015-6
strengthsfinder.com
10/25/2014 2parish.saintpats.org kofc809.org
A word from our hosts•Knights of Columbus www.kofc.org
o Founded in 1882
o Dedicated to “Saving Lives and Changing Lives”
o Promoting strong families through charitable giving and a AAA rated life insurance and annuity program.
oLocal projectsHabitat for Humanity Build, Blood Drive, Ultrasound for pregnancy care,
Coats for Kids, Wheelchair Mission.
10/25/2014 3parish.saintpats.org kofc809.org
Introduction•Joe Devlin - moderator
o Member of St Patrick’s Parish and K of C council 809
o Working as a web host for small to medium sized businesses.
o Interested in Javascript for the obvious reasons that it is a must for
web development, plus for the purposes of getting people together
to code; JS is a universal standard that comes with freely
downloadable browsers and tools. We can easily collaborate.
o t = F x d; torque equals force times distance or more commonly
“leverage”. [Information Analogy: outcome= cost*value ]
10/25/2014 4parish.saintpats.org kofc809.org
Time management
10/25/2014 5parish.saintpats.org kofc809.org
Present
Code
Discuss
10/25/2014 6parish.saintpats.org kofc809.org
Schedule
0830-0845 Reception, coffee and pastries
0845-0900 Introduce ourselves
0900-1000 Basic constructs
1000-1015 Break
1015-1100 DOM discussion
1100-1200 Modules and plug ins
1200-1230 Lunch
Rest Rooms•Down the “L” shaped hall
•Through two sets of doors to then left.
• If you end up upstairs or outside you have
gone too far!
10/25/2014 7parish.saintpats.org kofc809.org
Attendee Introduction• Let each of us introduce ourselves
o My name is ____________. (First name)
o Working as a ____________, or looking for work as a _________.
o Interested in Javascript for websites that ____________.
o I develop on a Mac / PC / Linux
oMy favorite text editor is ________.
oMy favorite Integrated Development Environment IDE is ______.
10/25/2014 8parish.saintpats.org kofc809.org
Requirements
10/25/2014 9parish.saintpats.org kofc809.org
HTML Validator
JS - valid
Test
http://validator.w3.org/nu/
http://www.jslint.com/http://www.jshint.com/
Design inputs to confirm the expected output.
Source:http://vividventures.biz/examples/js/browser_detection/helloworld.html
Building A Dynamic Foundation
10/25/2014 10parish.saintpats.org kofc809.org
•Specification
•Usage
•Revisions
Foundation: ECMA-262 ECMAScript Language Specification
10/25/2014 11parish.saintpats.org kofc809.org
•Apple•Mozilla
•Microsoft•Google
Chrome-JS
IE-JS
Safari-JSFirefox-
JS
• Find the specification at: www.ecma-international.orghttp://www.ecma-international.org/ecma-262/5.1/
• Vendors build a browser that interprets Javascript as defined by the specification.
•The challenge is that each Javascript may work a little differently depending on the
interpretation. There is potentially more than one Javascript to learn.
*
* *
*
Foundation: Browser Usage
10/25/2014 12parish.saintpats.org kofc809.org
•Current usage chart from
http://en.wikipedia.org/wiki/Web_browser with all the statistical
disclaimers.
•#1 Chrome
•#2 Internet Explorer
•#3 Firefox
•#4 Safari
•#5 Opera
•We know there is a growing mobile versions
trend that could be different as well.
Foundation: Browser Revisions
10/25/2014 13parish.saintpats.org kofc809.org
•There are some graphical representations of browser revisions:
ohttp://evolutionofweb.appspot.com/#/evolution/day
ohttp://meyerweb.com/eric/browsers/timeline-structured.html
ohttp://fresh-browsers.com/history
ohttp://en.wikipedia.org/wiki/Timeline_of_web_browsers
• When a user upgrades the browser revision it may deprecate or brake your code.
• In conclusion:
o The programmer has no control over which browser or revision level the user
will attempt to acquire a web page with, however they do have access to
some information about the browser.
Foundation: Browser Revision Detection
10/25/2014 14parish.saintpats.org kofc809.org
Source:
http://www.vividventures.biz/examples/js/browser_detection/user_agent1.html
Foundation: Browser Revision Detection
10/25/2014 15parish.saintpats.org kofc809.org
If only browser detection were as simple as the last example! More complex solutions:
•Whichbrowser - A combination of server side php and client side Javascript. http://whichbrowser.net/ (heed the warning about browser sniffing!)
•Bowser https://github.com/ded/bowserhttps://raw.githubusercontent.com/ded/bowser/master/bowser.js
What we really want to know is whether a browser complies with a particular feature, not the browser and revision.
The userAgent result is not accurate enough to adequately make decisions about which code to run, because someone has to continuously monitor browser revisions compared to features. There are alternate solutions that involve feature detection .
Foundation: Browser Feature Detection
10/25/2014 16parish.saintpats.org kofc809.org
• Modernizr http://modernizr.com/ runs quickly on page load to detect
features; it then creates a JavaScript object with the results, and adds classes to the html element for you to key your CSS on. Modernizr supports dozens of tests, and optionally includes YepNope.js for conditional loading of external .js and .cssresources.Code Deployment Network (CDN) -
http://cdnjs.com/libraries/modernizrhttp://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.js
Foundation: Browser Feature Detection
10/25/2014 17parish.saintpats.org kofc809.org
• Modernizrcode source: http://vividventures.biz/examples/js/browser_detection/feature_detection_modernizr.html
Try http:
Foundation: Browser Feature Detection
10/25/2014 18parish.saintpats.org kofc809.org
• Mootools - http://mootools.net/ MooTools is a compact, modular, Object-Oriented JavaScript framework designed for the intermediate to advanced JavaScript developer. It allows you to write powerful, flexible, and cross-browsercode with its elegant, well documented, and coherent API.
• It has a few feature detection methods:oBrowser.Features.xpath - (boolean) True if the browser supports DOM queries using XPath.oBrowser.Features.air - (boolean) True if the browser supports AIR.oBrowser.Features.query - (boolean) True if the browser supports querySelectorAll.oBrowser.Features.json - (boolean) True if the browser has a native JSON object.oBrowser.Features.xhr - (boolean) True if the browser supports native XMLHTTP object.
A Google hosted Code Deployment Network (CDN) at :https://developers.google.com/speed/libraries/devguide CDN- //ajax.googleapis.com/ajax/libs/mootools/1.5.1/mootools-yui-compressed.js
Foundation: Browser Feature Detection
10/25/2014 19parish.saintpats.org kofc809.org
• Source - http://vividventures.biz/examples/js/browser_detection/feature_detection_mootools.html
Foundation: Javascript not available?
10/25/2014 20parish.saintpats.org kofc809.org
•In an introduction to Javascript programming it may be a bit odd to ask what if Javascript is turned off in the users browser?
•Reference –http://stackoverflow.com/questions/121203/how-to-detect-if-javascript-is-disabled
Source: http://vividventures.biz/examples/js/browser_detection/nojavascript.html
10/25/2014 21parish.saintpats.org kofc809.org
Foundation: Javascript not Available?
Syntax and Statements: key and reserved words
10/25/2014 22parish.saintpats.org kofc809.org
•Reference the ECMAScript® Language Specification to find the key and reserved words.
Key words
break do instanceof typeofcase else new var catch finally return void continue for switch while debugger function this with
default if throw
delete in try
10/25/2014 23parish.saintpats.org kofc809.org
Syntax: using (almost) all the keywords
HMTLInput Buttons
onClick=“main()”
function list()list
looping
objects
failedtry
function looping()
function objects()
failedtry
main(c)
Return null
Source: http://vividventures.biz/examples/js/keywords/TestKeyWords.htmlhttp://www.vividventures.biz/examples/js/keywords/complete_list.js
10/25/2014 24parish.saintpats.org kofc809.org
Syntax: using (almost) all the keywords HTML
Source: http://vividventures.biz/examples/js/keywords/TestKeyWords.htmlhttp://www.vividventures.biz/examples/js/keywords/complete_list.js
10/25/2014 25parish.saintpats.org kofc809.org
Syntax: main()
Source: http://vividventures.biz/examples/js/keywords/TestKeyWords.htmlhttp://www.vividventures.biz/examples/js/keywords/complete_list.js
10/25/2014 26parish.saintpats.org kofc809.org
Syntax: using (almost) all the keywords, constants
Source: http://vividventures.biz/examples/js/keywords/TestKeyWords.htmlhttp://www.vividventures.biz/examples/js/keywords/complete_list.js
10/25/2014 27parish.saintpats.org kofc809.org
Syntax: using (almost) all the keywords, ARRAY
Source: http://asmarterwaytolearn.com/js/15.html
Arrayvar aryTheIndexValues = [0, 1, 2, 3, 4];
var aryCoders = [“Sue”, “Scott”, “Julia”, “Joe”];
var aryInventory = [100, 200, 500, 10, 9];
var aryOfArrays = [[1,2],[2,2]];
• Variable that represents a list of values• Any number of elements.*• First element is indexed with a zero [0], second element one [1] and so on.• Access to the array elements by var myresult = aryCoders[0];
o The number in the brackets is the indexo Only access by index, not by named index.
• array type is reference, so any change to the original changes all copiesvar aryFirst = [100, 200, 300, 400, 500];
var arySecond = aryFirst;
arySecond = [1, 2, 3, 4, 5];
//aryFirst is now made the same as arySecond
Reference: Javascript Step by Step p. 73, 97
10/25/2014 28parish.saintpats.org kofc809.org
Syntax: list
Source: http://vividventures.biz/examples/js/keywords/TestKeyWords.htmlhttp://www.vividventures.biz/examples/js/keywords/complete_list.js
10/25/2014 29parish.saintpats.org kofc809.org
Syntax: looping
10/25/2014 30parish.saintpats.org kofc809.org
Syntax: isArray
10/25/2014 31parish.saintpats.org kofc809.org
Syntax: objects
DOM: Parents, Children, Siblings
10/25/2014 32parish.saintpats.org kofc809.org
http://www.asmarterwaytolearn.com/js/59.html
• parent – encloses child nodes• child – enclosed by a parent node• sibling – nodes with the same parent
10 nodes here11 nodes here
DOM: Parents, Children, Siblings
10/25/2014 33parish.saintpats.org kofc809.org
Exploring with developer tools like Firebug
10/25/2014 34parish.saintpats.org kofc809.org
DOM: modification
Source: http://vividventures.biz/examples/js/dom_mod/modifyworld.html
Plugin: jQuery - DOM modification
10/25/2014 35parish.saintpats.org kofc809.org
• Reference: http://jquery.com/
• Plugin (libraries) allow code reuse, which saves you time and leverages your effectiveness.
• jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.
• Code Deployment Networks allow code to be retrieved from a server near the user allowing faster loading.Googles CDN: https://developers.google.com/speed/libraries/devguide#jquery
10/25/2014 36parish.saintpats.org kofc809.org
Plugins – jQuery DOM: modification
Source: http://vividventures.biz/examples/js/dom_mod/modifyworld2.htmljQuery ignores the “junk artifacts in the DOM”. reference: http://api.jquery.com/next/