-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
35 lines (26 loc) · 839 Bytes
/
index.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
/*global require, module, window, document */
'use strict';
var Emitter = require('tiny-emitter');
var emitter = new Emitter();
if (window && window.getComputedStyle && window.addEventListener) {
var style, last;
var getCurrentBreakpoint = function () {
if (!style) {
style = window.getComputedStyle(document.body, ':after');
}
return style.getPropertyValue('content').replace(/'|"/g, '');
};
var publishChange = function (breakpoint) {
emitter.emit(breakpoint).emit('change', breakpoint);
};
var checkBreakpoint = function () {
var current = getCurrentBreakpoint();
if (current !== last) {
publishChange(current);
last = current;
}
};
window.addEventListener('load', checkBreakpoint);
window.addEventListener('resize', checkBreakpoint);
}
module.exports = emitter;