GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — add changes :earth_americas: · xiaoruiguo/fullstack-javascript@82ad1c3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • chapter3
    • chapter3.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎chapter3/chapter3.md‎

Copy file name to clipboardExpand all lines: chapter3/chapter3.md
+49-70Lines changed: 49 additions & 70 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ block:
310310
</div> *<!-- col-md-12 -->*
311311
</div> *<!-- row-fluid -->*
312312

313-
This is the full source code of the `index.html` from
314-
[1-bootstrap](https://github.com/azat-co/fullstack-javascript/tree/master/code/01-bootstrap):
313+
This is the full source code of the `index.html` from the
314+
[1-bootstrap](https://github.com/azat-co/fullstack-javascript/tree/master/code/01-bootstrap) folder (<http://bit.ly/2JCbSTv>):
315315

316316
<!DOCTYPE html>
317317
<html lang="en">
@@ -339,50 +339,38 @@ This is the full source code of the `index.html` from
339339
</body>
340340
</html>
341341

342-
This example is available for downloading and pulling from the GitHub
343-
public [repository at
344-
`github.com/azat-co/fullstack-javascript`](https://github.com/azat-co/fullstack-javascript)
345-
under the [01-bootstrap
346-
folder](https://github.com/azat-co/fullstack-javascript/tree/master/code/01-bootstrap)
347-
(https://github.com/azat-co/fullstack-javascript/tree/master/code/01-bootstrap).
348-
If you prefer to watch screencasts, I recorded one on YouTube
349-
(http://bit.ly/1RKx9uY).
342+
This example is available for downloading and pulling from the GitHub public repository at <https://github.com/azat-co/fullstack-javascript> under the [01-bootstrap folder](https://github.com/azat-co/fullstack-javascript/tree/master/code/01-bootstrap) (<http://bit.ly/2JCbSTv>).
350343

351-
This and other videos, will walk you through the same steps as outlined
352-
in the book. So if you are reading this book in print, no worries. The
353-
information in the book is enough.
344+
CSS is not a real programming language. It does not have dependency mechanism, variables or functions. That's why some developers invented CSS frameworks and a lot of developers use them to a much success over plain CSS. There frameworks allow for a better CSS reuse and composition. Here are some other useful tools—CSS frameworks and CSS preprocessors—worth checking out:
354345

355-
Here are some other useful tools—CSS frameworks and CSS
356-
preprocessors—worth checking out:
346+
- [*Compass*](http://compass-style.org): CSS
347+
framework (<http://compass-style.org>)
357348

358-
- [*Compass*](http://compass-style.org/)*:* CSS
359-
framework (http://compass-style.org/)
349+
- [*Sass*](http://sass-lang.com): Extension of CSS3 and analog to
350+
Less (<http://sass-lang.com>)
360351

361-
- [*SASS*](http://sass-lang.com/)*:* Extension of CSS3 and analog to
362-
Less (http://sass-lang.com/)
352+
- [*Blueprint*](http://blueprintcss.io): CSS
353+
framework (<http://blueprintcss.io>)
363354

364-
- [*Blueprint*](http://blueprintcss.org/)*:* CSS
365-
framework (http://blueprintcss.org/)
355+
- [*Foundation*](http://foundation.zurb.com): Responsive front-end
356+
framework (<http://foundation.zurb.com>)
366357

367-
- [*Foundation*](http://foundation.zurb.com/)*:* Responsive front-end
368-
framework (http://foundation.zurb.com/)
358+
- [*Bootswatch*](http://bootswatch.com): Collection of customized
359+
Twitter Bootstrap themes (<http://bootswatch.com>)
369360

370-
- [*Bootswatch*](http://bootswatch.com/)*:* Collection of customized
371-
Twitter Bootstrap themes (http://bootswatch.com/)
361+
- [*WrapBootstrap*](https://wrapbootstrap.com): Marketplace for
362+
customized Bootstrap themes (<https://wrapbootstrap.com>)
372363

373-
- [*WrapBootstrap*](https://wrapbootstrap.com/)*:* Marketplace for
374-
customized Bootstrap themes (https://wrapbootstrap.com/)
375-
376-
To work with the Twitter Bootstrap source file, you need to use Less or
377-
[SASS](https://github.com/twbs/bootstrap-sass) (another CSS framework
378-
similar to Less).
364+
To work with the Bootstrap source files or its theme files, you need to use Less or
365+
[SASS](https://github.com/twbs/bootstrap-sass).
379366

380367
Less
381368
====
382369

383-
Less is a dynamic stylesheet language. Sometimes, and in this case, it's
370+
Less is a dynamic stylesheet language. Less has variables, mix-ins, and operators that make it faster for
371+
developers to reuse CSS rules. Sometimes, and in this case, it's
384372
true that less is more and more is less. A browser cannot interpret Less
385-
syntax, so Less source code must be compiled to CSS in one of the three
373+
syntax, so Less source code must be compiled to CSS in one of three
386374
ways:
387375

388376
1. In the browser by the Less JavaScript library
@@ -392,18 +380,15 @@ ways:
392380
module](https://npmjs.org/package/less) (https://www.npmjs.com/package/less)
393381

394382
3. Locally on your machine by command line (installed with npm by
395-
running `$ npm install -g less`), [WinLess](http://winless.org)
396-
(http://winless.org/), [Less App](http://incident57.com/less)
397-
(http://incident57.com/codekit/index.html),
398-
[SimpLess](http://wearekiss.com/simpless)
399-
(http://wearekiss.com/simpless), or a similar app
383+
running `$ npm install -g less`), or a desktop app such as [WinLess](http://winless.org)
384+
(<http://winless.org>), [CodeKit](https://codekitapp.com/index.html)
385+
(<https://codekitapp.com/index.html>),
386+
[SimpLess](https://github.com/Paratron/SimpLESS)
387+
(<https://github.com/Paratron/SimpLESS>)
400388

401-
The browser option is suitable for a development environment, but
389+
The browser option (on the fly compilation) is suitable for a development environment but
402390
suboptimal for a production environment.
403391

404-
Less has variables, mix-ins, and operators that make it faster for
405-
developers to reuse CSS rules.
406-
407392
Less Variables
408393
--------------
409394

@@ -437,8 +422,8 @@ one place versus two in CSS. This is abstraction at its best.
437422
Less Mix-ins
438423
------------
439424

440-
This about mix-ins as functions. The syntax for a mix-in is the same as
441-
for creating a class selector. For example this is a `.border` mix-in:
425+
This section is about mix-ins. They are like functions in JavaScript. The syntax for a mix-in is the same as
426+
for creating a class selector. For example, this is a `.border` mix-in:
442427

443428
.border {
444429
border-top: dotted 1px black;
@@ -549,7 +534,7 @@ reuse them in multiple apps.
549534
Other important [Less features](http://lesscss.org/#docs)
550535
(<http://lesscss.org/#docs>) include the following:
551536

552-
- Pattern-matching
537+
- Pattern matching
553538

554539
- Nested rules
555540

@@ -566,24 +551,19 @@ Other important [Less features](http://lesscss.org/#docs)
566551
An Example Using a Third-Party API (OpenWeatherMap) and jQuery
567552
==============================================================
568553

569-
Supplemental video which walks you through the implementation and
570-
demonstrates the project: <http://bit.ly/1RKxyxA>.
571-
572-
This example is for purely demonstrative purposes. It is not a part of
573-
the main Message Board application covered in later chapters. The goal
574-
is to just illustrate the combination of jQuery, JSONP, and REST API
575-
technologies.
576-
554+
In this section we will look at a Weather app example. It is a standalone example that is not a part of
555+
the main Message Board application introduced in this chapter and covered in details in later chapters.
577556

578-
The idea of this weather application is to show you an input field for
579-
the city name and buttons for metric and imperial systems. The first page of the Weather application has the input field for the city name and two buttons for metric and imperial forecasts (Figure 3-1).
557+
The goal of the Weather app is to just illustrate the combination of jQuery, JSONP, and REST API
558+
technologies. The idea of this weather application is to show you an input field for
559+
the city name and buttons for metric and imperial systems (C or F degrees). The first view of the Weather application is shown in Figure 3-1. The view has the input field for the city name and two buttons for metric and imperial forecasts (Figure 3-1).
580560

581561
![](media/weather-1.png)
582562

583-
***Figure 3-1.** Weather App has a text input field and two button for the forecasts.*
563+
***Figure 3-1.** Weather App has a text input field and two buttons for the forecasts.*
584564

585565
Once you enter the city name and click one of the buttons, the app will fetch the
586-
forecast from OpenWeatherMap. Depending on what button is pressed, the app will fetch the forecast in metric (C) or imperial (F) degrees. For example, I like in the heart of tech innovation, San Francisco and we use imperial F degrees here so my result will be similar to the one shown in Figure 3-2. The forecast will be for several days with a 3-hour difference between predictions.
566+
forecast from OpenWeatherMap. Depending on which button you press, the app will fetch the forecast in metric (C) or imperial (F) degrees. For example, I live in the heart of all the tech innovations, San Francisco, and we use imperial F degrees here, so my result will be similar to the one shown in Figure 3-2. The forecast will be for several days with a 3-hour difference between predictions.
587567

588568
![](media/weather-2.png)
589569

@@ -595,7 +575,7 @@ API](http://openweathermap.org) 2.5. The API requires an authentication
595575
(an app ID) for REST calls. You can get the necessary keys at
596576
<http://openweathermap.org/appid>. The API
597577
documentation is available at
598-
<http://openweathermap.org/api>. If you are starting the weather app from the code folder of the repository for this book, then make sure you update the API key as you might have my API key there which might not work in the future.
578+
<http://openweathermap.org/api>. If you are starting the weather app from the code folder of the repository for this book, then make sure you update the API key, because the key in the provided code may be my key and it may not work in the future.
599579

600580
In this example, we'll use jQuery's `$.ajax()` function. It has
601581
the following syntax:
@@ -611,13 +591,13 @@ the following syntax:
611591
alert('Error sending request')
612592
})
613593

614-
In the code fragment of an `ajax()` function just shown, we used
594+
In the code fragment of the `ajax()` function just shown, we used
615595
the following parameters:
616596

617597
- `url` is an endpoint of the API.
618598

619599
- `dataType` is the type of data we expect from the server; for
620-
example, "json", "xml", "jsonp" (JSON with padding—format for servers
600+
example, `json`, `xml`, `jsonp` (JSON with padding—format for servers
621601
that don't support CORS).
622602

623603
- `data` is the data to be sent to the server.
@@ -626,23 +606,22 @@ the following parameters:
626606
called after the request comes back; by default jQuery will create
627607
a name.
628608

629-
- `type` is HTTP method of the request; for example, "GET", "POST".
609+
- `type` is the HTTP method of the request; for example, `GET`, `POST`.
630610

631611
There is also a chained method `.fail`, which has logic for what to do
632612
when the request has an error (i.e., it fails).
633613

634-
For more parameters and examples of the `ajax()` function, go to
635-
[`api.jquery.com/jQuery.ajax`](http://api.jquery.com/jQuery.ajax/).
614+
For more parameters and examples of the `ajax()` function, go to <http://api.jquery.com/jQuery.ajax>.
636615

637616
To assign our function to a user-triggered event, we need to use the
638-
`click` function from the jQuery library. The syntax is very simple:
617+
`click()` function from the jQuery library. The syntax is very simple:
639618

640619
$('#btn').click(function() {
641620
...
642621
}
643622

644623
`$('#btn')` is a jQuery object that points to an HTML element
645-
in the DOM with the `id` of `btn`.
624+
in the DOM with the element ID (`id`) of `btn`.
646625

647626
To make sure that all of the elements we want to access and use are in
648627
the DOM, we need to enclose all of the DOM manipulation code inside of
@@ -659,7 +638,7 @@ DOM.
659638
We must put the event handlers for the buttons in the
660639
`$(document).ready()` callback. Otherwise, the code might try to
661640
attach an event listener to a nonexisting DOM element. The
662-
`$(document).ready()` ensures that the browser rendered all the DOM
641+
`$(document).ready()` callback ensures that the browser rendered all the DOM
663642
elements.
664643

665644
$(document).ready(function(){
@@ -731,7 +710,7 @@ say, we must pass the city name, app ID, and units as follows:
731710
}
732711

733712
The JSONP fetching function magically (thanks to jQuery) makes
734-
cross-domain calls by injecting script tag, and appending the callback
713+
cross-domain calls by injecting `<script>` tags and appending the callback
735714
function name to the request query string.
736715

737716
At this point, we need to implement `fetchData` and update the view with
@@ -875,17 +854,17 @@ the `index.html` file:
875854
Try launching it and see if it works with or without the local HTTP
876855
server (just opening `index.html` in the browser). It should not work
877856
without an HTTP server because of its reliance on JSONP technology. You
878-
can get `http-static` or `http-server` command-line tools as described
857+
can get `node-static` or `http-server` command-line tools as described
879858
in Chapter 2.
880859

881860
The source code is available in the
882861
[`03-weather`](https://github.com/azat-co/fullstack-javascript/tree/master/code/03-weather)
883-
folder and on GitHub (https://github.com/azat-co/fullstack-javascript/tree/master/code/03-weather). Don't forget that there's a [screencast video on YouTube](http://bit.ly/1RKxyxA) which walks you through the implementation and demonstrates the app.
862+
folder and on GitHub (https://github.com/azat-co/fullstack-javascript/tree/master/code/03-weather).
884863

885864
This example was built with OpenWeatherMap API v2.5 and might not work
886865
with later versions. Also, you need the API key called app ID. You can
887866
get the necessary keys at
888-
[`openweathermap.org/appid`](http://openweathermap.org/appid). If you
867+
<http://openweathermap.org/appid>. If you
889868
feel that there must be a working example, please submit your feedback
890869
to [the GitHub repository for the book's projects](https://github.com/azat-co/fullstack-javascript) (https://github.com/azat-co/fullstack-javascript).
891870

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.