From 55cd32bfaf9ed5bc5418751369e46fa1d7f098e8 Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Mon, 6 Jan 2014 10:50:22 -0800 Subject: Moves rule files to src/ --- guidelines/wikipedia/src/floatSandwiches.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 guidelines/wikipedia/src/floatSandwiches.js (limited to 'guidelines/wikipedia/src/floatSandwiches.js') diff --git a/guidelines/wikipedia/src/floatSandwiches.js b/guidelines/wikipedia/src/floatSandwiches.js new file mode 100644 index 0000000..ecdcdba --- /dev/null +++ b/guidelines/wikipedia/src/floatSandwiches.js @@ -0,0 +1,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; + }); +} -- cgit v1.2.3