Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1e1b6313

Von Sven Schöling vor mehr als 11 Jahren hinzugefügt

  • ID 1e1b63133d807a460f2714981da2b91ef6cec582
  • Vorgänger 686cf1ec
  • Nachfolger 6912c2df

Partpicker: key-events auch in chrome getestet

Unterschiede anzeigen:

js/autocomplete_part.js
4 4
    if ($real.data("part_picker"))
5 5
      return $real.data("part_picker");
6 6

  
7
    var KEY = {
8
      ESCAPE: 27,
9
      ENTER:  13,
10
      TAB:    9,
11
    };
7 12
    var o = $.extend({
8 13
      limit: 20,
9 14
      delay: 50,
......
109 114
     *  to fire a tab event later on, so we'd have to reimplement the "find
110 115
     *  next active element in tabindex order and focus it".
111 116
     */
112
    $dummy.keypress(function(event){
113
      if (event.keyCode == 13 || event.keyCode == 9) { // enter or tab or tab
117
    /* note:
118
     *  event.which does not contain tab events in keypressed in firefox but will report 0
119
     *  chrome does not fire keypressed at all on tab or escape
120
     *  TODO: users expect tab to work on keydown but enter to trigger on keyup,
121
     *        should be handled seperately
122
     */
123
    $dummy.keydown(function(event){
124
      if (event.which == KEY.ENTER || event.which == KEY.TAB) { // enter or tab or tab
114 125
        // if string is empty assume they want to delete
115 126
        if ($dummy.val() == '') {
116 127
          set_item({});
......
125 136
          success: function (data){
126 137
            if (data.length == 1) {
127 138
              set_item(data[0]);
128
              if (event.keyCode == 13)
139
              if (event.which == KEY.ENTER)
129 140
                $('#update_button').click();
130 141
            } else if (data.length > 1) {
131
             if (event.keyCode == 13)
142
             if (event.which == KEY.ENTER)
132 143
                open_dialog();
133 144
              else
134 145
                make_defined_state();
135 146
            } else {
136
              if (event.keyCode == 9)
147
              if (event.which == KEY.TAB)
137 148
                make_defined_state();
138 149
            }
139 150
          }
140 151
        });
141
        if (event.keyCode == 13)
152
        if (event.which == KEY.ENTER)
142 153
          return false;
143 154
      } else {
144 155
        state = STATES.UNDEFINED;
......
175 186
            return true;
176 187
          });
177 188
        });
178
        $('#part_selection').keypress(function(e){
179
           if (e.keyCode == 27) { // escape
189
        $('#part_selection').keydown(function(e){
190
           if (e.which == KEY.ESCAPE) {
180 191
             close_popup();
181 192
             $dummy.focus();
182 193
           }

Auch abrufbar als: Unified diff