Building YAP Applications with YUI

114
YUICONF 2009 @reid on twitter [email protected] Reid Burke Building YAP Applications with YUI

description

The Yahoo! Application Platform allows you to build apps for the new Yahoo! homepage, My Yahoo! and other Yahoo! destinations. This session will focus on leveraging YUI on YAP, addressing best practices and noting differences from a typical environment. Particular attention will be given to writing cajolable script under Caja, the source-to-source translator that secures untrusted third-party JavaScript in YAP.

Transcript of Building YAP Applications with YUI

Page 1: Building YAP Applications with YUI

YUICONF 2009

@reid on [email protected]

Reid BurkeBuilding YAP Applications with YUI

Page 2: Building YAP Applications with YUI

What is YUI?

Page 3: Building YAP Applications with YUI

What is YAP?

Page 4: Building YAP Applications with YUI

YUICONF 2009

Your web app

Page 5: Building YAP Applications with YUI

YUICONF 2009

Yahoo!’s network

Page 6: Building YAP Applications with YUI

YUICONF 2009

Page 7: Building YAP Applications with YUI

YUICONF 2009

330M+users every month

Page 8: Building YAP Applications with YUI

YUICONF 2009

40Mdaily users

Page 9: Building YAP Applications with YUI

Zynga

weRead.com

RockYou!

LabPixies

Page 10: Building YAP Applications with YUI

YUICONF 2009

Getting started

Page 11: Building YAP Applications with YUI

YUICONF 2009

developer.yahoo.com

My Projects

Page 12: Building YAP Applications with YUI

YUICONF 2009

developer.yahoo.com

My Projects Create an app

Page 13: Building YAP Applications with YUI

YUICONF 2009

Page 14: Building YAP Applications with YUI

YUICONF 2009

You’re all set,continue.

Page 15: Building YAP Applications with YUI

YUICONF 2009

Page 16: Building YAP Applications with YUI

YUICONF 2009

Two views

Page 17: Building YAP Applications with YUI

YUICONF 2009

Page 18: Building YAP Applications with YUI

YUICONF 2009

Small View

Full View

Page 19: Building YAP Applications with YUI

YUICONF 2009

Small Viewoverview of your app

HTML & YML only

Page 20: Building YAP Applications with YUI

YUICONF 2009

Page 21: Building YAP Applications with YUI

YUICONF 2009

Page 22: Building YAP Applications with YUI

YUICONF 2009

Full Viewproxied

supports JavaScript

Page 23: Building YAP Applications with YUI

YUICONF 2009

Page 24: Building YAP Applications with YUI

Your web server URL

Page 25: Building YAP Applications with YUI

YUICONF 2009

Need hosting?

Page 26: Building YAP Applications with YUI

YUICONF 2009

Need hosting?

Free Joyent Accelerator for a year.

signup.joyent.com/yahoo_signup

Page 27: Building YAP Applications with YUI

Your web server URL

Page 28: Building YAP Applications with YUI

http://reid.yahoo.joyent.us/game/

Page 29: Building YAP Applications with YUI

YUICONF 2009

http://reid.yahoo.joyent.us/game/

Page 30: Building YAP Applications with YUI

YUICONF 2009

http://reid.yahoo.joyent.us/game/fight.php

Page 31: Building YAP Applications with YUI

YUICONF 2009

http://apps.yahoo.com/-foo/fight.php

http://reid.yahoo.joyent.us/game/fight.php

Page 32: Building YAP Applications with YUI

YUICONF 2009

YAP isn’t always on apps.yahoo.com

Page 33: Building YAP Applications with YUI

YUICONF 2009

<a href=”http://apps.yahoo.com/-foo/fight.php?u={guid}”>Attack your friend!

</a>

Page 34: Building YAP Applications with YUI

YUICONF 2009

<a href=”http://apps.yahoo.com/-foo/fight.php?u={guid}”>Attack your friend!

</a>

Page 35: Building YAP Applications with YUI

YUICONF 2009

YML

Page 36: Building YAP Applications with YUI

YUICONF 2009

<yml:a params=”fight.php?u={guid}”>Attack them!

</yml:a>

Page 37: Building YAP Applications with YUI

YUICONF 2009

<yml:a

params=”fight.php?

u={guid}”

replace=”foo”>Attack them!

</yml:a>

Page 38: Building YAP Applications with YUI

YUICONF 2009

<yml:a

params=”fight.php?

u={guid}”

replace=”foo”>

Attack <yml:pronoun uid=”{guid}” objective=”true”/>!</yml:a>

Page 39: Building YAP Applications with YUI

YUICONF 2009

<div id=”content”>

Loading...</div>

<yml:include params=”smallView.php” replace=”content”/>

Page 40: Building YAP Applications with YUI

YUICONF 2009

Selected friend:

<yml:user-badge uid=”{friend}” linked=”true”/>.

Page 41: Building YAP Applications with YUI

YUICONF 2009

<style>

h1 { color red; }

<yml:if-env ua=”ie”>h1 { color: green; }</yml:if-env></style>

Page 42: Building YAP Applications with YUI

YUICONF 2009

developer.yahoo.com/yap/yml

Page 43: Building YAP Applications with YUI

YUICONF 2009

Make 2 apps:

Page 44: Building YAP Applications with YUI

YUICONF 2009

Make 2 apps:

test it on yahoo.com

Development

Page 45: Building YAP Applications with YUI

YUICONF 2009

Make 2 apps:

test it on yahoo.com

Development

Productionmake metadata

changes on dev first

Page 46: Building YAP Applications with YUI

YUICONF 2009

What’s the approval process?

Page 47: Building YAP Applications with YUI

YUICONF 2009

There isn’t one.

Page 48: Building YAP Applications with YUI

YUICONF 2009

No application review!

Page 49: Building YAP Applications with YUI

YUICONF 2009

Things can go wrong

Page 50: Building YAP Applications with YUI

YUICONF 2009

Page 51: Building YAP Applications with YUI

YUICONF 2009

•top.location

Page 52: Building YAP Applications with YUI

YUICONF 2009

•top.location

•Browser history

Page 53: Building YAP Applications with YUI

YUICONF 2009

•top.location

•Browser history

•Cookie & token stealing

Page 54: Building YAP Applications with YUI

YUICONF 2009

•top.location

•Browser history

•Cookie & token stealing

•Script injection

Page 55: Building YAP Applications with YUI

YUICONF 2009

•top.location

•Browser history

•Cookie & token stealing

•Script injection

•Host discovery

Page 56: Building YAP Applications with YUI

YUICONF 2009

•top.location

•Browser history

•Cookie & token stealing

•Script injection

•Host discovery

•XMLHttpRequest

Page 57: Building YAP Applications with YUI

YUICONF 2009

Caja

Page 58: Building YAP Applications with YUI

YUICONF 2009

Cajaunbiased review

Page 59: Building YAP Applications with YUI

YUICONF 2009

UntrustedJavaScript

Page 60: Building YAP Applications with YUI

YUICONF 2009

UntrustedJavaScript

evil.com/yap.php

Page 61: Building YAP Applications with YUI

YUICONF 2009

UntrustedJavaScript

YAPEngine

evil.com/yap.php

Page 62: Building YAP Applications with YUI

YUICONF 2009

UntrustedJavaScript

YAPEngine

Cajoledscript

evil.com/yap.php apps.yahoo.com/-3vi1

Page 63: Building YAP Applications with YUI

YUICONF 2009

Let’s get YUI

Page 64: Building YAP Applications with YUI

YUICONF 2009

YUI CoreThe YAHOO Global Object (base requirement for all YUI components)

DOM Collection (convenience methods for DOM interactions)Event Utility (event normalization and custom events)

UtilitiesAnimation

Connection ManagerDrag & Drop

ElementImageLoader

ResizeSelector

Controls / WidgetsAutoComplete

ButtonContainer

(includes Module, Overlay, Panel, Tooltip, Dialog, SimpleDialog)

MenuTabViewTreeView

Page 65: Building YAP Applications with YUI

YUICONF 2009

YAP supports 2.8

Page 66: Building YAP Applications with YUI

YUICONF 2009

YAP supports 2.8mostly

Page 67: Building YAP Applications with YUI

YUICONF 2009

Take advantage of our YUI hosting

Page 68: Building YAP Applications with YUI

YUICONF 2009

rewritten to pre-cajoled versions

<script src=”http://yui.yahooapis.com/2.8.0/”

Page 69: Building YAP Applications with YUI

YUICONF 2009

Page 70: Building YAP Applications with YUI

YUICONF 2009

2.8.0 in the URL

Page 71: Building YAP Applications with YUI

YUICONF 2009

Working with Caja

Page 72: Building YAP Applications with YUI

YUICONF 2009

Hello standards!

Page 73: Building YAP Applications with YUI

YUICONF 2009

W3C compliantJavaScript API

Page 74: Building YAP Applications with YUI

YUICONF 2009

Caja makes up for browser

deficiencies

Page 75: Building YAP Applications with YUI

YUICONF 2009

No external JavaScript or CSS

Page 76: Building YAP Applications with YUI

YUICONF 2009

Your HTML/JS/CSS needs to be inline

Page 77: Building YAP Applications with YUI

YUICONF 2009

<style>

#hd { background: #fff; }

</style>

<div id=”container”>

<div id=”hd”>

<h1>My Awesome App</h1>

</div>

</div>

<script>

document.getElementById(“hd”).innerHTML

= “Super Awesome App”;

</script>

Page 78: Building YAP Applications with YUI

YUICONF 2009

<script src=”my.js”>

</script><link href=”my.css”

rel=”stylesheet”>

<script>/* my.js */</script>

<style>/* my.css */</style>

Page 79: Building YAP Applications with YUI

YUICONF 2009

be lazygithub.com/reid/ungadget

Page 80: Building YAP Applications with YUI

YUICONF 2009

Externalized JavaScript and CSS.

We’re working on it.

Page 81: Building YAP Applications with YUI

YUICONF 2009

No access to computed styles

Page 82: Building YAP Applications with YUI

YUICONF 2009

Script is always run after your markup

Page 83: Building YAP Applications with YUI

YUICONF 2009

<script/><h1/><div/><script/>

<h1/><div/>

<script>/* Concatenated */</script>

Page 84: Building YAP Applications with YUI

YUICONF 2009

restricted this

Page 85: Building YAP Applications with YUI

YUICONF 2009

document.location can’t be set

document.location = myURL;

Page 86: Building YAP Applications with YUI

YUICONF 2009

No with

Page 87: Building YAP Applications with YUI

YUICONF 2009

No document.write

Page 88: Building YAP Applications with YUI

YUICONF 2009

document.write(“Hello world!”);

YAHOO.util.Dom.get(“foo”).innerHTML =

“Hello World!”;

Page 89: Building YAP Applications with YUI

YUICONF 2009

Avoid CSS hacks

Page 90: Building YAP Applications with YUI

YUICONF 2009

<style>

h1 { color: red; }

h1 { _color: green; }</style>

<style>

h1 { color red; }

<yml:if-env ua=”ie”>h1 { color: green; }</yml:if-env></style>

Page 91: Building YAP Applications with YUI

YUICONF 2009

Creating SWFs

Page 92: Building YAP Applications with YUI

YUICONF 2009

<yml:swf/>

Page 93: Building YAP Applications with YUI

YUICONF 2009

YAP caches images

Page 94: Building YAP Applications with YUI

YUICONF 2009

Changed images?Change the URL.

Page 95: Building YAP Applications with YUI

YUICONF 2009

Examples!github.com/reid/yap-examples

Page 96: Building YAP Applications with YUI

YUICONF 2009

Logger

Page 97: Building YAP Applications with YUI

YUICONF 2009

Logger

Page 98: Building YAP Applications with YUI

YUICONF 2009

Logger

Page 99: Building YAP Applications with YUI

YUICONF 2009

Logger

Page 100: Building YAP Applications with YUI

YUICONF 2009

Dialogs & CSS

Page 101: Building YAP Applications with YUI

YUICONF 2009

Dialogs & CSS

/* YUI Fonts CSS can’t apply rules to body */#app { /* rules from fonts.css */ }

Page 102: Building YAP Applications with YUI

YUICONF 2009

Dialogs & CSS

/* YUI Fonts CSS can’t apply rules to body */#app { /* rules from fonts.css */ }

Page 103: Building YAP Applications with YUI

YUICONF 2009

Examples!developer.yahoo.com/yap/guide/yui-examples.html

Page 104: Building YAP Applications with YUI

YUICONF 2009

developer.yahoo.com/yap

Page 105: Building YAP Applications with YUI

YUICONF 2009

Make some apps!

Page 106: Building YAP Applications with YUI

YUICONF 2009

•Small and Full Views

Page 107: Building YAP Applications with YUI

YUICONF 2009

•Small and Full Views

•Free Joyent Accelerator

Page 108: Building YAP Applications with YUI

YUICONF 2009

•Small and Full Views

•Free Joyent Accelerator

•YML tags

Page 109: Building YAP Applications with YUI

YUICONF 2009

•Small and Full Views

•Free Joyent Accelerator

•YML tags

•Cajoled scripts

Page 110: Building YAP Applications with YUI

YUICONF 2009

•Small and Full Views

•Free Joyent Accelerator

•YML tags

•Cajoled scripts

•YUI 2.8.0 pre-cajoled

Page 111: Building YAP Applications with YUI

YUICONF 2009

•Small and Full Views

•Free Joyent Accelerator

•YML tags

•Cajoled scripts

•YUI 2.8.0 pre-cajoled

•No external scripts

Page 112: Building YAP Applications with YUI

YUICONF 2009

Questions?

Page 113: Building YAP Applications with YUI

YUICONF 2009

@reid on Twitter

[email protected]

Page 114: Building YAP Applications with YUI

YUICONF 2009

Thank You

Photograph used under the CC BY 2.0 license.flickr.com/photos/soundfromwayout/143822346

Download this presentation:

slideshare.net/reidburke