diff options
author | 藍挺瑋 <lantw44@gmail.com> | 2012-12-12 02:38:50 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2012-12-12 02:41:02 +0800 |
commit | 2f86edbe47a3a521d5d5a225448c67c5727e2fae (patch) | |
tree | b7b23fd7ef63aa817d275cb943ba6db40054f1ec | |
parent | 1b6d29d927549568423ccef80de7d9ff089c0dbb (diff) | |
download | inccalendar-2f86edbe47a3a521d5d5a225448c67c5727e2fae.tar.gz inccalendar-2f86edbe47a3a521d5d5a225448c67c5727e2fae.tar.zst inccalendar-2f86edbe47a3a521d5d5a225448c67c5727e2fae.zip |
月曆版的年月份選擇器,已改用狀態列來顯示訊息,並且可用鍵盤操作。
-rw-r--r-- | jinhtml/month.html | 7 | ||||
-rw-r--r-- | js/month.js | 77 |
2 files changed, 75 insertions, 9 deletions
diff --git a/jinhtml/month.html b/jinhtml/month.html index 1e919f4..7d5c01a 100644 --- a/jinhtml/month.html +++ b/jinhtml/month.html @@ -39,10 +39,15 @@ var switchmonthobj = document.getElementById("switchmonth"); switchmonthobj.className += "selected"; switchmonthobj.onclick = ""; + status_bar_append("(y)修改年份 (m)修改月份"); {% endblock %} {% block headjs %} <script src="js/month.js" type="text/javascript"></script> + <script type="text/javascript"> + $(document).bind("keydown", "m", timeedit_month_kbd); + $(document).bind("keydown", "y", timeedit_year_kbd); + </script> {% endblock %} {% block body %} @@ -52,7 +57,7 @@ <input type="text" maxlength="4" id="timeedit_year"> 年 <span id="timeselect_month" onclick="timeselect_direct()">XX</span> - <input type="text" maxlength="4" id="timeedit_month"> + <input type="text" maxlength="2" id="timeedit_month"> 月 <input type="button" value=">" id="timeselect_fwd" onclick="timeselect_fwd()"> <input type="button" value="改" id="timeedit_button" onclick="timeselect_direct()"> diff --git a/js/month.js b/js/month.js index 34adb76..b7501b3 100644 --- a/js/month.js +++ b/js/month.js @@ -9,6 +9,9 @@ var objyear; /* 顯示年份的物件 */ var objmonth; /* 顯示月份的物件 */ var row_count = 0; /* 月曆列數 */ +var timeedit_year_backgroundcolor; +var timeedit_month_backgroundcolor; + function setyearmonth(){ var useryear = parseInt(getcookievalue(cookie_year)); var usermonth = parseInt(getcookievalue(cookie_month)); @@ -47,6 +50,18 @@ function timeselect_fwd(){ setmonthcal(); } +function timeedit_year_kbd(){ + timeselect_direct(); + $("#timeedit_year").focus(); + return false; +} + +function timeedit_month_kbd(){ + timeselect_direct(); + $("#timeedit_month").focus(); + return false; +} + function timeselect_direct(){ document.getElementById("timeedit_year").style.display = "inline"; document.getElementById("timeedit_month").style.display = "inline"; @@ -60,22 +75,46 @@ function timeselect_direct(){ document.getElementById("timeedit_year").value = value_year; document.getElementById("timeedit_month").value = value_month; + + $(document).bind("keydown", "esc", timeedit_cancel_kbd); + $(document).bind("keydown", "return", timeedit_apply_kbd); + $(document).unbind("keydown", "m", timeedit_month_kbd); + $(document).unbind("keydown", "y", timeedit_year_kbd); + + timeedit_year_backgroundcolor = + document.getElementById("timeedit_year").style.backgroundColor; + timeedit_month_backgroundcolor = + document.getElementById("timeedit_month").style.backgroundColor; + + status_bar_save(); + status_bar_set("(Esc)取消 (Enter)確定"); } function timeedit_apply(){ - var newyear = parseInt(document.getElementById("timeedit_year").value); - var newmonth = parseInt(document.getElementById("timeedit_month").value); + var edityearobj = document.getElementById("timeedit_year"); + var editmonthobj = document.getElementById("timeedit_month"); + var newyear = parseInt(edityearobj.value); + var newmonth = parseInt(editmonthobj.value); try{ - if(!isFinite(newyear) || !isFinite(newmonth)){ - throw "請輸入正確的數字!"; + if(!isFinite(newyear)){ + status_bar_warning("請輸入正確的年份!"); + edityearobj.style.backgroundColor = "red"; + throw false; + }else if(!isFinite(newmonth)){ + status_bar_warning("請輸入正確的月份!"); + editmonthobj.style.backgroundColor = "red"; + throw false; }else if(newyear < 1970){ - throw "請輸入 1970 年以後的年份!"; + status_bar_warning("請輸入 1970 年以後的年份!"); + edityearobj.style.backgroundColor = "red"; + throw false; }else if(newmonth < 1 || newmonth > 12){ - throw "請輸入正確的月份!"; + status_bar_warning("請輸入正確的月份!"); + editmonthobj.style.backgroundColor = "red"; + throw false; } }catch(err){ - alert(err); - return; + return err; } value_year = newyear; value_month = newmonth; @@ -83,6 +122,11 @@ function timeedit_apply(){ timeedit_cancel(); } +function timeedit_apply_kbd(){ + timeedit_apply(); + return false; +} + function timeedit_cancel(){ document.getElementById("timeedit_year").style.display = "none"; document.getElementById("timeedit_month").style.display = "none"; @@ -93,6 +137,23 @@ function timeedit_cancel(){ document.getElementById("timeselect_month").style.display = "inline"; document.getElementById("timeselect_prev").style.display = "inline"; document.getElementById("timeselect_fwd").style.display = "inline"; + + $(document).unbind("keydown", "esc", timeedit_cancel_kbd); + $(document).unbind("keydown", "return", timeedit_apply_kbd); + $(document).bind("keydown", "m", timeedit_month_kbd); + $(document).bind("keydown", "y", timeedit_year_kbd); + + document.getElementById("timeedit_year").style.backgroundColor = + timeedit_year_backgroundcolor; + document.getElementById("timeedit_month").style.backgroundColor = + timeedit_month_backgroundcolor; + + status_bar_restore(); +} + +function timeedit_cancel_kbd(){ + timeedit_cancel(); + return false; } function get_month_max_day(year, month){ |