Skip to content

Commit

Permalink
Updated README.
Browse files Browse the repository at this point in the history
  • Loading branch information
christophercliff committed Aug 31, 2013
1 parent 959d177 commit ef826f9
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 19 deletions.
118 changes: 101 additions & 17 deletions README.md
@@ -1,45 +1,52 @@
# chrx

__chrx__ is a collection of CommonJS modules for developing Chrome Extensions. The [`chrome.*` APIs](http://developer.chrome.com/extensions/api_index.html) provided in Chrome are powerful, but their complexity can make simple tasks rather difficult. This project is an attempt to collect some common abstractions and distribute them via [`npm`](https://npmjs.org/).
__chrx__ is a collection of CommonJS modules for developing Chrome Extensions. This project is an attempt to collect some useful abstractions for developing Chrome Extensions and distribute them via [`npm`](https://npmjs.org/).

## Installation

Install via [`npm`](https://npmjs.org/package/chrx):

```
$ npm install chrx
```

## API
## Usage

Reference using `require`:

## [`tabs`](#tabs-1)
```js
var chrx = require('chrx')
```

- [`getActive()`](#getactiveoptions-callback)
- [`executeScripts()`](#executescriptsoptions-callback)
- [`executeScriptsInActive()`](#executescriptsinactiveoptions-callback)
__chrx__ is designed to be used with [browserify](http://browserify.org/) (or [watchify](https://github.com/substack/watchify)). This approach is demonstrated in the [included examples](https://github.com/christophercliff/chrx/tree/master/examples). It's also explained in this [Chrome Apps Office Hours video](https://www.youtube.com/watch?v=gkb_x9ZN0Vo).

## [`window`](https://github.com/christophercliff/chrx#window-1)
## Background API

- [`getActive()`](#getactivecallback)
Modules and methods for use in [background](http://developer.chrome.com/extensions/background_pages.html) or [event](http://developer.chrome.com/extensions/event_pages.html) scripts.

## `tabs`
- [`tabs.getActive()`](#getactiveoptions-callback)
- [`tabs.executeScripts()`](#executescriptsoptions-callback)
- [`tabs.executeScriptsInActive()`](#executescriptsinactiveoptions-callback)
- [`window.getActive()`](#getactivecallback)

### `getActive([options][, callback])`
### `tabs.getActive([options][, callback])`

Gets the active tab in the active window.

```js
chrx.tabs.getActive(function(err, tab){})
tabs.getActive(function(err, tab){})
```

#### options

- `protocol`

### `executeScripts(options[, callback])`
### `tabs.executeScripts(options[, callback])`

Executes content scripts in a tab.

```js
chrx.tabs.executeScripts({
tabs.executeScripts({
tab: tab,
scripts: ['underscore.js', 'jquery.js']
}, function(err, tab){})
Expand All @@ -51,12 +58,12 @@ chrx.tabs.executeScripts({
- `scripts` (required)
- `runAt`

### `executeScriptsInActive(options[, callback])`
### `tabs.executeScriptsInActive(options[, callback])`

Executes content scripts in the active tab.

```js
chrx.tabs.executeScriptsInActive({
tabs.executeScriptsInActive({
scripts: ['underscore.js', 'jquery.js']
}, function(err, tab){})
```
Expand All @@ -66,12 +73,89 @@ chrx.tabs.executeScriptsInActive({
- `scripts` (required)
- `runAt`

### `getActive([callback])`
### `window.getActive([callback])`

Gets the active window.

```js
chrx.window.getActive(function(err, win){})
window.getActive(function(err, win){})
```

## Content API

Modules and methods for use in [content](http://developer.chrome.com/extensions/content_scripts.html) scripts.

- [`frame.create()`](#)
- [`frame.parent()`](#)

### `frame.create(options)`

Creates an iframe in in the web page. This is useful for creating sandboxed overlay applications that run on top of the current page.

```js
var f = frame.create({
src: 'pages/menu.html',
css: {
left: '10px',
top: '10px',
width: '100px',
height: '100px'
}
})
```

#### options

- `src` (required)
- `css`

### `f.on(event[, callback])`

Bind a callback function to the frame. The callback will be invoked whenever the event is fired.

```js
f.on('hide', f.hide)
```

### `f.trigger(event[, *args])`

Triggers callbacks for the given event. Subsequent arguments to trigger will be passed along to the event callbacks.

```js
f.trigger('alert', 'Hello!')
```

### `frame.parent()`

Creates an object that is "bound" to the parent context. Used in the context of a child frame, this object allows for simple two-way communication with the parent.

```js
var p = frame.parent()
```

### `p.on(event[, callback])`

Bind a callback function to the frame. The callback will be invoked whenever the event is fired.

```js
p.on('alert', displayAlertInsideTheFrame)
```

### `p.trigger(event[, *args])`

Triggers callbacks for the given event. Subsequent arguments to trigger will be passed along to the event callbacks.

```js
p.trigger('hide')
```

## Tests

Install dependencies and run:

```
$ npm install
$ npm test
```

## License
Expand Down
2 changes: 1 addition & 1 deletion lib/frame/index.js
Expand Up @@ -6,7 +6,7 @@ var process = require('process')
var util = require('../util')

exports.create = create
exports.createParent = createParent
exports.parent = createParent

var MAX_Z_INDEX = '99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'
var CSS = {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -8,7 +8,9 @@
"crx"
],
"main": "index.js",
"scripts": {},
"scripts": {
"test": "say sorry"
},
"repository": {
"type": "git",
"url": "http://github.com/christophercliff/chrx"
Expand Down

0 comments on commit ef826f9

Please sign in to comment.