aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jesse Hallett <jesse@galois.com>2013-12-19 14:51:58 -0800
committerGravatar Jesse Hallett <jesse@galois.com>2013-12-19 14:51:58 -0800
commitd7671a0d58824bcc421e89e8b4323f92fe00e6df (patch)
tree4acb86e4f4b6c93f954cd24109da3df6f52d4888
parent2f26ce9d6d06e92fdd10249e6b61d7c73122d572 (diff)
Wikipedia guideline: checks for floating content on both sides of screen
-rw-r--r--guidelines/wikipedia/floatSandwiches.js29
-rw-r--r--guidelines/wikipedia/wikipedia.json1
2 files changed, 30 insertions, 0 deletions
diff --git a/guidelines/wikipedia/floatSandwiches.js b/guidelines/wikipedia/floatSandwiches.js
new file mode 100644
index 0000000..ecdcdba
--- /dev/null
+++ b/guidelines/wikipedia/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;
+ });
+}
diff --git a/guidelines/wikipedia/wikipedia.json b/guidelines/wikipedia/wikipedia.json
index 67adf30..a2b24bc 100644
--- a/guidelines/wikipedia/wikipedia.json
+++ b/guidelines/wikipedia/wikipedia.json
@@ -11,5 +11,6 @@
, "imageSize.js"
, "horizontalRule.js"
, "pseudoHeadings.js"
+ , "floatSandwiches.js"
]
}