thedesk/app/js/common/keyshortcut.js

247 lines
5.9 KiB
JavaScript
Raw Normal View History

2019-07-12 01:53:55 +10:00
selectedColumn = 0
selectedToot = 0
2019-05-19 17:39:30 +10:00
$(function ($) {
2018-01-31 03:43:01 +11:00
//キーボードショートカット
2019-05-19 17:39:30 +10:00
$(window).keydown(function (e) {
2018-01-31 03:43:01 +11:00
var hasFocus = $('input').is(':focus');
var hasFocus2 = $('textarea').is(':focus');
2019-05-19 17:39:30 +10:00
if (document.getElementById("webview")) {
if ($("#webviewsel:checked").val()) {
var wv = false;
} else {
var wv = true;
}
} else {
var wv = true;
2018-09-10 03:06:00 +10:00
}
2018-09-17 21:55:00 +10:00
//Ctrl+Shift+Enter:Lgen
2018-09-11 04:59:44 +10:00
if (event.metaKey || event.ctrlKey && wv) {
2018-09-17 21:55:00 +10:00
if (event.shiftKey) {
if (e.keyCode === 13) {
post('local');
return false;
}
2018-01-31 03:43:01 +11:00
}
}
2018-09-17 21:55:00 +10:00
//Ctrl+Enter:投稿
if (event.metaKey || event.ctrlKey && wv) {
2018-02-05 01:56:31 +11:00
if (e.keyCode === 13) {
2018-09-17 21:55:00 +10:00
post();
2018-02-05 01:56:31 +11:00
return false;
}
}
2019-03-09 22:17:08 +11:00
//Alt+Enter:セカンダリー
if (event.metaKey || event.altKey && wv) {
if (e.keyCode === 13) {
sec();
return false;
}
}
2018-01-31 03:43:01 +11:00
//Esc:消す
2018-09-11 04:59:44 +10:00
if (e.keyCode === 27 && wv) {
2018-01-31 03:43:01 +11:00
hide();
return false;
}
2018-02-09 03:43:11 +11:00
//F5リロード
2018-09-11 04:59:44 +10:00
if (e.keyCode === 116 && wv) {
2018-01-31 03:43:01 +11:00
location.href = "index.html";
return false;
}
2018-03-21 16:36:02 +11:00
//Ctrl+Sift+C:全消し
2019-05-19 17:39:30 +10:00
if (((event.metaKey || event.ctrlKey) && event.shiftKey) && wv) {
2018-03-21 16:36:02 +11:00
if (e.keyCode === 67) {
clear();
return false;
}
}
//Ctrl+Sift+N:NowPlaying
2018-09-11 04:59:44 +10:00
if (((event.metaKey || event.ctrlKey) && event.shiftKey) && wv) {
2018-03-21 16:36:02 +11:00
if (e.keyCode === 78) {
2018-07-28 07:25:12 +10:00
show();
2018-03-21 16:36:02 +11:00
nowplaying()
return false;
}
}
2018-01-31 03:43:01 +11:00
//input/textareaにフォーカスなし時
2019-05-19 17:39:30 +10:00
if ((!hasFocus && !hasFocus2) && wv) {
if (!wv) {
2018-09-11 04:59:44 +10:00
return true;
}
2018-07-28 07:25:12 +10:00
//Ctrl+V:いつもの
2018-08-23 03:29:39 +10:00
if (event.metaKey || event.ctrlKey) {
2018-07-28 07:25:12 +10:00
if (e.keyCode === 86) {
show();
}
}
2018-01-31 03:43:01 +11:00
//X:開閉
if (e.keyCode === 88) {
2018-07-28 07:25:12 +10:00
if (!$("#post-box").hasClass("appear")) {
2018-01-31 03:43:01 +11:00
show();
2019-03-22 01:38:15 +11:00
$('textarea').focus();
2018-01-31 03:43:01 +11:00
} else {
hide();
}
return false;
}
//N:新トゥート
if (e.keyCode === 78) {
2018-07-28 07:25:12 +10:00
if (!$("#post-box").hasClass("appear")) {
2018-01-31 03:43:01 +11:00
show();
}
$('textarea').focus();
return false;
}
2018-07-28 07:25:12 +10:00
//Ctrl+E:全ての通知未読を既読にする
2018-08-23 03:29:39 +10:00
if (event.metaKey || event.ctrlKey) {
2018-07-28 07:25:12 +10:00
if (e.keyCode === 69) {
allNotfRead();
return false;
}
2018-01-31 03:43:01 +11:00
}
//Ctrl+Space:読み込み
2018-08-23 03:29:39 +10:00
if (event.metaKey || event.ctrlKey) {
2018-01-31 03:43:01 +11:00
if (e.keyCode === 32) {
parseColumn();
return false;
}
}
2018-03-21 16:36:02 +11:00
//Ctrl+Sift+S:設定
2018-08-23 03:29:39 +10:00
if ((event.metaKey || event.ctrlKey) && event.shiftKey) {
2018-03-21 16:36:02 +11:00
if (e.keyCode === 83) {
location.href = "setting.html";
return false;
}
}
//Ctrl+Sift+M:アカマネ
2018-08-23 03:29:39 +10:00
if ((event.metaKey || event.ctrlKey) && event.shiftKey) {
2018-03-21 16:36:02 +11:00
if (e.keyCode === 77) {
location.href = "acct.html";
return false;
}
}
//Ctrl+Sift+P:プロフ
2019-07-13 01:00:26 +10:00
if ((event.metaKey || event.ctrlKey) && event.shiftKey) {
2018-03-21 16:36:02 +11:00
if (e.keyCode === 80) {
profShow()
2018-01-31 03:43:01 +11:00
return false;
}
}
2018-03-27 13:39:35 +11:00
//数字:TL
2018-08-23 03:29:39 +10:00
if (event.metaKey || event.ctrlKey) {
2019-05-19 17:39:30 +10:00
if (e.keyCode >= 49 && e.keyCode <= 57) {
var kz = e.keyCode - 49;
goColumn(kz);
return false;
}
2018-03-27 13:39:35 +11:00
}
2019-07-12 01:53:55 +10:00
//矢印:選択
if (e.code == "ArrowLeft") {
//left
if ($("#imagemodal").hasClass("open")) {
imgCont('next');
return false;
}
2019-07-12 01:53:55 +10:00
if (selectedColumn > 0) {
selectedColumn--
}
tootSelector(selectedColumn, selectedToot)
return false;
} else if (e.code == "ArrowUp") {
//up
if ($("#imagemodal").hasClass("open")) {
return false;
}
2019-07-12 01:53:55 +10:00
if (selectedToot > 0) {
selectedToot--
}
tootSelector(selectedColumn, selectedToot)
return false;
} else if (e.code == "ArrowRight") {
//right
if ($("#imagemodal").hasClass("open")) {
imgCont('prev');
return false;
}
2019-07-12 01:53:55 +10:00
if (selectedColumn < $(".tl-box").length - 1) {
selectedColumn++
}
tootSelector(selectedColumn, selectedToot)
return false;
} else if (e.code == "ArrowDown") {
//down
if ($("#imagemodal").hasClass("open")) {
return false;
}
2019-07-12 01:53:55 +10:00
selectedToot++
tootSelector(selectedColumn, selectedToot)
return false;
}
2019-07-13 01:00:26 +10:00
//Ctrl+U:0,0選択
if (event.ctrlKey || event.metaKey) {
if (e.keyCode === 85) {
selectedToot = 0
selectedColumn = 0
tootSelector(0, 0)
return false;
}
}
2019-07-12 01:53:55 +10:00
//選択時
if (e.keyCode == 70) {
var id = $(".selectedToot").attr('unique-id')
var acct_id = $('#timeline_' + selectedColumn).attr("data-acct")
fav(id, acct_id, false)
return false;
}
if (e.keyCode == 66) {
var id = $(".selectedToot").attr('unique-id')
var acct_id = $('#timeline_' + selectedColumn).attr("data-acct")
rt(id, acct_id, false)
return false;
}
if (e.keyCode == 82) {
var id = $(".selectedToot").attr('unique-id')
var acct_id = $('#timeline_' + selectedColumn).attr("data-acct")
var ats_cm = $('.selectedToot .rep-btn').attr("data-men")
var mode = $('.selectedToot .rep-btn').attr("data-visen")
re(id, ats_cm, acct_id, mode)
return false;
}
2018-01-31 03:43:01 +11:00
}
//textareaフォーカス時
2018-09-11 04:59:44 +10:00
if (hasFocus2 && wv) {
2018-08-23 03:29:39 +10:00
if (event.metaKey || event.ctrlKey) {
2018-06-12 01:44:28 +10:00
//C+S+(No):ワンクリ
2018-08-23 03:29:39 +10:00
if ((event.metaKey || event.ctrlKey) && event.shiftKey) {
2018-06-12 01:44:28 +10:00
if (e.keyCode >= 49 && e.keyCode <= 51) {
2019-05-19 17:39:30 +10:00
var no = e.keyCode - 48;
if (localStorage.getItem("oks-" + no)) { $("#textarea").val($("#textarea").val() + localStorage.getItem("oks-" + no)) }
2018-06-12 01:44:28 +10:00
return false;
}
}
2018-01-31 03:43:01 +11:00
}
}
});
//クリアボタン
2019-05-19 17:39:30 +10:00
$("#clear").click(function () {
2018-01-31 03:43:01 +11:00
clear();
});
2019-07-12 01:53:55 +10:00
});
//選択する
function tootSelector(column, toot) {
$('.cvo').removeClass("selectedToot")
$('#timeline_' + column + ' .cvo').eq(toot).addClass("selectedToot")
var scr = $('.tl-box[tlid=' + column + ']').scrollTop()
var elem = $('.selectedToot').offset().top
var top = elem - $('.tl-box').height() + scr
if (top > 0) {
top = top + $('.selectedToot').height()
2019-07-13 01:00:26 +10:00
if (top > scr) {
$('.tl-box[tlid=' + column + ']').animate({ scrollTop: top })
2019-07-12 01:53:55 +10:00
}
} else if (elem < 0) {
var to = scr + elem - $('.selectedToot').height()
if (to < scr) {
$('.tl-box[tlid=' + column + ']').animate({ scrollTop: to })
}
}
}