Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nghiepdev committed Nov 12, 2017
0 parents commit 338b6ab
Show file tree
Hide file tree
Showing 9 changed files with 1,976 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": ["env"],
"env": {
"production": {
"presets": ["minify"]
}
}
}
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build
/lib

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
21 changes: 21 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Nghiệp

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# prevent-pull-refresh
Preventing the pull-to-refresh effect browser on mobile

[![NPM version](https://img.shields.io/npm/v/prevent-pull-refresh.svg)](https://www.npmjs.com/package/prevent-pull-refresh)
[![NPM monthly download](https://img.shields.io/npm/dm/prevent-pull-refresh.svg)](https://www.npmjs.com/package/prevent-pull-refresh)

## Document
https://docs.google.com/document/d/12Ay4s3NWake8Qd6xQeGiYimGJ_gCe0UMDZKwP9Ni4m8

![pull-refresh](https://lh3.googleusercontent.com/xCQZK2gd3R0pNmTXINDQkS4OXiPQa_I2H2i-W6frt40F17gnAjqpkpCXJeyroDcNzzhYZwHtApBSoNCt5inU1dYmgTSzdTLNBxVNF8GjoQLLdH51RzfNPrgVm21blWkgM_xkQKI=s300)

## Installation

```sh
$ yarn add prevent-pull-refresh
```

## Usage

```js
import 'prevent-pull-refresh'
```
or

```html
<script src="//unpkg.com/prevent-pull-refresh"></script>
```

## License
MIT © [Nghiệp](http://nghiepit.pro)
35 changes: 35 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(() => {
let lastTouchY = 0;
let maybePrevent = false;

const setTouchStartPoint = event => {
lastTouchY = event.touches[0].clientY;
};

const isScrollingUp = event => {
const touchY = event.touches[0].clientY;
const touchYDelta = touchY - lastTouchY;

lastTouchY = touchY;

return touchYDelta > 0;
};

const touchstartHandler = event => {
if (event.touches.length !== 1) return;
setTouchStartPoint(event);
maybePrevent = window.pageYOffset === 0;
};

const touchmoveHandler = event => {
if (maybePrevent) {
maybePrevent = false;
if (isScrollingUp(event)) {
return event.preventDefault();
}
}
};

document.addEventListener('touchstart', touchstartHandler);
document.addEventListener('touchmove', touchmoveHandler);
})();
3 changes: 3 additions & 0 deletions index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions index.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "prevent-pull-refresh",
"version": "0.0.1",
"description": "Preventing the pull-to-refresh effect browser on mobile",
"main": "index.min.js",
"scripts": {
"build": "cross-env NODE_ENV=production babel index.js -o index.min.js -s"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-minify": "^0.2.0",
"cross-env": "^5.1.1"
},
"repository": "https://github.com/tronghiep92/prevent-pull-refresh",
"author": "Nghiệp <[email protected]>",
"homepage": "http://nghiepit.pro",
"keywords": [
"pull refresh",
"refresh",
"prevent",
"browser",
"chrome",
"mobile",
"scroll",
"overscroll"
],
"license": "MIT"
}
Loading

0 comments on commit 338b6ab

Please sign in to comment.