extending your own and others' sites with html5

51
Extending your own and others' sites with HTML5 Mark Reeder

Upload: mark-reeder

Post on 11-May-2015

409 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Extending your own and others' sites with HTML5

Extending your own and others' sites with HTML5

Mark Reeder

Page 2: Extending your own and others' sites with HTML5

About Me

• UI Developer at Beatport• Front-end developer working in the online music space for

the past 5 years• http://twitter.com/Mark_Reeder• https://github.com/MarkReeder

Page 3: Extending your own and others' sites with HTML5

• Employed by• Read/write access to

source code• Able to change data that is

available

• No official connection• No ability to officially

modify code• Stuck with the data they

provide (and anything else I can infer or record)

Page 4: Extending your own and others' sites with HTML5
Page 5: Extending your own and others' sites with HTML5
Page 6: Extending your own and others' sites with HTML5

• pushState URLs• data- attributes• Local storage• HTML5 elements

Page 7: Extending your own and others' sites with HTML5

• pushState URLso Allow site URL to be updated without refreshing the

whole page and without resorting to # or #! URLs• data- attributes• Local storage• HTML5 elements

Page 8: Extending your own and others' sites with HTML5

• pushState URLso Allow site URL to be updated without refreshing the

whole page and without resorting to # or #! URLso Important for Beatport because of music playback

• data- attributes• Local storage• HTML5 elements

Page 9: Extending your own and others' sites with HTML5

• pushState URLso Allow site URL to be updated without refreshing the

whole page and without resorting to # or #! URLso Important for Beatport because of music playbacko Examples: github Beatport

• data- attributes• Local storage• HTML5 elements

Page 10: Extending your own and others' sites with HTML5

• pushState URLso Allow site URL to be updated without refreshing the

whole page and without resorting to # or #! URLso Important for Beatport because of music playbacko Examples: github Beatporto Using the history.js jQuery plugin

• data- attributes• Local storage• HTML5 elements

Page 11: Extending your own and others' sites with HTML5

• pushState URLs• data- attributes

o Used to embed data on elements• Local storage• HTML5 elements

Page 12: Extending your own and others' sites with HTML5

• pushState URLs• data- attributes

o Used to embed data on elementso data-queue-position in player queue

• Local storage• HTML5 elements

Page 13: Extending your own and others' sites with HTML5

• pushState URLs• data- attributes

o Used to embed data on elementso data-queue-position in player queueo data-json for track elements

• Local storage• HTML5 elements

Page 14: Extending your own and others' sites with HTML5

• pushState URLs• data- attributes• Local storage

o Persist user settings (items per page, for example)• HTML5 elements

Page 15: Extending your own and others' sites with HTML5

• pushState URLs• data- attributes• Local storage

o Persist user settings (items per page, for example)o Persist player queue

• HTML5 elements

Page 16: Extending your own and others' sites with HTML5

• pushState URLs• data- attributes• Local storage• HTML5 elements

o <!DOCTYPE html>

Page 17: Extending your own and others' sites with HTML5

• pushState URLs• data- attributes• Local storage• HTML5 elements

o <!DOCTYPE html>o <nav>

Page 18: Extending your own and others' sites with HTML5

• pushState URLs• data- attributes• Local storage• HTML5 elements

o <!DOCTYPE html>o <nav>o <input type="search">

Page 19: Extending your own and others' sites with HTML5

• pushState URLs• data- attributes• Local storage• HTML5 elements

o <!DOCTYPE html>o <nav>o <input type="search">o Why not <audio>?

Page 20: Extending your own and others' sites with HTML5
Page 21: Extending your own and others' sites with HTML5
Page 22: Extending your own and others' sites with HTML5
Page 23: Extending your own and others' sites with HTML5

• Extension started out as a bookmarklet

Page 24: Extending your own and others' sites with HTML5

• Extension started out as a bookmarklet• Motivations

o Rich front-end

Page 25: Extending your own and others' sites with HTML5

• Extension started out as a bookmarklet• Motivations

o Rich front-endo Started exploring, found data that wasn't surfaced in

the UI

Page 26: Extending your own and others' sites with HTML5

• Extension started out as a bookmarklet• Motivations

o Rich front-endo Started exploring, found data that wasn't surfaced in

the UIo My Music Hack Day Boston project: Living Playlist

Page 27: Extending your own and others' sites with HTML5

• Extension started out as a bookmarklet• Motivations

o Rich front-endo Started exploring, found data that wasn't surfaced in

the UIo My Music Hack Day Boston project: Living Playlist

• Outgrew bookmarklet when I wanted to add scrobbling

Page 28: Extending your own and others' sites with HTML5

• Extension started out as a bookmarklet• Motivations

o Rich front-endo Started exploring, found data that wasn't surfaced in

the UIo My Music Hack Day Boston project: Living Playlist

• Outgrew bookmarklet when I wanted to add scrobblingo http://gabek.github.com/TurntableScrobbler/

Page 29: Extending your own and others' sites with HTML5

• Extension started out as a bookmarklet• Motivations

o Rich front-endo Started exploring, found data that wasn't surfaced in

the UIo My Music Hack Day Boston project: Living Playlist

• Outgrew bookmarklet when I wanted to add scrobblingo http://gabek.github.com/TurntableScrobbler/

• Learned about manifest.json and isolated worlds: Google Chrome Extensions: Content Scripts

Page 30: Extending your own and others' sites with HTML5

Getting around Isolated Worlds - injectScript.js

(function() {    var js, css;    js = document.createElement('script');    js.src = chrome.extension.getURL("js/turntable.fm.extend.js?v=0.6_" + new Date().getTime());    document.body.appendChild(js);        css = document.createElement('link');    css.rel = "stylesheet";    css.type = "text/css";    css.href=chrome.extension.getURL("css/turntable.fm.extend.css?v=0.6_" + new Date().getTime());    document.body.appendChild(css);

    var themeCSS = document.createElement('link');    themeCSS.rel = "stylesheet";    themeCSS.type = "text/css";    themeCSS.href=chrome.extension.getURL("css/tt-ext-ui-theme/jquery-ui-1.8.14.custom.css?v=0.6_" + new Date().getTime());    document.body.appendChild(themeCSS);

})();

Page 31: Extending your own and others' sites with HTML5

• Extension started out as a bookmarklet• Motivations

o Rich front-endo Started exploring, found data that wasn't surfaced in

the UIo My Music Hack Day Boston project: Living Playlist

• Outgrew bookmarklet when I wanted to add scrobblingo http://gabek.github.com/TurntableScrobbler/

• Learned about manifest.json and isolated worlds: Google Chrome Extensions: Content Scripts

• Paid the $5 and registered with the Chrome Web Store: Turntable.fm Extended

Page 32: Extending your own and others' sites with HTML5

Extension Features

• Desktop Notifications: window.webkitNotifications.createNotification

Page 33: Extending your own and others' sites with HTML5

Extension Features

• Desktop Notifications: window.webkitNotifications.createNotificationo song change

Page 34: Extending your own and others' sites with HTML5

Extension Features

• Desktop Notifications: window.webkitNotifications.createNotificationo song changeo chat

Page 35: Extending your own and others' sites with HTML5

Extension Features

• Desktop Notifications: window.webkitNotifications.createNotificationo song changeo chato room users changes

Page 36: Extending your own and others' sites with HTML5

Extension Features

• Desktop Notifications: window.webkitNotifications.createNotificationo song changeo chato room users changeso DJ changes

Page 37: Extending your own and others' sites with HTML5

Extension Features

• Desktop Notifications: window.webkitNotifications.createNotificationo song changeo chato room users changeso DJ changeso vote notifications, both up and down

Page 38: Extending your own and others' sites with HTML5

Desktop Notifications

• Natively they're not highly configurable• Chrome Extension to use Growl

o Custom Growl Build for Mac

Page 39: Extending your own and others' sites with HTML5

Extension Features

• Desktop Notifications: window.webkitNotifications.createNotificationo song changeo chato room users changeso DJ changeso vote notifications, both up and down

•  localStorage to persist data

Page 40: Extending your own and others' sites with HTML5

Extension Features

• Desktop Notifications: window.webkitNotifications.createNotificationo song changeo chato room users changeso DJ changeso vote notifications, both up and down

•  localStorage to persist datao Extension Settings

Page 41: Extending your own and others' sites with HTML5

Extension Features

• Desktop Notifications: window.webkitNotifications.createNotificationo song changeo chato room users changeso DJ changeso vote notifications, both up and down

•  localStorage to persist datao Extension Settingso Tags

Page 42: Extending your own and others' sites with HTML5

Extension Features

• Desktop Notifications: window.webkitNotifications.createNotificationo song changeo chato room users changeso DJ changeso vote notifications, both up and down

•  localStorage to persist datao Extension Settingso Tags

• data- attributes for message passing via the DOM

Page 43: Extending your own and others' sites with HTML5

Message Passing

• Message Passing Div (MPD) created in contentscript.js

Page 44: Extending your own and others' sites with HTML5

Message Passing

• Message Passing Div (MPD) created in contentscript.js • Messages are passed through dispatchEventToContentScript

Page 45: Extending your own and others' sites with HTML5

Message Passing

• Message Passing Div (MPD) created in contentscript.js • Messages are passed through dispatchEventToContentScript• Event Listeners in contentscript on MPD

Page 46: Extending your own and others' sites with HTML5

Message Passing

• Message Passing Div (MPD) created in contentscript.js • Messages are passed through dispatchEventToContentScript• Event Listeners in contentscript on MPD

o Listeners get data from data- attributes on elements

Page 47: Extending your own and others' sites with HTML5

Extension Features

• Desktop Notifications: window.webkitNotifications.createNotificationo song changeo chato room users changeso DJ changeso vote notifications, both up and down

•  localStorage to persist datao Extension Settingso Tags

• data- attributes for message passing via the DOM• Canvas behind the scenes for local file saving

Page 48: Extending your own and others' sites with HTML5

Dangers of unofficially working with 3rd party code

• The weekend of June 25/26, the extension broke

Page 49: Extending your own and others' sites with HTML5

Dangers of unofficially working with 3rd party code

• The weekend of June 25/26, the extension brokeo Random names were introduced for certain objects

within the turntable object

Page 50: Extending your own and others' sites with HTML5

Dangers of unofficially working with 3rd party code

• The weekend of June 25/26, the extension brokeo Random names were introduced for certain objects

within the turntable objecto getTurntableObjects workaround

Page 51: Extending your own and others' sites with HTML5

Questions?

http://twitter.com/Mark_Reederhttps://github.com/MarkReeder