@@ -310,8 +310,8 @@ block: |
310 | 310 | </div> *<!-- col-md-12 -->* |
311 | 311 | </div> *<!-- row-fluid -->* |
312 | 312 |
|
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>): |
315 | 315 |
|
316 | 316 | <!DOCTYPE html> |
317 | 317 | <html lang="en"> |
@@ -339,50 +339,38 @@ This is the full source code of the `index.html` from |
339 | 339 | </body> |
340 | 340 | </html> |
341 | 341 |
|
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>). |
350 | 343 |
|
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: |
354 | 345 |
|
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>) |
357 | 348 |
|
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>) |
360 | 351 |
|
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>) |
363 | 354 |
|
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>) |
366 | 357 |
|
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>) |
369 | 360 |
|
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>) |
372 | 363 |
|
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). |
379 | 366 |
|
380 | 367 | Less |
381 | 368 | ==== |
382 | 369 |
|
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 |
384 | 372 | 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 |
386 | 374 | ways: |
387 | 375 |
|
388 | 376 | 1. In the browser by the Less JavaScript library |
@@ -392,18 +380,15 @@ ways: |
392 | 380 | module](https://npmjs.org/package/less) (https://www.npmjs.com/package/less) |
393 | 381 |
|
394 | 382 | 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>) |
400 | 388 |
|
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 |
402 | 390 | suboptimal for a production environment. |
403 | 391 |
|
404 | | -Less has variables, mix-ins, and operators that make it faster for |
405 | | -developers to reuse CSS rules. |
406 | | - |
407 | 392 | Less Variables |
408 | 393 | -------------- |
409 | 394 |
|
@@ -437,8 +422,8 @@ one place versus two in CSS. This is abstraction at its best. |
437 | 422 | Less Mix-ins |
438 | 423 | ------------ |
439 | 424 |
|
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: |
442 | 427 |
|
443 | 428 | .border { |
444 | 429 | border-top: dotted 1px black; |
@@ -549,7 +534,7 @@ reuse them in multiple apps. |
549 | 534 | Other important [Less features](http://lesscss.org/#docs) |
550 | 535 | (<http://lesscss.org/#docs>) include the following: |
551 | 536 |
|
552 | | -- Pattern-matching |
| 537 | +- Pattern matching |
553 | 538 |
|
554 | 539 | - Nested rules |
555 | 540 |
|
@@ -566,24 +551,19 @@ Other important [Less features](http://lesscss.org/#docs) |
566 | 551 | An Example Using a Third-Party API (OpenWeatherMap) and jQuery |
567 | 552 | ============================================================== |
568 | 553 |
|
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. |
577 | 556 |
|
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). |
580 | 560 |
|
581 | 561 |  |
582 | 562 |
|
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.* |
584 | 564 |
|
585 | 565 | 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. |
587 | 567 |
|
588 | 568 |  |
589 | 569 |
|
@@ -595,7 +575,7 @@ API](http://openweathermap.org) 2.5. The API requires an authentication |
595 | 575 | (an app ID) for REST calls. You can get the necessary keys at |
596 | 576 | <http://openweathermap.org/appid>. The API |
597 | 577 | 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. |
599 | 579 |
|
600 | 580 | In this example, we'll use jQuery's `$.ajax()` function. It has |
601 | 581 | the following syntax: |
@@ -611,13 +591,13 @@ the following syntax: |
611 | 591 | alert('Error sending request') |
612 | 592 | }) |
613 | 593 |
|
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 |
615 | 595 | the following parameters: |
616 | 596 |
|
617 | 597 | - `url` is an endpoint of the API. |
618 | 598 |
|
619 | 599 | - `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 |
621 | 601 | that don't support CORS). |
622 | 602 |
|
623 | 603 | - `data` is the data to be sent to the server. |
@@ -626,23 +606,22 @@ the following parameters: |
626 | 606 | called after the request comes back; by default jQuery will create |
627 | 607 | a name. |
628 | 608 |
|
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`. |
630 | 610 |
|
631 | 611 | There is also a chained method `.fail`, which has logic for what to do |
632 | 612 | when the request has an error (i.e., it fails). |
633 | 613 |
|
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>. |
636 | 615 |
|
637 | 616 | 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: |
639 | 618 |
|
640 | 619 | $('#btn').click(function() { |
641 | 620 | ... |
642 | 621 | } |
643 | 622 |
|
644 | 623 | `$('#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`. |
646 | 625 |
|
647 | 626 | To make sure that all of the elements we want to access and use are in |
648 | 627 | the DOM, we need to enclose all of the DOM manipulation code inside of |
|
659 | 638 | We must put the event handlers for the buttons in the |
660 | 639 | `$(document).ready()` callback. Otherwise, the code might try to |
661 | 640 | 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 |
663 | 642 | elements. |
664 | 643 |
|
665 | 644 | $(document).ready(function(){ |
@@ -731,7 +710,7 @@ say, we must pass the city name, app ID, and units as follows: |
731 | 710 | } |
732 | 711 |
|
733 | 712 | 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 |
735 | 714 | function name to the request query string. |
736 | 715 |
|
737 | 716 | At this point, we need to implement `fetchData` and update the view with |
@@ -875,17 +854,17 @@ the `index.html` file: |
875 | 854 | Try launching it and see if it works with or without the local HTTP |
876 | 855 | server (just opening `index.html` in the browser). It should not work |
877 | 856 | 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 |
879 | 858 | in Chapter 2. |
880 | 859 |
|
881 | 860 | The source code is available in the |
882 | 861 | [`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). |
884 | 863 |
|
885 | 864 | This example was built with OpenWeatherMap API v2.5 and might not work |
886 | 865 | with later versions. Also, you need the API key called app ID. You can |
887 | 866 | get the necessary keys at |
888 | | -[`openweathermap.org/appid`](http://openweathermap.org/appid). If you |
| 867 | +<http://openweathermap.org/appid>. If you |
889 | 868 | feel that there must be a working example, please submit your feedback |
890 | 869 | to [the GitHub repository for the book's projects](https://github.com/azat-co/fullstack-javascript) (https://github.com/azat-co/fullstack-javascript). |
891 | 870 |
|
|