Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #100 from Financial-Times/breaking
Browse files Browse the repository at this point in the history
4.0.0 changes
  • Loading branch information
notlee authored Nov 21, 2019
2 parents 1653701 + 70431ab commit c1aa597
Show file tree
Hide file tree
Showing 18 changed files with 1,439 additions and 1,530 deletions.
36 changes: 36 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: 2
jobs:
test:
docker:
- image: circleci/node:10-browsers
steps:
- checkout
- run: npm config set prefix "$HOME/.local"
- run: npm i -g origami-build-tools@^7
- run: $HOME/.local/bin/obt install
- run: $HOME/.local/bin/obt demo --demo-filter pa11y --suppress-errors
- run: $HOME/.local/bin/obt verify
- run: $HOME/.local/bin/obt test
- run: git clean -fxd
- run: npx occ 0.0.0
- run: $HOME/.local/bin/obt install --ignore-bower
- run: $HOME/.local/bin/obt test --ignore-bower
publish_to_npm:
docker:
- image: circleci/node:10
steps:
- checkout
- run: npx occ ${CIRCLE_TAG##v}
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > $HOME/.npmrc
- run: npm publish --access public
workflows:
version: 2
test:
jobs:
- test
- publish_to_npm:
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
14 changes: 9 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
node_modules
lcov-report
lcov.info
npm-debug.log
/build
.DS_Store
.env
/.sass-cache/
/bower_components/
/node_modules/
/build/
.idea/
/demos/local
/coverage
5 changes: 0 additions & 5 deletions .npmignore

This file was deleted.

16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

47 changes: 0 additions & 47 deletions GruntFile.js

This file was deleted.

35 changes: 35 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Migration

## Migrating from v3 to v4

To support IE11 and other older browsers v4 requires the [Element.prototype.matches](https://polyfill.io/v3/url-builder/#Element.prototype.matches-polyfill) polyfill.

It also uses [ES Modules over CommonJS](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/) syntax, and updates the default export to the constructor. We recommend to include `ftdomdelegate` using the es modules syntax.

If you used the `.Delegate` constructor update your import:

```diff
-const Delegate = require('ftdomdelegate').Delegate;
+import Delegate from 'ftdomdelegate';
let myDel = new Delegate(document.body);
```

If you used the previous default export, also update to use the constructor:
```diff
-const delegate = require('ftdomdelegate');
-let myDel = delegate(document.body);
+import Delegate from 'ftdomdelegate';
+let myDel = new Delegate(document.body);
```

However to use the CommonJS syntax, without a plugin like [babel-plugin-transform-es2015-modules-commonjs](https://babeljs.io/docs/en/babel-plugin-transform-es2015-modules-commonjs), add `.default`.

```diff
-const Delegate = require('ftdomdelegate').Delegate;
+const Delegate = require('ftdomdelegate').default;
let myDel = new Delegate(document.body);
```

## Migrating from v2 to v3

V3 is a name change and does not make any API changes. Replace `dom-delegate` in your `bower.json` with `ftdomdelegate`.
119 changes: 23 additions & 96 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,71 +1,24 @@
# ftdomdelegate [![Build Status](https://travis-ci.org/ftlabs/ftdomdelegate.svg?branch=master)](https://travis-ci.org/ftlabs/ftdomdelegate)

FT's dom delegate library is a component for binding to events on all target elements matching the given selector, irrespective of whether anything exists in the DOM at registration time or not. This allows developers to implement the [event delegation pattern](http://www.sitepoint.com/javascript-event-delegation-is-easier-than-you-think/).

FT DOM Delegate is developed by [FT Labs](http://labs.ft.com/), part of the Financial Times.

## Compatibility ##

The library has been deployed as part of the [FT Web App](http://app.ft.com/) and is tried and tested on the following browsers:

* Safari 5 +
* Mobile Safari on iOS 3 +
* Chrome 1 +
* Chrome on iOS 5 +
* Chrome on Android 4.0 +
* Opera 11.5 +
* Opera Mobile 11.5 +
* Firefox 4 +
* Internet Explorer 9 +
* Android Browser on Android 2 +
* PlayBook OS 1 +

For older browsers (IE8) you'll need the following polyfills

- [Event](https://polyfill.io/v2/docs/features/#Event)
- [Array.prototype.map](https://polyfill.io/v2/docs/features/#Array_prototype_map)
- [Function.prototype.bind](https://polyfill.io/v2/docs/features/#Function_prototype_bind)
- [document.querySelector](https://polyfill.io/v2/docs/features/#document_querySelector)
- [Element.prototype.matches](https://polyfill.io/v2/docs/features/#Element_prototype_matches)

The easiest way is to include the following script tag and let [Polyfill.io](https://Polyfill.io) work its magic

```js
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=Event,Array.prototype.map,Function.prototype.bind,document.querySelector,Element.prototype.matches"></script>
```

ftdomdelegate [![CircleCI](https://circleci.com/gh/Financial-Times/ftdomdelegate.svg?style=svg)](https://circleci.com/gh/Financial-Times/ftdomdelegate) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](#licence)
=================

## Installation ##

Get the [browserify](http://browserify.org/)-able source from a package manager:
FT's dom delegate library is a component for binding to events on all target elements matching the given selector, irrespective of whether anything exists in the DOM at registration time or not. This allows developers to implement the [event delegation pattern](http://www.sitepoint.com/javascript-event-delegation-is-easier-than-you-think/).

```
npm install ftdomdelegate
```
- [JavaScript](#javascript)
- [Migration](#migration)
- [Contact](#contact)
- [Licence](#licence)

or
## JavaScript

```
bower install ftdomdelegate
```

## Usage ##

The library is written in CommonJS and so can be `require` in.
To import ftdomdelegate:

```js
// If requiring the module via CommonJS, either:-
Delegate = require('ftdomdelegate').Delegate;
myDel = new Delegate(document.body);

// Or:-
delegate = require('ftdomdelegate');
myDel = delegate(document.body);
import Delegate from 'ftdomdelegate';
let myDel = new Delegate(document.body);
```

The script must be loaded prior to instantiating a Delegate object.

To instantiate Delegate on the `body` and listen to some events:
To instantiate `Delegate` on the `body` and listen to some events:

```js
function handleButtonClicks(event) {
Expand All @@ -83,7 +36,6 @@ document.addEventListener('DOMContentLoaded', function() {
// Listen to all touch move
// events that reach the body
delegate.on('touchmove', handleTouchMove);

});
```

Expand All @@ -100,41 +52,6 @@ document.addEventListener('DOMContentLoaded', function() {
});
```

Note: as of 0.1.2 you do not need to provide a DOM element at the point of instantiation, it can be set later via the `root` method.

Also note: as of 0.2.0 you cannot specify more than one `eventType` in a single call to `off` or `on`.

### Google Closure Compiler ###

Delegate supports compilation with `ADVANCED_OPTIMIZATIONS` ('advanced mode'), which should reduce its size by about 70% (60% gzipped). Note that exposure of the `Delegate` variable isn't forced therefore you must compile it along with all of your code.

## Tests ##

Tests are run using [buster](http://docs.busterjs.org/en/latest/) and sit in `test/`. To run the tests statically:

```
$ cd ftdomdelegate/
$ ./node_modules/.bin/buster-static -c test/buster.js
Starting server on http://localhost:8282/
```

...then point your browser to http://localhost:8282/.

```
$ ./node_modules/.bin/buster-server
buster-server running on http://localhost:1111
```

Point your browser to http://localhost:1111 and capture it, then in another terminal tab:

```
$ ./node_modules/.bin/buster-test -c test/buster.js
```

Code coverage is generated automatically with [istanbul](https://github.com/gotwarlost/istanbul). The report outputs to `lcov-report/index.html`.

## API ##

### .on(eventType[, selector], handler[, useCapture]) ###

#### `eventType (string)` ####
Expand Down Expand Up @@ -189,4 +106,14 @@ Short hand for off() and root(), ie both with no parameters. Used to reset the d

## Credits and collaboration ##

The developers of ftdomdelegate are [Matthew Andrews](https://twitter.com/andrewsmatt) and [Matthew Caruana Galizia](http://twitter.com/mcaruanagalizia). Test engineering by [Sam Giles](https://twitter.com/SamuelGiles_). The API is influenced by [jQuery Live](http://api.jquery.com/live/). All open source code released by FT Labs is licenced under the MIT licence. We welcome comments, feedback and suggestions. Please feel free to raise an issue or pull request.
FT DOM Delegate was developed by [FT Labs](http://labs.ft.com/), part of the Financial Times. It's now maintained by the [Origami Team](https://origami.ft.com/). The developers of ftdomdelegate were [Matthew Andrews](https://twitter.com/andrewsmatt) and [Matthew Caruana Galizia](http://twitter.com/mcaruanagalizia). Test engineering by [Sam Giles](https://twitter.com/SamuelGiles_). The API is influenced by [jQuery Live](http://api.jquery.com/live/).

## Migration guide

State | Major Version | Last Minor Release | Migration guide |
:---: | :---: | :---: | :---:
✨ active | 4 | N/A | [migrate to v4](MIGRATION.md#migrating-from-v3-to-v4) |
⚠ maintained | 3 | 3.1 | [migrate to v3](MIGRATION.md#migrating-from-v2-to-v3) |
╳ deprecated | 2 | 2.2 | N/A |
╳ deprecated | 1 | 1.0 | N/A |

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ftdomdelegate",
"description": "Create and manage a DOM event delegator.",
"main": "lib/delegate.js",
"main": "main.js",
"ignore": [".github", "test", ".npmignore", ".gitignore", "GruntFile.js"],
"license": "MIT"
}
Loading

0 comments on commit c1aa597

Please sign in to comment.