1 function handle_keyup(ev) {
2 if (ev.target.tagName != 'textbox') { return; }
3 //mw.sdump('D_CAT','keyCode:' + ev.keyCode + ' charCode:' + ev.charCode + ' shift:' + ev.shiftKey + ' ctrl:' + ev.ctrlKey + ' meta:' + ev.metaKey + '\n');
4 resizeWrapper(ev.target);
7 function handle_keypress(ev) {
8 mw.sdump('D_CAT','keyCode:' + ev.keyCode + ' charCode:' + ev.charCode + ' shift:' + ev.shiftKey + ' ctrl:' + ev.ctrlKey + ' meta:' + ev.metaKey + '\n');
9 if (ev.target.tagName != 'textbox') { return; }
14 if (ev.ctrlKey) { /* control+d */
15 rstatus = handle_key_c_d(ev);
19 } else if (ev.keyCode) {
22 case 77: /* mac enter */
23 rstatus = handle_key_enter(ev);
26 if (ev.ctrlKey) { /* control+del */
27 rstatus = handle_key_c_del(ev);
31 if (ev.shiftKey) { /* shift+tab */
32 rstatus = navigate_col_left(ev.target,true);
34 rstatus = navigate_col_right(ev.target,true);
39 resizeWrapper(ev.target);
46 function handle_key_c_d(ev) {
47 if (ev.target.tagName != 'textbox') { return; }
49 if ((ev.ctrlKey)&&(ev.charCode==100)&&(t.getAttribute('subfields')=='true')) {
50 var n_ev = document.createEvent("KeyEvents");
51 if (n_ev) { /* the best way... fake a keypress */
52 n_ev.initKeyEvent("keypress", 1, 1, null, 0, 0, 0, 0, 0, 8225);
53 t.inputField.dispatchEvent(n_ev);
54 } else { /* this destroys the widget's undo buffer */
55 var s_start = t.selectionStart; var s_end = t.selectionEnd;
56 var first_half = t.value.substr(0,s_start);
57 var second_half = t.value.substr(s_end);
58 t.value = first_half + String.fromCharCode(8225) + second_half;
59 t.setSelectionRange(s_start+1,s_start+1);
67 function handle_key_c_del(ev) {
68 // rows (rows) -> row (r) -> wrapper (w) -> textbox (t)
69 if (ev.target.tagName != 'textbox') { return; }
71 var r = t.parentNode.parentNode;
72 if ((ev.ctrlKey)&&(ev.keyCode==46)) {
73 r.setAttribute('hidden','true');
74 handle_tag_change(ev);
75 if (! navigate_row_down(t,which_col_am_i(t),false) ) {
76 navigate_row_up(t,which_col_am_i(t),false);
77 mw.sdump('D_CAT',"let's go up\n");
86 function handle_key_enter(ev) {
87 // rows (rows) -> row (r) -> wrapper (w) -> textbox (t)
88 if (ev.target.tagName != 'textbox') { return; }
90 if ((ev.keyCode == 13) || (ev.keyCode == 77)) {
91 if (ev.ctrlKey) { // add new row
92 var new_r = build_data_row('data_' + new_row_id--);
93 new_r.setAttribute('notempty','true');
94 new_r.setAttribute('newnode','true');
97 var rows = r.parentNode;
102 sibling_row = r.nextSibling;
105 rows.insertBefore(new_r,sibling_row);
107 rows.appendChild(new_r);
109 var c = new_r.childNodes;
110 apply_event_listeners(c,'data');
111 c[1].firstChild.value = ' '; // indicator 1
112 c[2].firstChild.value = ' '; // indicator 2
113 c[0].firstChild.focus();
115 } else { // move to next row
116 navigate_row_down(t,which_col_am_i(t),true);
124 function which_col_am_i(t) {
125 var r = t.parentNode.parentNode;
126 for (var i in r.childNodes) {
127 if (t == r.childNodes[i].firstChild) {
133 function nextSibling_not_hidden(e) {
134 var s = e.nextSibling;
135 while ((s)&&(s.getAttribute('hidden')=='true')) {
141 function previousSibling_not_hidden(e) {
142 var s = e.previousSibling;
143 while ((s)&&(s.getAttribute('hidden')=='true')) {
144 s = s.previousSibling;
149 function navigate_row_down(t,c,wrap) {
150 // rows -> row (r) -> wrapper -> textbox (t)
151 var r = t.parentNode.parentNode;
152 var sibling_row = nextSibling_not_hidden(r);
154 sibling_row.childNodes[c].firstChild.focus();
156 sibling_row.childNodes[c].firstChild.select();
160 r.parentNode.firstChild.childNodes[c].firstChild.focus();
168 function navigate_row_up(t,c,wrap) {
169 // rows -> row (r) -> wrapper -> textbox (t)
170 var r = t.parentNode.parentNode;
171 var sibling_row = previousSibling_not_hidden(r);
173 sibling_row.childNodes[c].firstChild.focus();
176 r.parentNode.lastChild.childNodes[c].firstChild.focus();
184 function navigate_col_left(t,wrap) {
185 // rows -> row -> wrapper (w) -> textbox (t)
186 var w = t.parentNode;
187 var sibling_wrapper = w.previousSibling;
188 if (sibling_wrapper) {
189 sibling_wrapper.firstChild.focus();
190 if (sibling_wrapper.parentNode.childNodes[3] != sibling_wrapper) {
191 sibling_wrapper.firstChild.select();
195 return navigate_row_up(t,3,false);
203 function navigate_col_right(t,wrap) {
204 // rows -> row -> wrapper (w) -> textbox (t)
205 var w = t.parentNode;
206 var sibling_wrapper = w.nextSibling;
207 if (sibling_wrapper) {
208 sibling_wrapper.firstChild.focus();
209 if (sibling_wrapper.parentNode.childNodes[3] != sibling_wrapper) {
210 sibling_wrapper.firstChild.select();
214 return navigate_row_down(t,0);