Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
YUI介绍和使用YUI构建web应用
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Adam Lu
March 29, 2013
Technology
2
3.7k
YUI介绍和使用YUI构建web应用
Adam Lu
March 29, 2013
Tweet
Share
More Decks by Adam Lu
See All by Adam Lu
YUI Rocks!
adamlu
3
3.1k
一步一步开发HTML5 Mobile Apps
adamlu
14
660
HTML5概览
adamlu
13
3.7k
Other Decks in Technology
See All in Technology
Kiro Powers 入門
k_adachi_01
0
130
AlloyDB 奮闘記
hatappi
0
180
スピンアウト講座02_ファイル管理
overflowinc
0
230
テストプロセスにおけるAI活用 :人間とAIの共存
hacomono
PRO
0
110
品質を経営にどう語るか #jassttokyo / Communicating the Strategic Value of Quality to Executive Leadership
kyonmm
PRO
2
910
_Architecture_Modernization_から学ぶ現状理解から設計への道のり.pdf
satohjohn
2
510
コンテキスト・ハーネスエンジニアリングの現在
hirosatogamo
PRO
6
660
Everything Claude Code を眺める
oikon48
13
8.8k
TypeScript 7.0の現在地と備え方
uhyo
7
2k
【Λ(らむだ)】最近のアプデ情報 / RPALT20260318
lambda
0
130
夢の無限スパゲッティ製造機 #phperkaigi
o0h
PRO
0
300
WebアクセシビリティをCI/CDで担保する ― axe DevTools × Playwright C#実践ガイド
tomokusaba
2
200
Featured
See All Featured
First, design no harm
axbom
PRO
2
1.1k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Writing Fast Ruby
sferik
630
63k
The Pragmatic Product Professional
lauravandoore
37
7.2k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Site-Speed That Sticks
csswizardry
13
1.1k
sira's awesome portfolio website redesign presentation
elsirapls
0
190
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.8k
Believing is Seeing
oripsolob
1
89
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
310
Become a Pro
speakerdeck
PRO
31
5.9k
Transcript
YUI 介绍和使用 YUI 构建 Web 用 鲁超伍 http://adamlu.com @adamlu
YUI 是什 ? http://yuilibrary.com/
YUI 项目 • JavaScript (YUI) • CSS 础 (Grid) •
文档工具 (yuidoc) • 构建工具 (shifter) • 测试工具 (yuitest) • 性能优化工具 (yui compressor) • 开发者 训 (Theater/Blog)
https://github.com/yui/yui3
模块 载 • 种子文件 – <script src="http://yui.yahooapis.com/3.5.0/build/yui/yui- min.js"></script> • 种子小,作用大
– 模块注册系统 – 核心 YUI 工具方法 – Lang, Object, Array 类 – Loader( 动态模块 载 )
模块注册 YUI.add('hello', function (Y) { Y.namespace('Hello'); Y.Hello.sayHello = function ()
{ return 'GREETINGS PROGRAMS'; }; });
模块使用 YUI().use('node-base', 'hello', function (Y) { Y.one('#demo').setHTML(Y.Hello.sayHello() ); });
有用的工具函数 • Y.merge • Y.mix • Y.later • Y.log •
Y.Lang • Y.Array • Y.Object • Y.UA http://jsfiddle.net/adamlu/LEEdc/
一个简单的 YUI 程序 <div id="test"></div> <button id="button">Turn Red</button> YUI().use('node', function(Y){
Y.one('#button').on('click', function() { Y.one('#test').addClass('red'); }); }); #test { height: 30px; background: gray; } #test.red { background: red; } <script src="http://yui.yahooapis.com/3.9.0/build/yui/yui-min.js"></script> http://jsfiddle.net/adamlu/YdBbL/
YUI vs. jQuery http://www.jsrosettastone.com/
YUI 让你把 JavaScript 写得更好 $.each([1, 2, 3], fn(index, value)) $.each({
key: value }, fn(key, value)) Y.Array.each([1, 2, 3], fn(value, index)) Y.Object.each({ key: value }, fn(value, key)) $.isPlainObject(obj) Y.Lang.isObject(obj) $(':radio') Y.all('input[type=radio]') 还有强大的面向对象编程支持
使用组件 • YUI 本身已经自带很多丰富组件如 AutoComplete, Calendar, DataTable 等 YUI 础结构
于 Base 创建组件 • Base 是 层的 础类,同时具备 Attribute 和
Event 特性 • 提供了创建 于属性对象的标准模板 • 提供了一致的 init() 和 destroy() 方法 http://jsfiddle.net/adamlu/7hXCV/
Attribute 类 • 对一些状态值和自定 逻辑 能相关配置 的封装 • 提供监听状态改变的机会 •
Gettters • Settters • 默认值 • Change 事件
// 实例化时设置属性的初始值 obj = new MyClass({name: value}); obj.addAttr(name, value); obj.set(name,
value); obj.get(name); obj.on(nameChanged, callback); obj.after(nameChanged, callback); YUI().use("attribute", function(Y) { function MyClass() { } MyClass.ATTRS = {}; Y.augment(MyClass, Y.Attribute); });
Attribute 设置流程
YUI 提供的事件 • DOM 事件,让你的程序响 用户操作 • 特别的 DOM 事件,当页面
载或渲染时可 以让你 阅有趣的瞬间 • 合成事件,让你定 全新的 DOM 事件,扩 大了用户和你的程序沟通的渠道 • 自定 事件,通过发出和 阅程序指定的 消息让组件之间互相通信
事件支持 • 控 事件传播和冒泡 • 阻止默认行为 • 委托事件 • EventTarget
– publish() – on()/detach() – fire() – addTarget()/removeTarget() http://jsfiddle.net/adamlu/5C5CC/
组件 • 组件 (widget) 是一个通用的可视元件设 在 不同网站被重用,如表格 日历 菜单或 图表
扩展组件 • 生命周期方法: initializer(), destructor(), renderUI(), bindUI(), syncUI() Y.Electron =
Y.Base.create('electron', Y.Widget, [], { destructor: function () { }, renderUI: function () {}, bindUI: function () {}, syncUI: function () {} }, { ATTRS: {} }); }, '1.1', {requires: ['base-build', 'widget']}); http://jsfiddle.net/adamlu/AQ8mg/
YUI on Mobile • Touch 事件支持 • Guesture • History
• Transition • ScrollView – 水平 / 垂直 / 拖动 新 / 分页 / 滚动条 YUI().use('scrollview', function (Y) { var scrollView = new Y.ScrollView({ srcNode: '#someContainer' }); scrollView.render(); }); http://yuilibrary.com/yui/docs/scrollview/scrollview-base-example.html
YUI App Framework • 由 App, Model, Model List, Router
和 View 组成 的包 • 写单页面 JavaScript 用程序的 MVC 风格的 框架 • 于 URL 的路由 • 类似 BackboneJs 框架
使用 App Framework 的例子 http://adamlu.com/fe/ContactApp/ https://github.com/adamlu/YUIAppDemo
HTML 页面
main.js
Y.App
ContactModel
ContactListModel
ContactView
ContactListView
YUI Cookbook
THANKS! @adamlu