Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit 338b6ab

Browse files
committed
Initial commit
0 parents  commit 338b6ab

File tree

9 files changed

+1976
-0
lines changed

9 files changed

+1976
-0
lines changed

.babelrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"presets": ["env"],
3+
"env": {
4+
"production": {
5+
"presets": ["minify"]
6+
}
7+
}
8+
}

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# See https://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
6+
# testing
7+
/coverage
8+
9+
# production
10+
/build
11+
/lib
12+
13+
# misc
14+
.DS_Store
15+
.env.local
16+
.env.development.local
17+
.env.test.local
18+
.env.production.local
19+
20+
npm-debug.log*
21+
yarn-debug.log*
22+
yarn-error.log*

LICENCE

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) 2017 Nghiệp
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# prevent-pull-refresh
2+
Preventing the pull-to-refresh effect browser on mobile
3+
4+
[![NPM version](https://img.shields.io/npm/v/prevent-pull-refresh.svg)](https://www.npmjs.com/package/prevent-pull-refresh)
5+
[![NPM monthly download](https://img.shields.io/npm/dm/prevent-pull-refresh.svg)](https://www.npmjs.com/package/prevent-pull-refresh)
6+
7+
## Document
8+
https://docs.google.com/document/d/12Ay4s3NWake8Qd6xQeGiYimGJ_gCe0UMDZKwP9Ni4m8
9+
10+
![pull-refresh](https://lh3.googleusercontent.com/xCQZK2gd3R0pNmTXINDQkS4OXiPQa_I2H2i-W6frt40F17gnAjqpkpCXJeyroDcNzzhYZwHtApBSoNCt5inU1dYmgTSzdTLNBxVNF8GjoQLLdH51RzfNPrgVm21blWkgM_xkQKI=s300)
11+
12+
## Installation
13+
14+
```sh
15+
$ yarn add prevent-pull-refresh
16+
```
17+
18+
## Usage
19+
20+
```js
21+
import 'prevent-pull-refresh'
22+
```
23+
or
24+
25+
```html
26+
<script src="//unpkg.com/prevent-pull-refresh"></script>
27+
```
28+
29+
## License
30+
MIT © [Nghiệp](http://nghiepit.pro)

index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(() => {
2+
let lastTouchY = 0;
3+
let maybePrevent = false;
4+
5+
const setTouchStartPoint = event => {
6+
lastTouchY = event.touches[0].clientY;
7+
};
8+
9+
const isScrollingUp = event => {
10+
const touchY = event.touches[0].clientY;
11+
const touchYDelta = touchY - lastTouchY;
12+
13+
lastTouchY = touchY;
14+
15+
return touchYDelta > 0;
16+
};
17+
18+
const touchstartHandler = event => {
19+
if (event.touches.length !== 1) return;
20+
setTouchStartPoint(event);
21+
maybePrevent = window.pageYOffset === 0;
22+
};
23+
24+
const touchmoveHandler = event => {
25+
if (maybePrevent) {
26+
maybePrevent = false;
27+
if (isScrollingUp(event)) {
28+
return event.preventDefault();
29+
}
30+
}
31+
};
32+
33+
document.addEventListener('touchstart', touchstartHandler);
34+
document.addEventListener('touchmove', touchmoveHandler);
35+
})();

index.min.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "prevent-pull-refresh",
3+
"version": "0.0.1",
4+
"description": "Preventing the pull-to-refresh effect browser on mobile",
5+
"main": "index.min.js",
6+
"scripts": {
7+
"build": "cross-env NODE_ENV=production babel index.js -o index.min.js -s"
8+
},
9+
"devDependencies": {
10+
"babel-cli": "^6.26.0",
11+
"babel-preset-env": "^1.6.1",
12+
"babel-preset-minify": "^0.2.0",
13+
"cross-env": "^5.1.1"
14+
},
15+
"repository": "https://github.com/tronghiep92/prevent-pull-refresh",
16+
"author": "Nghiệp <me@nghiepit.pro>",
17+
"homepage": "http://nghiepit.pro",
18+
"keywords": [
19+
"pull refresh",
20+
"refresh",
21+
"prevent",
22+
"browser",
23+
"chrome",
24+
"mobile",
25+
"scroll",
26+
"overscroll"
27+
],
28+
"license": "MIT"
29+
}

0 commit comments

Comments
 (0)