2016年3月29日 星期二

Responsive Web

沒有留言 :

在Google Chrome上使用Developers Tools(DevTools)

參考 devtools網頁

  1. 啟動方法:ctrl+shift+i 或者chrome menu>more tools>developer tools
  2. 按手機圖示,可以模擬各式各樣裝置,看看開發中的網頁在不同的裝置上的表現。
安裝 Udacity Front End Feedback Chrome Extension
參考這裡,安裝Udacity Front End Feedback Chrome Extension,它是 Udacity 在 Responsive Web Design Fundamentals 的課程中,用來檢查作業是否正確的工具。

將Android裝置連接到開發電腦上

 Remote Debugging on Android with Chrome學到:

開發網頁時,將手機連到開發電腦,可以看看網頁在手機瀏覽時的效果與速度

要將手機連接到開發程式電腦,需要一次性的設定:
  1. 首頁 > 設定 > 關於平板電腦 > 版本號碼(連按7次)。以後若再按版本號碼,會出現"不需要了,你已經是開發人員"。
  2. 首頁 > 設定 > 開發人員選項 > USB偵錯 > 允許USB-確定,之後"允許USB"選項呈現打勾狀態。
開發時,連結手機與開發電腦步驟如下:
  1. 用USB連接線將手機與開發電腦連上。
  2. 手機端打開chrome瀏覽器。
  3. 開發端打開google chrome,在URL上輸入 "chrome://inspect"。此時,手機端出現是否允許偵錯的對話框,按確定完成連線。
  4. 開發端出現許多devices,點擊想要的device的inspect連結,會出現debug視窗。在debug視窗右上角一個像手機的圖示上點擊,手機的畫面會同步到開發端
網頁技巧

media query

internal css: @media screen and (min-width:?) and (max-width:?){}
external css: <link rel="stylesheet" type="text/css" media="screen and (min-width:?) and (max-width:?)" href="...">

grids

Introduction to html and css
bootstrap

flexbox

order

common patterns

Column Drop
Mostly Fluid: nested container
Layout Shifter: order
Off Canvas

responsive images

responsive images 課程

responsive tables

hidden column
no more table
contained table: overflow-x:auto

fonts

45-90 characters per line
font-size at least 16px

2016年3月11日 星期五

Polymer

沒有留言 :
Polymer Library 是甚麼?根據Polymer首頁
The Polymer library is designed to make it easier and faster for developers to create great, reusable components for the modern web.
  • Web components. These standards provide the primitives you need to build new components. You can build your own custom elements using these primitives, but it can be a lot of work.
    Not all browsers support these standards yet, so the web components polyfill library fills the gaps, implementing the APIs in JavaScript.
  • The Polymer library. Provides a declarative syntax that makes it simpler to define custom elements. And it adds features like templating, two-way data binding and property observation to help you build powerful, reusable elements with less code.
  • Custom elements. If you don’t want to write your own elements, there are a number of elements built withPolymer that you can drop straight into your existing pages. These elements depend on the Polymer library, but you can use the elements without using Polymer directly.
看起來很吸引人,下面是 Polymer 初體驗:

一次性安裝

要使用 Polymer,必須有 Node.js 與 Git,且都必須透過環境變數 Path 讓系統可以找到執行檔。
若沒有 Node.js ,可到 nodejs.org 下載安裝,Node.js  包括了 npm。
若沒有 Git,請到 git-scm.com 下載並進行安裝,git 的執行檔必須放在環境變數 Path 中。

用指令 npm install -g bower 安裝 bower,以後用 bower 進行專案的安裝、更新。

用指令 npm install -g polyserve 安裝 polyserve ,polyserve是個 Web Server,以後會用polyserve來當作測試用的Web Server。

專案安裝

參考Get the polymer library製作專案。
製作一個專案用的檔案夾當作專案目錄。

以專案目錄為工作目錄,執行 bower init,過程中,所有的選項都可以<Return>鍵回應,產生專案檔案bower.json,裡面有專案的基本資料,包括專案倚賴哪些 polymer 物件的名稱。

執行指令 bower install --save Polymer/polymer,專案目錄下會產生子目錄 bower_components/,內有專案所需的 Polymer 物品,bower.json 會記錄專案的最新相依狀況。

開始學習

接著,開始寫網頁,下面依照 Quick Tour of Polymer 的教學,製作簡單網頁。

將前述教學中的第一個 index.html, proto-element.html存檔到專案目錄。

在專案目錄下,用指令 polyserve 啟動 Web Server,他會顯示專案根目錄的URL,所謂的專案URL。

用瀏覽器瀏覽專案URL, 就可看到網頁結果。

教學中有 proto-element.html, dom-element.html, picture-frame.html, name-tag.html, configurable-name-tag.html, editable-name-tag.html 等六個 Polymer Element,每一個搭配對應的 index.html,介紹一些 Polymer 的功能。

用 proto-element.html 介紹 Registering elements 與 Lifecycle callbacks。

用 dom-element.html 介紹 Local DOM template。

用 picture-frame.html 介紹 Compose with local DOM(註1)。

用 name-tag.html 介紹 Use data binding。

用 configurable-name-tag.html 介紹 Declare a property。

用 editable-name-tag.html 介紹 Bind to a property(註2)。

註1:在與 picture-frame.html 對應的 index.html 裡,圖檔 p-logo.svg 必須改成自己有的圖檔。

註2:editable-name-tag.html 有使用到 iron-input,它是一個 Polymer Element,必須到 Polymer Catalog 尋找下載,方法如下:
Polymer Catalog 網站尋找所要的零件,如 iron-input,點擊該連結,此時左邊欄 bower command 下方的文字方格出現下載所需的指令,本例是 bower install --save PolymerElements/iron-input。在專案目錄中執行它,就完成下載。下載時,它會自動更新bower.json 的內容,要是專案裡的 polymer 物件有更新版的東西出現,只要執行 bower update 就可以了。
註3: Developer Guide 提到,attribute name 與 property name的對應。例如 drawer-width 對應到 drawerWidth,使用 custom element時,一定要記得這點。

2016年3月5日 星期六

Service Workers

沒有留言 :
Service Worker API 節錄:
Service workers essentially act as proxy servers that sit between web applications, and the browser and network (when available). They are intended to (amongst other things) enable the creation of effective offline experiences, intercepting network requests and taking appropriate action based on whether the network is available and updated assets reside on the server. They will also allow access to push notifications and background sync APIs.
要了解 Service Worker 的基本概念,可閱讀 Mozilla Developer 與 Google Developer

這裡有一個簡單的示範。瀏覽該網頁之後,下次,即使拔掉網路線/關掉Wifi,仍然可以斷線的瀏覽它。換句話說,第一次瀏覽是連線瀏覽(online browse),以後就可斷線瀏覽(offline browse)。它的來源碼在這裡

因為 Service Worker 會攔截 network request,基於安全理由,網頁必須以 https 為架構來確保資料的安全。換句話說,網頁以 http 為架構的,不能使用 Service Worker。然而,開發環境中,通常沒有 https 所需的憑證。Jeff Posnick 在 Options for testing service workers via HTTP 提到如何在 Chrome 與 Firefox 中測試使用 Service Worker 的網頁。

Promise

沒有留言 :
網頁裡,我們可以利用 Javascript promise 進行非同步的運算,而且非同步運算的結果可以串聯起來依序處理。使用非同步的運算,可以減少使用者等候的時間,讓網頁更能處理(more responsive)使用者的輸入。

要了解 Promise 的基本概念可以看google developermozilla developer

這裡有最初淺的例子,利用 Promise 非同步下載圖檔,視圖檔下載是否成功而進行後續的處理。