Skip to content

Instantly share code, notes, and snippets.

@danmactough
Created March 26, 2013 21:00
Show Gist options
  • Save danmactough/5249197 to your computer and use it in GitHub Desktop.
Save danmactough/5249197 to your computer and use it in GitHub Desktop.
Save a copy of your Little Outline
var $target = $('div.divExplanation:first');
var $dl = $('<div></div>', { 'class': 'divExplanation' });
$dl.prepend($('<a></a>', {
'class': 'saveCopy', // IE 8 bug with the "class" attr requires quotes
href: '#',
title: 'Click here to save a copy of your Little Outline',
download: 'myLittleOutline.opml',
text: 'Download Your Litte Outline'
}));
$dl.insertBefore($target);
$('div.divExplanation').on('click', 'a.saveCopy', function (e) {
if (!window.btoa) {
// do nothing -- no browser support
// @todo replace with polyfill
e.preventDefault();
return false;
}
// Always serve the current data
var data = localStorage.getItem('savedOpmlText');
// encode UTF8
data = unescape(encodeURIComponent(data));
try {
this.href = 'data:application/octet-stream;base64,' + window.btoa(data);
} catch (err) {
e.preventDefault();
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment