Table of Contents

Open all
Close all
Materials for This Book
17
1 Introduction
19
1.1 What Can JavaScript Do?
19
1.2 What Can JavaScript Not Do?
20
1.3 Browsers and Mobile Browsers
20
1.4 ECMAScript
21
1.5 Structure of This Book
21
1.6 First Example with HTML and CSS
23
1.6.1 Output of the Program
23
1.6.2 HTML File
23
1.6.3 UTF-8 Encoding
25
1.6.4 Responsive Web Design
26
1.7 Some Special Characters
28
1.8 JavaScript in the Document
29
1.9 JavaScript from an External File
31
1.10 Comments
32
1.11 No JavaScript Is Possible
33
2 Basic Principles of Programming
35
2.1 Storing Values
35
2.1.1 Formatting Strings
35
2.1.2 Naming Rules
38
2.1.3 Input and Output of Strings
38
2.1.4 Storing Numbers
40
2.1.5 Storing Truth Values
42
2.2 Performing Complex Calculations
42
2.2.1 Calculation Operators
43
2.2.2 Combined Assignment
45
2.2.3 Entering Numbers
46
2.2.4 Number Systems
48
2.3 Different Branches in a Program
49
2.3.1 Branches with if
50
2.3.2 Requesting a Confirmation
52
2.3.3 Linking Multiple Conditions
53
2.3.4 Linking and Assigning
55
2.3.5 Checking the Input of Numbers
56
2.3.6 Checking the Value and Type
58
2.3.7 Priority of Operators
60
2.3.8 Branches with switch
60
2.4 Repeating Program Sections
61
2.4.1 Loops with for
62
2.4.2 Loops and Tables
64
2.4.3 Loops and Fields
66
2.4.4 Loops with while
68
2.4.5 Loops with do … while
69
2.4.6 A Game for Memory Training
71
2.5 Finding and Avoiding Errors
73
2.5.1 Developing a Program
74
2.5.2 Finding Errors Using onerror
74
2.5.3 Exception Handling Using try ... catch
76
2.5.4 Throwing Exceptions Using throw
77
2.5.5 Debugging a Program
78
2.6 Custom Functions
81
2.6.1 Simple Functions
82
2.6.2 Swapping Out Functions
83
2.6.3 Functions with Parameters
84
2.6.4 Changing Parameters
85
2.6.5 Functions with Return Value
87
2.6.6 Destructuring Assignment
88
2.6.7 Evaluation Using Short Circuit
90
2.6.8 Any Number of Parameters
92
2.6.9 Default Values for Parameters
93
2.6.10 The Validity of Variables
94
2.6.11 Recursive Functions
96
2.6.12 Anonymous Functions
97
2.6.13 Callback Functions
100
3 Custom Objects
103
3.1 Objects and Properties
103
3.2 Methods
105
3.3 Private Members
107
3.4 Setters and Getters
109
3.5 Static Members
111
3.6 Static Blocks
113
3.7 Reference to Nothing
113
3.8 Object in an Object
115
3.9 Inheritance
117
3.10 Operations with Objects
119
3.10.1 Access Operators
120
3.10.2 Creating and Comparing References to Objects
121
3.10.3 Checking Instances
122
3.10.4 Determining a Type
122
3.10.5 Checking a Member
123
3.10.6 Objects and Functions
123
3.10.7 Deleting Properties
124
3.11 Copying Objects
124
4 Forms and Events
129
4.1 First Form and First Event
129
4.2 Submitting and Resetting
132
4.2.1 The Submit Process
132
4.2.2 A Web Server as an Alternative
134
4.2.3 Code for Submitting
135
4.2.4 Code for Receiving
136
4.3 Mandatory Fields and Checking
136
4.4 Radio Buttons and Checkboxes
139
4.5 Selection Menus
142
4.6 Other Form Events
144
4.7 Mouse Events
147
4.8 Changing the Document
150
4.9 Other Types and Properties
151
4.9.1 Text Inputs, Search Fields, and Colors
152
4.9.2 Elements for Numbers
155
4.9.3 Elements for Time Information
160
4.9.4 Validating Forms
164
4.10 Dynamically Created Forms
168
5 The Document Object Model
171
5.1 Tree and Nodes
171
5.2 Retrieving Nodes
173
5.3 Child Nodes
175
5.4 Adding Nodes
177
5.5 Changing Nodes
179
5.6 Deleting Nodes
183
5.7 Creating a Table
184
6 Using Standard Objects
187
6.1 Arrays for Large Amounts of Data
187
6.1.1 One-Dimensional Arrays
187
6.1.2 Multidimensional Arrays
191
6.1.3 Arrays as Parameters and Return Values
195
6.1.4 Callback Functions
198
6.1.5 Adding and Removing Elements
200
6.1.6 Changing Arrays
202
6.1.7 Copying Arrays
205
6.1.8 Sorting Number Arrays
206
6.1.9 Finding Elements in an Array
208
6.1.10 Destructuring and the Spread Operator
209
6.1.11 Arrays of Objects
212
6.2 Processing Strings
213
6.2.1 Creating and Checking Strings
214
6.2.2 Elements of a String
215
6.2.3 Searches and Substrings
217
6.2.4 Changing Strings
218
6.2.5 Checking a Password
221
6.2.6 Unicode Characters
223
6.3 Numbers and Math
224
6.3.1 Math Object
224
6.3.2 Trigonometric Functions
226
6.3.3 Random Generators and Typed Arrays
228
6.3.4 Integers
229
6.3.5 Numbers with Decimal Places
231
6.3.6 Custom Extension for Numbers
233
6.4 Using Time Specifications
235
6.4.1 Creating Time Data
235
6.4.2 Outputting Time Data
237
6.4.3 Extension of the Date Object
238
6.4.4 Calculating with Time Data
240
6.4.5 Second Extension of the Date Object
243
6.5 Time-Controlled Processes
244
6.5.1 Starting Time-Controlled Processes
244
6.5.2 Starting and Ending Time-Controlled Processes
245
6.5.3 Controlling Processes
247
6.5.4 Slideshow and Single Image
248
6.6 Other Data Structures
251
6.6.1 Sets
252
6.6.2 Maps
253
6.7 JavaScript Object Notation
256
6.7.1 JSON Format and JSON Objects
256
6.7.2 Custom Classes and JSON Methods
257
6.7.3 JSON Object and Arrays
258
6.7.4 JSON Format and Arrays
259
6.7.5 Custom Classes and Arrays
260
7 Changes Using Ajax
263
7.1 Hello Ajax
263
7.2 Sending Parameters
266
7.3 Reading an XML File
269
7.3.1 Single Object
269
7.3.2 Collection of Objects
272
7.3.3 Search Suggestions
274
7.4 Reading a JSON File
278
7.4.1 Single Object
278
7.4.2 Collection of Objects
280
8 Design Using Cascading Style Sheets
283
8.1 Structure and Rules
283
8.1.1 Locations and Selectors
283
8.1.2 Combinations
286
8.1.3 Cascading and Overlaying
288
8.2 Changing Properties
289
8.2.1 Position
290
8.2.2 Size
293
8.2.3 Position in the Z Direction
295
8.2.4 Transparency
297
8.2.5 Visibility
299
8.2.6 Color
301
8.3 Additional Options
303
8.3.1 Transparency when Changing Images
304
8.3.2 Visibility of a Menu
306
8.3.3 Animated Throw
309
9 Two-Dimensional Graphics and Animations Using SVG
311
9.1 Creating an SVG File
311
9.2 Basic Shapes
313
9.2.1 Rectangles
313
9.2.2 Circles and Ellipses
314
9.2.3 Lines, Polylines, and Polygons
315
9.3 Paths
317
9.3.1 Filled Paths
317
9.3.2 Groups and Paths
318
9.3.3 Paths with Curves
319
9.4 Animations
320
9.4.1 Procedure
321
9.4.2 Time Control
322
9.4.3 Event Control
323
9.5 Rotations
324
9.6 SVG and JavaScript
326
9.7 Dynamic SVG Elements
327
9.7.1 Sequence of the Animation
328
9.7.2 Creating the Start State
329
9.7.3 Creating Animations
330
10 Three-Dimensional Graphics and Animations Using Three.js
333
10.1 First 3D Graphic
333
10.1.1 3D Coordinate System
334
10.1.2 Structure of the Program
335
10.1.3 3D Object with Geometry and Material
336
10.1.4 Camera
336
10.1.5 Canvas and Scenes
337
10.2 Moving the Camera
338
10.3 Animation
340
10.4 Various Shapes
340
11 jQuery
343
11.1 Structure
343
11.2 Selectors and Methods
346
11.3 Events
349
11.4 Animations
351
11.5 Example: Sinusoidal Movement
355
11.6 jQuery and Ajax
357
12 Mobile Apps Using Onsen UI
361
12.1 Structure of a Page
361
12.1.1 First Page
361
12.1.2 List of Elements
363
12.1.3 Table with Items
366
12.2 Elements within a Page
367
12.2.1 Icons and Floating Action Buttons
367
12.2.2 Standard Dialogs
370
12.2.3 Input Fields
373
12.2.4 Selection Fields
378
12.2.5 Selection from a Number Range
382
13 Mathematical Expressions Using MML and MathJax
385
13.1 Basic Elements
385
13.2 Parentheses and Tables
387
13.3 Summarizing Expressions
389
13.4 Fractions
391
13.5 Mathematical Symbols
393
13.6 Dynamically Generated Expressions
395
14 Sample Projects
399
14.1 Financial Investment
399
14.2 Fitness Values
400
14.3 Fun Run
401
14.4 Solitaire
402
14.5 Concentration
404
14.6 Snake
405
15 Media, Drawings, and Sensors
407
15.1 Playing Media Files
407
15.1.1 Audio Files
407
15.1.2 Video Files
411
15.2 Canvas
412
15.2.1 Drawings
412
15.2.2 Images
417
15.2.3 Formatted Texts
418
15.3 Sensors
421
15.3.1 Geolocation
421
15.3.2 Waytracking
424
15.3.3 Position Sensor
425
15.3.4 Acceleration Sensor
429
A Installation and Keywords
435
A.1 Installation of the XAMPP Package
435
A.1.1 Installation on Windows
435
A.1.2 Installation on Ubuntu Linux
436
A.1.3 Installation on macOS
437
A.2 List of Keywords
438
B The Author
439
Index
441