Moved Sketchy Projects to "projects" array in localStorage
This commit is contained in:
0
Web/js/desktop.css
Normal file
0
Web/js/desktop.css
Normal file
@ -11,16 +11,19 @@ $(window).resize(sizeAndPos);
|
||||
$('.load').click(function() {
|
||||
$('#load').removeClass('hidden');
|
||||
$('#load li').remove();
|
||||
for( var i = 0, len = localStorage.length; i < len; i++ ) {
|
||||
$('#load ol').append(
|
||||
$('<li><label><span>' + localStorage.key(i) + '</span></label></li>')
|
||||
);
|
||||
}
|
||||
if( localStorage.length < 1 ) {
|
||||
var list = JSON.parse(localStorage.getItem('projects'));
|
||||
if( !list || list.length < 1 ) {
|
||||
$('#load ol').append(
|
||||
$('<p>No sketch found.</p>')
|
||||
);
|
||||
return;
|
||||
}
|
||||
for( var i = 0, len = list.length; i < len; i++ ) {
|
||||
$('#load ol').append(
|
||||
$('<li><label><span>' + list[i].name + '</span></label></li>')
|
||||
);
|
||||
}
|
||||
|
||||
$confirm.find('li').off('click').click(function(e) {
|
||||
$(this).parent().find('li[aria-selected]').removeAttr('aria-selected');
|
||||
$(this).attr('aria-selected', 'true');
|
||||
|
0
Web/js/main.css
Normal file
0
Web/js/main.css
Normal file
@ -72,13 +72,28 @@ $(document).ready(function() {
|
||||
var data = $c[0].toDataURL();
|
||||
|
||||
if( save.type == 'sketchy project' ) {
|
||||
if( localStorage.getItem(save['file name']) ) {
|
||||
var list = JSON.parse(localStorage.getItem('projects'));
|
||||
if( list && list.some(function(a) { return a.name == save['file name'] }) ) {
|
||||
if( confirm('A sketch with this name already exists. Do you want to overwrite ' + save['file name']) + '?' ) {
|
||||
localStorage.setItem(save['file name'], JSON.stringify({data: data, points: window.points}));
|
||||
list.push({
|
||||
name: save['file name'],
|
||||
data: data,
|
||||
points: window.points
|
||||
})
|
||||
localStorage.setItem('projects', JSON.stringify(list));
|
||||
}
|
||||
}
|
||||
else
|
||||
localStorage.setItem(save['file name'], JSON.stringify({data: data, points: window.points}));
|
||||
list ? list.push({
|
||||
name: save['file name'],
|
||||
data: data,
|
||||
points: window.points
|
||||
}) : list = [{
|
||||
name: save['file name'],
|
||||
data: data,
|
||||
points: window.points
|
||||
}];
|
||||
localStorage.setItem('projects', JSON.stringify(list));
|
||||
} else {
|
||||
window.open(data, '_blank').focus();
|
||||
}
|
||||
@ -87,7 +102,7 @@ $(document).ready(function() {
|
||||
}
|
||||
|
||||
function load() {
|
||||
var file = JSON.parse(localStorage.getItem(load.file));
|
||||
var file = JSON.parse(localStorage.getItem('projects')).filter(function(a) { return a.name == load.file })[0];
|
||||
var img = document.createElement('img');
|
||||
img.src = file.data;
|
||||
img.onload = function() {
|
||||
|
Reference in New Issue
Block a user