Skip to content

Commit

Permalink
修复: 页面缩放时导致 devtools docked 检查错误
Browse files Browse the repository at this point in the history
  • Loading branch information
AEPKILL committed Mar 30, 2018
1 parent 59c420d commit a1bd0dd
Show file tree
Hide file tree
Showing 5 changed files with 369 additions and 11 deletions.
36 changes: 28 additions & 8 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,49 @@
### ES6 & TypeScript

```javascript
import { addListener , launch } from 'devtools-detector';
import { addListener, launch } from 'devtools-detector';
const view = document.createElement('div');
document.body.appendChild(view);

// 1. add listener
addListener(status => console.log(status));
addListener(
status =>
(view.innerText = status
? 'devtools status: open'
: 'devtools status: close')
);
// 2. launch detect
launch();
```

### AMD

```javascript
require(['devtools-detector'],function(devtoolsDetector){
devtoolsDetector.addListener(function(status){
console.log(status);
require(['devtools-detector'], function(devtoolsDetector) {
var view = document.createElement('div');
document.body.appendChild(view);

devtoolsDetector.addListener(function(status) {
view.innerText = status
? 'devtools status: open'
: 'devtools status: close';
});
devtoolsDetector.launch();
})
});
```

### No Module System

```html
<script src="node_modules/devtools-detector/lib/devtools-detector.js"></script>
<script>
devtoolsDetector.addListener(function(status){
console.log(status);
var view = document.createElement('div');
document.body.appendChild(view);
devtoolsDetector.addListener(function (status) {
view.innerText = status
? 'devtools status: open'
: 'devtools status: close'
});
devtoolsDetector.launch();
</script>
Expand All @@ -54,6 +72,8 @@ require(['devtools-detector'],function(devtoolsDetector){

* lanuch()

* stop()

* addListener(listener)

* removeListener(listener)
Expand Down
7 changes: 5 additions & 2 deletions src/docked.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import zoomDetail from './zoom-detail';

const threshold = 160;

export function devtoolsIsDocked() {
const zoom = zoomDetail().zoom;
return (
window.outerWidth - window.innerWidth > threshold ||
window.outerHeight - window.innerHeight > threshold
window.outerWidth - window.innerWidth * zoom > threshold ||
window.outerHeight - window.innerHeight * zoom > threshold
);
}

Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ export function setDetectDelay(value: number) {
export function launch() {
setDetectDelay(500);
}

export function stop() {
setDetectDelay(0);
}
Loading

0 comments on commit a1bd0dd

Please sign in to comment.