259
使用 YUI 函式庫 快速建立 Web 2.0 程式 講者:josephj http://josephj.com/training/yui

YUI

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: YUI

使用 YUI 函式庫快速建立 Web 2.0 程式

講者:josephj

http://josephj.com/training/yui

Page 4: YUI

• 2.5 年前端工程師(F2E)

@josephj6802http://josephj.com

[email protected]

Hi! 我是 josephj(啊嗚)

Page 5: YUI

• 2.5 年前端工程師(F2E)

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

@josephj6802http://josephj.com

[email protected]

Hi! 我是 josephj(啊嗚)

Page 6: YUI

• 2.5 年前端工程師(F2E)

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

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

@josephj6802http://josephj.com

[email protected]

Hi! 我是 josephj(啊嗚)

Page 7: YUI
Page 8: YUI

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

Page 9: YUI

Agenda

Page 10: YUI

Agenda

•什麼是前端工程(F2E)

Page 11: YUI

Agenda

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

Page 12: YUI

Agenda

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

Page 13: YUI

前端工程師

Front-end Engineer

Page 14: YUI

什麼是前端工程師?

Page 15: YUI

什麼是前端工程師?

• 撰寫 HTML / CSS / JavaScript

Page 16: YUI

什麼是前端工程師?

• 撰寫 HTML / CSS / JavaScript

• 告訴瀏覽器該怎麼做

Page 17: YUI

什麼是前端工程師?

• 撰寫 HTML / CSS / JavaScript

• 告訴瀏覽器該怎麼做

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

Page 18: YUI
Page 19: YUI

SOUNDS SIMPLE!

Page 20: YUI

no.

Page 21: YUI

server

Page 22: YUI

(X)HTML

server

Page 23: YUI

(X)HTML

Specification

server

Page 24: YUI

(X)HTML

Specification Implementation

server

Page 25: YUI

(X)HTML

Specification Implementation

Bugs

server

Page 26: YUI

(X)HTML

Specification Implementation

Bugs [ Theory / Practice ]

server

Page 27: YUI

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 28: YUI

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 29: YUI

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 30: YUI

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 31: YUI
Page 32: YUI

usability, internationalization, localization, visual design,

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

benchmarking, devices, portability

Page 33: YUI

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

Page 34: YUI

CSS Sprites

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

Page 35: YUI

CSS Sprites

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

Page 36: YUI

TabView 在沒有 JavaScript 的支援

Page 37: YUI

圖片在 No Image、Not Loaded 的處理

Page 38: YUI

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

Page 39: YUI

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

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

Page 40: YUI

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

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

Page 41: YUI

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

Page 42: YUI

from Lifted©2007 Pixar Animation Studios

Page 43: YUI

所以我們建立了...

Page 44: YUI

http://developer.yahoo.com/yui

Page 45: YUI

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

Page 46: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 47: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 48: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 49: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 50: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 51: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 52: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 53: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 54: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 55: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 56: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 57: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 58: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 59: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 60: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 61: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 62: YUI

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

Def. But.Button

Label Menu

Label Text Field

Label

Label

Text Area

click me

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

Page 63: YUI

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

Page 64: YUI

http://blogs.computerworld.com/nytimes_iphone_browser_marketshare

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

Page 65: YUI

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

Google Chrome 也一視同仁 ;)

Page 66: YUI

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

Google Chrome 也一視同仁 ;)

Page 67: YUI

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

Google Chrome 也一視同仁 ;)

Page 68: YUI

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

Page 69: YUI

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

Page 70: YUI

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

Page 71: YUI

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

Page 72: YUI

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

Page 73: YUI

無障礙網頁(Accessbility)

Page 74: YUI

YUI CSS 基礎

YUI開發工具

YUI 函式集

YUI 控制項

Page 75: YUI

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

Page 76: YUI

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

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

Page 77: YUI

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

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

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

Page 78: YUI

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

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

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

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

Page 79: YUI

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

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

Page 80: YUI
Page 81: YUI

點選下方的資料會更新

Page 82: YUI

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

Page 83: YUI

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

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

Page 84: YUI
Page 85: YUI
Page 86: YUI

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

Page 87: YUI

2. YUI 控制項

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

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

• Slider

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

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

Page 88: YUI

讓你的開發及產出更順暢

3. YUI 開發工具集

Page 89: YUI

YUI Compressor

Page 90: YUI

YUI Compressor

Page 91: YUI

YUI Compressor

Page 92: YUI

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

http://developer.yahoo.com/yslow

Page 93: YUI
Page 94: YUI
Page 95: YUI

4. YUI CSS 基礎

Page 96: YUI

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

4. YUI CSS 基礎

Page 97: YUI

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

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

4. YUI CSS 基礎

Page 98: YUI

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

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

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

4. YUI CSS 基礎

Page 99: YUI
Page 100: YUI

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

Page 101: YUI

reset.css

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

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

Page 102: YUI

grids.css

reset.css

fonts.css

輕鬆建立版型

讓使用者可縮放字型大小

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

Page 103: YUI

側邊欄寬度為 240px

平均分配 50%, 50%

版面寬度 950px

Page 104: YUI

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

Page 105: YUI

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

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

Page 106: YUI

YUI 有哪些優點?

Page 107: YUI

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

Page 108: YUI

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

Page 109: YUI

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 110: YUI

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

Page 111: YUI
Page 112: YUI

各類文件把你教到會

Page 113: YUI

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 114: YUI
Page 115: YUI
Page 116: YUI
Page 117: YUI

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

Page 118: YUI

有完整註解的版本

Page 119: YUI

-debug 偵錯版

Page 120: YUI

-min 最小化版

Page 121: YUI

版本改進的歷程說明

Page 122: YUI

完整 API 文件

Page 123: YUI

每個元件最常使用的方法

節省每次查詢的時間

速查表

Page 124: YUI

YUI 劇場

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

Page 125: YUI

YUI 的書

Page 126: YUI

雜誌評比名列前茅

Page 127: YUI

控制項的量

維護是否容易

下載速度

文件齊全度

Page 128: YUI
Page 129: YUI

客製化容易

Page 130: YUI

密碼強度顯示器

Page 131: YUI

跟桌面一樣的選取方式

Page 132: YUI

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

Page 133: YUI

翻頁(Carousel)模組

Page 134: YUI

手風琴模組

Page 135: YUI

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

Page 136: YUI

用 YUI 做的俄羅斯方塊

Page 137: YUI

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

Page 138: YUI
Page 139: YUI
Page 140: YUI

有哪些網站使用 YUI?

Page 141: YUI
Page 142: YUI
Page 143: YUI
Page 144: YUI
Page 145: YUI
Page 146: YUI
Page 147: YUI
Page 148: YUI
Page 149: YUI
Page 150: YUI
Page 151: YUI
Page 152: YUI
Page 153: YUI
Page 154: YUI
Page 155: YUI
Page 156: YUI
Page 157: YUI

Q & A

Page 158: YUI

問:YUI 是否會收費?

Page 159: YUI

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

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

Page 160: YUI

問:為什麼 Open Source ?

Page 161: YUI
Page 162: YUI

• Fasten Improvement 回應使用者的需求

Page 163: YUI

• Fasten Improvement 回應使用者的需求

• Fun 與使用者互動

Page 164: YUI

• Fasten Improvement 回應使用者的需求

• Fun 與使用者互動

• Innovation 有更多創新的應用

Page 165: YUI

• Fasten Improvement 回應使用者的需求

• Fun 與使用者互動

• Innovation 有更多創新的應用

• Recruiting 培養前端工程師

Page 166: YUI

• Fasten Improvement 回應使用者的需求

• Fun 與使用者互動

• Innovation 有更多創新的應用

• Recruiting 培養前端工程師

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

Page 167: YUI

• Fasten Improvement 回應使用者的需求

• Fun 與使用者互動

• Innovation 有更多創新的應用

• Recruiting 培養前端工程師

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

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

Page 168: YUI

問:跟別的函式庫

jQuery、Prototype、Dojo、GWT

有何差別?

Page 169: YUI
Page 170: YUI

• 純 JavaScript 函式庫

Page 171: YUI

• 純 JavaScript 函式庫

• 最齊全的文件

Page 172: YUI

• 純 JavaScript 函式庫

• 最齊全的文件

• 不改變 JavaScript 原本的結構

Page 173: YUI

• 純 JavaScript 函式庫

• 最齊全的文件

• 不改變 JavaScript 原本的結構

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

Page 174: YUI

• 純 JavaScript 函式庫

• 最齊全的文件

• 不改變 JavaScript 原本的結構

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

• 客製化最容易

Page 175: YUI

• 純 JavaScript 函式庫

• 最齊全的文件

• 不改變 JavaScript 原本的結構

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

• 客製化最容易

• 經過完整的 QA 流程測試

Page 176: YUI

• 純 JavaScript 函式庫

• 最齊全的文件

• 不改變 JavaScript 原本的結構

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

• 客製化最容易

• 經過完整的 QA 流程測試

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

Page 177: YUI

問:有沒有 IDE 編輯器?

Page 178: YUI

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

Page 179: YUI

Aptana

Page 180: YUI

問:有沒有跟後端程式

結合的計劃?

Page 181: YUI

no.

Page 182: YUI

• 無法滿足所有族群需求

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

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

• 但有 3rd Party 自行研發

Page 183: YUI

YUI 實例演練

Page 184: YUI

YUI 練功坊

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

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

Page 185: YUI

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

Page 186: YUI
Page 187: YUI
Page 188: YUI
Page 189: YUI

依照功能性切成一塊塊的模組檔案

/index.php

這邊的 HTML 只負責 Layout(YUI Grids)

Page 190: YUI

依照功能性切成一塊塊的模組檔案

/index.php

這邊的 HTML 只負責 Layout(YUI Grids)

以這個模組為例子

Page 191: YUI

<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

<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 193: YUI

<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 194: YUI

<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 195: YUI

模組:inc/search_box.php

Page 196: YUI

#ykpsb

模組:inc/search_box.php

Page 197: YUI

#ykpsb

• ykp 為知識+ 的 prefixhttp://twiki.corp.yahoo.com/view/Devel/PropertyPrefixesForNaming

模組:inc/search_box.php

Page 198: YUI

#ykpsb

• ykp 為知識+ 的 prefixhttp://twiki.corp.yahoo.com/view/Devel/PropertyPrefixesForNaming

• sb 為 search box 的縮寫

模組:inc/search_box.php

Page 199: YUI

<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 200: YUI
Page 201: YUI

#ykpsb

Page 202: YUI

#yhtw_masthead

#ykpmt

#ykpsb

#ykpimt

#ykpimqa #ykpimr

#ykpadv

#ykpug

#ykpiht#ykpiht

Page 203: YUI

練習 :HTML 模組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 204: YUI

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

快速 DIV + CSS 版面產生器

Page 205: YUI

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

YUI Grid Builder

Page 206: YUI
Page 207: YUI

版面寬度 950px

Page 208: YUI

側邊欄寬度為 240px

版面寬度 950px

Page 209: YUI

側邊欄寬度為 240px

版面寬度 950px

Page 210: YUI

側邊欄寬度為 240px

平均分配 50%, 50%

版面寬度 950px

Page 211: YUI

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

Web 2.0 的基礎

Page 212: YUI

YUI AJAXYUI 用來做 AJAX 叫做 Connection Manager

使用者瀏覽器

A 網站

傳統流程:

Page 213: YUI

YUI AJAXYUI 用來做 AJAX 叫做 Connection Manager

使用者瀏覽器

A 網站

1. 發出 Request

傳統流程:

Page 214: YUI

YUI AJAXYUI 用來做 AJAX 叫做 Connection Manager

使用者瀏覽器

A 網站

1. 發出 Request

A 網站伺服器

2. 伺服器處理 Request

傳統流程:

Page 215: YUI

YUI AJAXYUI 用來做 AJAX 叫做 Connection Manager

使用者瀏覽器

A 網站

1. 發出 Request

A 網站伺服器

2. 伺服器處理 Request

3. 伺服器回傳

傳統流程:

Page 216: YUI

YUI AJAXYUI 用來做 AJAX 叫做 Connection Manager

使用者瀏覽器

A 網站

1. 發出 Request

A 網站伺服器

2. 伺服器處理 Request

3. 伺服器回傳

4. 整份網頁重新整理

傳統流程:

Page 217: YUI

使用者瀏覽器

A 網站

AJAX流程:

YUI AJAX

Page 218: YUI

使用者瀏覽器

A 網站

1. 用 JavaScript 發出 Request

AJAX流程:

YUI AJAX

Page 219: YUI

使用者瀏覽器

A 網站

1. 用 JavaScript 發出 Request

A 網站伺服器

2. 伺服器處理 Request

AJAX流程:

YUI AJAX

Page 220: YUI

使用者瀏覽器

A 網站

1. 用 JavaScript 發出 Request

A 網站伺服器

2. 伺服器處理 Request

3. 伺服器回傳

AJAX流程:

YUI AJAX

Page 221: YUI

使用者瀏覽器

A 網站

1. 用 JavaScript 發出 Request

A 網站伺服器

2. 伺服器處理 Request

3. 伺服器回傳

4. 只有小部分更新

AJAX流程:

YUI AJAX

Page 222: YUI

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

Page 223: YUI

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

存取跨網域的資料

Page 224: YUI

利用外部 JavaScript 的特性

Page 225: YUI

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

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

Page 226: YUI

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

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

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

Page 227: YUI

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

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

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

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

Page 228: YUI

利用外部 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 229: YUI

利用外部 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 230: YUI

利用外部 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 231: YUI

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

搜尋 “交大資工”

Page 234: YUI

YUI Get Utility

Page 235: YUI

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

Page 236: YUI

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

Page 237: YUI

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

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

Page 238: YUI

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

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

Page 239: YUI

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

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

•動態新增 <link/> 節點

Page 240: YUI

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

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

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

Page 241: YUI

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

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

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

• ex. 動態更換佈景主題

Page 242: YUI

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

Page 243: YUI

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

Page 244: YUI

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

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

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

Page 245: YUI

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

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

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

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

常用屬性:

Page 246: YUI

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

Page 247: YUI

YUI Button

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

更提供各種形式的按鈕

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

Page 248: YUI

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

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

Page 249: YUI

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

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

Page 250: YUI

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

Page 251: YUI

YUI Container 家族

Page 252: YUI

YUI Container 家族

YAHOO.widget.Panel

Page 253: YUI

YUI Container 家族

YAHOO.widget.Panel

YAHOO.widget.Dialog

Page 254: YUI

YUI Container 家族

YAHOO.widget.Panel

YAHOO.widget.Panel

YAHOO.widget.Dialog

Page 255: YUI

YUI Container 家族

YAHOO.widget.Panel

YAHOO.widget.Panel

YAHOO.widget.Dialog

YAHOO.widget.SimpleDialog

Page 256: YUI

練習: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 257: YUI

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

close 是否要有關閉的按鈕

fixedcenter 是否要置中對齊

modal 是否為獨佔模式

underlay shadow’, ‘matte’

visible 預設是否顯示

width 視窗的寬度

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

Page 258: YUI

Questions?