aboutsummaryrefslogtreecommitdiff
path: root/guidelines/wikipedia/floatSandwiches.js
blob: ecdcdba08a436bdb998df26765ab2eb4cee84874 (plain)
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
exports.name = "Floating content on both sides of screen";
exports.description = "Be careful not to add images or other floating content on both sides of the screen simultaneously.";

exports.rule = function(report) {
  var $topElems = $5('#mw-content-text > *');
  var left      = floating($topElems, 'left').toArray().map($);
  var right     = floating($topElems, 'right').toArray().map($);

  left.forEach(function($l) {
    var ltop    = $l.offset().top;
    var lbottom = ltop + $l.outerHeight();

    if (right.some(function($r) {
      var rtop    = $r.offset().top;
      var rbottom = rtop + $r.outerHeight();

      return (rtop > ltop && rtop < lbottom) ||
        (rbottom > ltop && rbottom < lbottom);
    })) {
      report.warning('Left and right floating elements overlap vertically.', $l.get(0));
    }
  });
};

function floating($elems, leftOrRight) {
  return $elems.filter(function() {
    return $(this).css('float') === leftOrRight;
  });
}