SlideShare a Scribd company logo
1 of 38
New JavaScript HTML5 
Canvas, SVG, Workers 
Windows Store Apps 
Certificationkey 
www.Certificationkey.com
Table of Contents 
New JavaScript APIs 
New Selectors 
Canvas JavaScript API 
Web Workers 
Drag and Drop 
HTML5 Storage 
HTML DOM Extensions 
Event Listeners
New JavaScript APIs 
What a programmer must know? 
http://www.certificationkey.com/70-480.html
New JavaScript APIs 
New selectors 
Threading (Web Workers) 
UI APIs 
Canvas 
Drag and Drop 
Local and Session Storage 
Extension to HTMLDocument 
http://www.certificationkey.com/70-480.html
New Selectors 
http://www.certificationkey.com/70-480.html
New Selectors 
In HTML5 we can select elements by 
ClassName 
var elements = document.getElementsByClassName('entry'); 
Moreover there’s now possibility to fetch 
elements that match provided CSS syntax 
var elements = 
document.querySelectorAll("ul li:nth-child(odd)"); 
var first_td = 
document.querySelector("table.test > tr > td"); 
http://www.certificationkey.com/70-480.html
New Selectors (2) 
Selecting the first div met 
var elements = document.querySelector("div"); 
Selecting the first item with class SomeClass 
var elements = document.querySelector(".SomeClass"); 
Selecting the first item with id someID 
var elements = document.querySelector("#someID"); 
Selecting all the divs in the current container 
var elements = document.querySelectorAll("div"); 
http://www.certificationkey.com/70-480.html
Canvas 
JavaScript API 
How to Manipulate 
Canvas Dynamically? 
http://www.certificationkey.com/70-480.html
Canvas 
Canvas 
Dynamic, Scriptable rendering of 2D images 
Uses JavaScript to draw 
Resolution-dependent bitmap 
Can draw text as well 
<canvas id="ExampleCanvas" width="200" height="200"> 
This text is displayed if your browser does not support 
HTML5 Canvas. 
</canvas> 
var example = document.getElementById('ExampleCanvas'); 
var context = example.getContext('2d'); 
context.fillStyle = "rgb(255,0,0)"; 
context.fillRect(30, 30, 50, 50);
Canvas Properties and 
Methods 
fillStyle 
 Sets the drawing color 
 Default fillStyle is solid black 
 But you can set it to whatever you like 
fillRect(x, y, width, height) 
Draws a rectangle 
 Filled with the current fillStyle 
http://www.certificationkey.com/70-480.html
Canvas Properties and 
Methods (2) 
strokeStyle 
 Sets the stroke color 
strokeRect(x, y, width, height) 
Draws an rectangle with the current 
strokeStyle 
strokeRect doesn’t fill in the middle 
 It just draws the edges 
clearRect(x, y, width, height) clears 
the pixels in the specified rectangle 
http://www.certificationkey.com/70-480.html
Canvas Paths 
What is a Path? 
Something that is about to be drawn 
 It is not drawn yet 
context.beginPath(); 
context.moveTo(0, 40); 
context.lineTo(240, 40); 
context.moveTo(260, 40); 
context.lineTo(500, 40); 
context.moveTo(495, 35); 
context.lineTo(500, 40); 
context.lineTo(495, 45); 
http://www.certificationkey.com/70-480.html
Certificationkey 
Live Demo
Web Workers 
Multithreading in JavaScript 
http://www.certificationkey.com/70-480.html
What are Web Workers? 
API for running scripts in the background 
Independently of any user interface scripts 
Workers are expected to be long-lived 
 Have a high start-up performance cost and a 
high per-instance memory cost 
Might be partially replaced by 
Window.setTimeout() function 
http://www.certificationkey.com/70-480.html
What are Web Workers? (2) 
Workers are separate JavaScript processes 
running in separate threads 
Workers execute concurrently 
Workers don’t block the UI 
Workers allow you to extract up to the last drop 
of juice from a multicore CPU 
Workers can be dedicated (single tab) or shared 
among tabs/windows 
Workers will be persistent too (coming soon) 
 They’ll keep running after the browser has quit
What are Web Workers? (3) 
If we call function by setTimeout, the 
execution of script and UI are suspended 
When we call function in worker, it doesn’t 
affect UI and execution flow in any way 
To create Worker, we put JavaScript in 
separate file and create new Worker instance: 
var worker = new Worker(‘extra_work.js'); 
We can communicate with worker using 
postMessage function and onmessage listener 
http://www.certificationkey.com/70-480.html
What are Web Workers? (4) 
Messages are send to all threads in our 
application: 
main.js: 
var worker = new Worker(‘extra_work.js'); 
worker.onmessage = function (event) { alert(event.data); }; 
extra_work.js: 
//do some work; when done post message. 
// some_data could be string, array, object etc. 
postMessage(some_data); 
http://www.certificationkey.com/70-480.html
Web Workers 
Live Demo 
http://www.certificationkey.com/70-480.html
Drag and Drop 
Drag and Drop, Local and Session Storage 
http://www.certificationkey.com/70-480.html
Drag and Drop 
Drag and Drop 
<element> attribute draggable="true" 
 Events: dragstart, dragstop, dragenter, 
dragleave, dropend 
http://www.certificationkey.com/70-480.html
Drag And Drop 
Live Demo 
http://www.certificationkey.com/70-480.html
HTML5 Storage 
Local and Session 
http://www.certificationkey.com/70-480.html
Local Storage 
Local Storage 
Store data locally 
 Similar to cookies, but can store much larger 
amount of data 
Same Origin Restrictions 
localStorage.setItem(key, value) 
localStorage.getItem(key) 
Local and Session Storages can only store 
strings! 
http://www.certificationkey.com/70-480.html
Local Storage Example 
Local Storage 
function saveState(text){ 
localStorage["text"] = text; 
} 
function restoreState(){ 
return localStorage["text"]; 
} 
Same as 
function saveState(text){ 
localStorage.setValue("text", text); 
} 
function restoreState(){ 
return localStorage.getValue("text"); 
}
Session Storage 
Session Storage 
Similar to Local Storage 
 Lasts as long as browser is open 
Opening page in new window or tab starts new 
sessions 
 Great for sensitive data (e.g. banking sessions) 
http://www.certificationkey.com/70-480.html
Session Storage Example 
Session Storage 
function incrementLoads() { 
if (!sessionStorage.loadCounter) { 
sessionStorage["loadCounter"] = 0; 
} 
var currentCount = 
parseInt(sessionStorage["loadCounter"]); 
currentCount++; 
sessionStorage["loadCounter"] = currentCount; 
document.getElementById("countDiv").innerHTML = 
currentCount; 
} 
http://www.certificationkey.com/70-480.html
HTML5 Storages 
Live Demo 
http://www.certificationkey.com/70-480.html
HTML DOM Extensions 
http://www.certificationkey.com/70-480.html
HTML DOM Extensions 
HTML DOM Extensions: 
getElementsByClassName() 
innerHTML 
hasFocus 
getSelection() 
http://www.certificationkey.com/70-480.html
HTML DOM Extensions 
Live Demo 
http://www.certificationkey.com/70-480.html
Event Listeners 
How to Listen for 
Something to Happen? 
http://www.certificationkey.com/70-480.html
Event Listeners 
Event Listener is an event that tracks for 
something to happen 
 i.e. a key to be pressed, a mouse click, etc. 
Available in JavaScript 
 addEventListener() registers a single event 
listener on a single target 
The event target may be 
 A single node in a document 
 The document itself 
 A window 
http://www.certificationkey.com/70-480.html
Registering Event Listener 
Example 
 Adding a click event listener to a div element 
document.GetElementById("someElement"). 
addEventListener("click", 
function (e) { 
alert("element clicked"); 
}, false); 
http://www.certificationkey.com/70-480.html
Event Listeners 
Live Demo 
http://www.certificationkey.com/70-480.html
HTML5 New JavaScript APIs 
Questions? 
http://www.certificationkey.com/70-480.html
Exercises 
1. Write wrapper function as follows: 
$(ID) to return either a single element, 
whose ID is the one passed or null 
$$(selector) to return an array of elements 
or empty array with results; 
Use mapping to existing DOM methods 
 e.g. getElementByClassName, 
querySelectorAll 
http://www.certificationkey.com/70-480.html
Exercises (2) 
2. Write an event delegate function member of 
the Event global object e.g. 
Event.delegate("selector", "eventName", 
handlerName) using the previously written 
functions to match selectors. 
Map the global listeners to the document or 
body element; 
Use w3c style events. 
http://www.certificationkey.com/70-480.html

More Related Content

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Recently uploaded (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

Featured

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

Featured (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

Preparing rogramming in HTML5 with JavaScript

  • 1. New JavaScript HTML5 Canvas, SVG, Workers Windows Store Apps Certificationkey www.Certificationkey.com
  • 2. Table of Contents New JavaScript APIs New Selectors Canvas JavaScript API Web Workers Drag and Drop HTML5 Storage HTML DOM Extensions Event Listeners
  • 3. New JavaScript APIs What a programmer must know? http://www.certificationkey.com/70-480.html
  • 4. New JavaScript APIs New selectors Threading (Web Workers) UI APIs Canvas Drag and Drop Local and Session Storage Extension to HTMLDocument http://www.certificationkey.com/70-480.html
  • 6. New Selectors In HTML5 we can select elements by ClassName var elements = document.getElementsByClassName('entry'); Moreover there’s now possibility to fetch elements that match provided CSS syntax var elements = document.querySelectorAll("ul li:nth-child(odd)"); var first_td = document.querySelector("table.test > tr > td"); http://www.certificationkey.com/70-480.html
  • 7. New Selectors (2) Selecting the first div met var elements = document.querySelector("div"); Selecting the first item with class SomeClass var elements = document.querySelector(".SomeClass"); Selecting the first item with id someID var elements = document.querySelector("#someID"); Selecting all the divs in the current container var elements = document.querySelectorAll("div"); http://www.certificationkey.com/70-480.html
  • 8. Canvas JavaScript API How to Manipulate Canvas Dynamically? http://www.certificationkey.com/70-480.html
  • 9. Canvas Canvas Dynamic, Scriptable rendering of 2D images Uses JavaScript to draw Resolution-dependent bitmap Can draw text as well <canvas id="ExampleCanvas" width="200" height="200"> This text is displayed if your browser does not support HTML5 Canvas. </canvas> var example = document.getElementById('ExampleCanvas'); var context = example.getContext('2d'); context.fillStyle = "rgb(255,0,0)"; context.fillRect(30, 30, 50, 50);
  • 10. Canvas Properties and Methods fillStyle  Sets the drawing color  Default fillStyle is solid black  But you can set it to whatever you like fillRect(x, y, width, height) Draws a rectangle  Filled with the current fillStyle http://www.certificationkey.com/70-480.html
  • 11. Canvas Properties and Methods (2) strokeStyle  Sets the stroke color strokeRect(x, y, width, height) Draws an rectangle with the current strokeStyle strokeRect doesn’t fill in the middle  It just draws the edges clearRect(x, y, width, height) clears the pixels in the specified rectangle http://www.certificationkey.com/70-480.html
  • 12. Canvas Paths What is a Path? Something that is about to be drawn  It is not drawn yet context.beginPath(); context.moveTo(0, 40); context.lineTo(240, 40); context.moveTo(260, 40); context.lineTo(500, 40); context.moveTo(495, 35); context.lineTo(500, 40); context.lineTo(495, 45); http://www.certificationkey.com/70-480.html
  • 14. Web Workers Multithreading in JavaScript http://www.certificationkey.com/70-480.html
  • 15. What are Web Workers? API for running scripts in the background Independently of any user interface scripts Workers are expected to be long-lived  Have a high start-up performance cost and a high per-instance memory cost Might be partially replaced by Window.setTimeout() function http://www.certificationkey.com/70-480.html
  • 16. What are Web Workers? (2) Workers are separate JavaScript processes running in separate threads Workers execute concurrently Workers don’t block the UI Workers allow you to extract up to the last drop of juice from a multicore CPU Workers can be dedicated (single tab) or shared among tabs/windows Workers will be persistent too (coming soon)  They’ll keep running after the browser has quit
  • 17. What are Web Workers? (3) If we call function by setTimeout, the execution of script and UI are suspended When we call function in worker, it doesn’t affect UI and execution flow in any way To create Worker, we put JavaScript in separate file and create new Worker instance: var worker = new Worker(‘extra_work.js'); We can communicate with worker using postMessage function and onmessage listener http://www.certificationkey.com/70-480.html
  • 18. What are Web Workers? (4) Messages are send to all threads in our application: main.js: var worker = new Worker(‘extra_work.js'); worker.onmessage = function (event) { alert(event.data); }; extra_work.js: //do some work; when done post message. // some_data could be string, array, object etc. postMessage(some_data); http://www.certificationkey.com/70-480.html
  • 19. Web Workers Live Demo http://www.certificationkey.com/70-480.html
  • 20. Drag and Drop Drag and Drop, Local and Session Storage http://www.certificationkey.com/70-480.html
  • 21. Drag and Drop Drag and Drop <element> attribute draggable="true"  Events: dragstart, dragstop, dragenter, dragleave, dropend http://www.certificationkey.com/70-480.html
  • 22. Drag And Drop Live Demo http://www.certificationkey.com/70-480.html
  • 23. HTML5 Storage Local and Session http://www.certificationkey.com/70-480.html
  • 24. Local Storage Local Storage Store data locally  Similar to cookies, but can store much larger amount of data Same Origin Restrictions localStorage.setItem(key, value) localStorage.getItem(key) Local and Session Storages can only store strings! http://www.certificationkey.com/70-480.html
  • 25. Local Storage Example Local Storage function saveState(text){ localStorage["text"] = text; } function restoreState(){ return localStorage["text"]; } Same as function saveState(text){ localStorage.setValue("text", text); } function restoreState(){ return localStorage.getValue("text"); }
  • 26. Session Storage Session Storage Similar to Local Storage  Lasts as long as browser is open Opening page in new window or tab starts new sessions  Great for sensitive data (e.g. banking sessions) http://www.certificationkey.com/70-480.html
  • 27. Session Storage Example Session Storage function incrementLoads() { if (!sessionStorage.loadCounter) { sessionStorage["loadCounter"] = 0; } var currentCount = parseInt(sessionStorage["loadCounter"]); currentCount++; sessionStorage["loadCounter"] = currentCount; document.getElementById("countDiv").innerHTML = currentCount; } http://www.certificationkey.com/70-480.html
  • 28. HTML5 Storages Live Demo http://www.certificationkey.com/70-480.html
  • 29. HTML DOM Extensions http://www.certificationkey.com/70-480.html
  • 30. HTML DOM Extensions HTML DOM Extensions: getElementsByClassName() innerHTML hasFocus getSelection() http://www.certificationkey.com/70-480.html
  • 31. HTML DOM Extensions Live Demo http://www.certificationkey.com/70-480.html
  • 32. Event Listeners How to Listen for Something to Happen? http://www.certificationkey.com/70-480.html
  • 33. Event Listeners Event Listener is an event that tracks for something to happen  i.e. a key to be pressed, a mouse click, etc. Available in JavaScript  addEventListener() registers a single event listener on a single target The event target may be  A single node in a document  The document itself  A window http://www.certificationkey.com/70-480.html
  • 34. Registering Event Listener Example  Adding a click event listener to a div element document.GetElementById("someElement"). addEventListener("click", function (e) { alert("element clicked"); }, false); http://www.certificationkey.com/70-480.html
  • 35. Event Listeners Live Demo http://www.certificationkey.com/70-480.html
  • 36. HTML5 New JavaScript APIs Questions? http://www.certificationkey.com/70-480.html
  • 37. Exercises 1. Write wrapper function as follows: $(ID) to return either a single element, whose ID is the one passed or null $$(selector) to return an array of elements or empty array with results; Use mapping to existing DOM methods  e.g. getElementByClassName, querySelectorAll http://www.certificationkey.com/70-480.html
  • 38. Exercises (2) 2. Write an event delegate function member of the Event global object e.g. Event.delegate("selector", "eventName", handlerName) using the previously written functions to match selectors. Map the global listeners to the document or body element; Use w3c style events. http://www.certificationkey.com/70-480.html