Skip to content

Commit

Permalink
remove polymer-cli dependency, run tests with mocha (#13)
Browse files Browse the repository at this point in the history
* s/wigc/wicg, udpate readme with example, use npm packages.

* update local development section

* test with mocha

* try with previous credentials

* update readme

* remove safari 9

* include Set polyfill, add safari 9 and ie11

* no es2015 in tests

* no es2015 for Fixture either

* no use of Promise

* max 2 min for tests

* remove ie11

* [skip ci] mention usage of Set

* [skip ci] image in new paragraph

* [skip ci] format title

* [skip ci] explain why $blockingElements
  • Loading branch information
valdrinkoshi authored Mar 20, 2018
1 parent 3666b9f commit c2dc499
Show file tree
Hide file tree
Showing 14 changed files with 2,013 additions and 523 deletions.
15 changes: 0 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
language: node_js
sudo: required
before_script:
- npm install -g bower polymer-cli
- polymer install
node_js: '6'
addons:
firefox: latest
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
script:
- xvfb-run polymer test
- if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then polymer test -s 'windows 10/microsoftedge@14' -s 'os x 10.11/safari@9' -s 'macos 10.12/safari@10'; fi
dist: trusty
env:
global:
- secure: VpPRx1TJb2Kw3+Em4ViH3H2CRHwM+mzliygcWc+kH0k9+iYnKfTOfI+ZsrzE5joCy7qZPAQgNKduvZ9/oDAZrGx/byhFcu5a+/I4sJPQP7kHXVtGK5+WN3Db8uKGkTc5J2539qAhYLmER+gRhazz2c7QQL6zS4cfkYArprEXANJk6neW+kyRN0TYl0YZVp2vW6ZqRxgCv7UDma2u/DIq37Z2T+CzAOYOoZccIWMN4qeEucZZDLf15c+MuTC2sq+BR9t4360Lj4Cp6WPOm5MWpo2pYFHTWOCEviVlzumQh4V9Xb5OXpASoZ7mTHiqXhgkmIWhk527A3GOo2VYPmOH7s/C3VbMabgJhmQVOIIg/IwRnIeTOLbPyOaQFmz2fA9s799noUV7PSCelBISacn0OtYfE6HcWWzICRv7ji6P/lTPOMBarxfqBQx3tgDoGEe019qxEoA3XT6T36MBntg7SKLNu/3Ankt0euC8x65v/zOLpnDfjbzBcgz8p4XCThpwNJNobo0ZMwljHqBqrsd2CDAWixCuVbKoUwuzn8PusG8HYZKCDOUsiRi42Ub0mcubJpqZTx3mcmgb/iAJAf/6s4iropqzpzeAM4sX/CwS/HaqdRa/KW/6jCBVLJApvGOJ862GXpUh7AKgIi0VW1zfMolBSyFEJNV4wFhGfFqsZ3M=
Expand Down
52 changes: 42 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[![Build Status](https://travis-ci.org/PolymerLabs/blockingElements.svg?branch=master)](https://travis-ci.org/PolymerLabs/blockingElements)
[![Build Status](https://travis-ci.org/PolymerLabs/blocking-elements.svg?branch=master)](https://travis-ci.org/PolymerLabs/blocking-elements)

# `blockingElements` stack API
# Blocking Elements stack API

Implementation of proposal <https://github.com/whatwg/html/issues/897>
Implementation of proposal https://github.com/whatwg/html/issues/897

> The polyfill chooses a non-colliding name (`document.$blockingElements` instead of `document.blockingElements`) as the proposal is still work in progress and hasn't yet reached consensus on the semantics and functionality (see [this discussion](https://github.com/PolymerLabs/blocking-elements/pull/1#issuecomment-235102344) for more details).
`document.$blockingElements` manages a stack of elements that inert the interaction outside them.

Expand All @@ -15,7 +17,7 @@ This polyfill will:
- search for the path of the element to block up to `document.body`
- set `inert` to all the siblings of each parent, skipping the parents and the element's distributed content (if any)

Use this polyfill together with the [WICG/inert](https://github.com/WICG/inert) polyfill to disable interactions on the rest of the document. See the [demo page](https://github.com/PolymerLabs/blockingElements/blob/master/demo/index.html) as an example.
Use this polyfill together with the [wicg-inert](https://github.com/WICG/inert) polyfill to disable interactions on the rest of the document. See the [demo page](https://github.com/PolymerLabs/blocking-elements/blob/master/demo/index.html) as an example.

## Why not listening to events that trigger focus change?

Expand All @@ -25,21 +27,51 @@ Wrapping the focus requires to find all the focusable nodes within the top block

This approach doesn't allow the focus to move outside the window (e.g. to the browser's url bar, dev console if opened, etc.), and is less robust when used with assistive technology (e.g. android talkback allows to move focus with swipe on screen, Apple Voiceover allows to move focus with special keyboard combinations).

## Install & run locally
## Install & use

Install the dependencies with `bower install`.
Blocking Elements relies on the [`inert` attribute](https://github.com/WICG/inert) and uses [`Set` objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set), so make sure to include their polyfills as needed.

Serve the resources via the [polymer CLI](https://github.com/Polymer/polymer-cli):
```bash
$ npm install -g polymer-cli
$ polymer serve
npm install --save babel-polyfill
npm install --save wicg-inert
npm install --save blocking-elements
```

```html
<script src="./node_modules/babel-polyfill/dist/polyfill.min.js"></script>
<script src="./node_modules/wicg-inert/dist/inert.min.js"></script>
<script src="./node_modules/blocking-elements/dist/blocking-elements.min.js"></script>

<div id="container">
<button onclick="makeBlocking(container)">make blocking</button>
<button onclick="undoBlocking(container)">undo blocking</button>
</div>

<button>some button</button>

<script>
function makeBlocking(element) {
document.$blockingElements.push(element);
}
function undoBlocking(element) {
document.$blockingElements.remove(element);
}
</script>
```

## Local development

Install the dependencies with `npm install` and serve the resources.

Run the tests locally by navigating to http://localhost:8080/test/

## Performance

Performance is dependent on the `inert` polyfill performance. Chrome recently landed [the `inert` attribute implementation](https://codereview.chromium.org/2088453002/) behind a flag.

Let's compare the how long it takes to toggle the deepest `x-trap-focus` inside nested `x-b` of the demo page (<http://localhost:8080/components/blockingElements/demo/ce.html?ce=v1>) ![results](https://cloud.githubusercontent.com/assets/6173664/17538133/914f365a-5e57-11e6-9b91-1c6b7eb22d57.png).
Let's compare the how long it takes to toggle the deepest `x-trap-focus` inside nested `x-b` of the demo page (<http://localhost:8080/demo/ce.html?ce=v1>)

![results](https://cloud.githubusercontent.com/assets/6173664/17538133/914f365a-5e57-11e6-9b91-1c6b7eb22d57.png).

`blockingElements` with native inert is **~15x faster** than polyfilled inert 🎉 🎉 🎉

Expand Down
23 changes: 0 additions & 23 deletions bower.json

This file was deleted.

7 changes: 4 additions & 3 deletions demo/ce.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
<head>
<meta charset="utf-8">
<title>blockingElements polyfill test page</title>
<script src="../../webcomponentsjs/webcomponents-loader.js"></script>
<script src="../../inert/dist/inert.js"></script>
<script src="../dist/blocking-elements.js"></script>
<script src="../node_modules/babel-polyfill/dist/polyfill.min.js"></script>
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="../node_modules/wicg-inert/dist/inert.js"></script>
<!-- blocking-elements polyfill imported by x-trap-focus.html -->

<script>
// Dynamic import according to query param ce=v0|v1.
Expand Down
3 changes: 2 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<head>
<meta charset="utf-8">
<title>blockingElements polyfill test page</title>
<script src="../../inert/dist/inert.js"></script>
<script src="../node_modules/babel-polyfill/dist/polyfill.min.js"></script>
<script src="../node_modules/wicg-inert/dist/inert.js"></script>
<script src="../dist/blocking-elements.js"></script>

<style>
Expand Down
3 changes: 2 additions & 1 deletion demo/nytimes.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<head>
<meta charset="utf-8">
<title>blockingElements polyfill test page</title>
<script src="../../inert/dist/inert.js"></script>
<script src="../node_modules/babel-polyfill/dist/polyfill.min.js"></script>
<script src="../node_modules/wicg-inert/dist/inert.js"></script>
<script src="../dist/blocking-elements.js"></script>

<style>
Expand Down
Loading

0 comments on commit c2dc499

Please sign in to comment.