Table of Contents

HTML5 and Javascript

Understand about HTML5

HTML5 Browser Support:

HTML5 browser support:

Javascript tools

Node.js

refer:

Node.js® is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

Node.js makes it possible to write applications in JavaScript on the server. It’s built on the V8 JavaScript runtime and written in C++ — so it’s fast. Originally, it was intended as a server environment for applications, but developers started using it to create tools to aid them in local task automation. Since then, a whole new ecosystem of Node-based tools (such as Grunt and Gulp) has evolved to transform the face of front-end development.

To make use of these tools (or packages) in Node.js we need to be able to install and manage them in a useful way. This is where npm, the node package manager, comes in. It installs the packages you want to use and provides a useful interface to work with them. But before we can start using npm, we first have to install Node.js on our system.

Check node version:

node --version

output:

v4.2.6

Install nodejs from source on linux:

  1. Step1: Get nodejs source
    https://nodejs.org/dist/v8.11.1/node-v8.11.1.tar.gz
  2. Step2: Install
    tar xzvf node-v* && cd node-v*
    ./configure
    make
    make install
  3. Error:
    WARNING: C++ compiler too old, need g++ 4.9.4 or clang++ 3.4.2 (CXX=g++)

Install nodejs from linux binary: https://github.com/nodejs/help/wiki/Installation

  1. Step1: Get linux binay
    wget https://nodejs.org/dist/v8.11.1/node-v8.11.1-linux-x64.tar.xz
  2. Step2: Unzip linux binary to /usr/local/nodejs
    mkdir /usr/local/nodejs
    yum install xz
    tar -xJvf node-v8.11.1-linux-x64.tar.xz -C /usr/local/nodejs
  3. Step3: Set the environment variable ~/.profile or ~/.bash_profile, add below to the end
    # Nodejs
    export NODEJS_HOME=/usr/local/nodejs/node-v8.11.1/bin
    export PATH=$NODEJS_HOME:$PATH
  4. Step4:Refresh profile
    .~/.profile
  5. Step6: Check environment:
    echo $PATH
    /usr/local/nodejs/node-v8.11.1/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
  6. Step5: Test installation using
    node -v
    npm version

    output:

    v8.11.1
    { npm: '5.6.0',
      ares: '1.10.1-DEV',
      cldr: '32.0',
      http_parser: '2.8.0',
      icu: '60.1',
      modules: '57',
      nghttp2: '1.25.0',
      node: '8.11.1',
      openssl: '1.0.2o',
      tz: '2017c',
      unicode: '10.0',
      uv: '1.19.1',
      v8: '6.2.414.50',
      zlib: '1.2.11' }

npm(node package manager for javascript...)

refer:

Install and Update npm:

Some command lines of npm:

Grunt(Javascript Task Runner)

refer: http://gruntjs.com/

In one word: automation. The less work you have to do when performing repetitive tasks like minification, compilation, unit testing, linting, etc, the easier your job becomes. After you've configured it through a Gruntfile, a task runner can do most of that mundane work for you—and your team—with basically zero effort.

A typical setup will involve adding two files to your project: package.json and the Gruntfile.

bower(package manager for the web)

refer: http://bower.io/ Web sites are made of lots of things — frameworks, libraries, assets, utilities, and rainbows. Bower manages all these things for you.

Dust

refer: http://akdubya.github.io/dustjs/

Javascript Framework

Javascript and design Experience

Trong trường hợp ta có 1 bộ magamenu với HTML và javascript mẫu, làm thế nào bỏ megamenu vào design của mình?

Javascript framework comparison

refer: https://www.airpair.com/js/javascript-framework-comparison

ExtJs

backbone.js

refer:

Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.

emberjs

refer: http://emberjs.com/

angularjs

refer: https://angularjs.org/
AngularJS lets you write client-side web applications as if you had a smarter browser. It lets you use good old HTML (or HAML, Jade and friends!) as your template language and lets you extend HTML’s syntax to express your application’s components clearly and succinctly. It automatically synchronizes data from your UI (view) with your JavaScript objects (model) through 2-way data binding. To help you structure your application better and make it easy to test, AngularJS teaches the browser how to do dependency injection and inversion of control.
And it helps with server-side communication, taming async callbacks with promises and deferreds. It also makes client-side navigation and deeplinking with hashbang urls or HTML5 pushState a piece of cake. Best of all?? It makes development fun!

opensource apps base on angularjs:

Ionic framework base on angularjs

refer:

Ionic is a powerful HTML5 SDK that helps you build native-feeling mobile apps using web technologies like HTML, CSS, and Javascript.

Ionic is focused mainly on the look and feel, and UI interaction of your app. That means we aren't a replacement for PhoneGap or your favorite Javascript framework. Instead, Ionic simply fits in well with these projects in order to simplify one big part of your app: the front end.

Top Opensources which using javascript framework

Javascript library

underscore.js

refer: http://underscorejs.org/
Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects

requirejs

refer: http://requirejs.org/

highcharts

refer: http://www.highcharts.com/

Javascript with cross domain

a web browser permits scripts contained in a first web page to access data in a second web page(Or cross domain) which Same-origin policy

Same-origin policy

refer: http://en.wikipedia.org/wiki/Same-origin_policy
In computing, the same-origin policy is an important concept in the web application security model. Under the policy, a web browser permits scripts contained in a first web page to access data in a second web page, but only if both web pages have the same origin. An origin is defined as a combination of URI scheme, hostname, and port number\\. Example:

This mechanism bears a particular significance for modern web applications that extensively depend on HTTP cookies to maintain authenticated user sessions, as servers act based on the HTTP cookie information to reveal sensitive information or take state-changing actions. A strict separation between content provided by unrelated sites must be maintained on the client side to prevent the loss of data confidentiality or integrity.

Relaxing the same-origin policy(Nởi lỏng rule gốc)

refer: https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

By Changing origin with document.domain property

A page may change its own origin with some limitations. A script can set the value of document.domain to a subset of the current domain. If it does so, the shorter domain is used for subsequent origin checks. For example, assume a script in the document at http://store.company.com/dir/other.html executes the following statement:

document.domain = "company.com";

After that statement executes, the page would pass the origin check with http://company.com/dir/page.html. However, by the same reasoning, company.com could not set document.domain to othercompany.com.

The port number is kept separately by the browser. Any call to the setter, including document.domain = document.domain causes the port number to be overwritten with null. Therefore one cannot make company.com:8080 talk to company.com by only setting document.domain = “company.com” in the first. It has to be set in both so that port numbers are both null.

The Cross-Origin Resource Sharing method

refer:

Cross-document messaging

Jsonp

Web Sockets

form post cross domain

The same origin policy is applicable only for browser side programming languages. So if you try to post to a different server than the origin server using JavaScript, then the same origin policy comes into play but if you post directly from the form i.e. the action points to a different server like:

<form action="http://someotherserver.com">

and there is no javascript involved in posting the form, then the same origin policy is not applicable.

CSS tools

Sass(CSS pre-processor which wroten with Ruby Language)

refer:

Install:

Sass is an extension of CSS that adds power and elegance to the basic language. It allows you to use variables, nested rules, mixins, inline imports, and more, all with a fully CSS-compatible syntax. Sass helps keep large stylesheets well-organized, and get small stylesheets up and running quickly, particularly with the help of the Compass style library.

Install sass with ruby:

  1. Step1: download and install Ruby from http://rubyinstaller.org/
  2. Step2: install sass with gem tool:
    gem install sass
    gem install compass

Using sass:

Install User-defined language scss to edit with notepad++ :

  1. Step1: download user-defined language for scss from https://github.com/marvinlabs/notepad-plus-plus-scss-syntax-highlighting
  2. Step2: Go to Language→Define Your Language to import 2 xml files
  3. Step3: go to your Notepad++ folder then to plugins/APIs/ and duplicate the css.xml and rename this file to SCSS-Light.xml or SCSS-Dark.xml

Less(CSS pre-processor which wroten with Javascript Language)

refer:

Less is a CSS pre-processor, meaning that it extends the CSS language, adding features that allow variables, mixins, functions and many other techniques that allow you to make CSS that is more maintainable, themable and extendable.

Less(less.js) runs inside Node, in the browser and inside Rhino. There are also many 3rd party tools that allow you to compile your files and watch for changes.

Install less:

npm install -g less

Compile less file to css:

lessc styles.less > styles.css

Basic about less language:

Compat Framework

refer: http://compass-style.org/

css to less

refer:

intern

refer: https://github.com/theintern/intern

Bootstrap

refer:

Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile first projects on the web

Build bootstrap from source with gruntjs

Install some basic tool before build

  1. Step1: Install npm tool by install nodejs to d:\tools\nodejs
  2. Step2: Install grunt(Package Manager for Javascript):
    npm install -g grunt-cli

Build Bootstrap

  1. Step1: Navigate to the root /bootstrap/ directory, then run below command:
    npm install

    ⇒ npm will look at the package.json file and automatically install the necessary local dependencies listed there

  2. Step2: Regenerates the /dist/ directory with compiled and minified CSS and JavaScript files
    grunt dist

Create custom style

You can create a custom navbar class(navbar-custom), and then reference it to change the navbar without impacting other Bootstrap navbars..

<nav class="navbar navbar-custom">
  <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">...
    </button>
    <a class="navbar-brand" href="#">Title</a>
  </div>
   ...
</nav>

CSS

.navbar-custom {
    background-color:#229922;
    color:#ffffff;
    border-radius:0;
}
 
.navbar-custom .navbar-nav > li > a {
    color:#fff;
}
.navbar-custom .navbar-nav > .active > a, .navbar-nav > .active > a:hover, .navbar-nav > .active > a:focus {
    color: #ffffff;
    background-color:transparent;
}
.navbar-custom .navbar-brand {
    color:#eeeeee;
}

Create custom style for bootstrap with less

Advantages of this method

Using Less, especially with Bootstrap 3, gives you a few advantages that really make it a awesome choice

Advantages of less language:

Advantages of importing bootstrap.less:

Custom css with less file which don't change variables of bootstrap.less

We create the new less file and using less tool to rebuild new less file

  1. Step1: Create style.less which import bootstrap and other changes in nav.less, header.less, footer.less
    @import "bootstrap/bootstrap.less";
    @import "font-awesome/font-awesome.less";
     
    @import "variables.less";
    @import "mixins.less";
    @import "nav.less";
    @import "header.less";
    @import "footer.less";
  2. Step2: create files variables.less, mixins.less, nav.less, header.less, footer.less which contain your changes
  3. Step3: Using less tool to compile style.css
    lessc style.less > style.css

Custom css with less file and change variables of bootstrap.less

refer: http://slicejack.com/bootstrap-with-less-workflow/

  1. Step1: create custom-variables.less:
    // Single primary color that all mixins use. Str8 ballin.
    @primary:        hsl(202, 100%, 50%);
     
    // Primary Variants -
    @primaryLight:   hsl(hue(@primary), 100%, 70%);
    @primaryDark:    hsl(hue(@primary), 60%, 40%);
    @primaryFaded:   hsl(hue(@primary), 60%, 65%);
     
    // 180degree Variants
    @variant:         spin((@primary), 180);
    @variantLight:    hsl(hue(@variant), 100%, 70%);
    @variantDark:     hsl(hue(@variant), 60%, 40%);
    @variantFaded:    hsl(hue(@variant), 60%, 65%);
     
    // 90degree Variants
    @corner:         spin((@primary), 70);
    @cornerLight:    hsl(hue(@corner), 100%, 70%);
    @cornerDark:     hsl(hue(@corner), 60%, 40%);
    @cornerFaded:    hsl(hue(@corner), 60%, 65%);
  2. Step2: create styles.less which import custom-variables.less and other less files of bootstrap(We create this file by editing content of bootstrap.less):
    // Core variables and mixins
    @import "boostrap/variables.less";
    @import "boostrap/custom-variables.less";
    @import "boostrap/mixins.less";
     
    // Reset and dependencies
    @import "boostrap/normalize.less";
    @import "boostrap/print.less";
    @import "boostrap/glyphicons.less";
     
    // Core CSS
    @import "boostrap/scaffolding.less";
    @import "boostrap/type.less";
    @import "boostrap/code.less";
    @import "boostrap/grid.less";
    @import "boostrap/tables.less";
    @import "boostrap/forms.less";
    @import "boostrap/buttons.less";
     
    // Components
    @import "boostrap/component-animations.less";
    @import "boostrap/dropdowns.less";
    @import "boostrap/button-groups.less";
    @import "boostrap/input-groups.less";
    @import "boostrap/navs.less";
    @import "boostrap/navbar.less";
    @import "boostrap/breadcrumbs.less";
    @import "boostrap/pagination.less";
    @import "boostrap/pager.less";
    @import "boostrap/labels.less";
    @import "boostrap/badges.less";
    @import "boostrap/jumbotron.less";
    @import "boostrap/thumbnails.less";
    @import "boostrap/alerts.less";
    @import "boostrap/progress-bars.less";
    @import "boostrap/media.less";
    @import "boostrap/list-group.less";
    @import "boostrap/panels.less";
    @import "boostrap/responsive-embed.less";
    @import "boostrap/wells.less";
    @import "boostrap/close.less";
     
    // Components w/ JavaScript
    @import "boostrap/modals.less";
    @import "boostrap/tooltip.less";
    @import "boostrap/popovers.less";
    @import "boostrap/carousel.less";
     
    // Utility classes
    @import "boostrap/utilities.less";
    @import "boostrap/responsive-utilities.less";

Themes and templates for bootstrap

refer:

Build less file in bootswatch

Create below script to build all less file in bootswatch(Base on https://github.com/no-dice/django-bootstrap-themes):

#!/bin/sh
 
set -e
 
cd bootstrap_themes/static/bootstrap/themes
for theme in *; do
  if [ -d "$theme" ]; then
    mkdir -p "$theme/css"
    lessc "$theme/less/bootstrap.less" > "$theme/css/bootstrap.css"
    recess --compress "$theme/css/bootstrap.css" > "$theme/css/bootstrap.min.css"
  fi
done

Javascript Resources which support for designer

Respond.js

Respond.js: https://github.com/scottjehl/Respond

Modernizr

Modernizr – http://modernizr.com/

UI Kits

Flat UI

refer:

Boot Flat

refer: