-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathindex.js
72 lines (61 loc) · 1.86 KB
/
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
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
/**
* @fileOverview
* Provides functions for checking if a stylesheet has been loaded previously
*/
// Imports
var global = require('../global');
var body = require('../body');
/**
* Function to add the test div to the page
*
* @param {string} className - The class name used to check if the css file has loaded yet
* (does not include the '.' out front, just the name)
* @return {object} The element that was just created for the purposes of
* testing whether the CSS has loaded or not
*/
var _loadTestDiv = function (className) {
var testDiv;
testDiv = global.document.createElement('div');
testDiv.style.height = '0px';
testDiv.style.width = '0px';
testDiv.style.border = '0px';
testDiv.className = className;
body().appendChild(testDiv);
return testDiv;
};
/**
* Function to remove the test div from the page
*
* @param {object} testDiv - The element that was created for the purposes of
* testing whether the CSS has loaded or not
*/
var _cleanupTestDiv = function (testDiv) {
testDiv.parentNode.removeChild(testDiv);
};
module.exports = {
/**
* Check the test div to see if the styles have loaded
*
* @param {string} className - The class name used to check if the css file has loaded yet
* (does not include the '.' out front, just the name)
* @return {boolean} True or false as to whether the style sheet has been loaded.
*/
isCssLoaded: function (className) {
var testDiv = _loadTestDiv(className);
var displayVal;
var result = false;
// add support for IE8
if (!global.getComputedStyle) {
displayVal = testDiv.currentStyle['display'];
}
else {
var computedStyles = global.getComputedStyle(testDiv);
displayVal = computedStyles.getPropertyValue('display');
}
if (displayVal === 'none') {
result = true;
}
_cleanupTestDiv(testDiv);
return result;
}
};