Download - Beyond the page

Transcript
Page 1: Beyond the page

Glenn JonesFullfrontal – Brighton, UK11 Nov 2011

Beyond the page

Page 2: Beyond the page

Window into a another world

Page 3: Beyond the page

Objects and things made of data

Page 4: Beyond the page

<audio src="knowingme.mp3" control></audio>

a piece of audio

Any semantic structure

Page 5: Beyond the page

Drag and drop API was born of IE and now seems

to be driven by Gmail

The HTML5 drag and drop disaster – by PPKIt’s so funny you have to read it

Page 6: Beyond the page

Dragging between apps

Page 7: Beyond the page

<a href="http://glennjones.net" draggable="true">Glenn</a>

Making something draggable

Page 8: Beyond the page

onDragStarte.dataTransfer.setData('Text', 'Glenn');

onDropvar name = e.dataTransfer.getData('Text');

Passing data with drag and drop

Page 9: Beyond the page

draggables.com

Page 10: Beyond the page

.setData('application/json', '{name: "glenn"}');.setData('text/x-vcard', 'BEGIN:VCARD…');

mime-types

Page 11: Beyond the page

Dragging files from the desktop using the gang of

three

Checkout Ryan Seddon articles on thecssninja.com

Page 12: Beyond the page

for (i = 0; i <= e.dataTransfer.files.length - 1; i++) { var file = e.dataTransfer.files[i];

var reader = new FileReader(); reader.onload = function (e) {

console.log( e.target.result ); }; reader.onerror = function (e) {

console.log(‘Error reading file’); }; reader.readAsText(file);}

Reading a file dragged onto a page

Page 13: Beyond the page

for (i = 0; i <= e.dataTransfer.files.length - 1; i++) { var file = e.dataTransfer.files[i];

var reader = new FileReader(); reader.onload = function (e) {

console.log( e.target.result ); }; reader.onerror = function (e) {

console.log(‘Error reading file’); };

reader.readAsText(file);}

Reading a file dragged onto a page

Page 14: Beyond the page

for (i = 0; i <= e.dataTransfer.files.length - 1; i++) { var file = e.dataTransfer.files[i];

var reader = new FileReader();

reader.onload = function (e) { console.log( e.target.result );

}; reader.onerror = function (e) {

console.log(‘Error reading file’); }; reader.readAsText(file);} Reading a file dragged onto a page

Page 15: Beyond the page

Dragging files to the desktop is only for the

owners of Chrome

Page 16: Beyond the page

e.dataTransfer.setData('DownloadURL', '…');

mime-type : file name : urlimage/png:logo.png:http://glennjones.net/images/logo.png

Dragging files with DownloadURL

Page 17: Beyond the page

var img = 'data:image/png;base64,iVBORw … var durl = "image/png:logo.png:" + img;

.setData('DownloadURL', durl);

DownloadURL and Data URL

Page 18: Beyond the page

Copy and paste is one hell of a mess

Page 19: Beyond the page

clipboardData.setData

Page 20: Beyond the page

Use content editable area to capture HTML and semantic

mark-up during a paste

Page 21: Beyond the page

Downloading virtual filesThe good the bad and the

ugly

Page 22: Beyond the page

Virtual file download

Page 23: Beyond the page

window.URL = window.webkitURL || window.URL;window.BlobBuilder = window.BlobBuilder ||

window.WebKitBlobBuilder || window.MozBlobBuilder;

var builder = new window.BlobBuilder();builder.append(vcard);var link = document.getElementById('virtual-file-link'); link.download = ‘glennjones.vcf';link.href = window.URL.createObjectURL(builder.getBlob('text/x-vcard'));

The Download Attribute a[download]

Page 24: Beyond the page

var name = ‘glennjones‘;window[name] = vcard;

var link = document.createElement('a');link.setAttribute("type","text/x-vcard"); link.setAttribute("href","javascript:" + name); link.appendChild( document.createTextNode('vCard Download') ); document.body.appendChild(link);

Firefox hack – virtual download

Page 25: Beyond the page

Web IntentsGluing web functionality

together

Page 26: Beyond the page
Page 27: Beyond the page

Verb and Objects

Post a StatusEdit an Image

Share a BookmarkReply to PostPick a Profile

Page 28: Beyond the page
Page 29: Beyond the page
Page 30: Beyond the page

Registering a Web Intent

Page 31: Beyond the page

<intent action="http://webintents.org/pick" type="text/x-vcard" href="http://codebits.glennjones.net/contact-intent/"title="Pick a profile"></intent>

Registering a Web Intent

Page 32: Beyond the page

Sending data

Page 33: Beyond the page

var intent = new Intent(); intent.action = "http://webintents.org/save"; intent.type = "text/x-vcard"; intent.data = card;

window.navigator.startActivity(intent);

Sending data

Page 34: Beyond the page

Receiving data

Page 35: Beyond the page

var intent = new Intent();intent.action = "http://webintents.org/save";intent.type = "text/x-vcard ";intent.data = " ";window.navigator.startActivity(intent, returnSelection)

function returnSelection(){ var vcards = intent.data}

Receiving data

Page 36: Beyond the page

http://codebits.glennjones.net/webintents/contact-intent.html

Page 37: Beyond the page

In the real world

Page 38: Beyond the page
Page 39: Beyond the page

Creative independenceData ownership and portability

Page 40: Beyond the page

Thank you

@glennjoneshttp://glennjones.net

Page 41: Beyond the page

Creative Commons Attribution-Non-Commercial 2.0 UK: England & Wales Licence.

Copyright Glenn Jones 2011glennjones.net

Page 42: Beyond the page

Photo attribution:Jonas Seaman - http://www.flickr.com/photos/americanvirus/4167946259/Licence: Attribution-NonCommercial-NoDerivs 2.0 Generic (CC BY-NC-ND 2.0)