2018-10-24 15:14:46 +00:00
|
|
|
|
|
|
|
var dragging = false
|
|
|
|
var drawing = false
|
|
|
|
var erasing = false
|
|
|
|
var selecting = false
|
|
|
|
var filling = false
|
|
|
|
var changed = false
|
|
|
|
var transforming = false
|
|
|
|
var focused
|
|
|
|
|
2018-11-24 07:49:02 +00:00
|
|
|
var canvas, tools, palette, controls, brush, mode
|
2018-10-24 15:14:46 +00:00
|
|
|
var current_tool, current_filetool, current_canvas
|
|
|
|
var mouse = { x: 0, y: 0 }
|
|
|
|
|
|
|
|
function init () {
|
|
|
|
build()
|
|
|
|
bind()
|
|
|
|
}
|
|
|
|
function build () {
|
2018-11-25 10:57:06 +00:00
|
|
|
canvas.append(canvas_wrapper)
|
|
|
|
brush.append(brush_wrapper)
|
|
|
|
palette.append(palette_wrapper)
|
|
|
|
letters.append(letters_wrapper)
|
2018-10-24 15:14:46 +00:00
|
|
|
letters.repaint("Basic Latin")
|
2018-11-24 07:49:02 +00:00
|
|
|
|
2018-10-24 15:14:46 +00:00
|
|
|
controls.circle.focus()
|
|
|
|
|
|
|
|
brush.bg = colors.red
|
|
|
|
brush.generate()
|
|
|
|
brush.build()
|
|
|
|
|
|
|
|
// controls.grid.use()
|
2018-11-25 10:57:06 +00:00
|
|
|
canvas.resize_wrapper()
|
2018-10-24 15:14:46 +00:00
|
|
|
}
|
|
|
|
function bind () {
|
|
|
|
canvas.bind()
|
|
|
|
palette.bind()
|
|
|
|
letters.bind()
|
|
|
|
brush.bind()
|
|
|
|
controls.bind()
|
|
|
|
keys.bind()
|
|
|
|
clipboard.bind()
|
2018-11-24 07:49:02 +00:00
|
|
|
|
2018-10-24 15:14:46 +00:00
|
|
|
window.addEventListener('mouseup', function(e){
|
|
|
|
dragging = erasing = false
|
2018-11-24 07:49:02 +00:00
|
|
|
|
2018-10-24 15:14:46 +00:00
|
|
|
var ae = document.activeElement
|
|
|
|
|
2018-11-23 18:32:02 +00:00
|
|
|
if (ae !== import_textarea) {
|
2018-11-24 07:14:29 +00:00
|
|
|
cursor_input.focus()
|
2018-10-24 15:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (selecting) {
|
|
|
|
selection.up(e)
|
|
|
|
}
|
|
|
|
else if (transforming) {
|
|
|
|
transform.up(e)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
window.addEventListener("touchend", function(){
|
|
|
|
if (current_tool.name === "text") {
|
2018-11-24 07:14:29 +00:00
|
|
|
cursor_input.focus()
|
2018-10-24 15:14:46 +00:00
|
|
|
}
|
|
|
|
dragging = false
|
|
|
|
})
|
2018-11-24 07:49:02 +00:00
|
|
|
|
2018-10-24 15:14:46 +00:00
|
|
|
window.addEventListener('mousedown', function(e){
|
2018-11-24 07:14:29 +00:00
|
|
|
// cursor_input.focus()
|
2018-10-24 15:14:46 +00:00
|
|
|
})
|
2018-11-24 07:49:02 +00:00
|
|
|
|
2018-10-24 15:14:46 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', function(){
|
2018-11-24 07:14:29 +00:00
|
|
|
cursor_input.focus()
|
2018-10-24 15:14:46 +00:00
|
|
|
document.body.classList.remove('loading')
|
|
|
|
})
|
2018-11-24 07:49:02 +00:00
|
|
|
|
2018-10-24 15:14:46 +00:00
|
|
|
window.onbeforeunload = function() {
|
|
|
|
// if (changed && !in_iframe()) return "You have edited this drawing."
|
|
|
|
}
|
|
|
|
|
|
|
|
function in_iframe () {
|
|
|
|
try {
|
|
|
|
return window.self !== window.top;
|
|
|
|
} catch (e) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
init()
|