Web Programming Pingmei Xu World Wide Web Wikipedia definition: a - - PowerPoint PPT Presentation

web programming
SMART_READER_LITE
LIVE PREVIEW

Web Programming Pingmei Xu World Wide Web Wikipedia definition: a - - PowerPoint PPT Presentation

Web Programming Pingmei Xu World Wide Web Wikipedia definition: a system of interlinked hypertext documents accessed via the Internet. image from http://www.syslog.cl.cam.ac.uk/ Web Internet World Wide Web : a collection Internet : a


slide-1
SLIDE 1

Web Programming

Pingmei Xu

slide-2
SLIDE 2

World Wide Web

  • Wikipedia definition: a system of interlinked

hypertext documents accessed via the Internet.

image from http://www.syslog.cl.cam.ac.uk/

slide-3
SLIDE 3

Web ≠ Internet

World Wide Web: a collection

  • f interlinked multimedia

documents that are stored on the Internet and accessed using a common protocol (HTTP) Internet: a physical network connecting millions of computers using the same protocols for sharing/ transmitting information (TCP/IP)

slide-4
SLIDE 4

Web Programming

user types in a url browser sends requests to server browser parses the returned response and displays the output to the user server runs PHP, MySQL etc. then responds to browser with HTML, CSS and JavaScript

slide-5
SLIDE 5

Web Programming

Static Dynamic

  • Web Document (HTML, CSS)
  • Client-side programming (JavaScript …)

can download program with Web page, execute on client machine

  • Server-side programming (PHP, CGI, Perl …)

can store and execute program on Web server, link from Web page

slide-6
SLIDE 6

HTML

slide-7
SLIDE 7

What is HTML?

HyperText Markup Language (HTML) is the core language of nearly all Web content.

webpage .html format HTML code

slide-8
SLIDE 8

HTML: The Document Tree

head body This hierarchical structure is called the DOM: the Document Object Model.

slide-9
SLIDE 9

HTML: Elements

Elements: the basic building blocks which defjne the semantic meaning of their content. "<p>" element indicates a paragraph the "<img>" element indicates an image

slide-10
SLIDE 10

HTML: Tags

<h1>: opening tag <h1>: closing tag empty elements like <img> doesn’t need closing tag

slide-11
SLIDE 11

HTML: Attributes

Atuributes usually consist of 2 parts: An aturibute name: e.g. width An aturibute value: e.g. 200

slide-12
SLIDE 12

HTML: <img> Tag

The <img> tag defjnes an image in an HTML page. It has two required atuributes: src - specifjes the URL of an image alt - specifjes an alternate text for an image

slide-13
SLIDE 13

HTML: Doctype and Comments

an HTML document must contain a doctype declaration as the fjrst line

slide-14
SLIDE 14

In-Class Exercise

  • Task List
  • 1. Change the content shown on the tab
  • 2. Create a paragraph and write some stuff in that paragraph
  • 3. Change the width of the image to 500px
  • Cheat sheet
  • 1. <title> … </title>
  • 2. <p> … </p>
  • 3. <img … width=“…”>
slide-15
SLIDE 15

CSS

some examples borrowed from https://developer.mozilla.org/

slide-16
SLIDE 16

What is CSS?

Cascading Style Sheets (CSS) is a language for specifying how documents are presented to users.

defjne the color of body CSS syntax

image from w3school

slide-17
SLIDE 17

Why Use CSS?

Keep the information content of a document separate from the details of how to display it (also know as ‘style’) so that you can:

  • Avoid duplication
  • Make maintenance easier
  • Use the same content with different styles for

different purposes

slide-18
SLIDE 18

How to Insert CSS?

  • External Style Sheet
  • Internal Style Sheet
  • Inline Styles
slide-19
SLIDE 19

CSS Box Model and Positioning

All HTML elements can be considered as boxes.

  • You can specify an element's position in four ways:

relative, fixed, absolute, static

slide-20
SLIDE 20

In-Class Exercise

  • Task List
  • 1. Write CSS as internal style sheet and change the color of the body

content to ‘#FF0000’

  • 2. Write CSS as inline style sheet and change the font size of one

paragraph to ‘50px’

  • Cheat sheet
  • 1. <style> … </style>
  • 2. <p style=“font-size:…”>
slide-21
SLIDE 21

JavaScript

slide-22
SLIDE 22

A scripting language. JavaScript code can be inserted into any HTML page, and it can be executed by all types of web browsers.

What is JavaScript?

put all your JavaScript code in <script> block

slide-23
SLIDE 23

JavaScript: Syntax

  • Comment: // or /* */
  • Variables: var x = 0
  • Data types: undefined, null, number, string, boolean …
  • Operators: +,-,*,/%, >, < …
  • Control structure: if… else, for, while, switch …
  • Native objects: array, date, error, math
slide-24
SLIDE 24

JavaScript: Object

create an JavaScript object accessing object properties:

  • bjectName.propertyName

accessing object methods:

  • bjectName.methodName()
slide-25
SLIDE 25

JavaScript: Array

create an array: you can have different

  • bjects in on array

access data modify data For Matlab users, note: index starts from zero!

slide-26
SLIDE 26

JavaScript: Math

  • Constants:
  • Math.PI
  • Methods:
  • Math.round(), Math.floor(), Math.ceil()
  • Math.sin(), Math.cos()
  • Math.abs()
  • Math.sqrt(), Math.pow(), Math.exp()
  • Math.max(), Math.min()
  • Math.random()
slide-27
SLIDE 27
  • A simple example
  • Important concept: callback functions

JavaScript: Function

function name arguments call a function

slide-28
SLIDE 28

JavaScript: Library

  • To use a JavaScript framework library in your web

pages, just include the library in a <script> tag:

  • Computer Vision library:

http://inspirit.github.io/jsfeat/

slide-29
SLIDE 29

In-Class Exercise

  • Write a function to compute the multiplication of two

numbers

  • Define two variables num1=5, num2=7
  • Define another variable num3, set the value as the

multiplication of num1 and num2 using the function that you just created, and check check the value of num3f

slide-30
SLIDE 30

jQuery

some examples borrowed from http://www.w3schools.com/

slide-31
SLIDE 31

What is jQuery?

  • jQuery is a lightweight JavaScript library to make it

much easier to use JavaScript on your website.

  • Install jQuery
  • Download the jQuery library from jQuery.com
  • Include jQuery from a CDN, like Google
slide-32
SLIDE 32

jQuery Syntax

  • $(selector).action()
  • Some commonly used DOM events:

$ sign to access jQuery A (selector) to "query (or fjnd)" HTML elements A jQuery action() to be performed on the element(s)

slide-33
SLIDE 33

jQuery Basics

It is good practice to wait for the document to be fully loaded and ready before working with it.

slide-34
SLIDE 34

jQuery Tablesorter

Tablesorter is a jQuery plugin for turning a standard HTML table with THEAD and TBODY tags into a sortable table without page refreshes:http://tablesorter.com/

sort by fjrst name in descending order sort by money in ascending order

slide-35
SLIDE 35

jQuery Tablesorter

Step 1: create a table in HTML Step 2: include a single line of code Step 3: sit there and collect money from your classmates

slide-36
SLIDE 36

JavaScript Minification

  • Minification is the process of removing all

unnecessary characters from source code without changing its functionality.

what’s in jquery.min.js: a simple example

Online Javascript Compression Tool white space characters, new line characters, comments are removed

slide-37
SLIDE 37

JSON

  • JSON (JavaScript Object Notation) is a way to store

information in an organized, easy-to-access manner (especially compared to old fashion: XML).

JSON data is writuen as name/value pairs: “lastName”:”Song” an array of objects access the fjrst entry modifjed the data

slide-38
SLIDE 38

Debugging JavaScript

some examples borrowed from https://developers.google.com

slide-39
SLIDE 39

Chrome DevTools

https://developers.google.com/chrome-developer-tools/

slide-40
SLIDE 40

Chrome DevTools: Console

you can enter commands and interact with the document and the Chrome DevTools

slide-41
SLIDE 41

Chrome DevTools: Inspect Element

DOM tree view DOM element CSS style DOM node

slide-42
SLIDE 42

Debugging Javascript: the Sources Panel

slide-43
SLIDE 43

Debugging Javascript: Breakpoints

set breakpoints multiple breakpoints

slide-44
SLIDE 44

Debugging Javascript: Conditional Statement

Type any expression and the breakpoint will pause only if the condition is true.

slide-45
SLIDE 45

Debugging Javascript: Evaluate While Paused

  • pen up the console to experiment

complete execution path

slide-46
SLIDE 46

Debugging Javascript: Intercept Network Data

you can fjnd download link here visualize 3D model by MeshLab

slide-47
SLIDE 47

HTML5

some examples borrowed from http://code.tutsplus.com/

slide-48
SLIDE 48

HTML5: Canvas Element

canvas element 2d rendering context draw a rectangle ctx.fjllRect(x, y, width, height);

slide-49
SLIDE 49

HTML5 Canvas: Fill vs. Stroke

strokeRect() fillRect()

slide-50
SLIDE 50

HTML5 Canvas: Changing Color

fillStyle() fillRect()

slide-51
SLIDE 51

HTML5 Canvas: Changing Color

strokeStyle() strokeRect()

slide-52
SLIDE 52

HTML5 Canvas: Setting Line Width

lineWidth strokeStyle()

slide-53
SLIDE 53

HTML5 Canvas: Drawing Paths

start a new path move the cursor draw a line close the path fjll the path

  • utline the path
slide-54
SLIDE 54

HTML5 Canvas: Drawing an Image

an HTML DOM element: image element image load event draw the image on 2d rendering context bug: you should swap these two lines

slide-55
SLIDE 55

HTML5 Canvas: Drawing an Image

slide-56
SLIDE 56

HTML5 Canvas: Accessing Pixels

slide-57
SLIDE 57

HTML5 Canvas: Pixel Manipulation

draw the image on 2d rendering context

slide-58
SLIDE 58

HTML5 Canvas: Pixel Manipulation

invert R, G, B colors clear canvas draw the new image access pixel values

slide-59
SLIDE 59

HTML5 Canvas: Pixel Manipulation

slide-60
SLIDE 60

HTML5: getUserMedia() & Video

Step 1: include the following codes in your JavaScript Step 2: allow access to your camera Step 3: you are ready to spy on your friends using this web app

slide-61
SLIDE 61

Server-side Programming

some examples borrowed from http://www.w3schools.com/

slide-62
SLIDE 62

Server-side Programming

  • AJAX: exchange data with a server & update parts of a web page

— without reloading the whole page.

  • Examples: Google Maps, Gmail, Youtube …
  • Turn your computer to a server: 1) ip address 2) install apache2

CGI

script/binary program C++/C, PHP, Python, Matlab, ASP, .net

AJAX

slide-63
SLIDE 63

Summary

Language Role Where it Runs HTML Content and Stucture Browser CSS Style and Presentation Browser JavaScript Client Side Scripting Browser PHP/Python/ ASP/… Server Side Scripting Server MySQL Data Management Server

slide-64
SLIDE 64

Useful Resources

  • w3schools
  • Google
slide-65
SLIDE 65

Thank You