Version 1.2
This commit is contained in:
@ -2,41 +2,42 @@
|
||||
|
||||
$(window).resize(sizeAndPos);
|
||||
|
||||
// Check for update
|
||||
|
||||
function save() {
|
||||
var cData = c.getImageData(0, 0, width(), height());
|
||||
switch(save.background) {
|
||||
case 'white': {
|
||||
c.fillStyle = 'white';
|
||||
c.globalCompositeOperation = 'destination-over';
|
||||
c.fillRect(0, 0, width(), height());
|
||||
c.fillStyle = settings.color;
|
||||
c.globalCompositeOperation = settings.composite;
|
||||
break;
|
||||
}
|
||||
case 'current color': {
|
||||
c.fillStyle = settings.color;
|
||||
c.globalCompositeOperation = 'destination-over';
|
||||
c.fillRect(0, 0, width(), height());
|
||||
c.fillStyle = settings.color;
|
||||
c.globalCompositeOperation = settings.composite;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var data = $c[0].toDataURL();
|
||||
window.open(data, '_blank').focus();
|
||||
|
||||
c.putImageData(cData, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
$('.menu').click(function() {
|
||||
$('#menu').toggleClass('pulled');
|
||||
})
|
||||
$('.save').click(function() {
|
||||
$('#save').removeClass('hidden');
|
||||
})
|
||||
$('.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 ) {
|
||||
$('#load ol').append(
|
||||
$('<p>No sketch found.</p>')
|
||||
);
|
||||
}
|
||||
$confirm.find('li').off('click').click(function(e) {
|
||||
$(this).parent().find('li[aria-selected]').removeAttr('aria-selected');
|
||||
$(this).attr('aria-selected', 'true');
|
||||
})
|
||||
})
|
||||
$('#pro').click(function() {
|
||||
$('#save ol:nth-of-type(2) li').each(function() {
|
||||
if( $(this).find('span').html() !== 'Transparent' ) {
|
||||
$(this).addClass('hidden');
|
||||
$(this).removeAttr('aria-selected');
|
||||
}
|
||||
else $(this).attr('aria-selected', 'true');
|
||||
})
|
||||
})
|
||||
$('#exp').click(function() {
|
||||
$('#save ol:nth-of-type(2) li').removeClass('hidden');
|
||||
})
|
||||
$c.last().on('mousedown', function(e) {
|
||||
e.preventDefault();
|
||||
var xy = relative(e.pageX, e.pageY);
|
||||
@ -68,7 +69,7 @@ function save() {
|
||||
|
||||
// Single
|
||||
|
||||
var $single = $('form[data-type="value-selector"].single');
|
||||
var $single = $('form.single');
|
||||
|
||||
$single.find('li').click(function(e) {
|
||||
$(this).parent().find('li[aria-selected]').removeAttr('aria-selected');
|
||||
@ -90,28 +91,33 @@ function save() {
|
||||
|
||||
// Confirm
|
||||
|
||||
var $confirm = $('form[data-type="value-selector"].confirm');
|
||||
var $confirm = $('form.confirm');
|
||||
|
||||
$confirm.find('li').click(function(e) {
|
||||
$(this).parent().find('li[aria-selected]').removeAttr('aria-selected');
|
||||
$(this).attr('aria-selected', 'true');
|
||||
})
|
||||
$confirm.find('button').last().click(function(e) {
|
||||
e.preventDefault();
|
||||
var v = $(this).parents('form').attr('id');
|
||||
$(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().toLowerCase();
|
||||
window[v][key] = value;
|
||||
}
|
||||
$confirm.each(function() {
|
||||
|
||||
$(this).find('li').click(function(e) {
|
||||
$(this).parent().find('li[aria-selected]').removeAttr('aria-selected');
|
||||
$(this).attr('aria-selected', 'true');
|
||||
})
|
||||
$(this).parents('form').addClass('hidden');
|
||||
window[v]();
|
||||
})
|
||||
$confirm.find('button').first().click(function(e) {
|
||||
e.preventDefault();
|
||||
$(this).parents('form').addClass('hidden');
|
||||
$(this).find('button').last().click(function(e) {
|
||||
e.preventDefault();
|
||||
var v = $(this).parents('form').attr('id');
|
||||
$(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' && key !== 'file' ) value = value.toLowerCase();
|
||||
window[v][key] = value;
|
||||
}
|
||||
})
|
||||
$(this).parents('form').addClass('hidden');
|
||||
window[v]();
|
||||
})
|
||||
$(this).find('button').first().click(function(e) {
|
||||
e.preventDefault();
|
||||
$(this).parents('form').addClass('hidden');
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
// Value Selector Callers
|
||||
|
@ -35,4 +35,65 @@ $(document).ready(function() {
|
||||
nope: ['js/desktop.js', 'js/libs/color-picker.js']
|
||||
})
|
||||
|
||||
|
||||
function save() {
|
||||
switch(save.background) {
|
||||
case 'white': {
|
||||
c.fillStyle = 'white';
|
||||
c.globalCompositeOperation = 'destination-over';
|
||||
c.fillRect(0, 0, width(), height());
|
||||
c.fillStyle = settings.color;
|
||||
c.globalCompositeOperation = settings.composite;
|
||||
break;
|
||||
}
|
||||
case 'current color': {
|
||||
c.fillStyle = settings.color;
|
||||
c.globalCompositeOperation = 'destination-over';
|
||||
c.fillRect(0, 0, width(), height());
|
||||
c.fillStyle = settings.color;
|
||||
c.globalCompositeOperation = settings.composite;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var data = $c[0].toDataURL();
|
||||
|
||||
if( save.type == 'sketchy project' ) {
|
||||
if( localStorage.getItem(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}));
|
||||
}
|
||||
}
|
||||
else
|
||||
localStorage.setItem(save['file name'], JSON.stringify({data: data, points: window.points}));
|
||||
} else {
|
||||
window.open(data, '_blank').focus();
|
||||
}
|
||||
|
||||
c.putImageData(window.points.history[window.points.history.last].data, 0, 0);
|
||||
}
|
||||
|
||||
function load() {
|
||||
var file = JSON.parse(localStorage.getItem(load.file));
|
||||
var img = document.createElement('img');
|
||||
img.src = file.data;
|
||||
img.onload = function() {
|
||||
c.clearRect(0, 0, width(), height());
|
||||
c.drawImage(img, 0, 0);
|
||||
window.points = file.points;
|
||||
window.points.history = [{ data: c.createImageData($c.width(), $c.height()), points: []}, { data: c.getImageData(0, 0, width(), height()), points: file.points}];
|
||||
}
|
||||
}
|
||||
window.load = load;
|
||||
window.save = save;
|
||||
|
||||
// Check for Update
|
||||
|
||||
var request = navigator.mozApps.getSelf();
|
||||
|
||||
request.onsuccess = function() {
|
||||
var manifest = this.manifest;
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
0
Web/js/mobile.css
Normal file
0
Web/js/mobile.css
Normal file
323
Web/js/mobile.js
323
Web/js/mobile.js
@ -1,207 +1,196 @@
|
||||
"use strict";
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
// Open External Links in browser
|
||||
|
||||
$('*').click(function(e) {
|
||||
e.preventDefault();
|
||||
$('.menu').tap(function() {
|
||||
$('#menu').toggleClass('pulled');
|
||||
})
|
||||
|
||||
$('a[href^="http"]').on('tap', function(e) {
|
||||
e.preventDefault();
|
||||
var href = $(this).attr('href');
|
||||
var view = new MozActivity({
|
||||
name: 'view',
|
||||
data: {
|
||||
type: 'url',
|
||||
url: href
|
||||
}
|
||||
})
|
||||
$('.save').tap(function() {
|
||||
$('#save').removeClass('hidden');
|
||||
})
|
||||
|
||||
function save() {
|
||||
var cData = c.getImageData(0, 0, width(), height());
|
||||
switch(save.background) {
|
||||
case 'white': {
|
||||
c.fillStyle = 'white';
|
||||
c.globalCompositeOperation = 'destination-over';
|
||||
c.fillRect(0, 0, width(), height());
|
||||
c.fillStyle = settings.color;
|
||||
c.globalCompositeOperation = settings.composite;
|
||||
break;
|
||||
}
|
||||
case 'current color': {
|
||||
c.fillStyle = settings.color;
|
||||
c.globalCompositeOperation = 'destination-over';
|
||||
c.fillRect(0, 0, width(), height());
|
||||
c.fillStyle = settings.color;
|
||||
c.globalCompositeOperation = settings.composite;
|
||||
break;
|
||||
}
|
||||
$('.load').tap(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>')
|
||||
);
|
||||
}
|
||||
var data = $c[0].toDataURL();
|
||||
window.open(data, '_blank').focus();
|
||||
|
||||
c.putImageData(cData, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
$('.menu').tap(function() {
|
||||
$('#menu').toggleClass('pulled');
|
||||
if( localStorage.length < 1 ) {
|
||||
$('#load ol').append(
|
||||
$('<p>No sketch found.</p>')
|
||||
);
|
||||
}
|
||||
$confirm.find('li').off('tap').tap(function(e) {
|
||||
$(this).parent().find('li[aria-selected]').removeAttr('aria-selected');
|
||||
$(this).attr('aria-selected', 'true');
|
||||
})
|
||||
$('.save').tap(function() {
|
||||
$('#save').removeClass('hidden');
|
||||
})
|
||||
$('#pro').click(function() {
|
||||
$('#save ol:nth-of-type(2) li').each(function() {
|
||||
if( $(this).find('span').html() !== 'Transparent' ) {
|
||||
$(this).addClass('hidden');
|
||||
$(this).removeAttr('aria-selected');
|
||||
}
|
||||
else $(this).attr('aria-selected', 'true');
|
||||
})
|
||||
$c.last().on('touchstart', function(e) {
|
||||
var xy = relative(e.changedTouches[0].pageX, e.changedTouches[0].pageY);
|
||||
startPoint(xy.x, xy.y);
|
||||
window.active = true;
|
||||
}).on('touchmove', function(e) {
|
||||
if (!window.active || settings.type == 'line') return;
|
||||
var xy = relative(e.changedTouches[0].pageX, e.changedTouches[0].pageY);
|
||||
drawPoint(xy.x, xy.y);
|
||||
}).on('touchend', function(e) {
|
||||
})
|
||||
$('#exp').click(function() {
|
||||
$('#save ol:nth-of-type(2) li').removeClass('hidden');
|
||||
})
|
||||
$c.last().on('touchstart', function(e) {
|
||||
var xy = relative(e.changedTouches[0].pageX, e.changedTouches[0].pageY);
|
||||
startPoint(xy.x, xy.y);
|
||||
window.active = true;
|
||||
}).on('touchmove', function(e) {
|
||||
if (!window.active || settings.type == 'line') return;
|
||||
var xy = relative(e.changedTouches[0].pageX, e.changedTouches[0].pageY);
|
||||
drawPoint(xy.x, xy.y);
|
||||
}).on('touchend', function(e) {
|
||||
window.active = false;
|
||||
if( settings.type == 'eraser' ) return;
|
||||
|
||||
if(window.points.history.last < window.points.history.length-1) {
|
||||
window.points.history.splice(window.points.history.last+1);
|
||||
}
|
||||
|
||||
window.points.history.push({
|
||||
data: c.getImageData(0, 0, width(), height()),
|
||||
points: window.points.slice(0)
|
||||
})
|
||||
window.points.history.last = window.points.history.length-1;
|
||||
}).on('longTap', function(e) {
|
||||
if( points[points.length-1].type == 'line' ) {
|
||||
window.active = false;
|
||||
if( settings.type == 'eraser' ) return;
|
||||
points[points.length-1].type = '';
|
||||
points[points.length-1].start = undefined;
|
||||
}
|
||||
})
|
||||
|
||||
if(window.points.history.last < window.points.history.length-1) {
|
||||
window.points.history.splice(window.points.history.last+1);
|
||||
}
|
||||
// Value Selector
|
||||
|
||||
window.points.history.push({
|
||||
data: c.getImageData(0, 0, width(), height()),
|
||||
points: window.points.slice(0)
|
||||
})
|
||||
window.points.history.last = window.points.history.length-1;
|
||||
}).on('longTap', function(e) {
|
||||
if( points[points.length-1].type == 'line' ) {
|
||||
window.active = false;
|
||||
points[points.length-1].type = '';
|
||||
points[points.length-1].start = undefined;
|
||||
}
|
||||
})
|
||||
var $single = $('form[data-type="value-selector"].single');
|
||||
|
||||
$single.find('li').tap(function(e) {
|
||||
e.preventDefault();
|
||||
$(this).parent().find('li[aria-selected]').removeAttr('aria-selected');
|
||||
$(this).attr('aria-selected', 'true');
|
||||
var key = $(this).parents('form').attr('id'),
|
||||
value = $(this).find('label span').html().toLowerCase();
|
||||
window.settings[key] = value;
|
||||
|
||||
$('button[id="set' + key + '"] span').html(value[0].toUpperCase() + value.substr(1));
|
||||
$('#menu div.options > div').addClass('hidden');
|
||||
$('#menu div.options > .general, #menu div.options > .'+value).removeClass('hidden');
|
||||
|
||||
$(this).parents('form').addClass('hidden');
|
||||
})
|
||||
|
||||
$single.submit(function(e) {
|
||||
e.preventDefault();
|
||||
$(this).addClass('hidden');
|
||||
})
|
||||
|
||||
// Confirm
|
||||
|
||||
var $confirm = $('form[data-type="value-selector"].confirm');
|
||||
|
||||
$confirm.each(function() {
|
||||
|
||||
// Value Selector
|
||||
|
||||
var $single = $('form[data-type="value-selector"].single');
|
||||
|
||||
$single.find('li').tap(function(e) {
|
||||
e.preventDefault();
|
||||
$(this).parent().find('li[aria-selected]').removeAttr('aria-selected');
|
||||
$(this).attr('aria-selected', 'true');
|
||||
var key = $(this).parents('form').attr('id'),
|
||||
value = $(this).find('label span').html().toLowerCase();
|
||||
window.settings[key] = value;
|
||||
|
||||
$('button[id="set' + key + '"] span').html(value[0].toUpperCase() + value.substr(1));
|
||||
$('#menu div.options > div').addClass('hidden');
|
||||
$('#menu div.options > .general, #menu div.options > .'+value).removeClass('hidden');
|
||||
|
||||
$(this).parents('form').addClass('hidden');
|
||||
})
|
||||
|
||||
$single.submit(function(e) {
|
||||
e.preventDefault();
|
||||
$(this).addClass('hidden');
|
||||
})
|
||||
|
||||
// Confirm
|
||||
|
||||
var $confirm = $('form[data-type="value-selector"].confirm');
|
||||
|
||||
$confirm.find('li').tap(function(e) {
|
||||
$(this).find('li').click(function(e) {
|
||||
$(this).parent().find('li[aria-selected]').removeAttr('aria-selected');
|
||||
$(this).attr('aria-selected', 'true');
|
||||
})
|
||||
$confirm.find('button').last().tap(function(e) {
|
||||
$(this).find('button').last().click(function(e) {
|
||||
e.preventDefault();
|
||||
var v = $(this).parents('form').attr('id');
|
||||
$(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().toLowerCase();
|
||||
var value = $(this).parent().find('ol:nth-of-type('+i+') li[aria-selected] span').html();
|
||||
if( key !== 'file name' && key !== 'file' ) value = value.toLowerCase();
|
||||
window[v][key] = value;
|
||||
}
|
||||
})
|
||||
$(this).parents('form').addClass('hidden');
|
||||
window[v]();
|
||||
})
|
||||
$confirm.find('button').first().tap(function(e) {
|
||||
$(this).find('button').first().click(function(e) {
|
||||
e.preventDefault();
|
||||
$(this).parents('form').addClass('hidden');
|
||||
})
|
||||
|
||||
// Value Selector Callers
|
||||
|
||||
var $btn = $('button[id^="set"]');
|
||||
$btn.each(function() {
|
||||
var target = /set(.*)/.exec($(this).attr('id'))[1];
|
||||
if( target == 'color' ) {
|
||||
return $(this).tap(function() {
|
||||
$('.picker').removeClass('hidden');
|
||||
})
|
||||
}
|
||||
$(this).tap(function(e) {
|
||||
e.preventDefault();
|
||||
$('form[id="' + target + '"]').removeClass('hidden');
|
||||
})
|
||||
|
||||
// Value Selector Callers
|
||||
|
||||
var $btn = $('button[id^="set"]');
|
||||
$btn.each(function() {
|
||||
var target = /set(.*)/.exec($(this).attr('id'))[1];
|
||||
if( target == 'color' ) {
|
||||
return $(this).tap(function() {
|
||||
$('.picker').removeClass('hidden');
|
||||
})
|
||||
}
|
||||
$(this).tap(function(e) {
|
||||
e.preventDefault();
|
||||
$('form[id="' + target + '"]').removeClass('hidden');
|
||||
})
|
||||
})
|
||||
|
||||
// Seekbar
|
||||
// Seekbar
|
||||
|
||||
var sliderLeft;
|
||||
$('div[role="slider"] button').on('touchstart', function() {
|
||||
$(this).attr('data-moving','true');
|
||||
if( !sliderLeft ) sliderLeft = $('div[role="slider"] button').offset().left;
|
||||
}).on('touchmove', function(e) {
|
||||
if( $(this).attr('data-moving') ) {
|
||||
var x = parseInt(e.changedTouches[0].pageX - sliderLeft - 15);
|
||||
var $c = $('.'+$(this).parents('div[role="slider"]').attr('class'));
|
||||
var progress = $c.find('progress');
|
||||
var max = +progress.attr('max');
|
||||
var min = +progress.attr('min');
|
||||
if( x <= max && x >= min ) {
|
||||
$c.find('button').css('left', x+'%');
|
||||
progress.attr('value', x);
|
||||
var key = $c.attr('class');
|
||||
settings[key] = x;
|
||||
$('#'+ key +' span').html(x);
|
||||
}
|
||||
var sliderLeft;
|
||||
$('div[role="slider"] button').on('touchstart', function() {
|
||||
$(this).attr('data-moving','true');
|
||||
if( !sliderLeft ) sliderLeft = $('div[role="slider"] button').offset().left;
|
||||
}).on('touchmove', function(e) {
|
||||
if( $(this).attr('data-moving') ) {
|
||||
var x = parseInt(e.changedTouches[0].pageX - sliderLeft - 15);
|
||||
var $c = $('.'+$(this).parents('div[role="slider"]').attr('class'));
|
||||
var progress = $c.find('progress');
|
||||
var max = +progress.attr('max');
|
||||
var min = +progress.attr('min');
|
||||
if( x <= max && x >= min ) {
|
||||
$c.find('button').css('left', x+'%');
|
||||
progress.attr('value', x);
|
||||
var key = $c.attr('class');
|
||||
settings[key] = x;
|
||||
$('#'+ key +' span').html(x);
|
||||
}
|
||||
}).on('touchend', function() {
|
||||
$(this).removeAttr('data-moving');
|
||||
}
|
||||
}).on('touchend', function() {
|
||||
$(this).removeAttr('data-moving');
|
||||
})
|
||||
|
||||
// Color Picker
|
||||
|
||||
$('.close').tap(function() {
|
||||
$(this).parent().addClass('hidden');
|
||||
})
|
||||
|
||||
// Bottom
|
||||
|
||||
$('#clear').tap(function() {
|
||||
c.clearRect(0, 0, width(), height());
|
||||
var h = window.points.history;
|
||||
window.points = [];
|
||||
window.points.history = h;
|
||||
if(window.points.history.last < window.points.history.length-1) {
|
||||
window.points.history.splice(window.points.history.last+1);
|
||||
}
|
||||
|
||||
window.points.history.push({
|
||||
data: c.getImageData(0, 0, width(), height()),
|
||||
points: []
|
||||
})
|
||||
window.points.history.last = window.points.history.length-1;
|
||||
})
|
||||
|
||||
// Color Picker
|
||||
|
||||
$('.close').tap(function() {
|
||||
$(this).parent().addClass('hidden');
|
||||
})
|
||||
$('#undo').tap(undo);
|
||||
$('#redo').tap(redo);
|
||||
|
||||
// Bottom
|
||||
$('#about').tap(function() {
|
||||
$('.about').removeClass('hidden');
|
||||
})
|
||||
|
||||
$('#clear').tap(function() {
|
||||
c.clearRect(0, 0, width(), height());
|
||||
var h = window.points.history;
|
||||
window.points = [];
|
||||
window.points.history = h;
|
||||
if(window.points.history.last < window.points.history.length-1) {
|
||||
window.points.history.splice(window.points.history.last+1);
|
||||
}
|
||||
|
||||
window.points.history.push({
|
||||
data: c.getImageData(0, 0, width(), height()),
|
||||
points: []
|
||||
})
|
||||
window.points.history.last = window.points.history.length-1;
|
||||
})
|
||||
|
||||
$('#undo').tap(undo);
|
||||
$('#redo').tap(redo);
|
||||
|
||||
$('#about').tap(function() {
|
||||
$('.about').removeClass('hidden');
|
||||
})
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user