yui - hacku 2010 iit mumbai

18
1

Upload: knutties

Post on 18-Dec-2014

756 views

Category:

Technology


0 download

DESCRIPTION

YUI presentation at HackU 2010

TRANSCRIPT

Page 1: YUI - HackU 2010 IIT Mumbai

1

Page 2: YUI - HackU 2010 IIT Mumbai

`

Using YUI to get things done

Natarajan  KannanWeb Developer

twitter: @knutties

Page 3: YUI - HackU 2010 IIT Mumbai

Demo time

3

Page 4: YUI - HackU 2010 IIT Mumbai

• YUI is a Javascript/CSS library• Highly modular, extensible and heavily 

documented• Lets you do a lot with less code

• Very suitable for hacks

• Probably the only javascript library that comes with its own package management

Overview

4

Page 5: YUI - HackU 2010 IIT Mumbai

• Create websites/templates• Manipulate web pages easily• Fetch data from remote sources• Interact with YQL• Use pre­built UI widgets

What can you do with YUI? 

5

Page 6: YUI - HackU 2010 IIT Mumbai

• First task in creating a website– select a layout

• YUI CSS grids builder– Interface to create layout– http://developer.yahoo.com/yui/grids/builder/

• Default CSS styling with YUI base

Creating website templates

6

Page 7: YUI - HackU 2010 IIT Mumbai

• Locate elements on web pages– Using CSS selectors

• Update portions of web pages– By adding/removing/changing content

• Change styling of elements– hide/resize/overlay elements

Manipulate web pages

7

Page 8: YUI - HackU 2010 IIT Mumbai

// get an element reference, add a click handler

Y.one('#demo').on('click', function(e) {/*handle click*/});

// add content to an element

Y.one('#demo').append(" Additional content added to #demo.");

// move #demo to the location of any click on the document

Y.one('document').on('click', function(e) {

     Y.one('#demo').setXY([e.pageX, e.pageY]);

}

);

Examples – Using Simple YUI

8

Page 9: YUI - HackU 2010 IIT Mumbai

// fade #demo off to full opacity, then remove it from the dom:

Y.one('#demo').transition({

    easing: 'ease­out',

    duration: 2, // seconds

    opacity: 0

}, function() {

    this.remove();

});

Examples – Using Simple YUI

9

Page 10: YUI - HackU 2010 IIT Mumbai

• Allows you to fetch data from different sources– Local functions– Remote sources over http

• Helps you work around cross­domain restrictions • Y.io and Y.DataSource are your friends

Fetch data from remote sources

10

Page 11: YUI - HackU 2010 IIT Mumbai

// Make an HTTP request to 'get.php'.

Y.io('get.php', {

    on: {

        complete: function (id, response) {

            var id = id, // Transaction ID.

                data = response.responseText; // Response data.

            // ... handle the response ...

        }

    }

});

Examples – Using Simple YUI

11

Page 12: YUI - HackU 2010 IIT Mumbai

YUI makes YQL very easy

12

Page 13: YUI - HackU 2010 IIT Mumbai

YUI().use('yql', function(Y) {

 

    Y.YQL('select * from weather.forecast where location=90210', function(r) {

       // r now contains the result of the YQL Query

// use the YQL Developer console to learn

// what data is coming back in this object

// and how that data is structured.

    });

 

});

Examples – Using stock YUI 3

13

Page 14: YUI - HackU 2010 IIT Mumbai

• YUI 3 (default)– Overlays– Sliders– Tab views– Rich Text Editor

• YUI 3 (gallery)– Accordion– Tree view– Resize

Using pre­built UI widgets – YUI 3

14

Page 15: YUI - HackU 2010 IIT Mumbai

• YUI 2 (default)– Overlays– Sliders– Tab views– Rich Text Editor– Image Cropper– Image loader– Progress bar– Tree view– Charts – Colour picker

Using pre­built UI widgets – YUI 2

15

Page 16: YUI - HackU 2010 IIT Mumbai

• Greasemonkey lets you add functionality to existing web pages– http://diveintogreasemonkey.org/

• YUI 3 with greasemonkey– http://blog.davglass.com/files/yui3/greasemonkey/

YUI with Greasemonkey

16

Page 17: YUI - HackU 2010 IIT Mumbai

• Simple YUI (based on YUI 3)– Start fast– Basic AJAX and DOM manipulation– http://ericmiraglia.com/yui/demos/quickyui.php

• YUI 3 – Performance– Sand­boxing

• YUI 2 – For its widget collection– If you are already used to it

Choosing your YUI

17

Page 18: YUI - HackU 2010 IIT Mumbai

• http://developer.yahoo.com/yui/3/• http://developer.yahoo.com/yui/3/examples/• http://yuilibrary.com/gallery/• http://developer.yahoo.com/yui/2• http://blog.davglass.com/files/yui3/greasemonkey

Links for you

18