Slide 1

Slide 1 text

Mashing up JavaScript @BastianHofmann

Slide 2

Slide 2 text

Wtf?

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

• JavaScript Apps • CORS and OAuth2 • Local Storage • OEmbed and Caja • WebSockets, ActivityStrea.ms and PubsubHubbub • What‘s next?

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

http://speakerdeck.com/u/bastianhofmann

Slide 21

Slide 21 text

Let‘s write a JS App

Slide 22

Slide 22 text

https://github.com/bashofmann/statusnet_js_mashup_2nd

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

CSS Bastian

Slide 25

Slide 25 text

http://twitter.github.com/bootstrap

Slide 26

Slide 26 text

History & Bookmarking

Slide 27

Slide 27 text

www.example.com#Page

Slide 28

Slide 28 text

www.example.com/Page

Slide 29

Slide 29 text

http://sammyjs.org/

Slide 30

Slide 30 text

API Access

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Same Origin Policy

Slide 33

Slide 33 text

Cross-Origin Resource Sharing Backend api.twitter.com Client client.net AJAX Access-Control-Allow-Origin: * http://www.w3.org/TR/cors/

Slide 34

Slide 34 text

var html="
    "; for (var i=0; i < viewers.length; i++) { html += "
  • " + viewers[i].displayName + "
  • "; } html += "
      "; document.getElementById("#div").innerHTML = html; Where is the error?

Slide 35

Slide 35 text

Templates

Slide 36

Slide 36 text

Mustache.JS https://github.com/janl/mustache.js }

Slide 37

Slide 37 text

var app = Sammy('#main', function() { var feed = []; this.use(Mustache, 'ms'); this.get('/', function() { this.trigger('getFeed'); }); ... }); jQuery(function() { app.run(); });

Slide 38

Slide 38 text

this.bind('getFeed', function() { var that = this; $.ajax({ url: 'http://..._timeline.json', success: function(response) { feed = response; that.trigger('renderFeed'); } }); }); this.bind('renderFeed', function() { this.feed = feed; this.partial('js/templates/feed.ms'); });

Slide 39

Slide 39 text

    {{#feed}}
  • {{{statusnet_html}}}

    {{created_at}} {{#user}} {{name}} {{/user}}

  • {{/feed}}

Slide 40

Slide 40 text

Authorization

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

http://oauth.net/

Slide 43

Slide 43 text

User-Agent Profile

Slide 44

Slide 44 text

http://twitter.com/authorize?&clientId=... Open Popup lanyrd.com

Slide 45

Slide 45 text

http://twitter.com/authorize?&clientId=... Open Popup lanyrd.com HTTPS GET twitter.co m/ authorize

Slide 46

Slide 46 text

http://twitter.com/authorize?&clientId=... Open Popup lanyrd.com Login twitter.co m/ authorize

Slide 47

Slide 47 text

http://twitter.com/authorize?&clientId=... Open Popup lanyrd.com Grant Permission twitter.co m/ authorize

Slide 48

Slide 48 text

lanyrd.com HTTPS Redirect RedirectURI# accessToken twitter.co m/ authorize RedirectURI# accessToken lanyrd.com

Slide 49

Slide 49 text

lanyrd.com RedirectURI# accessToken Parse Access Token from Fragment Send it to opening window Close popup lanyrd.com

Slide 50

Slide 50 text

Same Origin Policy

Slide 51

Slide 51 text

lanyrd.com HTTPS Ajax Request to API Access Token twitter.com

Slide 52

Slide 52 text

Storing the access token

Slide 53

Slide 53 text

Local Storage http://www.w3.org/TR/webstorage/

Slide 54

Slide 54 text

this.around(function(callback) { ... if (! oauth2.isLoggedIn()) { this.redirect('/Login'); return; } callback(); });

Slide 55

Slide 55 text

this.get('/Login', function() { this.partial('login.ms'); });

Slide 56

Slide 56 text

Slide 57

Slide 57 text

this.post('/Login', function() { var consumerKey = 'abc....'; window.open('http://status.net/api/oauth2/ authorize?response_toke=token&client_id=' + consumerKey); });

Slide 58

Slide 58 text

var fragment = location.hash.substr(1); opener.parent.oauth2.storeToken(fragment); window.close();

Slide 59

Slide 59 text

Slide 60

Slide 60 text

this.post('/Entry', function() { var that = this; $.ajax({ url: 'http://status.net/.../ update.json?oauth_token=' + oauth2.store['access_token'], type: 'POST', data: { 'status': that.params['status'] }, success: function() { that.redirect('/'); } }); });

Slide 61

Slide 61 text

DEMO

Slide 62

Slide 62 text

Mash it up!

Slide 63

Slide 63 text

cool video: http://www.youtube.com/ watch?v=OFzkTxiwziQ

Slide 64

Slide 64 text

OEmbed http://oembed.com/

Slide 65

Slide 65 text

http://www.youtube.com/watch?v=OyJd2qsRkNk

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

http://www.youtube.com/oembed?url=http%3A%2F %2Fwww.youtube.com%2Fwatch%3Fv %3DOyJd2qsRkNk&maxwidth=500&format=json

Slide 68

Slide 68 text

{ "provider_url":"http:\/\/www.youtube.com\/", "title":"Jupiter Jones - Das Jahr in dem ich schlief (Musik Video)", "html":"\u003cobject width=\"500\" height=\"306\"\u003e \u003cparam name=\"movie\" value=\"http:\/\/www.youtube.com\/v\/ OyJd2qsRkNk?version=3\"\u003e\u003c\/param\u003e\u003cparam name= \"allowFullScreen\" value=\"true\"\u003e\u003c\/param\u003e \u003cparam name=\"allowscriptaccess\" value=\"always\"\u003e \u003c\/param\u003e\u003cembed src=\"http:\/\/www.youtube.com\/v\/ OyJd2qsRkNk?version=3\" type=\"application\/x-shockwave-flash \" width=\"500\" height=\"306\" allowscriptaccess=\"always \" allowfullscreen=\"true\"\u003e\u003c\/embed\u003e\u003c\/object \u003e", "author_name":"St182", "height":306, "thumbnail_width":480, "width":500, "version":"1.0", "author_url":"http:\/\/www.youtube.com\/user\/Stinkfist182", "provider_name":"YouTube", "thumbnail_url":"http:\/\/i4.ytimg.com\/vi\/OyJd2qsRkNk\/ hqdefault.jpg", "type":"video", "thumbnail_height":360 }

Slide 69

Slide 69 text

cool video:

Slide 70

Slide 70 text

http://embed.ly/

Slide 71

Slide 71 text

this.bind('changed', function() { embeds = []; $('div.feed-item h3').embedly({ key:'...', maxWidth: 450, wmode: 'transparent', method: 'after' }); });

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

Caja http://code.google.com/p/google-caja/

Slide 74

Slide 74 text

html_sanitize(result.html);

Slide 75

Slide 75 text

DEMO

Slide 76

Slide 76 text

Instant updates without reloading

Slide 77

Slide 77 text

PubSubHubbub retrieves Atom feed with Hub URL Hub posts sth pings every subscriber subscribes for feed acks subscription http://code.google.com/p/pubsubhubbub/

Slide 78

Slide 78 text

Slide 79

Slide 79 text

http://activitystrea.ms/schema/1.0/ note http://status.net.xyz:8061/index.php/notice/20 hello from client hello from client http://activitystrea.ms/schema/1.0/post 2011-05-23T21:07:33+00:00 2011-05-23T21:07:33+00:00 52.52437 13.41053

Slide 80

Slide 80 text

http://activitystrea.ms/

Slide 81

Slide 81 text

Slide 82

Slide 82 text

PubSubHubbub retrieves Atom feed with Hub URL Hub posts sth pings every subscriber subscribes for feed acks subscription http://code.google.com/p/pubsubhubbub/

Slide 83

Slide 83 text

http://nodejs.org/

Slide 84

Slide 84 text

HTTP Server for PubsubHubbub

Slide 85

Slide 85 text

WebSockets http://dev.w3.org/html5/websockets/

Slide 86

Slide 86 text

socket.io http://socket.io/

Slide 87

Slide 87 text

(Webkit) Browser Notifications

Slide 88

Slide 88 text

retrieve Stream with Hub Ajax: request Subscription WebSockets: new Post subscribe at hub challenge ack new post Notification new post

Slide 89

Slide 89 text

DEMO

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

Meteor http://www.meteor.com

Slide 92

Slide 92 text

https://github.com/bashofmann/meteor_shoutbox_demo

Slide 93

Slide 93 text

DEMO

Slide 94

Slide 94 text

Did you like this talk? http://bit.ly/oscon12_js_mashup h"p://twi"er.com/Bas2anHofmann h"p://profiles.google.com/bashofmann h"p://lanyrd.com/people/Bas2anHofmann h"p://speakerdeck.com/u/bas2anhofmann h"ps://github.com/bashofmann [email protected]