-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsameWidth.js
48 lines (40 loc) · 1.24 KB
/
sameWidth.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
"use strict";
var LayoutQueue = require('layout-queue');
var SameWidth = (function () {
function getBiggestWidth(selector) {
var biggestWidth = 0;
[].forEach.call(document.querySelectorAll(selector), function(element) {
if (element.clientWidth > biggestWidth) {
biggestWidth = element.clientWidth;
}
});
return biggestWidth;
}
function enqueue(selector) {
LayoutQueue.add(unsetWidths, [selector]);
LayoutQueue.add(setWidths, [selector]);
}
function setWidths(selector) {
var biggestWidth = getBiggestWidth(selector);
[].forEach.call(document.querySelectorAll(selector), function(element) {
element.style.width = biggestWidth + 'px';
});
}
function unsetWidths(selector) {
[].forEach.call(document.querySelectorAll(selector), function(element) {
element.style.width = "auto";
});
}
return {
init: function (selector) {
enqueue(selector);
},
set: function (selector) {
setWidths (selector);
},
unset: function (selector) {
unsetWidths(selector);
}
}
})();
module.exports = SameWidth;