Revision 72d64df1
Von Sven Schöling vor fast 8 Jahren hinzugefügt
js/kivi.ActionBar.js | ||
---|---|---|
26 | 26 |
event.stopPropagation(); |
27 | 27 |
}); |
28 | 28 |
} |
29 |
} |
|
29 |
}; |
|
30 |
|
|
31 |
k.ActionBarAccesskeys = { |
|
32 |
known_keys: { |
|
33 |
'enter': 13, |
|
34 |
'esc': 27, |
|
35 |
}, |
|
36 |
actions: {}, |
|
37 |
bound_targets: {}, |
|
38 |
|
|
39 |
add_accesskey: function (target, keystring, action) { |
|
40 |
if (target === undefined) { |
|
41 |
target = 'document'; |
|
42 |
} |
|
43 |
if (!(target in this.actions)) |
|
44 |
this.actions[target] = {}; |
|
45 |
this.actions[target][keystring] = action; |
|
46 |
}, |
|
47 |
|
|
48 |
bind_targets: function(){ |
|
49 |
for (var target in this.actions) { |
|
50 |
if (target in this.bound_targets) continue; |
|
51 |
$(target).on('keypress', null, { 'target': target }, this.handle_accesskey); |
|
52 |
this.bound_targets[target] = 1; |
|
53 |
} |
|
54 |
}, |
|
55 |
|
|
56 |
handle_accesskey: function(e,t) { |
|
57 |
var target = e.data.target; |
|
58 |
var key = e.which; |
|
59 |
var accesskey = ''; |
|
60 |
if (e.ctrlKey) accesskey += 'crtl+' |
|
61 |
if (e.altKey) accesskey += 'alt+' |
|
62 |
accesskey += e.which; |
|
63 |
|
|
64 |
// special case. HTML elements that make legitimate use of enter will also trigger the enter accesskey. |
|
65 |
// so. if accesskey is '13' and the event source is one of these (currently only textarea) ignore it. |
|
66 |
// higher level widgets will usually prevent their key events from bubbling if used. |
|
67 |
if (accesskey == 13 && e.target.tagName == 'TEXTAREA') return true; |
|
68 |
|
|
69 |
if ((target in k.ActionBarAccesskeys.actions) && (accesskey in k.ActionBarAccesskeys.actions[target])) { |
|
70 |
e.stopPropagation(); |
|
71 |
k.ActionBarAccesskeys.actions[target][accesskey].click(); |
|
72 |
|
|
73 |
// and another special case. |
|
74 |
// if the form contains submit buttons the default action will click them instead. |
|
75 |
// prevent that |
|
76 |
if (accesskey == 13) return false; |
|
77 |
} |
|
78 |
return true; |
|
79 |
} |
|
80 |
}; |
|
30 | 81 |
|
31 | 82 |
k.ActionBarAction = function(e) { |
32 | 83 |
var data = $(e).data('action'); |
... | ... | |
36 | 87 |
$(e).addClass(CLASSES.disabled); |
37 | 88 |
} |
38 | 89 |
|
90 |
if (data.accesskey) { |
|
91 |
if (data.submit) { |
|
92 |
k.ActionBarAccesskeys.add_accesskey(data.submit[0], data.accesskey, $(e)); |
|
93 |
} |
|
94 |
if (data.call) { |
|
95 |
k.ActionBarAccesskeys.add_accesskey(undefined, data.accesskey, $(e)); |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
39 | 99 |
if (data.call || data.submit) { |
40 | 100 |
$(e).click(function(event) { |
41 | 101 |
var $hidden, key, func, check; |
... | ... | |
79 | 139 |
$('div.layout-actionbar-combobox').each(function(_, e) { |
80 | 140 |
$(e).data('combobox', new kivi.ActionBarCombobox(e)); |
81 | 141 |
}); |
82 |
$(document).click(function() {
|
|
142 |
$(document).click(function() { |
|
83 | 143 |
$('div.layout-actionbar-combobox').removeClass('active'); |
84 | 144 |
}); |
145 |
kivi.ActionBarAccesskeys.bind_targets(); |
|
85 | 146 |
}); |
Auch abrufbar als: Unified diff
ActionBar: accesskeys