-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser.js
98 lines (82 loc) · 2.36 KB
/
browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
$( document ).ready( function () {
let windowWidth = $( window ).width();
let windowHeight = $( window ).height();
const copyArea = document.querySelector( '.debug-container' );
const screenWidthContainer = document.querySelector( '.screen-width' );
const screenHeightContainer = document.querySelector( '.screen-height' );
const viewportWidthContainer = document.querySelector( '.viewport-width' );
const viewportHeightContainer = document.querySelector( '.viewport-height' );
/**
* Resize Event Watcher.
*/
$( window ).resize( function () {
// Check for iOS fake resize
if ( $( window ).width() != windowWidth ) {
windowWidth = $( window ).width();
load();
}
if ( $( window ).height() != windowHeight ) {
windowHeight = $( window ).height();
load();
}
} );
/**
* Get window viewport dimensions
* @returns object
*/
function getViewportDimensions() {
var doc = document;
var w = window;
var docEl = ( doc.compatMode && doc.compatMode === 'CSS1Compat' ) ?
doc.documentElement : doc.body;
var width = docEl.clientWidth;
var height = docEl.clientHeight;
// mobile zoomed in?
if ( w.innerWidth && width > w.innerWidth ) {
width = w.innerWidth;
height = w.innerHeight;
}
return {
width: width,
height: height
};
}
/**
* Watch Debug Container for Click, then Copy.
*/
copyArea.addEventListener( 'click',function () {
var range = document.createRange();
range.selectNode( copyArea );
window.getSelection().addRange( range );
try {
var successful = document.execCommand( 'copy' );
toastr.options.timeOut = 1000;
toastr.options.fadeOut = 250;
toastr.options.fadeIn = 0;
toastr.options.showEasing = 'swing';
toastr.options.hideEasing = 'swing';
toastr.options.positionClass = 'toast-bottom-center';
if ( successful ) {
toastr.success( 'Copied' )
} else {
toastr.error( 'Error, please copy manually' )
}
} catch ( err ) {
toastr.error( 'Error, please copy manually' )
}
window.getSelection().removeAllRanges();
} );
/**
* Load everyting.
*/
function load() {
let viewport = getViewportDimensions();
viewportWidthContainer.innerHTML = viewport.width;
viewportHeightContainer.innerHTML = viewport.height;
screenWidthContainer.innerHTML = window.screen.width;
screenHeightContainer.innerHTML = window.screen.height;
}
( function () {
load();
} )();
} );