fixed background settings not applying ( save )

This commit is contained in:
Mahdi Dibaiee 2014-02-07 17:47:17 +03:30
parent dac9aaada9
commit 6a47a2ff9d
6 changed files with 21 additions and 49 deletions

View File

@ -23,27 +23,18 @@ $('a[href^="http"]').on('tap', function(e) {
window.save = function() {
switch(save.background) {
case 'white': {
var cache = {
fillStyle: c.color,
composite: c.globalCompositeOperation
}
c.fillStyle = 'white';
c.globalCompositeOperation = 'destination-over';
c.fillRect(0, 0, width(), height());
c.fillStyle = cache.fillStyle;
c.globalCompositeOperation = cache.composite;
c.fillStyle = settings.color;
c.globalCompositeOperation = settings.composite;
break;
}
case 'current color': {
var cache = {
fillStyle: c.color,
composite: c.globalCompositeOperation
}
c.fillStyle = settings.strokeStyle;
c.globalCompositeOperation = 'destination-over';
c.fillRect(0, 0, width(), height());
c.fillStyle = cache.fillStyle;
c.globalCompositeOperation = cache.composite;
c.globalCompositeOperation = settings.composite;
break;
}
}

View File

@ -26,6 +26,7 @@ Changelog
* No load-time for Mobile
* Added preloader for images
* Fixed low lineWidth for sketches rendering invisible in Chrome
* Fixed background settings not applying ( save )
License
=======

View File

@ -138,10 +138,6 @@
<li><label><span>Current Color</span></label></li>
<li><label><span>Transparent</span></label></li>
</ol>
<h1>File Name</h1>
<ol role='listbox'>
<li aria-selected='true' data-input><label><span contenteditable>My Sketch</span></label></li>
</ol>
<br>
<span>Note: You must disable pop-up blocker to save your sketch.</span>
</section>

View File

@ -5,36 +5,29 @@ $(window).resize(sizeAndPos);
// Check for update
function save() {
var cData = c.getImageData(0, 0, width(), height());
switch(save.background) {
case 'white': {
var cache = {
color: c.color,
composite: c.globalCompositeOperation
}
c.fillStyle = 'white';
c.globalCompositeOperation = 'destination-over';
c.fillRect(0, 0, width(), height());
c.fillStyle = cache.fillStyle;
c.globalCompositeOperation = cache.composite;
c.fillStyle = settings.color;
c.globalCompositeOperation = settings.composite;
break;
}
case 'current color': {
var cache = {
fillStyle: c.color,
composite: c.globalCompositeOperation
}
c.fillStyle = settings.strokeStyle;
c.globalCompositeOperation = 'destination-over';
c.fillRect(0, 0, width(), height());
c.fillStyle = cache.fillStyle;
c.globalCompositeOperation = cache.composite;
c.fillStyle = settings.color;
c.globalCompositeOperation = settings.composite;
break;
}
}
var data = $c[0].toDataURL();
window.open(data, save['file name']).focus();
window.open(data, '_blank').focus();
c.putImageData(window.points.history[window.points.history.length-1].data, 0, 0);
c.putImageData(cData, 0, 0);
}
@ -109,9 +102,7 @@ function save() {
$(this).parents('form').find('h1').each(function(i) {
if( i > 0 ) {
var key = $(this).html().toLowerCase();
var value = $(this).parent().find('ol:nth-of-type('+i+') li[aria-selected] span').html();
if( key !== 'file name' ) value = key.toLowerCase();
var value = $(this).parent().find('ol:nth-of-type('+i+') li[aria-selected] span').html().toLowerCase();
window[v][key] = value;
}
})

View File

@ -21,10 +21,11 @@ $('a[href^="http"]').on('tap', function(e) {
})
function save() {
var cData = c.getImageData(0, 0, width(), height());
switch(save.background) {
case 'white': {
var cache = {
fillStyle: c.color,
color: c.color,
composite: c.globalCompositeOperation
}
c.fillStyle = 'white';
@ -48,17 +49,10 @@ function save() {
}
}
var data = $c[0].toDataURL();
var file = dataToBlob($c[0].toDataURL());
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')
console.warn(this.error);
}
c.putImageData(window.points.history[window.points.history.last].data, 0, 0);
window.open(data, '_blank').focus();
c.putImageData(cData, 0, 0);
}
$('.menu').tap(function() {
@ -134,9 +128,7 @@ function save() {
$(this).parents('form').find('h1').each(function(i) {
if( i > 0 ) {
var key = $(this).html().toLowerCase();
var value = $(this).parent().find('ol:nth-of-type('+i+') li[aria-selected] span').html();
if( key !== 'file name' ) value = value.toLowerCase();
var value = $(this).parent().find('ol:nth-of-type('+i+') li[aria-selected] span').html().toLowerCase();
window[v][key] = value;
}
})

View File

@ -9,6 +9,7 @@
<li>No Load-time for mobile</li>
<li>Added preloader for images</li>
<li>Fixed low lineWidth for sketches rendering invisible in Chrome</li>
<li>Fixed background settings not applying ( save )</li>
</ul>
</body>
</html>