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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Adam Lu
March 29, 2013
Technology
3.7k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
YUI介绍和使用YUI构建web应用
Adam Lu
March 29, 2013
More Decks by Adam Lu
See All by Adam Lu
YUI Rocks!
adamlu
3
3.1k
一步一步开发HTML5 Mobile Apps
adamlu
14
670
HTML5概览
adamlu
13
3.7k
Other Decks in Technology
See All in Technology
「ビジネスがわかるエンジニア」とは何か?
ryooob
0
290
いまさら聞けない「仕様駆動開発入門」 〜AI活用時代の開発プロセスを考える〜
findy_eventslides
2
200
「勝手に広まる」人気 AI エージェントを爆速で作ろう!(AWS Summit Japan 2026講演資料)
minorun365
PRO
10
2.5k
AI Agentをシステムに組み込む前にゆるく向き合ってみる
hayama17
0
130
事業会社における 機械学習・推薦システム技術の活用事例と必要な能力 / ml-recsys-in-layerx-wantedly-2026
yuya4
0
160
從開發到部署全都交給 AI:實作 AI 驅動的自動化流程
appleboy
0
160
GitHub Copilot app最速の発信の裏側
tomokusaba
1
250
Microsoft のサポートとフィードバック総まとめ
murachiakira
PRO
0
110
自宅LLMの話
jacopen
1
720
フィジカル版Github Onshapeの紹介
shiba_8ro
0
320
水を運ぶ人としてのリーダーシップ
izumii19
4
990
不要なレビューをAIにまかせて AIコーディングの環境改善を加速した
shoota
1
260
Featured
See All Featured
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
160
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
66
55k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
How to make the Groovebox
asonas
2
2.2k
We Are The Robots
honzajavorek
0
250
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
320
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
210
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