Skip to content

Commit

Permalink
add README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Nov 6, 2013
1 parent 47ab394 commit b89bc34
Show file tree
Hide file tree
Showing 5 changed files with 583 additions and 0 deletions.
213 changes: 213 additions & 0 deletions keymaster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
# keymaster.js

Keymaster is a simple micro-library for defining and
dispatching keyboard shortcuts in web applications.

It has no dependencies.

*It’s a work in progress (e.g. beta), so spare me your nerdrage and instead
contribute! Patches are welcome, but they are not guaranteed to make
it in.*

## Usage

Include `keymaster.min.js` in your web app, by loading it as usual:

```html
<script src="keymaster.min.js"></script>
```

Keymaster has no dependencies and can be used completely standalone.
It should not interfere with any JavaScript libraries or frameworks.

## Defining shortcuts

One global method is exposed, `key` which defines shortcuts when
called directly.

```javascript
// define short of 'a'
key('a', function(){ alert('you pressed a!') });

// returning false stops the event and prevents default browser events
key('ctrl+r', function(){ alert('stopped reload!'); return false });

// multiple shortcuts that do the same thing
key('⌘+r, ctrl+r', function(){ });
```

The handler method is called with two arguments set, the keydown `event` fired, and
an object containing, among others, the following two properties:

`shortcut`: a string that contains the shortcut used, e.g. `ctrl+r`
`scope`: a string describing the scope (or `all`)

```javascript
key('⌘+r, ctrl+r', function(event, handler){
console.log(handler.shortcut, handler.scope);
});

// "ctrl+r", "all"
```

## Supported keys

Keymaster understands the following modifiers:
``, `shift`, `option`, ``, `alt`, `ctrl`, `control`, `command`, and ``.

The following special keys can be used for shortcuts:
`backspace`, `tab`, `clear`, `enter`, `return`, `esc`, `escape`, `space`,
`up`, `down`, `left`, `right`, `home`, `end`, `pageup`, `pagedown`, `del`, `delete`
and `f1` through `f19`.

## Modifier key queries

At any point in time (even in code other than key shortcut handlers),
you can query the `key` object for the state of any keys. This
allows easy implementation of things like shift+click handlers. For example,
`key.shift` is `true` if the shift key is currently pressed.

```javascript
if(key.shift) alert('shift is pressed, OMGZ!');
```

## Other key queries

At any point in time (even in code other than key shortcut handlers),
you can query the `key` object for the state of any key. This
is very helpful for game development using a game loop. For example,
`key.isPressed(77)` is `true` if the M key is currently pressed.

```javascript
if(key.isPressed("M")) alert('M key is pressed, can ya believe it!?');
if(key.isPressed(77)) alert('M key is pressed, can ya believe it!?');
```

You can also get these as an array using...
```javascript
key.getPressedKeyCodes() // returns an array of key codes currently pressed
```


## Scopes

If you want to reuse the same shortcut for seperate areas in your single page app,
Keymaster supports switching between scopes. Use the `key.setScope` method to set scope.

```javascript
// define shortcuts with a scope
key('o, enter', 'issues', function(){ /* do something */ });
key('o, enter', 'files', function(){ /* do something else */ });

// set the scope (only 'all' and 'issues' shortcuts will be honored)
key.setScope('issues'); // default scope is 'all'
```

## Filter key presses

By default, when an `INPUT`, `SELECT` or `TEXTAREA` element is focused, Keymaster doesn't process any shortcuts.

You can change this by overwriting `key.filter` with a new function. This function is called before
Keymaster processes shortcuts, with the keydown event as argument.

If your function returns false, then the no shortcuts will be processed.

Here's the default implementation for reference:

```javascript
function filter(event){
var tagName = (event.target || event.srcElement).tagName;
return !(tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA');
}
```

If you only want _some_ shortcuts to work while in an input element, you can change the scope in the
`key.filter` function. Here's an example implementation, setting the scope to either `'input'` or `'other'`.
Don't forget to return `true` so the any shortcuts get processed.

```javascript
key.filter = function(event){
var tagName = (event.target || event.srcElement).tagName;
key.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(tagName) ? 'input' : 'other');
return true;
}
```

However a more robust way to handle this is to use proper
focus and blur event handlers on your input element, and change scopes there as you see fit.

## noConflict mode

You can call ```key.noConflict``` to remove the ```key``` function from global scope and restore whatever ```key``` was defined to before Keymaster was loaded. Calling ```key.noConflict``` will return the Keymaster ```key``` function.

```javascript
var k = key.noConflict();
k('a', function() { /* ... */ });

key()
// --> TypeError: 'undefined' is not a function
```

## Unbinding shortcuts

Similar to defining shortcuts, they can be unbound using `key.unbind`.

```javascript
// unbind 'a' handler
key.unbind('a');

// unbind a key only for a single scope
// when no scope is specified it defaults to the current scope (key.getScope())
key.unbind('o, enter', 'issues');
key.unbind('o, enter', 'files');
```

## Notes

Keymaster should work with any browser that fires `keyup` and `keydown` events,
and is tested with IE (6+), Safari, Firefox and Chrome.

See [http://madrobby.github.com/keymaster/](http://madrobby.github.com/keymaster/) for a live demo.

## CoffeeScript

If you're using CoffeeScript, configuring key shortcuts couldn't be simpler:

```coffeescript
key 'a', -> alert('you pressed a!')

key '⌘+r, ctrl+r', ->
alert 'stopped reload!'
off

key 'o, enter', 'issues', ->
whatevs()

alert 'shift is pressed, OMGZ!' if key.shift
```

## Ender support

Add `keymaster` as a top level method to your [Ender](http://ender.no.de) compilation.

$ ender add keymaster

Use it:

``` js
$.key('⌘+r', function () {
alert('reload!')
})
```

## Contributing

To contribute, please fork Keymaster, add your patch and tests for it (in the `test/` folder) and
submit a pull request.

## TODOs

* Finish test suite

Keymaster is (c) 2011-2013 Thomas Fuchs and may be freely distributed under the MIT license.
See the `MIT-LICENSE` file.
54 changes: 54 additions & 0 deletions normalize/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# normalize.css v2

Normalize.css is a customisable CSS file that makes browsers render all
elements more consistently and in line with modern standards.

The project relies on researching the differences between default browser
styles in order to precisely target only the styles that need or benefit from
normalizing.

[Check out the demo](http://necolas.github.io/normalize.css/latest/test.html)

## Install

Download from the [project page](http://necolas.github.io/normalize.css/).

Install with [Bower](http://bower.io/): `bower install --save normalize-css`

Install with [Component(1)](http://component.io/): `component install necolas/normalize.css`

## What does it do?

* Preserves useful defaults, unlike many CSS resets.
* Normalizes styles for a wide range of elements.
* Corrects bugs and common browser inconsistencies.
* Improves usability with subtle improvements.
* Explains what code does using detailed comments.

## How to use it

No other styles should come before Normalize.css.

It is recommended that you include the `normalize.css` file as untouched
library code.

## Browser support

* Google Chrome
* Mozilla Firefox 4+
* Apple Safari 5+
* Opera 12+
* Internet Explorer 8+

[Normalize.css v1 provides legacy browser
support](https://github.com/necolas/normalize.css/tree/v1) (IE 6+, Safari 4+),
but is no longer actively developed.

## Contributing

Please read the CONTRIBUTING.md

## Acknowledgements

Normalize.css is a project by [Nicolas Gallagher](https://github.com/necolas),
co-created with [Jonathan Neal](https://github.com/jonathantneal).
27 changes: 27 additions & 0 deletions placeholders/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#Placeholders.js - An HTML5 placeholder attribute polyfill

Placeholders.js is a polyfill (or shim, or whatever you like to call it) for the HTML5 placeholder attribute, as defined in the <a href="http://dev.w3.org/html5/spec/Overview.html#attr-input-placeholder">HTML5 draft specification</a>. Placeholder attributes are valid on `input` elements of various types and `textarea` elements.

Placeholders.js is licensed under the [MIT License](http://en.wikipedia.org/wiki/MIT_License). See the unminified file for the full license text.

## Get it!

Download the polyfill and get a whole load of information and instructions at [our new website](http://jamesallardice.github.com/Placeholders.js/).

##Supported Browsers

Placeholders.js aims to support the widest range of browsers possible. The idea is that you will be able to use the native `placeholder` attribute along with Placeholders.js and your users on any platform will get the same experience. This table will be updated as and when further browsers are tested. Mobile browser testing is a big one that's high on the list. Currently tested and working in the following browsers on (where applicable) both Windows 7 and CentOS 6:

- Internet Explorer 6 - 9 (with Placeholders.js)
- Firefox 1 - 3 (with Placeholders.js), 4+ (native)
- Opera 7 - 10 (with Placeholders.js), 11+ (native)
- Safari 3.2 (with Placeholders.js), 4+ (native)
- Chrome 4+ (native)
- Flock 1.0+ (with Placeholders.js)
- Konqueror 4.3 (with Placeholders.js)
- SeaMonkey 1+ (with Placeholders.js)
- Maxthon 1+ (with Placeholders.js)
- SlimBrowser 5 (with Placeholders.js)
- K-Meleon 0.7+ (with Placeholders.js)

Do you use some obscure browser that doesn't have native `placeholder` attribute support? If so, please let me know so I can make sure Placeholders.js works with it.
Loading

0 comments on commit b89bc34

Please sign in to comment.