Revision a45a5332
Von Sven Schöling vor fast 8 Jahren hinzugefügt
js/kivi.Part.js | ||
---|---|---|
400 | 400 |
} |
401 | 401 |
}); |
402 | 402 |
}, |
403 |
/* In case users are impatient and want to skip ahead: |
|
404 |
* Capture <enter> key events and check if it's a unique hit. |
|
405 |
* If it is, go ahead and assume it was selected. If it wasn't don't do |
|
406 |
* anything so that autocompletion kicks in. For <tab> don't prevent |
|
407 |
* propagation. It would be nice to catch it, but javascript is too stupid |
|
408 |
* to fire a tab event later on, so we'd have to reimplement the "find |
|
409 |
* next active element in tabindex order and focus it". |
|
410 |
*/ |
|
411 |
/* note: |
|
412 |
* event.which does not contain tab events in keypressed in firefox but will report 0 |
|
413 |
* chrome does not fire keypressed at all on tab or escape |
|
414 |
*/ |
|
415 |
handle_keydown: function(event) { |
|
416 |
var self = this; |
|
417 |
if (event.which == KEY.ENTER || event.which == KEY.TAB) { |
|
418 |
// if string is empty assume they want to delete |
|
419 |
if (self.$dummy.val() === '') { |
|
420 |
self.set_item({}); |
|
421 |
return true; |
|
422 |
} else if (self.state == self.STATES.PICKED) { |
|
423 |
return true; |
|
424 |
} |
|
425 |
if (event.which == KEY.TAB) { |
|
426 |
event.preventDefault(); |
|
427 |
self.handle_changed_text(); |
|
428 |
} |
|
429 |
if (event.which == KEY.ENTER) { |
|
430 |
self.handle_changed_text({ |
|
431 |
match_one: self.o.action.on_enter_match_one, |
|
432 |
match_many: self.o.action.on_enter_match_many |
|
433 |
}); |
|
434 |
return false; |
|
435 |
} |
|
436 |
} else if (event.which == KEY.DOWN && !self.autocomplete_open) { |
|
437 |
var old_options = self.$dummy.autocomplete('option'); |
|
438 |
self.$dummy.autocomplete('option', 'minLength', 0); |
|
439 |
self.$dummy.autocomplete('search', self.$dummy.val()); |
|
440 |
self.$dummy.autocomplete('option', 'minLength', old_options.minLength); |
|
441 |
} else if ((event.which != KEY.SHIFT) && (event.which != KEY.CTRL) && (event.which != KEY.ALT)) { |
|
442 |
self.state = self.STATES.UNDEFINED; |
|
443 |
} |
|
444 |
}, |
|
403 | 445 |
open_dialog: function() { |
404 |
// TODO: take the actual object here |
|
405 |
var dialog = new ns.PickerPopup(this); |
|
446 |
new ns.PickerPopup(this); |
|
406 | 447 |
}, |
407 | 448 |
init: function() { |
408 | 449 |
var self = this; |
... | ... | |
429 | 470 |
self.autocomplete_open = false; |
430 | 471 |
} |
431 | 472 |
}); |
432 |
/* In case users are impatient and want to skip ahead: |
|
433 |
* Capture <enter> key events and check if it's a unique hit. |
|
434 |
* If it is, go ahead and assume it was selected. If it wasn't don't do |
|
435 |
* anything so that autocompletion kicks in. For <tab> don't prevent |
|
436 |
* propagation. It would be nice to catch it, but javascript is too stupid |
|
437 |
* to fire a tab event later on, so we'd have to reimplement the "find |
|
438 |
* next active element in tabindex order and focus it". |
|
439 |
*/ |
|
440 |
/* note: |
|
441 |
* event.which does not contain tab events in keypressed in firefox but will report 0 |
|
442 |
* chrome does not fire keypressed at all on tab or escape |
|
443 |
*/ |
|
444 |
this.$dummy.keydown(function(event){ |
|
445 |
if (event.which == KEY.ENTER || event.which == KEY.TAB) { |
|
446 |
// if string is empty assume they want to delete |
|
447 |
if (self.$dummy.val() === '') { |
|
448 |
self.set_item({}); |
|
449 |
return true; |
|
450 |
} else if (self.state == self.STATES.PICKED) { |
|
451 |
return true; |
|
452 |
} |
|
453 |
if (event.which == KEY.TAB) { |
|
454 |
event.preventDefault(); |
|
455 |
self.handle_changed_text(); |
|
456 |
} |
|
457 |
if (event.which == KEY.ENTER) { |
|
458 |
self.handle_changed_text({ |
|
459 |
match_one: self.o.action.on_enter_match_one, |
|
460 |
match_many: self.o.action.on_enter_match_many |
|
461 |
}); |
|
462 |
return false; |
|
463 |
} |
|
464 |
} else if (event.which == KEY.DOWN && !self.autocomplete_open) { |
|
465 |
var old_options = self.$dummy.autocomplete('option'); |
|
466 |
self.$dummy.autocomplete('option', 'minLength', 0); |
|
467 |
self.$dummy.autocomplete('search', self.$dummy.val()); |
|
468 |
self.$dummy.autocomplete('option', 'minLength', old_options.minLength); |
|
469 |
} else if ((event.which != KEY.SHIFT) && (event.which != KEY.CTRL) && (event.which != KEY.ALT)) { |
|
470 |
self.state = self.STATES.UNDEFINED; |
|
471 |
} |
|
472 |
}); |
|
473 |
|
|
473 |
this.$dummy.keydown(function(event){ self.handle_keydown(event) }); |
|
474 | 474 |
this.$dummy.on('paste', function(){ |
475 | 475 |
setTimeout(function() { |
476 | 476 |
self.handle_changed_text(); |
477 | 477 |
}, 1); |
478 | 478 |
}); |
479 |
|
|
480 | 479 |
this.$dummy.blur(function(){ |
481 | 480 |
window.clearTimeout(self.timer); |
482 | 481 |
self.timer = window.setTimeout(function() { self.annotate_state() }, 100); |
Auch abrufbar als: Unified diff
kivi.Part.js: keydown ausgelagert in eigenen handler