249
使用 YUI 函式庫 2009/3/10 @ NCTU 快速建立 Web 2.0 程式 講者:josephj http://www.slideshare.net/josephj/josephj-yui-nctu

YUI Introduction @ NCTU

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: YUI Introduction @ NCTU

使用 YUI 函式庫

2009/3/10 @ NCTU

快速建立 Web 2.0 程式

講者:josephj

http://www.slideshare.net/josephj/josephj-yui-nctu

Page 4: YUI Introduction @ NCTU

• 2.5 年前端工程師(F2E)

@josephj6802http://josephj.com

[email protected]

Hi! 我是 josephj(啊嗚)

Page 5: YUI Introduction @ NCTU

• 2.5 年前端工程師(F2E)

• 0.5 年科技推廣傳教士(Evangelist)

@josephj6802http://josephj.com

[email protected]

Hi! 我是 josephj(啊嗚)

Page 6: YUI Introduction @ NCTU

• 2.5 年前端工程師(F2E)

• 0.5 年科技推廣傳教士(Evangelist)

•目前在無名小站擔任工程師(SDE)

@josephj6802http://josephj.com

[email protected]

Hi! 我是 josephj(啊嗚)

Page 7: YUI Introduction @ NCTU
Page 8: YUI Introduction @ NCTU

2008.5 跑步環島ITHome 的報導:http://farm4.static.flickr.com/3251/3017901989_9252512e77_o.jpg

Page 9: YUI Introduction @ NCTU

Yahoo! Course 課程表

Page 10: YUI Introduction @ NCTU

Yahoo! Course 課程表

Page 11: YUI Introduction @ NCTU

YDN 論壇 3/13 @ 成大

•知識+ API

•斷詞與關鍵字擷取 API

•YAP 應用程式平台

Page 12: YUI Introduction @ NCTU

Agenda

Page 13: YUI Introduction @ NCTU

Agenda

•什麼是前端工程(F2E)

Page 14: YUI Introduction @ NCTU

Agenda

•什麼是前端工程(F2E)•認識 YUI

Page 15: YUI Introduction @ NCTU

Agenda

•什麼是前端工程(F2E)•認識 YUI•實例演練

Page 16: YUI Introduction @ NCTU

前端工程師

Front-end Engineer

Page 17: YUI Introduction @ NCTU

什麼是前端工程師?

Page 18: YUI Introduction @ NCTU

什麼是前端工程師?

• 撰寫 HTML / CSS / JavaScript

Page 19: YUI Introduction @ NCTU

什麼是前端工程師?

• 撰寫 HTML / CSS / JavaScript

• 告訴瀏覽器該怎麼做

Page 20: YUI Introduction @ NCTU

什麼是前端工程師?

• 撰寫 HTML / CSS / JavaScript

• 告訴瀏覽器該怎麼做

• 所有「檢視原始碼」看得到的都是處理的範圍

Page 21: YUI Introduction @ NCTU
Page 22: YUI Introduction @ NCTU

SOUNDS SIMPLE!

Page 23: YUI Introduction @ NCTU

no.

Page 24: YUI Introduction @ NCTU

server

Page 25: YUI Introduction @ NCTU

(X)HTML

server

Page 26: YUI Introduction @ NCTU

(X)HTML

Specification

server

Page 27: YUI Introduction @ NCTU

(X)HTML

Specification Implementation

server

Page 28: YUI Introduction @ NCTU

(X)HTML

Specification Implementation

Bugs

server

Page 29: YUI Introduction @ NCTU

(X)HTML

Specification Implementation

Bugs [ Theory / Practice ]

server

Page 30: YUI Introduction @ NCTU

Dat

a Tr

ansp

ort

data

: cus

tom

, xm

l,

js

onbe

havi

or: j

sm

ixed

: new

xht

ml

(X)HTML DOM JavaScript

Specification Implementation

Bugs [ Theory / Practice ]

BOM API

DOM API

CSS

server

Page 31: YUI Introduction @ NCTU

Dat

a Tr

ansp

ort

data

: cus

tom

, xm

l,

js

onbe

havi

or: j

sm

ixed

: new

xht

ml

(X)HTML DOM JavaScript

Specification Implementation

Bugs [ Theory / Practice ]

BOM API

DOM API

CSS

server

Macintosh

Safari Firefox Opera

Windows

OperaIE5, 6, 7 Firefox

Linux, Unix, Mobile

10,000+ UAs

Page 32: YUI Introduction @ NCTU

Dat

a Tr

ansp

ort

data

: cus

tom

, xm

l,

js

onbe

havi

or: j

sm

ixed

: new

xht

ml,

(X)HTML DOM JavaScript

Specification Implementation

Defects [ Theory / Practice ]

BOM API

DOM API

CSS

server

MacintoshSafari Firefox Opera

WindowsOperaIE5, 6, 7 Firefox

Linux, Unix, Mobile10,000+ UAs

Page 33: YUI Introduction @ NCTU

Dat

a Tr

ansp

ort

data

: cus

tom

, xm

l,

js

onbe

havi

or: j

sm

ixed

: new

xht

ml,

(X)HTML DOM JavaScript

Specification Implementation

Defects [ Theory / Practice ]

BOM API

DOM API

CSS

server

MacintoshSafari Firefox Opera

WindowsOperaIE5, 6, 7 Firefox

Linux, Unix, Mobile10,000+ UAs

knowledge areas: 7dimensions: x 4

platforms: x 3browsers per platform: x 4

rendering modes: x 2

=672

Page 34: YUI Introduction @ NCTU
Page 35: YUI Introduction @ NCTU

usability, internationalization, localization, visual design,

accessibility, information architecture, security, build processes, performance,

benchmarking, devices, portability

Page 36: YUI Introduction @ NCTU

有人知道以上的圖在 Yahoo 的哪個服務嗎?

Page 37: YUI Introduction @ NCTU

CSS Sprites

有人知道以上的圖在 Yahoo 的哪個服務嗎?

Page 38: YUI Introduction @ NCTU

CSS Sprites

有人知道以上的圖在 Yahoo 的哪個服務嗎?

Page 39: YUI Introduction @ NCTU

TabView 在沒有 JavaScript 的支援

Page 40: YUI Introduction @ NCTU

圖片在 No Image、Not Loaded 的處理

Page 41: YUI Introduction @ NCTU

字型大小放大數倍後仍維持完美

Page 42: YUI Introduction @ NCTU

<link rel="stylesheet" type="text/css" href=".../i8/ykp_qack_min_20080707.css" media="screen">

不同的設備製作不同的樣式表:Screen

Page 43: YUI Introduction @ NCTU

<link rel="stylesheet" type="text/css" href=".../i8/ykp_print_min_20080707.css" media="print">

不同的設備製作不同的樣式表:Print

Page 44: YUI Introduction @ NCTU

15 種不同瀏覽器與系統的相容性

Page 45: YUI Introduction @ NCTU

from Lifted©2007 Pixar Animation Studios

Page 46: YUI Introduction @ NCTU

所以我們建立了...

Page 47: YUI Introduction @ NCTU

http://developer.yahoo.com/yui

Page 48: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)傳統內建 UI 使用 YUI 所建立的 UI

Page 49: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 50: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 51: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 52: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 53: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 54: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 55: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 56: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 57: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 58: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 59: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 60: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 61: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 62: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 63: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 64: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 65: YUI Introduction @ NCTU

在瀏覽器上建立使用者 UI(控制項)

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

傳統內建 UI 使用 YUI 所建立的 UI

Page 66: YUI Introduction @ NCTU

即使是 iPhone 上的瀏覽器,YUI 也支援

Page 67: YUI Introduction @ NCTU

http://blogs.computerworld.com/nytimes_iphone_browser_marketshare

即使是 iPhone 上的瀏覽器,YUI 也支援

Page 68: YUI Introduction @ NCTU

http://marketshare.hitslink.com/report.aspx?sample=21&qprid=43&qpcustom=Chrome+0.2

Google Chrome 也一視同仁 ;)

Page 69: YUI Introduction @ NCTU

http://marketshare.hitslink.com/report.aspx?sample=21&qprid=43&qpcustom=Chrome+0.2

Google Chrome 也一視同仁 ;)

Page 70: YUI Introduction @ NCTU

http://marketshare.hitslink.com/report.aspx?sample=21&qprid=43&qpcustom=Chrome+0.2

Google Chrome 也一視同仁 ;)

Page 71: YUI Introduction @ NCTU

Button + Menu + Container + ... = RTE Editor

Page 72: YUI Introduction @ NCTU

結構複雜、但使用起來簡單愉快

Page 73: YUI Introduction @ NCTU

結構複雜、但使用起來簡單愉快

Page 74: YUI Introduction @ NCTU

且保證在每個主流瀏覽器都支援

Page 75: YUI Introduction @ NCTU

且保證在每個主流瀏覽器都支援

Page 76: YUI Introduction @ NCTU

無障礙網頁(Accessbility)

Page 77: YUI Introduction @ NCTU

YUI CSS 基礎

YUI開發工具

YUI 函式集

YUI 控制項

Page 78: YUI Introduction @ NCTU

1. YUI 函式集YAHOO.util.* : 好用的 Web 2.0 功能

Page 79: YUI Introduction @ NCTU

1. YUI 函式集YAHOO.util.* : 好用的 Web 2.0 功能

• AJAX 相關一般 AJAX 功能、跨網域存取、JSON 解析、資料來源處理、歷史紀錄

Page 80: YUI Introduction @ NCTU

1. YUI 函式集YAHOO.util.* : 好用的 Web 2.0 功能

• AJAX 相關一般 AJAX 功能、跨網域存取、JSON 解析、資料來源處理、歷史紀錄

• 炫麗技巧拖拉、動畫、縮放區塊大小

Page 81: YUI Introduction @ NCTU

1. YUI 函式集YAHOO.util.* : 好用的 Web 2.0 功能

• AJAX 相關一般 AJAX 功能、跨網域存取、JSON 解析、資料來源處理、歷史紀錄

• 炫麗技巧拖拉、動畫、縮放區塊大小

• 實用功能Cookie 存取、Selector 存取、物件導向

Page 82: YUI Introduction @ NCTU

Browser History Manager解決 AJAX 沒有上一頁、下一頁的問題

http://tw.knowledge.yahoo.com/my/my_trace?show=AC00668153

Page 83: YUI Introduction @ NCTU
Page 84: YUI Introduction @ NCTU

點選下方的資料會更新

Page 85: YUI Introduction @ NCTU

更新內容離頂端過遠,用傳統作法會讓使用者不便且個人資料較少 SEO 的問題因此決定採用 AJAX

Page 86: YUI Introduction @ NCTU

更新內容離頂端過遠,用傳統作法會讓使用者不便且個人資料較少 SEO 的問題因此決定採用 AJAX

一般的 AJAX 程式網址不會更新

Page 87: YUI Introduction @ NCTU
Page 88: YUI Introduction @ NCTU
Page 89: YUI Introduction @ NCTU

多了這一串,可以回到上一頁或把此網址加入最愛但還是維持下面的狀態

Page 90: YUI Introduction @ NCTU

2. YUI 控制項

• 自動完成• 按鈕• 日曆• 圖表• 顏色選取• 視窗• 資料表格• 截圖

• 版面管理員• 選單• HTML 編輯器

• Slider

• 頁籤組• 樹狀瀏覽• 上傳

YAHOO.widget.* : 功能強大的且易擴充的控制項

Page 91: YUI Introduction @ NCTU

讓你的開發及產出更順暢

3. YUI 開發工具集

Page 92: YUI Introduction @ NCTU

YUI Compressor

Page 93: YUI Introduction @ NCTU

YUI Compressor

Page 94: YUI Introduction @ NCTU

YUI Compressor

Page 95: YUI Introduction @ NCTU

Y! Slow檢測網頁效能的好工具

http://developer.yahoo.com/yslow

Page 96: YUI Introduction @ NCTU
Page 97: YUI Introduction @ NCTU
Page 98: YUI Introduction @ NCTU

4. YUI CSS 基礎

Page 99: YUI Introduction @ NCTU

• Reset 將所有標籤預設樣式歸零

4. YUI CSS 基礎

Page 100: YUI Introduction @ NCTU

• Reset 將所有標籤預設樣式歸零

• Fonts相對字型大小、可被縮放

4. YUI CSS 基礎

Page 101: YUI Introduction @ NCTU

• Reset 將所有標籤預設樣式歸零

• Fonts相對字型大小、可被縮放

• Grids快速製作彈性 DIVs+CSS 版面

4. YUI CSS 基礎

Page 102: YUI Introduction @ NCTU
Page 103: YUI Introduction @ NCTU

reset.css 讓每個瀏覽器的預設樣式相同

Page 104: YUI Introduction @ NCTU

reset.css

fonts.css 讓使用者可縮放字型大小

讓每個瀏覽器的預設樣式相同

Page 105: YUI Introduction @ NCTU

grids.css

reset.css

fonts.css

輕鬆建立版型

讓使用者可縮放字型大小

讓每個瀏覽器的預設樣式相同

Page 106: YUI Introduction @ NCTU

側邊欄寬度為 240px

平均分配 50%, 50%

版面寬度 950px

Page 107: YUI Introduction @ NCTU

#doc3 = 989px.yui-t6 = Right, 300px

Page 108: YUI Introduction @ NCTU

#doc4 = 974px.yui-t3 = Left, 300px

只需更換兩個屬性值,版面就會完全不一樣

Page 109: YUI Introduction @ NCTU

YUI 有哪些優點?

Page 110: YUI Introduction @ NCTU

最符合使用者需求你每天都在用的網站是?

Page 111: YUI Introduction @ NCTU

所有的 Library 必需符合使用者經驗的設計

Page 112: YUI Introduction @ NCTU

Problem Summary

The user needs to enter an item into a text box which could ambiguous or hard to

remember and therefore has the potential to be mis-typed.

EXAMPLE:

Auto completion of contacts in Yahoo! Mail Beta

Use When

The suggestions can be pulled from a manageable set of data.

The input item can be entered in multiple ways.

The input item can be matched with a specific data item in the system.

Speed and accuracy of entry is an important goal.

The total number of items would be too large or inconvenient for displaying in a

standard drop down box.

Solution

Layout

Use a standard text box for input.

Label the text box to match the user's expection of what field will be searched against.

Interaction

As the user types, display a list of suggested items that most closely match what the

user has typed. Continue to narrow or broaden the list of suggested items based on the

user's input.

Display the suggested items list in a drop down box directly underneath the text box.

The suggested items list may be based on the complete set of data or more narrowly

based on other criteria such as each item's frequency of use.

When available, show multiple fields of information for each suggested item. In the

Yahoo! Mail example above, two fields are presented: the contact's full name and the

contact's email address.

Highlight the closest matching item within the suggested items list.

Show the matched item as first in the list.

Highlight the background of the matched item.

When multiple fields are shown for each suggested item the match may occur

with the initial characters of any of the fields presented.

For each suggested item in the suggest items list show the characters that exactly

match the user's input. When multiple fields are shown in a suggested item the

matching characters may appear in any of the fields presented. In the example below,

the characters 'Yu' have been typed by the user. The match is on three items. Notice

that the first item matched on the contact's email address '<yuiblogger.com>' whereas

the second and third items are matched on the contact's name (e.g., 'Yusef Jones'.)

Allow the user to delete a character of input and display the previous suggested items

list.

Allow the user to complete the input field by pressing the Tab key or Enter; key. The

current matched item in the suggested items list will be accepted as the value for the

input field.

Allow the user to optionally highlight an item of their choice from the suggested item list

with the mouse or with the up and down arrow keys.

Allow the user to cancel the suggested items list by pressing the Esc key. The drop

down list will close. Subsequently pressing the Tab key or Enter key will accept the

value from the input field. However, typing more characters after hitting the Esc key will

restart the auto completion behavior displaying the suggested items list.

If multiple input items are allowed in a single input field, allow the user to use the

Comma key to separate each input item.

Pressing the comma key will complete an individual item match.

The auto complete behavior restarts when the user begins typing characters for

the next input item.

Rationale

Reducing the number of keystrokes allows for faster user input.

Showing additional formatting information in the suggested items list (like the email

address in the example above) removes ambiguity.

Continual feedback helps the user narrow in on the correct choice.

Accessibility

Label the text box to match the user's expection of what field will be searched against.

Allow the user to highlight a desired match either using a mouse or navigating to it with

the up or down arrow keys.

Allow the user to complete the form by pressing the Tab or Enter keys.

Allow the user to cancel suggestions by pressing the Esc key.

Allow the input field to receive keyboard focus by pressing the Tab key.

Once the edit field is in focus make sure that the focus stays in the edit field during

autocomplete.

Do not send any page refreshes when updating the field (page refreshes will signal

assistive technology to start reading the page again.)

The insertion cursor should move as the left/right arrow keys are pressed in the text

field.

QUICK JUMP

Solution

Rationale

Accessibility

RELATED PATTERNS

Calendar Picker

AS USED ON YAHOO!

Yahoo! Mail Beta

Yahoo! Maps Beta

Yahoo! My Web 2

BLOG

Blog Article

Y! UI CODE EXAMPLES

Auto Complete

Component

Y! Search (JSON)

Y! Search (XML)

In-Memory (array)

In-Memory (function)

Flickr (XML)

Flat data

Playground

Show with revisions

This work is licensed under a

Creative Commons Attribution 2.5

License.

Design Pattern Library

Auto Complete

Copyright © 2005-2007 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings

Developer Network Home Help Site Search

Yahoo! Developer Network > Design Pattern Library > Auto Complete

Page 113: YUI Introduction @ NCTU

超完整的範例目前在 YUI 官網上超過 300 個範例

Page 114: YUI Introduction @ NCTU
Page 115: YUI Introduction @ NCTU

各類文件把你教到會

Page 116: YUI Introduction @ NCTU

Yahoo! User Interface Blog

In the Wild for November 30thNate Koechley 11/30/07 19:45:25

Implementation Focus: TripItEric Miraglia 11/14/07 11:22:42

Caridy Patiño Mayea’s Bubbling Library UpdatedEric Miraglia 11/07/07 09:23:45

Implementation Focus: NestoriaEric Miraglia 11/06/07 17:58:27

Using the Yahoo Global Object to Manage ObjectInheritance and Composition: Four New YUIExamplesEric Miraglia 11/06/07 17:54:03

YUI Forum on Yahoo! Groups

Using DataTable with Drag and Dropguiltyspark05 12/03/07 21:52:02

Re: autocomplete and ie layoutGopal Venkatesan 12/03/07 20:29:02

Re: connection manager problemGopal Venkatesan 12/03/07 20:20:00

Re: Cant get a connect manager return from.ASMX webservice into a Jtssha 12/03/07 20:19:06

Please tell me the reason (about treeview)liaolliso.2007 12/03/07 19:09:31

Cant get a connect manager return from .ASMXwebservice into a JSONfredpal99 12/03/07 17:01:09

Re: fixed-width layout with 100% background - is itpossible?Jim Davis 12/03/07 15:38:13

YUI on del.icio.us

bookmark on del.icio.us

tags: css yui javascript library webdesign ajaxweb2.0 programming ui development yahoo

saved by 7335 people

Getting Started

1. Check out the examples of YUI in action. We recommend starting withthe Event Utility and Dom Collection examples; Event and Dom are part ofthe YUI Core (along with the YAHOO Global Object) and provide animportant foundation for JavaScript developers using YUI. Once you'vereviewed those foundational pieces, go on to explore utilities like Drag andDrop and Animation or UI controls like Button, Calendar and TabView. Ifyou're interested in YUI's CSS components, read through the examples forReset, Base, Fonts, and Grids in that order.

2. Remember that there are full user's guides for each component here onthe website. If you have any questions about a component as you play withthe examples, check out the component's user's guide (by following any ofthe links along the left side of the page) or the searchable APIdocumentation.

3. You have cheat sheets for each component available on landing pagesand downloadable as a full set. These documents support the online user'sguides by providing concise print documentation for YUI components.

4. Start building. You can include YUI scripts and CSS from the YUIdownload (in the /build directory) or directly from Yahoo! servers. The

YUI Loader Utility is a client-side loading package that can dynamically pullin YUI scripts as needed, whether from your servers or from ours.

5. Become a member of the YUI community. YUI developers andimplementers share thoughts and solutions and provide a helping hand inour forums. YUI developers also contribute to the YUIBlog, where you'll findin-depth articles, videos and other great content about YUI and the world offrontend engineering.

Licensing

All of the YUI Library components are provided free of charge under a liberalBSD license.

Articles

Graded Browser Support: This article details the browser-supportphilosophy we use in developing the YUI Library. Graded BrowserSupport provides a sane path to achieving accessibility and gracefuldegradation while still building richly interactive interfaces in thebrowser.Skinning YUI: YUI components get their look and feel from a visual"skin" that you can modify or replace in your own applications.

Cheat Sheets

Cheat Sheets for the YUI Library provide quick references to the key methods,properties, and syntax patterns of each component. When you find yourselfelbow-deep in a coding problem, sometimes it's quicker to turn to these ratherthan firing up a browser to review documentation and examples — and reviewingthe cheat sheets can help you discover hidden gems you didn't know were there.

These one page references aren't comprehensive, but we think you'll find themvaluable to have on hand. (Cheat Sheets are currently provided for all YUIUtilities, nearly all UI Controls, and for the YUI CSS foundation.)

Support & Community

The YUI Library and related topics are discussed on the on the ydn-javascriptmailing list.

In addition, please visit the YUIBlog for updates and articles about the YUILibrary written by the library's developers.

Filing Bugs & Feature Requests

The YUI Library's public bug tracking and feature request repositories are locatedon the YUI SourceForge project site. Before filing new feature requests or bugreports, please review our reporting guidelines.

Guidelines for YUI feature requests and bug reports.Review current bug list or file a new bug.Review current feature requests or file a new feature request.

Copyright © 2007 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings

Developer Network Home Help

[more videos ]YUI Theater

Nate Koechley — "The YUI CSS

Foundation"

Senior YUI engineer Nate Koechley guides youthrough the YUI CSS foundation in this October 2007tech talk.

enter email address

Site Search Search

The Yahoo! User Interface Library (YUI)

Using YUI:

FAQ

Getting Started

Licensing

Articles

Cheat Sheets

Support &Community

Filing Bugs &Feature Requests

Searchable APIDocumentation:

API docs are availabefor every YUIcomponent. You cansearch the APIdocumentation withinstant filtering on themain API page.

The YUI Compressor:

The YUI Compressor isa build-processcomponent that helpsyou minify yourJavaScript and CSS.Documentation anddownload informationare available here.

YUI Core:

The YAHOOGlobal Object(base requirementfor all YUIcomponents)

DOM Collection(conveniencemethods for DOMinteractions)

Event Utility (eventnormalization andtools)

YUI Library Utilities:

Animation Utility

Browser HistoryManager

ConnectionManager (forXHR/Ajax)

DataSource Utility

Drag and DropUtility

Element Utility

ImageLoader Utility[experimental]

The YUILoaderUtility

The YUI TestUtility

YUI LibraryControls/Widgets:

AutoComplete

Button Control

Calendar

Color Picker

Container(including Module,Overlay, Panel,Tooltip, Dialog,SimpleDialog)

DataTable

Logger

Menu

Rich Text Editor

Slider

TabView

TreeView

YUI Library CSSTools:

CSS Reset(neutralizesbrowser CSSstyles)

CSS Base (appliesconsistent stylefoundation forcommon elements)

CSS Fonts(foundation fortypography andfont-sizing)

CSS Grids (morethan 1,000 CSS-driven wireframesin a 4KB file)

The Yahoo! User Interface Library (YUI)

The Yahoo! User Interface (YUI) Library is a set of utilities andcontrols, written in JavaScript, for building richly interactive webapplications using techniques such as DOM scripting, DHTML andAJAX. The YUI Library also includes several core CSS resources. Allcomponents in the YUI Library have been released as open sourceunder a BSD license and are free for all uses.

Download YUI version 2.3.1, including full APIdocumentation and more than 200 functional examples

from Sourceforge.

The library's developers blog at the YUI Blog and the YUI Library communityexchanges ideas at YDN-JavaScript on Yahoo! Groups.

Yahoo! UI Library

Home

YUIBlog

YUI Discussion Forum

YUI on Sourceforge

API Documentation

YUI Examples Gallery

Powered by YUI

YUI Theater

YUI License

YUI Articles

YUI FAQ

Graded Browser Support

Skinning YUI

Bug Reports/Feature Requests

Serving YUI Files from Yahoo!

Security Best Practices

YUI Components

Animation

AutoComplete

Browser History Manager

Button

Calendar

Color Picker

Connection Manager

Container

DataSource

DataTable

Dom

Drag & Drop

Element

Event

ImageLoader [experimental]

Logger

Menu

Rich Text Editor

Slider

TabView

TreeView

Yahoo Global Object

YUI Loader

YUI Test

Reset CSS

Base CSS

Fonts CSS

Grids CSS

YUI Tools

YUI Compressor

Yahoo! Developer Network

Home

About Us

Developer Network Blog

YDN FAQ

Support Communities

Working Examples

Page 117: YUI Introduction @ NCTU
Page 118: YUI Introduction @ NCTU
Page 119: YUI Introduction @ NCTU
Page 120: YUI Introduction @ NCTU

每個元件都提供了三種版本

Page 121: YUI Introduction @ NCTU

有完整註解的版本

Page 122: YUI Introduction @ NCTU

-debug 偵錯版

Page 123: YUI Introduction @ NCTU

-min 最小化版

Page 124: YUI Introduction @ NCTU

版本改進的歷程說明

Page 125: YUI Introduction @ NCTU

完整 API 文件

Page 126: YUI Introduction @ NCTU

每個元件最常使用的方法

節省每次查詢的時間

速查表

Page 127: YUI Introduction @ NCTU

YUI 劇場

共計約 50 個小時講者由 YUI 成員或專家所組成developer.yahoo.com/yui/theater

Page 128: YUI Introduction @ NCTU

YUI 的書

Page 129: YUI Introduction @ NCTU

雜誌評比名列前茅

Page 130: YUI Introduction @ NCTU

控制項的量

維護是否容易

下載速度

文件齊全度

Page 131: YUI Introduction @ NCTU
Page 132: YUI Introduction @ NCTU

客製化容易

Page 133: YUI Introduction @ NCTU

密碼強度顯示器

Page 134: YUI Introduction @ NCTU

跟桌面一樣的選取方式

Page 135: YUI Introduction @ NCTU

用 YUI 來製作簡報系統(為去年的 OSDC 所做的)

Page 136: YUI Introduction @ NCTU

翻頁(Carousel)模組

Page 137: YUI Introduction @ NCTU

手風琴模組

Page 138: YUI Introduction @ NCTU

用於「知識+名片」的手風琴模組

Page 139: YUI Introduction @ NCTU

用 YUI 做的俄羅斯方塊

Page 140: YUI Introduction @ NCTU

提供專業視覺設計師的樣式

Page 141: YUI Introduction @ NCTU
Page 142: YUI Introduction @ NCTU
Page 143: YUI Introduction @ NCTU

有哪些網站使用 YUI?

Page 144: YUI Introduction @ NCTU
Page 145: YUI Introduction @ NCTU
Page 146: YUI Introduction @ NCTU
Page 147: YUI Introduction @ NCTU
Page 148: YUI Introduction @ NCTU
Page 149: YUI Introduction @ NCTU
Page 150: YUI Introduction @ NCTU
Page 151: YUI Introduction @ NCTU
Page 152: YUI Introduction @ NCTU
Page 153: YUI Introduction @ NCTU
Page 154: YUI Introduction @ NCTU
Page 155: YUI Introduction @ NCTU
Page 156: YUI Introduction @ NCTU
Page 157: YUI Introduction @ NCTU
Page 158: YUI Introduction @ NCTU
Page 159: YUI Introduction @ NCTU
Page 160: YUI Introduction @ NCTU

Q & A

Page 161: YUI Introduction @ NCTU

問:YUI 是否會收費?

Page 162: YUI Introduction @ NCTU

YUI 是基於最鬆散的 BSD License 條款授權

你可以自由引用、修改、甚至放在商業軟體販售

Page 163: YUI Introduction @ NCTU

問:為什麼 Open Source ?

Page 164: YUI Introduction @ NCTU
Page 165: YUI Introduction @ NCTU

• Fasten Improvement 回應使用者的需求

Page 166: YUI Introduction @ NCTU

• Fasten Improvement 回應使用者的需求

• Fun 與使用者互動

Page 167: YUI Introduction @ NCTU

• Fasten Improvement 回應使用者的需求

• Fun 與使用者互動

• Innovation 有更多創新的應用

Page 168: YUI Introduction @ NCTU

• Fasten Improvement 回應使用者的需求

• Fun 與使用者互動

• Innovation 有更多創新的應用

• Recruiting 培養前端工程師

Page 169: YUI Introduction @ NCTU

• Fasten Improvement 回應使用者的需求

• Fun 與使用者互動

• Innovation 有更多創新的應用

• Recruiting 培養前端工程師

• 也沒辦法不開放,檢視原始碼就看光了

Page 170: YUI Introduction @ NCTU

• Fasten Improvement 回應使用者的需求

• Fun 與使用者互動

• Innovation 有更多創新的應用

• Recruiting 培養前端工程師

• 也沒辦法不開放,檢視原始碼就看光了

• 現在你可以簽約成為 YUI Contributor

Page 171: YUI Introduction @ NCTU

問:跟別的函式庫

jQuery、Prototype、Dojo、GWT

有何差別?

Page 172: YUI Introduction @ NCTU
Page 173: YUI Introduction @ NCTU

• 純 JavaScript 函式庫

Page 174: YUI Introduction @ NCTU

• 純 JavaScript 函式庫

• 最齊全的文件

Page 175: YUI Introduction @ NCTU

• 純 JavaScript 函式庫

• 最齊全的文件

• 不改變 JavaScript 原本的結構

Page 176: YUI Introduction @ NCTU

• 純 JavaScript 函式庫

• 最齊全的文件

• 不改變 JavaScript 原本的結構

• 不污染、違反網頁標準化的精神

Page 177: YUI Introduction @ NCTU

• 純 JavaScript 函式庫

• 最齊全的文件

• 不改變 JavaScript 原本的結構

• 不污染、違反網頁標準化的精神

• 客製化最容易

Page 178: YUI Introduction @ NCTU

• 純 JavaScript 函式庫

• 最齊全的文件

• 不改變 JavaScript 原本的結構

• 不污染、違反網頁標準化的精神

• 客製化最容易

• 經過完整的 QA 流程測試

Page 179: YUI Introduction @ NCTU

• 純 JavaScript 函式庫

• 最齊全的文件

• 不改變 JavaScript 原本的結構

• 不污染、違反網頁標準化的精神

• 客製化最容易

• 經過完整的 QA 流程測試

• 在標準瀏覽器上皆能正常運作

Page 180: YUI Introduction @ NCTU

問:有沒有 IDE 編輯器?

Page 181: YUI Introduction @ NCTU

問:有沒有 IDE 編輯器?為什麼不體驗一下打字的爽快感呢...?

Page 182: YUI Introduction @ NCTU

Aptana

Page 183: YUI Introduction @ NCTU

問:有沒有跟後端程式

結合的計劃?

Page 184: YUI Introduction @ NCTU

no.

Page 185: YUI Introduction @ NCTU

• 無法滿足所有族群需求

• ASP, PHP, RoR, Python, JAVA...

• 必需考慮後續維護的問題

• 但有 3rd Party 自行研發

Page 186: YUI Introduction @ NCTU

YUI 實例演練

Page 187: YUI Introduction @ NCTU

YUI 練功坊

http://www.wallpapergate.com/wallpaper22725.html

練習網站:http://josephj.com/training/nctu/

Page 188: YUI Introduction @ NCTU

1. HTML 模組在 Yahoo! 每一頁都是由許多的模組所構成

Page 189: YUI Introduction @ NCTU
Page 190: YUI Introduction @ NCTU

<div id=”nav”> <div class=”hd”> <h2>標題</h2> </div> <div class=”bd”> <p>內文</p> </div> <div class=”ft”> <a href=”...”>更多... </a> </div></div>

模組的結構

Page 191: YUI Introduction @ NCTU

<div id=”nav”> <div class=”hd”> <h2>標題</h2> </div> <div class=”bd”> <p>內文</p> </div> <div class=”ft”> <a href=”...”>更多... </a> </div></div>

<div id=”nav”> <div class=”hd”> <h2>標題</h2> </div> <div class=”bd”> <p>內文</p> </div> <div class=”ft”> <a href=”...”>更多... </a> </div></div>

模組的結構

Page 192: YUI Introduction @ NCTU

<div id=”nav”> <div class=”hd”> <h2>標題</h2> </div> <div class=”bd”> <p>內文</p> </div> <div class=”ft”> <a href=”...”>更多... </a> </div></div>

<div id=”nav”> <div class=”hd”> <h2>標題</h2> </div> <div class=”bd”> <p>內文</p> </div> <div class=”ft”> <a href=”...”>更多... </a> </div></div>

模組的結構

一個 ID 代表一個模組不能重複

Page 193: YUI Introduction @ NCTU

<div id=”nav”> <div class=”hd”> <h2>標題</h2> </div> <div class=”bd”> <p>內文</p> </div> <div class=”ft”> <a href=”...”>更多... </a> </div></div>

<div id=”nav”> <div class=”hd”> <h2>標題</h2> </div> <div class=”bd”> <p>內文</p> </div> <div class=”ft”> <a href=”...”>更多... </a> </div></div>

模組的結構

一個 ID 代表一個模組不能重複

.hd, .bd, .ft 分別代表模組的header、body、footer

Page 194: YUI Introduction @ NCTU

#yhtw_masthead

#ykpmt

#ykpsb

#ykpimt

#ykpimqa #ykpimr

#ykpadv

#ykpug

#ykpiht#ykpiht

Page 195: YUI Introduction @ NCTU

#ykpsb

•ykp 為知識+ 的 prefix

•sb 為 search box 的縮寫

•檔案:inc/search_box.php

Page 196: YUI Introduction @ NCTU

<div id=”ykpsb”> <div class=”bd clearfix”> <form ...> ... </form> <div class=”extra”> ... </div> </div></div>

form .extra

[HTML]<style>#ykpsb { margin-bottom:10px;}#ykpsb form { float:left;}#ykpsb .extra { float:right;}</style>

[CSS]

因每個模組有 id,所以 CSS 可以寫得很 namespace

好處就是很安全,不同模組不會互相干擾

Page 197: YUI Introduction @ NCTU

練習 1:HTML 模組 (3 Mins)http://josephj.com/training/nctu/html-module.html

1. 替此文章模組取個適合的 id2. 加上 hd, bd, ft 的 class3. 利用前頁的方法設定 CSS

color:#369;background:#ffe;

font-weight:bold;font-size:16px;

Page 198: YUI Introduction @ NCTU

2. YUI Gridshttp://developer.yahoo.com/yui/grids/builder/

快速 DIV + CSS 版面產生器

Page 199: YUI Introduction @ NCTU

http://developer.yahoo.com/yui/grids/builder/

YUI Grid Builder

Page 200: YUI Introduction @ NCTU

側邊欄寬度為 240px

平均分配 50%, 50%

版面寬度 950px

Page 201: YUI Introduction @ NCTU

3. YUI AJAXhttp://josephj.com/training/nctu/yui-ajax.html

Web 2.0 的基礎

Page 202: YUI Introduction @ NCTU

YUI AJAXYUI 用來做 AJAX 叫做 Connection Manager

使用者瀏覽器

A 網站

傳統流程:

Page 203: YUI Introduction @ NCTU

YUI AJAXYUI 用來做 AJAX 叫做 Connection Manager

使用者瀏覽器

A 網站

1. 發出 Request

傳統流程:

Page 204: YUI Introduction @ NCTU

YUI AJAXYUI 用來做 AJAX 叫做 Connection Manager

使用者瀏覽器

A 網站

1. 發出 Request

A 網站伺服器

2. 伺服器處理 Request

傳統流程:

Page 205: YUI Introduction @ NCTU

YUI AJAXYUI 用來做 AJAX 叫做 Connection Manager

使用者瀏覽器

A 網站

1. 發出 Request

A 網站伺服器

2. 伺服器處理 Request

3. 伺服器回傳

傳統流程:

Page 206: YUI Introduction @ NCTU

YUI AJAXYUI 用來做 AJAX 叫做 Connection Manager

使用者瀏覽器

A 網站

1. 發出 Request

A 網站伺服器

2. 伺服器處理 Request

3. 伺服器回傳

4. 整份網頁重新整理

傳統流程:

Page 207: YUI Introduction @ NCTU

使用者瀏覽器

A 網站

AJAX流程:

YUI AJAX

Page 208: YUI Introduction @ NCTU

使用者瀏覽器

A 網站

1. 用 JavaScript 發出 Request

AJAX流程:

YUI AJAX

Page 209: YUI Introduction @ NCTU

使用者瀏覽器

A 網站

1. 用 JavaScript 發出 Request

A 網站伺服器

2. 伺服器處理 Request

AJAX流程:

YUI AJAX

Page 210: YUI Introduction @ NCTU

使用者瀏覽器

A 網站

1. 用 JavaScript 發出 Request

A 網站伺服器

2. 伺服器處理 Request

3. 伺服器回傳

AJAX流程:

YUI AJAX

Page 211: YUI Introduction @ NCTU

使用者瀏覽器

A 網站

1. 用 JavaScript 發出 Request

A 網站伺服器

2. 伺服器處理 Request

3. 伺服器回傳

4. 只有小部分更新

AJAX流程:

YUI AJAX

Page 212: YUI Introduction @ NCTU

練習 3:YUI Connectionhttp://josephj.com/training/nctu/yui-ajax.html

Page 213: YUI Introduction @ NCTU

4. YUI Get Utilityhttp://josephj.com/training/nctu/yui-get.html

存取跨網域的資料

Page 214: YUI Introduction @ NCTU

利用外部 JavaScript 的特性

Page 215: YUI Introduction @ NCTU

利用外部 JavaScript 的特性AJAX 不能做跨網域的存取!

http://tw.yahoo.com http://tw.lifestyle.yahoo.com

Page 216: YUI Introduction @ NCTU

利用外部 JavaScript 的特性AJAX 不能做跨網域的存取!

http://tw.yahoo.com http://tw.lifestyle.yahoo.com

但 <script src=”...”></script> 可以

Page 217: YUI Introduction @ NCTU

利用外部 JavaScript 的特性AJAX 不能做跨網域的存取!

http://tw.yahoo.com http://tw.lifestyle.yahoo.com

但 <script src=”...”></script> 可以

http://josephj.com/training/ncu-tsung/script.html

Page 218: YUI Introduction @ NCTU

利用外部 JavaScript 的特性AJAX 不能做跨網域的存取!

http://tw.yahoo.com http://tw.lifestyle.yahoo.com

但 <script src=”...”></script> 可以

http://josephj.com/training/ncu-tsung/script.html

http://www.josephjiang.com/training/ncu-tsung/data.js<script src=” “></script>

Page 219: YUI Introduction @ NCTU

利用外部 JavaScript 的特性AJAX 不能做跨網域的存取!

http://tw.yahoo.com http://tw.lifestyle.yahoo.com

但 <script src=”...”></script> 可以

http://josephj.com/training/ncu-tsung/script.html

http://www.josephjiang.com/training/ncu-tsung/data.js<script src=” “></script>

var outputString = ‘hello’;getData(outputString);

Page 220: YUI Introduction @ NCTU

利用外部 JavaScript 的特性AJAX 不能做跨網域的存取!

http://tw.yahoo.com http://tw.lifestyle.yahoo.com

但 <script src=”...”></script> 可以

http://josephj.com/training/ncu-tsung/script.html

http://www.josephjiang.com/training/ncu-tsung/data.js<script src=” “></script>

<script>function getData (data) { alert(data);} </script>

var outputString = ‘hello’;getData(outputString);

Page 221: YUI Introduction @ NCTU

用 JavaScript 把照片抓到你的網站上?

搜尋 “交大資工”

Page 224: YUI Introduction @ NCTU

YUI Get Utility

Page 225: YUI Introduction @ NCTU

YUI Get Utility•動態新增 <script/> 節點

Page 226: YUI Introduction @ NCTU

YUI Get Utility•動態新增 <script/> 節點• YAHOO.util.Get.script(url)

Page 227: YUI Introduction @ NCTU

YUI Get Utility•動態新增 <script/> 節點• YAHOO.util.Get.script(url)

• ex1. 載入函式庫(YUI、jQuery...)

Page 228: YUI Introduction @ NCTU

YUI Get Utility•動態新增 <script/> 節點• YAHOO.util.Get.script(url)

• ex1. 載入函式庫(YUI、jQuery...)• ex2. 載入外部資料(JSON)

Page 229: YUI Introduction @ NCTU

YUI Get Utility•動態新增 <script/> 節點• YAHOO.util.Get.script(url)

• ex1. 載入函式庫(YUI、jQuery...)• ex2. 載入外部資料(JSON)

•動態新增 <link/> 節點

Page 230: YUI Introduction @ NCTU

YUI Get Utility•動態新增 <script/> 節點• YAHOO.util.Get.script(url)

• ex1. 載入函式庫(YUI、jQuery...)• ex2. 載入外部資料(JSON)

•動態新增 <link/> 節點• YAHOO.util.Get.css(url)

Page 231: YUI Introduction @ NCTU

YUI Get Utility•動態新增 <script/> 節點• YAHOO.util.Get.script(url)

• ex1. 載入函式庫(YUI、jQuery...)• ex2. 載入外部資料(JSON)

•動態新增 <link/> 節點• YAHOO.util.Get.css(url)

• ex. 動態更換佈景主題

Page 232: YUI Introduction @ NCTU

練習 4:YUI Get Utilityhttp://josephj.com/training/nctu/yui-get.html

Page 233: YUI Introduction @ NCTU

5. YUI 選單輕鬆地做出巢狀式浮動選單

Page 234: YUI Introduction @ NCTU

練習 5:YUI 選單http://josephj.com/training/nctu/yui-menu.html

1.請以 new YAHOO.widget.MenuBar([模組id]); 新增一個 YUI 選單物件

2.執行這個物件的 render() 方法

Page 235: YUI Introduction @ NCTU

練習 5:YUI 選單http://josephj.com/training/nctu/yui-menu.html

autosubmenudisplay (true 或 false) 是否自動顯示子選單

hidedelay (毫秒)滑鼠移開 n 毫秒後才隱藏

lazyload (true 或 false) 是否滑過去時才建立子選單

常用屬性:

Page 236: YUI Introduction @ NCTU

6. YUI 按鈕輕鬆做出互動性豐富的按鈕 UI

Page 237: YUI Introduction @ NCTU

YUI Button

一個按鈕該有的互動效果, YUI Button 都提供

更提供各種形式的按鈕

HTML 預設的按鈕醜又缺乏互動

Page 238: YUI Introduction @ NCTU

練習 6:YUI 按鈕http://josephj.com/training/nctu/yui-button.html

1.請以 new YAHOO.widget.Button([連結 id]); 將連結轉換為按鈕

Page 239: YUI Introduction @ NCTU

練習 6:YUI 按鈕http://josephj.com/training/nctu/yui-button.html

1.請以 new YAHOO.widget.Button([連結 id]); 將連結轉換為按鈕

Page 240: YUI Introduction @ NCTU

7. YUI 視窗Web 2.0 的「開新視窗」

Page 241: YUI Introduction @ NCTU

YUI Container 家族

Page 242: YUI Introduction @ NCTU

YUI Container 家族

YAHOO.widget.Panel

Page 243: YUI Introduction @ NCTU

YUI Container 家族

YAHOO.widget.Panel

YAHOO.widget.Dialog

Page 244: YUI Introduction @ NCTU

YUI Container 家族

YAHOO.widget.Panel

YAHOO.widget.Panel

YAHOO.widget.Dialog

Page 245: YUI Introduction @ NCTU

YUI Container 家族

YAHOO.widget.Panel

YAHOO.widget.Panel

YAHOO.widget.Dialog

YAHOO.widget.SimpleDialog

Page 246: YUI Introduction @ NCTU

練習 7:YUI 視窗http://josephj.com/training/nctu/yui-panel.html

1. 請以 var oPanel = new YAHOO.widget.Panel([模組 id], [屬性]); 將 #panel 模組轉換為視窗(屬性設定請看下一頁)

2. oPanel.render(document.body): 將模組 append 到最外層3. oButton.addListener(‘click’, onButtonClick)

onButtonClick 函式:oPanel.show();

Page 247: YUI Introduction @ NCTU

練習 7:YUI 視窗http://josephj.com/training/nctu/yui-panel.html

close 是否要有關閉的按鈕

fixedcenter 是否要置中對齊

modal 是否為獨佔模式

underlay shadow’, ‘matte’

visible 預設是否顯示

width 視窗的寬度

{屬性1 : 屬性值 1, 屬性 2 : 屬性值 2}

Page 248: YUI Introduction @ NCTU

Questions?