diff --git a/appendix_c_ide.asciidoc b/appendix_c_ide.asciidoc index 7bc650d0..62ebc3b6 100644 --- a/appendix_c_ide.asciidoc +++ b/appendix_c_ide.asciidoc @@ -1,14 +1,14 @@ [[appendix_c]] [appendix] -= Appendix C. Running Code Samples and IDE +== Appendix C. Running Code Samples and IDE The code samples used in this book are available on https://github.com/Farata/EnterpriseWebBook_sources[Github] - they are grouped by chapters. If a chapter has code samples, look for the directory with the respective name. Technically, you don't have to use any Integrated Development Environment (IDE) to run code examples (except the CDB example from Chapter 5) - just open the main file in a Web browser and off you go. But using an IDE will make you more productive. -== Which IDE to Use +=== Which IDE to Use Selecting an IDE that supports JavaScript is a matter of your personal preference. Since there is no compilation stage and most of your debugging will be done using the Web browser tools, picking a text editor that supports syntax highlighting is all that most developers need. For example, there is an excellent text editor http://www.sublimetext.com[Sublime Text 2]. Among many programming languages this editor understands the keywords of HTML, CSS, and JavaScript, and it offers not only syntax highlighting, context sensitive help, and auto-complete too. @@ -22,7 +22,7 @@ Appcelerator offers a free Eclipse-based http://aptana.com[Aptana Studio 3 IDE]. The authors of this book like and recommend using the http://www.jetbrains.com/webstorm[IDE WebStorm] from JetBrains. In addition to smart context sensitive help, auto-complete, and syntax highlighting it offers HTML5 templates, and the code coverage feature that identifies the code fragment that haven't been tested. -== Running Code Samples in WebStorm IDE +=== Running Code Samples in WebStorm IDE WebStorm IDE is pretty intuitive to use. If you've never used it before, refer to its http://www.jetbrains.com/webstorm/quickstart/[Quick Start Guide]. When you first start WebStorm IDE, select the option _Open Directory_ in the Welcome screen. Then select the directory where you downloaded the samples of a specific book chapter. For example, after opening code samples from Chapter 1 the WebStorm IDE may look as follows: @@ -37,7 +37,7 @@ For example, if the WebStorm's opened directory chapter1 as in Figure < TIP: You can configure in WebStorm the port number of the internal Web Server via Preferences | Debugger | JavaScript | Built-in server port. -== Using two IDEs: WebStorm and Eclipse +=== Using two IDEs: WebStorm and Eclipse Although we prefer using WebStorm for JavaScript development, but have to use Eclipse for some Java-related projects. In such cases we create a project in WebStorm pointing at the WebContent directory of your Eclipse project. This way we still enjoy a very smart context sensitive help offered by WebStorm, and all code modifications become immediately visible in the Eclipse project. diff --git a/ch11_responsive.asciidoc b/ch11_responsive.asciidoc index 098082a9..426d7a67 100644 --- a/ch11_responsive.asciidoc +++ b/ch11_responsive.asciidoc @@ -2,7 +2,7 @@ :toclevels: 4 :imagesdir: ./ -= Part 3. Responsive Web Design and Mobile += Responsive Web Design and Mobile BYOD stands for Bring Your Own Device. It became a new trend - many enterprises started allowing their employees to access corporate applications from personal tablets or smartphones. CYOD stands for Choose Your Own Device - corporations let their employees to choose a device that belongs to the enterprise. Developers of new Web applications should always think of the users that will try to run this application on a mobile device. This part is about various strategies of developing Web applications that look and perform well not only on the desktop computers but on a smaller screens too. diff --git a/ch1_advancedjs.asciidoc b/ch1_advancedjs.asciidoc index 342fcfa7..b5377bb1 100644 --- a/ch1_advancedjs.asciidoc +++ b/ch1_advancedjs.asciidoc @@ -1,7 +1,7 @@ [[appendix_a]] [appendix] -= Appendix A. Advanced Introduction to JavaScript +== Appendix A. Advanced Introduction to JavaScript _"Atwood's Law: any application that can be written in JavaScript, will eventually be written in JavaScript._ @@ -13,7 +13,7 @@ NOTE: If you're absolute beginner with Web development and had no previous expos Besides the JavaScript coverage this Appendix includes a section on the tools (IDEs, debuggers, Web inspectors et al.) that will make your development process more productive. -== JavaScript: A Brief History +=== JavaScript: A Brief History The JavaScript programming language was designed in 1995 by Brendan Eich, who was working for Netscape Communications Corporation at the time. His goal was to allow developers create more interactive Web pages. Initially the name of this language was Mocha, then LiveScript, and finally Netscape agreed with Sun Microsystems, creator of Java to rename it to JavaScript. @@ -42,7 +42,7 @@ JavaScript became the lowest common denominator available on thousands of differ JavaScript is an interpreted language that arrives to the Web browser as text. The JavaScript engine optimizes and compiles the code before the execution. The JavaScript engine is a part of the Web browser, which will load and execute the JavaScript code embedded or referenced between the HTML tags ``. JavaScript was originally created for Web browsers, which were supposed to display whatever content has successfully arrived. What if an image has not arrived from the server? You’ll see a broken image icon. What if erroneous JavaScript code with syntax errors has arrived to the browser? Well, the engine will try to execute whatever code has arrived. The end users may appreciate such browser's forgiveness when at least some content is available, but the software developers should be ready to spend more time debugging (in multiple browsers) the errors that could have been caught by compilers in other programming languages. -== JavaScript Variables +=== JavaScript Variables JavaScript is a weakly typed language hence the developers don’t have a luxury of strong compiler's help that Java or C# developers enjoy. For those unfamiliar with weakly typed languages, let us explain. Imagine that if in Java or C# instead of declaring variables of specific data types everything would be of type `Object`, and you could assign to it any value – a string, a number, or a custom object `Person`. This would substantially complicate the ability of the compiler to weed out all possible errors. You don’t need to declare variables in JavaScript – just assign a value and the JavaScript engine will figure out the proper type during the execution of your code.For example, the variable named `girlfriend` will have a data type of `String`: @@ -59,8 +59,8 @@ Variables declared with the `var` keyword inside functions are have local scope function addPersonalInfo(){ var address ="123 Main Street"; // local String variable age=25; // global Number variable - var isMarried = true; // local boolean variable - isMarried = "don't remember"; // now it's of String type + var isMarried == true; // local boolean variable + isMarried == "don't remember"; // now it's of String type } ---- @@ -69,7 +69,7 @@ The variables `address` and `isMarried` are visible only inside the function `ad The variable `isMarried` changes its type from `Boolean` to `String` during the execution of the above script, and JavaScript engine won't complain assuming that the programmer knows what she’s doing. So be ready for the run-time surprises and allocate a lot more time for testing than with programs written in compiled languages. -== Getting Familiar with Aptana IDE +=== Getting Familiar with Aptana IDE Download and install Aptana Studio 3 from http://aptana.com[http://aptana.com]. Start Aptana IDE, then close its initial tab view by clicking on the little X on the tab. Then customize the color theme of this IDE by clicking the rainbow-colored circle on its toolbar. We usually select the theme called Eclipse. After the first start of Aptana you’ll see the message on the left side that reads ``There are no projects in your workspace. To get started, please create or import an existing one.'' @@ -99,7 +99,7 @@ To configure the Web Browser that Aptana should open by default, open its Prefer TIP: you can find various HTML5 boilerplate projects on the Web that can be used as a starting point of your project. You don't have to select the Aptana's HTML5 boilerplate if it doesn't fit your needs. For example, you can download a bare minimum boilerplate http://projects.craftedpixelz.co.uk/shibui/[Shibui] or more comprehensive http://html5boilerplate.com/[HTML5 Boilerplate]. Just download and unzip such a boilerplate project into your Aptana's workspace and start adding your code, styles, and other resources. -== Adding JavaScript to HTML +=== Adding JavaScript to HTML Software developers either directly include the JavaScript code to the HTML document by placing it between the tags `` or include a reference to the external location of the code (e.g. a local file name or a URL) in the `src` attribute of the ` @@ -1562,12 +1562,12 @@ While manipulating the content of your Web page you may you may need to traverse function walkTheDOM(node, processNode){ processNode(node) - node = node.firstChild; + node == node.firstChild; while(node){ // call wakTheDOM recursively for each child walkTheDOM(node,processNode); - node = node.nextSibling; + node == node.nextSibling; } } @@ -1696,7 +1696,7 @@ If you run this example and click on the button "Show me" you'll see an image of .After clicking the button "Show me" image::images/fig_02_23.jpg[] -=== DOM Events +==== DOM Events Web browser will notify your application when some changes or interactions occur. In such cases the browser will dispatch an appropriate event, for example `load`, `unload`, `mousemove`, `click`, `keydown` etc. When the Web page finished loading the browser will dispatch the `load` event. When the user will click on the button on a Web page the `click` event will be dispatched. A Web developer needs to provide JavaScript code that will react on the events important to the application. The browser events will occur regardless of if you provided the code to handle them or not. It's important to understand some terms related to event processing. @@ -1838,7 +1838,7 @@ You can see another example of using intercepting the event during the capture p TIP: The Microsoft's Web browsers Internet Explorer 8 and below didn't implement the W3C DOM Level 3 event model - they handled events differently. You can read more on the subject at this MSDN article http://blogs.msdn.com/b/ie/archive/2010/03/26/dom-level-3-events-support-in-ie9.aspx[http://bit.ly/anZZgZ]. -== Summary +=== Summary This appendix covered the JavaScript language constructs that any professional Web developer should know. A smaller portion of this chapter was illustrating how to combine JavaScript, HTML, and CSS. There are lots of online resources and books that cover just the HTML markup and CSS, and you'll definitely need to spend more time mastering details of the Web tools like Firebug or Google Developer Tools. diff --git a/ch2_html.asciidoc b/ch2_html.asciidoc index e84a2a39..f2342e11 100644 --- a/ch2_html.asciidoc +++ b/ch2_html.asciidoc @@ -3,7 +3,7 @@ [[appendix_b]] [appendix] -= Appendix B. Selected HTML5 APIs +== Appendix B. Selected HTML5 APIs This appendix is a brief review of selected HTML5 APIs. HTML5 is just a commonly used term for a combination of HTML, JavaScript, CSS, and several new APIs that appeared during the last several years. Five years ago people were using the term _Web 2.0_ to define modern looking applications. These days HTML5 is almost a household name, and we'll go along with it. But HTML5 is about the same old development in JavaScript plus latest advances in HTML and CSS. @@ -11,7 +11,7 @@ This appendix is more of an overview of selected APIs that are included in HTML5 NOTE: To understand code samples included in this appendix you have to be familiar with JavaScript and some monitoring tools like Chrome Developer Tools. We assume that you are familiar with the materials covered in Appendix A. -== Does your Browser Support HTML5? +=== Does your Browser Support HTML5? The majority of the modern Web browsers already support the current version of http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#workers[HTML5 specification], which will become a W3C standard in 2014. The question is if the users of your Web application have a modern browser installed on their device? There are two groups of users that will stick to the outdated browsers for some time: @@ -36,7 +36,7 @@ http://net.tutsplus.com/tutorials/html-css-techniques/the-official-guide-to-html screencast by Paul Irish], a co-creator of HTML5 Boilerplate. You can also read the current version of the https://github.com/h5bp/html5-boilerplate/blob/v4.0.0/doc/usage.md[Getting started with HTML5 Boilerplate] on Github. -== Handling Differences in Browsers +=== Handling Differences in Browsers This appendix is about selected HTML APIs that we find important to understand in Web applications. But before using any of the API's listed here you want to check if the versions of the Web browsers you have to user support these APIs. The Web site http://caniuse.com[http://caniuse.com] will give you the up-to-date information about all major browsers and their versions that do (or don't) support the API in question. For example, to see which browsers support Worker API visit http://caniuse.com/#search=Worker[caniuse.com]. @@ -62,11 +62,11 @@ if (Modernizr.Worker) { ) ---- -== HTML5 Web Messaging API +=== HTML5 Web Messaging API http://www.w3.org/TR/webmessaging/[HTML5 Web Messaging] allows you to arrange for communication between different Web pages of the same Web application. More officially, it's about "communicating between browsing contexts in HTML documents". Web messaging also allows you to work around the "same domain" policy that would result in security error if a browser's page A has one origin (the combination of URL scheme, host name and port, e.g. http://myserver.com:8080) and tries to access property of a page B that was downloaded from another origin. But with messaging API windows downloaded from different origins can send messages to each other. -=== Sending and Receiving Messages +==== Sending and Receiving Messages The API is pretty straightforward: if a script in the page `WindowA` has a reference to `WindowB` where you want to send a message, invoke the following method: @@ -90,9 +90,9 @@ function myEventHandler(event){ } ---- -//The window-receiver can reject messages from untrusted origins. The event's property `origin` contains the scheme, host name and the port of the message sender (not the full URI). A simple statement like `if event.origin == 'http://mytrusteddomain:8080'` will ensure that only the messages arrived from the trusted origin are processed. +//The window-receiver can reject messages from untrusted origins. The event's property `origin` contains the scheme, host name and the port of the message sender (not the full URI). A simple statement like `if event.origin === 'http://mytrusteddomain:8080'` will ensure that only the messages arrived from the trusted origin are processed. -=== Communicating with an iFrame +==== Communicating with an iFrame Let's consider an example where an HTML Window creates an iFrame and needs to communicate with it. In particular, the iFrame will notify the main window that it has loaded, and the main window will acknowledge receiving of this message. @@ -147,10 +147,10 @@ The source code of this example is shown next. It's just two HTML files: mainWin } } - window.onload = function() { // <4> + window.onload == function() { // <4> window.addEventListener('message', handleMessage, false); - theiFrame = document.getElementById('myFrame'); - theiFrame.src = "myFrame.html"; + theiFrame == document.getElementById('myFrame'); + theiFrame.src == "myFrame.html"; } @@ -168,7 +168,7 @@ The source code of this example is shown next. It's just two HTML files: mainWin [source, javascript] ---- - var myPopupWindow = window.open(...); + var myPopupWindow == window.open(...); myPopupWindow.postMessage("Hello Popup", "*"); ---- + @@ -192,15 +192,15 @@ The code of the myFrame.html comes next. This frame contains two buttons Buy and