단축키를 지정하는 자바스크립트를 응용한
그누보드에 '쓰기' '수정' '목록' 기능에 단축키를 지정하는 소스입니다.
우선 아래의 코드로 shortcut.js 파일을 만들어 그누보드의 js 폴더에 집어넣습니다.
그리고 나서 수정에 단축키에 사용될 wr_id 값을 자바스크립트로 가져오기 위해 head.sub.php 중 스크립트를 지정하는 부분 ( // 자바스크립트에 사용하는 전역변수 선언 부분)에 아래의 코드를 집어넣습니다.
그리고 다시 head.sub.php 에 js 파일 임베드하는 부분에 아래의 코드를 넣어서 아까만든 shortcut.js 파일을 임베드 합니다.
그누보드에 '쓰기' '수정' '목록' 기능에 단축키를 지정하는 소스입니다.
우선 아래의 코드로 shortcut.js 파일을 만들어 그누보드의 js 폴더에 집어넣습니다.
var NS = (window.Event) ? 1 : 0
function checkKey(e) {
if (e == null) {
code = event.keyCode;
if(event.srcElement.tagName == "INPUT" || event.srcElement.tagName == "TEXTAREA") return true;
}
else {
if (e.altKey || e.ctrlKey) {
return true;
}
if(e.target.tagName == "INPUT" || e.target.tagName == "TEXTAREA") return;
code = e.which;
}
key = String.fromCharCode(code).toLowerCase();
if(code==13) key="enter";
var code = (NS) ? e.which : event.keyCode;
var key = String.fromCharCode(code);
for (var i = 0; i < ar.length; i++) {
if (key == ar[i].key) location.href = ar[i].url;
}
}
function hotKey(key, url) {
this.key = key;
this.url = url;
}
if (NS) document.captureEvents(Event.KEYPRESS)
document.onkeypress = checkKey;
var ar = new Array();
if (g4_bo_table) {
ar[ar.length] = new hotKey("w", g4_path + "/bbs/write.php?bo_table=" + g4_bo_table); // 쓰기 단축키 "w" 입니다.
ar[ar.length] = new hotKey("l", g4_path + "/bbs/board.php?bo_table=" + g4_bo_table); // 목록 단축키 "l" 입니다.
ar[ar.length] = new hotKey("m", g4_path + "/bbs/write.php?w=u&bo_table=" + g4_bo_table + "&wr_id=" +g4_wr_id);
} // 수정 단축키 "m" 입니다.
function checkKey(e) {
if (e == null) {
code = event.keyCode;
if(event.srcElement.tagName == "INPUT" || event.srcElement.tagName == "TEXTAREA") return true;
}
else {
if (e.altKey || e.ctrlKey) {
return true;
}
if(e.target.tagName == "INPUT" || e.target.tagName == "TEXTAREA") return;
code = e.which;
}
key = String.fromCharCode(code).toLowerCase();
if(code==13) key="enter";
var code = (NS) ? e.which : event.keyCode;
var key = String.fromCharCode(code);
for (var i = 0; i < ar.length; i++) {
if (key == ar[i].key) location.href = ar[i].url;
}
}
function hotKey(key, url) {
this.key = key;
this.url = url;
}
if (NS) document.captureEvents(Event.KEYPRESS)
document.onkeypress = checkKey;
var ar = new Array();
if (g4_bo_table) {
ar[ar.length] = new hotKey("w", g4_path + "/bbs/write.php?bo_table=" + g4_bo_table); // 쓰기 단축키 "w" 입니다.
ar[ar.length] = new hotKey("l", g4_path + "/bbs/board.php?bo_table=" + g4_bo_table); // 목록 단축키 "l" 입니다.
ar[ar.length] = new hotKey("m", g4_path + "/bbs/write.php?w=u&bo_table=" + g4_bo_table + "&wr_id=" +g4_wr_id);
} // 수정 단축키 "m" 입니다.
그리고 나서 수정에 단축키에 사용될 wr_id 값을 자바스크립트로 가져오기 위해 head.sub.php 중 스크립트를 지정하는 부분 ( // 자바스크립트에 사용하는 전역변수 선언 부분)에 아래의 코드를 집어넣습니다.
<? if ($wr_id) { ?>var g4_wr_id = "<?=$wr_id?>";<? } // wr_id 가 있다면 wr_id 값을 가져옴 ?>
그리고 다시 head.sub.php 에 js 파일 임베드하는 부분에 아래의 코드를 넣어서 아까만든 shortcut.js 파일을 임베드 합니다.
<script type="text/javascript" src="<?=$g4['path']?>/js/shortcut.js"></script>
첨부파일
|
댓글을 작성하시려면 로그인이 필요합니다.
댓글 5개
좋은 팁을 읽기 붚편하게 만들어 버리셨네요