hack with yui
DESCRIPTION
This presentation will be a quick introduction to YUI version 3.3.0 and some of its core functions that should be most useful for building your hacks. We'll cover DOM manipulation and event subscription, animations, drag and drop, Ajax and YQL, and how to use CSS Grids for layout.TRANSCRIPT
HACK WITH
Luke Smith
@ls_n
YUI EXISTS TO BUILD WEB APPLICATIONS FASTER
WHAT IS YUI?
The YUI Library is a set of utilities and controls, written with JavaScript and CSS, for building richly interactive web applications.
Open source under the liberal BSD license.
Driven by the YUI Team at Yahoo! And contributors around the world.
http://yuilibrary.com
WHAT IS YUI?
1K new sites every month, among the top 1M sites.
“YUI Library is the only other library that is gaining market share.”
- http://w3techs.com/blog/entry/highlights_of_web_technology_surveys_march_2011
WHO USES YUI?
Mint Target LinkedIn
Microsoft Google Reuters
Walgreens NFL Ford
Harley-Davidson Flickr
National Geographic
Gatorade Duck Duck Go
http://yuiblog.com/blog/category/in-the-wild/
WHY HACK WITH YUI?
• You don’t have time to find and workaround browser bugs• Avoid reinventing the wheel
• Core: Rock solid DOM manipulation, events, and more• Transition: Rich effects using CSS3• Drag and Drop that works• Gesture Events: Swipe, flicks, and more for touch devices• ScrollView: Scrollable content on mobile and desktop alike
YUI
<script
src="http://yui.yahooapis.com/3.3.0
/build/simpleyui/simpleyui-min.js"></script>
<script>
Y.one("#foo").addClass("highlight");
</script>
DOM EVENTS
Y.one("#demo").on(“click”, function (e) {
/* handle click */});
ADD HTML
Y.one("#demo").append(“<p>I’m new here.</p>”);
EVENT DELEGATION
// any click on an <li> inside #demo will trigger
Y.one("#demo").delegate(“click”, function (e) {
/* handle click */
}, “li”);
MOVE STUFF AROUND
// #demo will move to wherever a click happens
Y.one(”document”).on (“click”, function (e) {
Y.one(“#demo”).setXY( [ e.pageX, e.pageY ] );
});
ANIMATED TRANSITIONS
// Hello HTML5!
Y.one(”#demo”).transition({
easing: “ease-out”,
duration: 2, // seconds
opacity: 0
}, function () {// callback executed when done
this.remove();
});
Same API if the browser supports CSS3 transitions or not.
AJAX
Y.io(“my.aweso.me/service.php”, {
on: {
complete: function (id, response) {
var data = Y.JSON.parse(response);
/* handle response */
}
}
});
ADD MORE FEATURES WITH Y.USE()
Y.use(“dd-plugin”, function () {
Y.one(“#foo”).plug(Y.Plugin.Drag);
});
YQL
Y.use(“yql”, function () {
function render(res) {
Y.one(“#demo”).append(
“<h2>Weather for “ + zip + “</h2>” +
res.query.results.channel.item.description);
}
Y.YQL(“select * from weather.forecast “ +
“where location=“ + zip, render);
});
YUI GALLERY
The YUI of tomorrow, today.• Community collection of YUI 3 modules• BSD license• Hosted on Yahoo!’s CDN• All available from Y.use(“here!”)
http://yuilibrary.com/gallery
Ratings, paginator, resize, loading mask, inline editing, and lots more.
KNOW YUI 2?
Use YUI 2 widgets inside YUI 3.
• ImageCropper
• ColorPicker
• ProgressBar
• SimpleDialog
Y.use(“yui2-datatable”, function () {
var YAHOO = Y.YUI2;
new YAHOO.widget.DataTable(“simple”);
});
KNOW JQUERY?
http://jsrosettastone.com/
Great resource for jQuery users• Provides one-to-one reference from jQuery to YUI 3• Maintained by Paul Irish and the YUI Team
YUI ON NODE.JS
Use Node.js, jsdom, and YUI to manipulate pages on the server!
• Progressive enhancement• Write once, works on the client and server• Our wrapper creates a simulated DOM for you
http://yuilibrary.com/projects/nodejs-yui3
Easy installation
$ npm install yui3
See http://npmjs.org
YUI RESET, FONTS, GRIDS
Stylesheets to make your life easier
You want to use this. Just drop it in.
RESET & FONTS
Reset CSS makes browser styling consistent.
Fonts CSS provides typographical normalization, while allowing users to change font size.
<link href=“http://yui.yahooapis.com/3.3.0/build/
cssreset/cssreset-min.css”>
<link href=“http://yui.yahooapis.com/3.3.0/build/
cssfonts/cssfonts-min.css”>
CSS GRIDS
Simple, flexible, infinitely nestable in 1.2K
Divide into three equal units
<link href=“http://yui.yahooapis.com/3.3.0/build/
cssgrids/cssgrids-min.css”>
<div class=“yui3-g”>
<div class=“yui3-u-1-3”></div>
<div class=“yui3-u-1-3”></div>
<div class=“yui3-u-1-3”></div>
</div>
THANKS!
Luke Smith
@ls_n
@yuilibrary
http://developer.yahoo.com/yui/3/