Skip to content

Commit

Permalink
remove babel
Browse files Browse the repository at this point in the history
  • Loading branch information
nghiepdev committed Aug 8, 2019
1 parent 043fd67 commit 39625bc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1,920 deletions.
8 changes: 0 additions & 8 deletions .babelrc

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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)
[![NPM yearly download](https://img.shields.io/npm/dy/prevent-pull-refresh.svg)](https://www.npmjs.com/package/prevent-pull-refresh)

## Document

Expand Down Expand Up @@ -32,4 +32,4 @@ or

## License

MIT © [Nghiệp](http://nghiepit.pro)
MIT © [Nghiep](http://nghiepit.dev)
65 changes: 31 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
(() => {
const isChrome = window.chrome || navigator.userAgent.match('CriOS');
const isTouch = 'ontouchstart' in document.documentElement;
'use strict';

(function() {
var isChrome = window.chrome || navigator.userAgent.match('CriOS');
var isTouch = 'ontouchstart' in document.documentElement;

if (!isChrome || !isTouch) {
return;
}

let supportsOverscroll = false;
let supportsPassive = false;
let lastTouchY = 0;
let maybePrevent = false;
var supportsOverscroll = false;
var supportsPassive = false;
var lastTouchY = 0;
var maybePrevent = false;

try {
if (CSS.supports('overscroll-behavior-y', 'contain')) {
Expand All @@ -20,21 +22,10 @@
if (supportsOverscroll) {
return (document.body.style.overscrollBehaviorY = 'contain');
} else {
const head = document.head || document.body;
const style = document.createElement('style');
const css = `
::-webkit-scrollbar {
width: 5px;
}
::-webkit-scrollbar-thumb {
border-radius: 5px;
background-color: rgba(0, 0, 0, 0.2);
}
body {
-webkit-overflow-scrolling: auto!important;
}
`;

var head = document.head || document.body;
var style = document.createElement('style');
var css =
'\n ::-webkit-scrollbar {\n width: 5px;\n }\n ::-webkit-scrollbar-thumb {\n border-radius: 5px;\n background-color: rgba(0, 0, 0, 0.2);\n }\n body {\n -webkit-overflow-scrolling: auto!important;\n }\n ';
style.type = 'text/css';

if (style.styleSheet) {
Expand All @@ -47,35 +38,34 @@
}

try {
addEventListener('test', null, {
window.addEventListener('test', null, {
get passive() {
supportsPassive = true;
},
});
} catch (e) {}

const setTouchStartPoint = event => {
var setTouchStartPoint = function setTouchStartPoint(event) {
lastTouchY = event.touches[0].clientY;
};

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

var isScrollingUp = function isScrollingUp(event) {
var touchY = event.touches[0].clientY;
var touchYDelta = touchY - lastTouchY;
lastTouchY = touchY;

return touchYDelta > 0;
};

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

const touchmoveHandler = event => {
var touchmoveHandler = function touchmoveHandler(event) {
if (maybePrevent) {
maybePrevent = false;

if (isScrollingUp(event)) {
return event.preventDefault();
}
Expand All @@ -85,12 +75,19 @@
document.addEventListener(
'touchstart',
touchstartHandler,
supportsPassive ? {passive: true} : false,
supportsPassive
? {
passive: true,
}
: false,
);

document.addEventListener(
'touchmove',
touchmoveHandler,
supportsPassive ? {passive: false} : false,
supportsPassive
? {
passive: false,
}
: false,
);
})();
16 changes: 2 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,10 @@
"version": "1.0.4",
"description": "Preventing the pull-to-refresh effect browser on mobile",
"files": [
"index.min.js",
"index.min.js.map",
"LICENCE",
"README.md"
],
"main": "index.min.js",
"scripts": {
"build": "cross-env NODE_ENV=production babel index.js -o index.min.js -s",
"prepublish": "npm run build"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-minify": "^0.5.0",
"cross-env": "^5.2.0"
},
"main": "index.js",
"homepage": "https://github.com/nghiepit/prevent-pull-refresh",
"repository": "https://github.com/nghiepit/prevent-pull-refresh",
"keywords": [
Expand All @@ -31,6 +19,6 @@
"scroll",
"overscroll"
],
"author": "Nghiep <me@nghiepit.pro>",
"author": "Nghiep <me@nghiepit.dev>",
"license": "MIT"
}
Loading

0 comments on commit 39625bc

Please sign in to comment.