Skip to content

Commit ce74314

Browse files
First commit
0 parents  commit ce74314

File tree

9 files changed

+242
-0
lines changed

9 files changed

+242
-0
lines changed

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extends: "@gianlucaguarini/eslint-config"
2+
env:
3+
mocha: true

.gitignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
11+
# Directory for instrumented libs generated by jscoverage/JSCover
12+
lib-cov
13+
14+
# Coverage directory used by tools like istanbul
15+
coverage
16+
17+
# nyc test coverage
18+
.nyc_output
19+
20+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21+
.grunt
22+
23+
# node-waf configuration
24+
.lock-wscript
25+
26+
# Compiled binary addons (http://nodejs.org/api/addons.html)
27+
build/Release
28+
29+
# Dependency directories
30+
node_modules
31+
jspm_packages
32+
33+
# Optional npm cache directory
34+
.npm
35+
36+
# Optional REPL history
37+
.node_repl_history
38+
39+
# generated files
40+
index.js

.travis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
language: node_js
2+
node_js:
3+
- "6.*"
4+
5+
branches:
6+
only:
7+
- master
8+
9+
before_install:
10+
11+
12+
- npm i @gianlucaguarini/[email protected]
13+
14+
15+
before_script:
16+
- npm run build
17+
18+
notifications:
19+
email: false
20+
21+
sudo: false

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Gianluca Guarini
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# bianco.force-reflow
2+
3+
[![Build Status][travis-image]][travis-url]
4+
5+
[![NPM version][npm-version-image]][npm-url]
6+
[![NPM downloads][npm-downloads-image]][npm-url]
7+
[![MIT License][license-image]][license-url]
8+
9+
## Usage
10+
11+
```js
12+
import $ from 'bianco.force-reflow'
13+
```
14+
15+
[travis-image]: https://img.shields.io/travis/biancojs/force-reflow.svg?style=flat-square
16+
17+
[travis-url]: https://travis-ci.org/biancojs/force-reflow
18+
19+
[license-image]: http://img.shields.io/badge/license-MIT-000000.svg?style=flat-square
20+
21+
[license-url]: LICENSE.txt
22+
23+
[npm-version-image]: http://img.shields.io/npm/v/bianco.force-reflow.svg?style=flat-square
24+
25+
[npm-downloads-image]: http://img.shields.io/npm/dm/bianco.force-reflow.svg?style=flat-square
26+
27+
[npm-url]: https://npmjs.org/package/bianco.force-reflow
28+
29+
## API
30+
31+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
32+
33+
### forceReflow
34+
35+
Force the reflow of one or a list of DOM elements
36+
37+
**Parameters**
38+
39+
- `el` **([HTMLElement](https://developer.mozilla.org/en-US/docs/Web/HTML/Element) \| [NodeList](https://developer.mozilla.org/en-US/docs/Web/API/NodeList) \| [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array))** single or multiple DOM elements
40+
41+
**Examples**
42+
43+
```javascript
44+
import forceReflow from 'bianco.force-reflow'
45+
46+
// force reflow on a list of elements
47+
forceReflow(document.querySelectorAll('.list'))
48+
49+
// force reflow on a single element
50+
forceReflow(document.querySelector('.post'))
51+
```
52+
53+
Returns **any** the argument received

index.next.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import domToArray from 'bianco.dom-to-array'
2+
3+
/**
4+
* Force the reflow of one or a list of DOM elements
5+
* @param { HTMLElement|NodeList|Array } el - single or multiple DOM elements
6+
* @returns {*} - the argument received
7+
* @example
8+
* import forceReflow from 'bianco.force-reflow'
9+
*
10+
* // force reflow on a list of elements
11+
* forceReflow(document.querySelectorAll('.list'))
12+
*
13+
* // force reflow on a single element
14+
* forceReflow(document.querySelector('.post'))
15+
*/
16+
export default function forceReflow (el) {
17+
return domToArray(el).map(el => el.scrollTop) && el
18+
}
19+
20+
21+

package.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "bianco.force-reflow",
3+
"version": "0.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"jsnext:main": "index.next.js",
7+
"module": "index.next.js",
8+
"scripts": {
9+
"prepare": "npm run build && npm test",
10+
"lint": "eslint index.next.js test.js rollup.config.js",
11+
"build": "rollup -c",
12+
"doc": "documentation readme index.next.js -s API",
13+
"test": "npm run lint && mocha test.js"
14+
},
15+
"files": [
16+
"index.js",
17+
"index.next.js"
18+
],
19+
"repository": {
20+
"type": "git",
21+
"url": "git+https://github.com/biancojs/force-reflow.git"
22+
},
23+
"keywords": [
24+
"es6",
25+
"es2015"
26+
],
27+
"author": "Gianluca Guarini <[email protected]> (http://gianlucaguarini.com)",
28+
"license": "MIT",
29+
"bugs": {
30+
"url": "https://github.com/biancojs/force-reflow/issues"
31+
},
32+
"homepage": "https://github.com/biancojs/force-reflow#readme",
33+
"devDependencies": {
34+
"jsdom": "9.5.0",
35+
"jsdom-global": "^2.1.0",
36+
"rollup-plugin-node-resolve": "^2.1.1"
37+
},
38+
"dependencies": {
39+
"bianco.dom-to-array": "0.0.8"
40+
}
41+
}

rollup.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import resolve from 'rollup-plugin-node-resolve'
2+
3+
export default {
4+
entry: 'index.next.js',
5+
plugins: [
6+
resolve({
7+
jsnext: true
8+
})
9+
],
10+
targets: [
11+
{
12+
dest: 'index.js',
13+
format: 'cjs'
14+
}
15+
]
16+
}

test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require('jsdom-global')()
2+
const assert = require('assert')
3+
const forceReflow = require('./')
4+
const body = document.body
5+
6+
describe('Bianco forceReflow', function() {
7+
beforeEach(function () {
8+
var div = document.createElement('div')
9+
div.innerHTML = `
10+
<p>hello</p>
11+
<ul>
12+
<li>uno
13+
<li>due
14+
<li>tre
15+
</ul>
16+
`
17+
body.appendChild(div)
18+
})
19+
20+
it('return a the element as it was received', function() {
21+
const p = document.querySelector('p')
22+
const lis = document.querySelectorAll('li')
23+
assert.equal(forceReflow(p), p)
24+
assert.equal(forceReflow(lis), lis)
25+
})
26+
})

0 commit comments

Comments
 (0)