Skip to content

Commit

Permalink
Merge branch 'master' into firefox-alt-key
Browse files Browse the repository at this point in the history
  • Loading branch information
pmusaraj committed Mar 25, 2019
2 parents 9d60d81 + 6833a23 commit 0d41aa7
Show file tree
Hide file tree
Showing 15 changed files with 2,717 additions and 9,382 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
*.sublime-workspace
15 changes: 1 addition & 14 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@ module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

mocha: {
options: {
reporter: 'Nyan',
run: true,
growlOnSuccess: false
},
mousetrap: {
src: ['tests/mousetrap.html']
}
},

complexity: {
options: {
errorsOnly: false,
Expand All @@ -39,10 +28,8 @@ module.exports = function(grunt) {
});

grunt.loadNpmTasks('grunt-complexity');
grunt.loadNpmTasks('grunt-mocha');

grunt.registerTask('default', [
'complexity',
'mocha'
'complexity'
]);
};
30 changes: 12 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ It is around **2kb** minified and gzipped and **4.5kb** minified, has no externa
- Firefox
- Chrome

It has support for ``keypress``, ``keydown``, and ``keyup`` events on specific keys, keyboard combinations, or key sequences.
It has support for `keypress`, `keydown`, and `keyup` events on specific keys, keyboard combinations, or key sequences.

## Getting started

1. Include mousetrap on your page before the closing ``</body>`` tag
1. Include mousetrap on your page before the closing `</body>` tag

```html
<script src="/path/to/mousetrap.min.js"></script>
Expand All @@ -28,7 +28,7 @@ It has support for ``keypress``, ``keydown``, and ``keyup`` events on specific k
var Mousetrap = require('mousetrap');
```

2. Add some keyboard events to listen for
2. Add some keyboard events to listen for

```html
<script>
Expand Down Expand Up @@ -65,40 +65,34 @@ It has support for ``keypress``, ``keydown``, and ``keyup`` events on specific k
There are a number of other similar libraries out there so what makes this one different?

- There are no external dependencies, no framework is required
- You are not limited to ``keydown`` events (You can specify ``keypress``, ``keydown``, or ``keyup`` or let Mousetrap choose for you).
- You can bind key events directly to special keys such as ``?`` or ``*`` without having to specify ``shift+/`` or ``shift+8`` which are not consistent across all keyboards
- You are not limited to `keydown` events (You can specify `keypress`, `keydown`, or `keyup` or let Mousetrap choose for you).
- You can bind key events directly to special keys such as `?` or `*` without having to specify `shift+/` or `shift+8` which are not consistent across all keyboards
- It works with international keyboard layouts
- You can bind Gmail like key sequences in addition to regular keys and key combinations
- You can programatically trigger key events with the ``trigger()`` method
- You can programatically trigger key events with the `trigger()` method
- It works with the numeric keypad on your keyboard
- The code is well documented/commented

## Tests

Unit tests run via <a href="http://mochajs.org/" target="_blank">mocha</a>.
Unit tests are run with <a href="https://mochajs.org/">mocha</a>.

### Running in browser

[View it online](http://rawgit.com/ccampbell/mousetrap/master/tests/mousetrap.html) to check your browser compatibility. You may also download the repo and open `tests/mousetrap.html` in your browser.

### Running with Grunt and PhantomJS
### Running with Node.js

1. Install grunt-cli
1. Install development dependencies

```bash
npm install -g grunt-cli
```

2. Install npm packages

```bash
```sh
cd /path/to/repo
npm install
```

3. Run tests
3. Run tests

```bash
```sh
npm test
```

Expand Down
16 changes: 15 additions & 1 deletion mousetrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Mousetrap is a simple keyboard shortcut library for Javascript with
* no external dependencies
*
* @version 1.6.2
* @version 1.6.3
* @url craig.is/killing/mice
*/
(function(window, document, undefined) {
Expand Down Expand Up @@ -982,6 +982,20 @@
return false;
}

// Events originating from a shadow DOM are re-targetted and `e.target` is the shadow host,
// not the initial event target in the shadow tree. Note that not all events cross the
// shadow boundary.
// For shadow trees with `mode: 'open'`, the initial event target is the first element in
// the event’s composed path. For shadow trees with `mode: 'closed'`, the initial event
// target cannot be obtained.
if ('composedPath' in e && typeof e.composedPath === 'function') {
// For open shadow trees, update `element` so that the following check works.
var initialEventTarget = e.composedPath()[0];
if (initialEventTarget !== e.target) {
element = initialEventTarget;
}
}

// stop for input, select, and textarea
return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || element.isContentEditable;
};
Expand Down
22 changes: 11 additions & 11 deletions mousetrap.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions mousetrap.sublime-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"settings":
{
"detect_indentation": true,
"ensure_newline_at_eof_on_save": true,
"tab_size": 4,
"translate_tabs_to_spaces": true,
"trim_automatic_white_space": false,
"trim_trailing_white_space_on_save": true,
},
"folders":
[
{
"path": "./",
"folder_exclude_patterns": ["bin", "coverage", "node_modules"],
"file_exclude_patterns": ["*.sublime-workspace"]
}
]
}

Loading

0 comments on commit 0d41aa7

Please sign in to comment.