forked from auipga/bootstrap-xxs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bsdebug_bookmarklet.js
119 lines (106 loc) · 4.72 KB
/
bsdebug_bookmarklet.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* Created by auipga on 18.08.14.
*/
var runBsDebug = function() {
$('head').append('<style type="text/css">\
#bsdebug {\
position: fixed;\
top: 10px;\
left: 10px;\
background-color: rgba(255, 255, 255, 0.80);\
color: #00000;\
z-index: 9999;\
}\
#bsdebug table {\
border: 1px;\
}\
#bsdebug td,\
#bsdebug th {\
border: 1px solid black;\
padding:2px;\
}\
#bsdebug td {\
text-align: center;\
}\
#bsdebug .bold {\
font-weight: bold;\
}\
#bsdebug .highlighted {\
background-color: rgba(15, 230, 0, 0.67);\
}\
</style>');
$('body').append('<div id="bsdebug">\
<table>\
<tr id="bsdebug-size">\
<td colspan="7" style="text-align: left">\
<span class="bold hidden-tn hidden-xxs"><a href="https://github.com/auipga/bootstrap-xxs/">BS-Debug</a></span>\
| w<span class="hidden-tn">idth</span>:\
<span class="bold" id="bsdebug-width">?</span>px\
<span title="ScrollbarWidth" class="small" style="border-bottom: 1px black dotted; cursor: help;">(-'+getScrollbarWidth()+'px)</span>\
| h<span class="hidden-tn">eigth</span>:\
<span class="bold" id="bsdebug-height">?</span>px\
</td>\
</tr>\
<tr id="bsdebug-breakpoint">\
<th></th>\
<td><span class="visible-tn-block highlighted">TN</span><span class="hidden-tn">TN</span></td>\
<td><span class="visible-xxs-block highlighted">XXS</span><span class="hidden-xxs">XXS</span></td>\
<td><span class="visible-xs-block highlighted">XS</span><span class="hidden-xs">XS</span></td>\
<td class="hidden-tn"><span class="visible-sm-block highlighted">SM</span><span class="hidden-sm">SM</span></td>\
<td class="hidden-tn hidden-xxs"><span class="visible-md-block highlighted">MD</span><span class="hidden-md">MD</span></td>\
<td class="hidden-tn hidden-xxs"><span class="visible-lg-block highlighted">LG</span><span class="hidden-lg">LG</span></td>\
</tr>\
<tr id="bsdebug-min" class="small"><th>Min</th><td>0px</td><td>≥384px</td><td>≥480px</td><td class="hidden-tn">≥768px</td><td class="hidden-tn hidden-xxs">≥992px</td><td class="hidden-tn hidden-xxs">≥1200px</td></tr>\
<tr id="bsdebug-max" class="small"><th>Max</th><td><383px</td><td><479px</td><td><767px</td><td class="hidden-tn"><991px</td><td class="hidden-tn hidden-xxs"><1199px</td><td class="hidden-tn hidden-xxs">∞</td></tr>\
<tr id="bsdebug-diff"><th>Diff</th><td></td><td></td><td></td><td class="hidden-tn"></td><td class="hidden-tn hidden-xxs"></td><td class="hidden-tn hidden-xxs"></td></tr>\
</table>\
</div>');
var ScrollbarWidth = getScrollbarWidth();
$(window).on('resize', function (e) {
var $window = $(window);
var width = $window.width() + ScrollbarWidth;
var height = $window.height();
$('#bsdebug-width').text(width);
$('#bsdebug-height').text(height);
var breakpoints = [0, 384, 480, 768, 992, 1200, 9999];
$('#bsdebug-diff>td').each(function (i) {
var diff = width - breakpoints[i];
if (diff >= 0) {
$("#bsdebug-min td").eq(i).css({ 'background-color':'rgba(127, 219, 124, 0.67)', 'font-weight': 'bold' });
} else {
$("#bsdebug-min td").eq(i).css({ 'background-color':'', 'font-weight': '' });
}
if (breakpoints[i + 1] > width) {
$("#bsdebug-max td").eq(i).css({ 'background-color':'rgba(127, 219, 124, 0.67)', 'font-weight': 'bold' });
} else {
$("#bsdebug-max td").eq(i).css({ 'background-color':'', 'font-weight': '' });
}
if (diff > 0) {
diff = "+" + diff;
}
$(this).text(diff);
});
});
$(window).trigger('resize');
};
runBsDebug();
/*
source: http://stackoverflow.com/a/13382873/816362
*/
function getScrollbarWidth() {
var outer = document.createElement("div");
outer.style.visibility = "hidden";
outer.style.width = "100px";
document.body.appendChild(outer);
var widthNoScroll = outer.offsetWidth;
// force scrollbars
outer.style.overflow = "scroll";
// add innerdiv
var inner = document.createElement("div");
inner.style.width = "100%";
outer.appendChild(inner);
var widthWithScroll = inner.offsetWidth;
// remove divs
outer.parentNode.removeChild(outer);
return widthNoScroll - widthWithScroll;
}