Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

キーボードショートカットを追加 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions static/js/mine.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var always_only_one_sample = false; // 一つの画像に高々一つしか正解データがないときtrueにする
var coords = new Array();
var curcrd;
var canvas;
Expand All @@ -17,7 +18,23 @@ onload = function(){
$('.bar').css({'width': count*100/imgnum + '%'});
};

function keypressed(e) {
if (e.keyCode == 32) { // space
if (!released_flag) {
released();
}
nextajax(skip=0);
}
else if (e.keyCode == 83) { // s
nextajax(skip=1);
}
else if (e.keyCode == 82) { // r
resetstatus();
}
}

function draw(){
released_flag = false;
var image = new Image();
image.src = imgsrc;
image.onload = function(){
Expand All @@ -34,10 +51,13 @@ function draw(){
context.drawImage(image, 0, 0);
$(function(){
$('#cnvs').Jcrop({
onSelect: selected,
onRelease: released,
onSelect: selected,
onRelease: released,
keySupport: true
});
$('.jcrop-keymgr').keydown(keypressed);
});
document.onkeydown = keypressed;
}
}

Expand All @@ -51,6 +71,7 @@ function released(c){
context.lineWidth = 3;
context.strokeStyle = 'rgba(238, 26, 26, 1)';
context.strokeRect(curcrd[0], curcrd[1], curcrd[2], curcrd[3]);
released_flag = true;
}

function resetstatus(){
Expand All @@ -62,17 +83,17 @@ function nextajax(skip){
console.log('座標:'+coords);
coords = JSON.stringify(coords);
$.ajax({
type: 'GET',
type: 'GET',
dataType: "json",
data: {'coords': coords, 'skip': skip},
data: {'coords': coords, 'skip': skip},
url: "/_next",
success: function (data) {
imgsrc = data.imgsrc;
var count = data.count;
var finished = data.finished;
$('.bar').css({'width': count*100/imgnum + '%'});
console.log(count + '/' + imgnum);

if (finished){
w = $('.head-wrapper').width()
$('.main-wrapper').css({'width': w, 'minWidth': w});
Expand Down