Moved Sketchy Projects to "projects" array in localStorage
This commit is contained in:
parent
6d32146ca8
commit
36ef8fd63f
@ -52,31 +52,39 @@ window.save = function() {
|
|||||||
}
|
}
|
||||||
var data = $c[0].toDataURL();
|
var data = $c[0].toDataURL();
|
||||||
if( save.type == 'sketchy project' ) {
|
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']) + '?' ) {
|
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
|
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 {
|
} else {
|
||||||
var file = dataToBlob($c[0].toDataURL());
|
window.open(data, '_blank').focus();
|
||||||
var pics = navigator.getDeviceStorage('pictures');
|
|
||||||
var r = pics.addNamed(file, save['file name'] + '.png');
|
|
||||||
r.onsuccess = function() {
|
|
||||||
alert('Your sketch was successfuly saved to ' + this.result);
|
|
||||||
}
|
|
||||||
r.onerror = function() {
|
|
||||||
alert('Something bad happened when we tried to save your file\n Possible problems: \n Duplicate name \n Permission problems')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.putImageData(window.points.history[window.points.history.last].data, 0, 0);
|
c.putImageData(window.points.history[window.points.history.last].data, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.load = function() {
|
window.load = function() {
|
||||||
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');
|
var img = document.createElement('img');
|
||||||
img.src = file.data;
|
img.src = file.data;
|
||||||
console.log(file.data);
|
|
||||||
img.onload = function() {
|
img.onload = function() {
|
||||||
c.clearRect(0, 0, width(), height());
|
c.clearRect(0, 0, width(), height());
|
||||||
c.drawImage(img, 0, 0);
|
c.drawImage(img, 0, 0);
|
||||||
@ -85,6 +93,11 @@ window.load = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( localStorage.getItem('sawTips') != settings.version ) {
|
||||||
|
$('.tour').removeClass('hidden');
|
||||||
|
localStorage.setItem('sawTips', settings.version);
|
||||||
|
}
|
||||||
|
|
||||||
$('.menu').tap(function() {
|
$('.menu').tap(function() {
|
||||||
$('#menu').toggleClass('pulled');
|
$('#menu').toggleClass('pulled');
|
||||||
})
|
})
|
||||||
@ -94,15 +107,17 @@ window.load = function() {
|
|||||||
$('.load').tap(function() {
|
$('.load').tap(function() {
|
||||||
$('#load').removeClass('hidden');
|
$('#load').removeClass('hidden');
|
||||||
$('#load li').remove();
|
$('#load li').remove();
|
||||||
for( var i = 0, len = localStorage.length; i < len; i++ ) {
|
var list = JSON.parse(localStorage.getItem('projects'));
|
||||||
$('#load ol').append(
|
if( !list || list.length < 1 ) {
|
||||||
$('<li><label><span>' + localStorage.key(i) + '</span></label></li>')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if( localStorage.length < 1 ) {
|
|
||||||
$('#load ol').append(
|
$('#load ol').append(
|
||||||
$('<p>No Sketch found.</p>')
|
$('<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('tap').tap(function(e) {
|
$confirm.find('li').off('tap').tap(function(e) {
|
||||||
$(this).parent().find('li[aria-selected]').removeAttr('aria-selected');
|
$(this).parent().find('li[aria-selected]').removeAttr('aria-selected');
|
||||||
|
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').click(function() {
|
||||||
$('#load').removeClass('hidden');
|
$('#load').removeClass('hidden');
|
||||||
$('#load li').remove();
|
$('#load li').remove();
|
||||||
for( var i = 0, len = localStorage.length; i < len; i++ ) {
|
var list = JSON.parse(localStorage.getItem('projects'));
|
||||||
$('#load ol').append(
|
if( !list || list.length < 1 ) {
|
||||||
$('<li><label><span>' + localStorage.key(i) + '</span></label></li>')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if( localStorage.length < 1 ) {
|
|
||||||
$('#load ol').append(
|
$('#load ol').append(
|
||||||
$('<p>No sketch found.</p>')
|
$('<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) {
|
$confirm.find('li').off('click').click(function(e) {
|
||||||
$(this).parent().find('li[aria-selected]').removeAttr('aria-selected');
|
$(this).parent().find('li[aria-selected]').removeAttr('aria-selected');
|
||||||
$(this).attr('aria-selected', 'true');
|
$(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();
|
var data = $c[0].toDataURL();
|
||||||
|
|
||||||
if( save.type == 'sketchy project' ) {
|
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']) + '?' ) {
|
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
|
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 {
|
} else {
|
||||||
window.open(data, '_blank').focus();
|
window.open(data, '_blank').focus();
|
||||||
}
|
}
|
||||||
@ -87,7 +102,7 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function load() {
|
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');
|
var img = document.createElement('img');
|
||||||
img.src = file.data;
|
img.src = file.data;
|
||||||
img.onload = function() {
|
img.onload = function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user