Commit 7db4f03ac2679d1be0c9a09ff176391bc87a68d2
- Diff rendering mode:
- inline
- side by side
live/live.js
(12 / 12)
|   | |||
| 11 | 11 | return $('<pre>'+text.replace(/&/g, '&').replace(/</g, '<')+'</pre>'); | |
| 12 | 12 | } | |
| 13 | 13 | ||
| 14 | function downloadIt($appendee, mime, data) { | ||
| 15 | $appendee.append($('<a class="download" href="data:'+mime+','+encodeURI(data)+'">Download it!</a>')); | ||
| 14 | function downloadIt(mime, data) { | ||
| 15 | return $('<a class="download" href="data:'+mime+';charset=UTF-8,'+encodeURI(data)+'">Download it!</a>'); | ||
| 16 | 16 | } | |
| 17 | 17 | ||
| 18 | function noItems($appendee, name, itemtype, spec) { | ||
| 19 | $appendee.append($('<i>No <a href="'+spec+'">'+name+'</a> items (items with <code>itemtype="'+itemtype+'"</code>)</i>')); | ||
| 18 | function noItems(name, itemtype, spec) { | ||
| 19 | return $('<i>No <a href="'+spec+'">'+name+'</a> items (items with <code>itemtype="'+itemtype+'"</code>)</i>'); | ||
| 20 | 20 | } | |
| 21 | 21 | ||
| 22 | 22 | function updateTab(index) { | |
| … | … | ||
| 25 | 25 | var $json = $('#json').empty(); | |
| 26 | 26 | var jsonText = $.microdata.json(); | |
| 27 | 27 | $json.append(pre(jsonText)); | |
| 28 | downloadIt($json, 'application/json;encoding=utf-8', jsonText); | ||
| 28 | $json.append(downloadIt('application/json', jsonText)); | ||
| 29 | 29 | break; | |
| 30 | 30 | case 2: | |
| 31 | 31 | var $turtle = $('#turtle').empty(); | |
| 32 | 32 | var turtleText = $.microdata.turtle(); | |
| 33 | 33 | $turtle.append(pre(turtleText)); | |
| 34 | downloadIt($turtle, 'text/turtle;encoding=utf-8', turtleText); | ||
| 34 | $turtle.append(downloadIt('text/turtle', turtleText)); | ||
| 35 | 35 | break; | |
| 36 | 36 | case 3: | |
| 37 | 37 | var $vcard = $('#vcard').empty(); | |
| … | … | ||
| 42 | 42 | if (i > 0) | |
| 43 | 43 | $vcard.append(document.createElement('hr')); | |
| 44 | 44 | $vcard.append(pre(vcardText)); | |
| 45 | downloadIt($vcard, 'text/directory;profile=vCard;encoding=utf-8', vcardText); | ||
| 45 | $vcard.append(downloadIt('text/directory;profile=vCard', vcardText)); | ||
| 46 | 46 | }); | |
| 47 | 47 | } else { | |
| 48 | noItems($vcard, 'vCard', 'http://microformats.org/profile/hcard', | ||
| 49 | 'http://www.whatwg.org/specs/web-apps/current-work/multipage/microdata.html#vcard'); | ||
| 48 | $vcard.append(noItems('vCard', 'http://microformats.org/profile/hcard', | ||
| 49 | 'http://www.whatwg.org/specs/web-apps/current-work/multipage/microdata.html#vcard')); | ||
| 50 | 50 | } | |
| 51 | 51 | break; | |
| 52 | 52 | case 4: // iCal | |
| … | … | ||
| 54 | 54 | var icalText = $.microdata.ical(); | |
| 55 | 55 | if (icalText) { | |
| 56 | 56 | $ical.append(pre(icalText)); | |
| 57 | downloadIt($ical, 'text/calendar;componenet=vevent;encoding=utf-8', icalText); | ||
| 57 | $ical.append(downloadIt('text/calendar;componenet=vevent', icalText)); | ||
| 58 | 58 | } else { | |
| 59 | noItems($ical, 'vEvent', 'http://microformats.org/profile/hcalendar#vevent', | ||
| 60 | 'http://www.whatwg.org/specs/web-apps/current-work/multipage/microdata.html#vevent'); | ||
| 59 | $ical.append(noItems('vEvent', 'http://microformats.org/profile/hcalendar#vevent', | ||
| 60 | 'http://www.whatwg.org/specs/web-apps/current-work/multipage/microdata.html#vevent')); | ||
| 61 | 61 | } | |
| 62 | 62 | break; | |
| 63 | 63 | } |

