aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jesse Hallett <jesse@galois.com>2013-12-23 16:11:30 -0800
committerGravatar Jesse Hallett <jesse@galois.com>2013-12-23 16:11:30 -0800
commit6d63c61bb97591c0e97f00e606468754f6180b80 (patch)
treec89e3604ae6c747165ebc6ce87ab64228f738888
parent3ce47cad3750be90fc57110bb0a80456bf58dbba (diff)
Wikipedia guideline: do not use inline styles
-rw-r--r--guidelines/wikipedia/inlineStyle.js47
-rw-r--r--guidelines/wikipedia/wikipedia.json1
2 files changed, 48 insertions, 0 deletions
diff --git a/guidelines/wikipedia/inlineStyle.js b/guidelines/wikipedia/inlineStyle.js
new file mode 100644
index 0000000..261586d
--- /dev/null
+++ b/guidelines/wikipedia/inlineStyle.js
@@ -0,0 +1,47 @@
+exports.name = "Do not use in-line styles";
+exports.description = "In-line styles make it much harder for people with specific needs to change the wikimedia styles and to retain consistency.";
+
+exports.rule = function(report) {
+ $5('#mw-content-text [style]').filter(excludes).each(function(i, elem) {
+ report.error("Element contains in-line style rules.", elem);
+ });
+};
+
+function excludes(i, elem) {
+ var $elem = $(elem);
+
+ // Ignore width rules.
+ var widthRule = everyStyle($elem, function(s) {
+ return s === 'width';
+ });
+
+ // It seems that Wikipedia's standard table templates include some
+ // inline styles. Ignore these.
+ var table = $elem.is('table, th, td');
+
+ // The standard reference list template also seems to include some
+ // inline styles.
+ var reference = $elem.hasClass('reflist references-column-width') ||
+ $elem.hasClass('error') ||
+ ($elem.is('.citation ~ * *') && !$.trim($elem.text())); // <span>&nbsp;</span>
+
+ // The [citation needed] template includes a white-space:nowrap style.
+ var citationNeeded = $elem.hasClass('Template-Fact') && everyStyle($elem, function(s) {
+ return s === 'white-space';
+ });
+
+ var navboxPadding = $elem.closest('.navbox').length > 0 && everyStyle($elem, function(s) {
+ return s.slice(0,7) === 'padding';
+ });
+
+ // Ignore hidden microformat fields.
+ var microformat = $elem.css('display') === 'none' &&
+ $elem.closest('.vcard, .vevent').length > 0;
+
+ return !widthRule && !table && !reference && !citationNeeded &&
+ !navboxPadding && !microformat;
+}
+
+function everyStyle($elem, fn) {
+ return Array.prototype.every.call($elem.prop('style'), fn);
+}
diff --git a/guidelines/wikipedia/wikipedia.json b/guidelines/wikipedia/wikipedia.json
index bb36baa..e6030ac 100644
--- a/guidelines/wikipedia/wikipedia.json
+++ b/guidelines/wikipedia/wikipedia.json
@@ -16,5 +16,6 @@
, "spaceBetweenListItems.js"
, "imageAlt.js"
, "imageCaption.js"
+ , "inlineStyle.js"
]
}