* Collects active keys, sets active binds and fires on key down callbacks * @param event
(event)
| 168 | * @param event |
| 169 | */ |
| 170 | function executeActiveKeyBindings(event) { |
| 171 | |
| 172 | if(activeKeys < 1) { |
| 173 | return true; |
| 174 | } |
| 175 | |
| 176 | var bindingStack = queryActiveBindings(), |
| 177 | spentKeys = [], |
| 178 | output; |
| 179 | |
| 180 | //loop through each active binding |
| 181 | for (var bindingIndex = 0; bindingIndex < bindingStack.length; bindingIndex += 1) { |
| 182 | var binding = bindingStack[bindingIndex], |
| 183 | usesSpentKey = false; |
| 184 | |
| 185 | //check each of the required keys. Make sure they have not been used by another binding |
| 186 | for(var keyIndex = 0; keyIndex < binding.keys.length; keyIndex += 1) { |
| 187 | var key = binding.keys[keyIndex]; |
| 188 | if(spentKeys.indexOf(key) > -1) { |
| 189 | usesSpentKey = true; |
| 190 | break; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | //if the binding does not use a key that has been spent then execute it |
| 195 | if(!usesSpentKey) { |
| 196 | |
| 197 | //fire the callback |
| 198 | if(typeof binding.callback === "function") { |
| 199 | if(!binding.callback(event, binding.keys, binding.keyCombo)) { |
| 200 | output = false |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | //add the binding's combo to the active bindings array |
| 205 | if(!activeBindings[binding.keyCombo]) { |
| 206 | activeBindings[binding.keyCombo] = binding; |
| 207 | } |
| 208 | |
| 209 | //add the current key binding's keys to the spent keys array |
| 210 | for(var keyIndex = 0; keyIndex < binding.keys.length; keyIndex += 1) { |
| 211 | var key = binding.keys[keyIndex]; |
| 212 | if(spentKeys.indexOf(key) < 0) { |
| 213 | spentKeys.push(key); |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | //if there are spent keys then we know a binding was fired |
| 220 | // and that we need to tell jQuery to prevent event bubbling. |
| 221 | if(spentKeys.length) { |
| 222 | return false; |
| 223 | } |
| 224 | |
| 225 | return output; |
| 226 | } |
| 227 |
no test coverage detected