Skip to content

Commit 3cc86a5

Browse files
committed
Added module.exports and removed (almost) all _global
1 parent c187a4b commit 3cc86a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+409
-370
lines changed

Auditor/HTMLCSAuditor.js

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*/
1313

14-
_global.HTMLCSAuditor = new function()
14+
var HTMLCSAuditor = new function()
1515
{
1616
var _prefix = 'HTMLCS-';
1717
var _screen = '';
@@ -151,7 +151,7 @@ _global.HTMLCSAuditor = new function()
151151
var header = _doc.createElement('div');
152152
header.className = _prefix + 'header';
153153
header.innerHTML = 'HTML_CodeSniffer by Squiz';
154-
header.setAttribute('title', _global.HTMLCS.getTranslation("auditor_using_standard") + standard);
154+
header.setAttribute('title', HTMLCS.getTranslation("auditor_using_standard") + standard);
155155

156156
var dragging = false;
157157
var prevX = 0;
@@ -210,7 +210,7 @@ _global.HTMLCSAuditor = new function()
210210

211211
var closeIcon = _doc.createElement('div');
212212
closeIcon.className = _prefix + 'close';
213-
closeIcon.setAttribute('title', _global.HTMLCS.getTranslation("auditor_close"));
213+
closeIcon.setAttribute('title', HTMLCS.getTranslation("auditor_close"));
214214
closeIcon.onmousedown = function() {
215215
self.close.call(self);
216216
};
@@ -245,25 +245,25 @@ _global.HTMLCSAuditor = new function()
245245
var divider = ', &#160;<span class="' + _prefix + 'divider"></span>';
246246

247247
if (errors > 0) {
248-
var typeName = _global.HTMLCS.getTranslation("auditor_errors");
248+
var typeName = HTMLCS.getTranslation("auditor_errors");
249249
if (errors === 1) {
250-
typeName = _global.HTMLCS.getTranslation("auditor_error");
250+
typeName = HTMLCS.getTranslation("auditor_error");
251251
}
252252
leftContents.push('<strong>' + errors + '</strong> ' + typeName);
253253
}
254254

255255
if (warnings > 0) {
256-
var typeName = _global.HTMLCS.getTranslation("auditor_warnings");
256+
var typeName = HTMLCS.getTranslation("auditor_warnings");
257257
if (warnings === 1) {
258-
typeName = _global.HTMLCS.getTranslation("auditor_warning");
258+
typeName = HTMLCS.getTranslation("auditor_warning");
259259
}
260260
leftContents.push('<strong>' + warnings + '</strong> ' + typeName);
261261
}
262262

263263
if (notices > 0) {
264-
var typeName = _global.HTMLCS.getTranslation("auditor_notices");
264+
var typeName = HTMLCS.getTranslation("auditor_notices");
265265
if (notices === 1) {
266-
typeName = _global.HTMLCS.getTranslation("auditor_notice");
266+
typeName = HTMLCS.getTranslation("auditor_notice");
267267
}
268268
leftContents.push('<strong>' + notices + '</strong> ' + typeName);
269269
}
@@ -333,7 +333,7 @@ _global.HTMLCSAuditor = new function()
333333
lineageHomeLink.href = 'javascript:';
334334

335335
var lineageHomeSpan = _doc.createElement('span');
336-
lineageHomeSpan.innerHTML = _global.HTMLCS.getTranslation("auditor_home");
336+
lineageHomeSpan.innerHTML = HTMLCS.getTranslation("auditor_home");
337337
lineageHomeLink.appendChild(lineageHomeSpan);
338338

339339
lineageHomeLink.onmousedown = function() {
@@ -347,8 +347,8 @@ _global.HTMLCSAuditor = new function()
347347
var lineageReportLink = _doc.createElement('a');
348348
lineageReportLink.className = _prefix + 'lineage-link';
349349
lineageReportLink.href = 'javascript:';
350-
lineageReportLink.innerHTML = _global.HTMLCS.getTranslation("auditor_report");
351-
lineageReportLink.setAttribute('title', _global.HTMLCS.getTranslation("auditor_back_to_report"));
350+
lineageReportLink.innerHTML = HTMLCS.getTranslation("auditor_report");
351+
lineageReportLink.setAttribute('title', HTMLCS.getTranslation("auditor_back_to_report"));
352352

353353
lineageReportLink.onmousedown = function() {
354354
var list = _doc.querySelectorAll('.HTMLCS-inner-wrapper')[0];
@@ -363,7 +363,7 @@ _global.HTMLCSAuditor = new function()
363363
// Issue Count item.
364364
var lineageTotalsItem = _doc.createElement('li');
365365
lineageTotalsItem.className = _prefix + 'lineage-item';
366-
lineageTotalsItem.innerHTML = _global.HTMLCS.getTranslation("auditor_issue") + ' ' + issue + ' ' + _global.HTMLCS.getTranslation("auditor_of") + ' ' + totalIssues;
366+
lineageTotalsItem.innerHTML = HTMLCS.getTranslation("auditor_issue") + ' ' + issue + ' ' + HTMLCS.getTranslation("auditor_of") + ' ' + totalIssues;
367367

368368
lineageHomeItem.appendChild(lineageHomeLink);
369369
lineageReportItem.appendChild(lineageReportLink);
@@ -375,7 +375,7 @@ _global.HTMLCSAuditor = new function()
375375
var buttonGroup = _doc.createElement('div');
376376
buttonGroup.className = _prefix + 'button-group';
377377

378-
var prevButton = buildSummaryButton(_prefix + 'button-previous-issue', 'previous', _global.HTMLCS.getTranslation("auditor_previous_issue"), function(target) {
378+
var prevButton = buildSummaryButton(_prefix + 'button-previous-issue', 'previous', HTMLCS.getTranslation("auditor_previous_issue"), function(target) {
379379
var newIssue = Number(issue) - 1;
380380

381381
if (newIssue >= 1) {
@@ -391,7 +391,7 @@ _global.HTMLCSAuditor = new function()
391391
}//end if
392392
});
393393

394-
var nextButton = buildSummaryButton(_prefix + 'button-next-issue', 'next', _global.HTMLCS.getTranslation("auditor_next_issue"), function(target) {
394+
var nextButton = buildSummaryButton(_prefix + 'button-next-issue', 'next', HTMLCS.getTranslation("auditor_next_issue"), function(target) {
395395
var newIssue = Number(issue) + 1;
396396

397397
if (newIssue <= _messages.length) {
@@ -489,7 +489,7 @@ _global.HTMLCSAuditor = new function()
489489
useStandardDiv.id = _prefix + 'settings-use-standard';
490490

491491
var useStandardLabel = _doc.createElement('label');
492-
useStandardLabel.innerHTML = _global.HTMLCS.getTranslation("auditor_standards") + ':';
492+
useStandardLabel.innerHTML = HTMLCS.getTranslation("auditor_standards") + ':';
493493
useStandardLabel.setAttribute('for', _prefix + 'settings-use-standard-select');
494494

495495
var useStandardSelect = _doc.createElement('select');
@@ -519,11 +519,11 @@ _global.HTMLCSAuditor = new function()
519519

520520
var issueCountHelpDiv = _doc.createElement('div');
521521
issueCountHelpDiv.id = _prefix + 'settings-issue-count-help';
522-
issueCountHelpDiv.innerHTML = _global.HTMLCS.getTranslation("auditor_select_types");
522+
issueCountHelpDiv.innerHTML = HTMLCS.getTranslation("auditor_select_types");
523523

524524
var viewReportDiv = _doc.createElement('div');
525525
viewReportDiv.id = _prefix + 'settings-view-report';
526-
viewReportDiv.innerHTML = _global.HTMLCS.getTranslation("auditor_view_report");
526+
viewReportDiv.innerHTML = HTMLCS.getTranslation("auditor_view_report");
527527

528528
viewReportDiv.onclick = function() {
529529
if (/disabled/.test(this.className) === false) {
@@ -576,23 +576,23 @@ _global.HTMLCSAuditor = new function()
576576
levelCountDiv.className = 'HTMLCS-tile-text';
577577

578578
if(level == "error") {
579-
levelName = _global.HTMLCS.getTranslation('auditor_error');
579+
levelName = HTMLCS.getTranslation('auditor_error');
580580
if (msgCount !== 1) {
581-
levelName = _global.HTMLCS.getTranslation('auditor_errors');
581+
levelName = HTMLCS.getTranslation('auditor_errors');
582582
}
583583
}
584584

585585
if(level == "warning") {
586-
levelName = _global.HTMLCS.getTranslation('auditor_warning');
586+
levelName = HTMLCS.getTranslation('auditor_warning');
587587
if (msgCount !== 1) {
588-
levelName = _global.HTMLCS.getTranslation('auditor_warnings');
588+
levelName = HTMLCS.getTranslation('auditor_warnings');
589589
}
590590
}
591591

592592
if(level == "notice") {
593-
levelName = _global.HTMLCS.getTranslation('auditor_notice');
593+
levelName = HTMLCS.getTranslation('auditor_notice');
594594
if (msgCount !== 1) {
595-
levelName = _global.HTMLCS.getTranslation('auditor_notices');
595+
levelName = HTMLCS.getTranslation('auditor_notices');
596596
}
597597
}
598598
var content = '<strong>' + msgCount + '</strong> ' + levelName;
@@ -822,20 +822,20 @@ _global.HTMLCSAuditor = new function()
822822

823823
var msgElementSourceInner = _doc.createElement('div');
824824
msgElementSourceInner.className = _prefix + 'issue-source-inner-u2p';
825-
var msg = _global.HTMLCS.getTranslation('auditor_unable_to_point');
825+
var msg = HTMLCS.getTranslation('auditor_unable_to_point');
826826

827827
if (message.element.nodeName === '#document') {
828-
msg = _global.HTMLCS.getTranslation('auditor_applies_entire_document');
828+
msg = HTMLCS.getTranslation('auditor_applies_entire_document');
829829
} else if (message.element.ownerDocument === null) {
830-
msg = _global.HTMLCS.getTranslation('auditor_unable_to_point_removed');
830+
msg = HTMLCS.getTranslation('auditor_unable_to_point_removed');
831831
} else {
832832
var body = message.element.ownerDocument.getElementsByTagName('body')[0];
833833
if (HTMLCS.util.isInDocument(message.element) === false) {
834-
msg += _global.HTMLCS.getTranslation('auditor_unable_to_point_entire');
834+
msg += HTMLCS.getTranslation('auditor_unable_to_point_entire');
835835
} else if (HTMLCS.util.contains(body, message.element) === false) {
836-
msg = _global.HTMLCS.getTranslation('auditor_unable_to_point_outside');
836+
msg = HTMLCS.getTranslation('auditor_unable_to_point_outside');
837837
} else {
838-
msg += ' ' + _global.HTMLCS.getTranslation('auditor_unable_to_point_outside');
838+
msg += ' ' + HTMLCS.getTranslation('auditor_unable_to_point_outside');
839839
}
840840
}
841841

@@ -865,9 +865,9 @@ _global.HTMLCSAuditor = new function()
865865
msgElementSourceHeader.className = _prefix + 'issue-source-header';
866866

867867
var msgSourceHeaderText = _doc.createElement('strong');
868-
msgSourceHeaderText.innerHTML = _global.HTMLCS.getTranslation("auditor_code_snippet");
868+
msgSourceHeaderText.innerHTML = HTMLCS.getTranslation("auditor_code_snippet");
869869

870-
var btnPointTo = buildSummaryButton(_prefix + 'button-point-to-element-' + id, 'pointer', _global.HTMLCS.getTranslation("auditor_point_to_element"), function() {
870+
var btnPointTo = buildSummaryButton(_prefix + 'button-point-to-element-' + id, 'pointer', HTMLCS.getTranslation("auditor_point_to_element"), function() {
871871
self.pointToElement(message.element);
872872
});
873873

@@ -960,7 +960,7 @@ _global.HTMLCSAuditor = new function()
960960
var msgElementSourceInner = _doc.createElement('div');
961961
msgElementSourceInner.className = _prefix + 'issue-source-not-supported';
962962

963-
var nsText = _global.HTMLCS.getTranslation('auditor_unsupported_browser');
963+
var nsText = HTMLCS.getTranslation('auditor_unsupported_browser');
964964

965965
msgElementSourceInner.appendChild(_doc.createTextNode(nsText));
966966
msgElementSource.appendChild(msgElementSourceInner);
@@ -989,7 +989,7 @@ _global.HTMLCSAuditor = new function()
989989
var pageNum = _doc.createElement('span');
990990
pageNum.className = _prefix + 'page-number';
991991
// pageNum.innerHTML = 'Page ' + page + ' of ' + totalPages;
992-
pageNum.innerHTML = _global.HTMLCS.getTranslation("auditor_page") + ' ' + page + ' ' + _global.HTMLCS.getTranslation("auditor_of") + ' ' + totalPages;
992+
pageNum.innerHTML = HTMLCS.getTranslation("auditor_page") + ' ' + page + ' ' + HTMLCS.getTranslation("auditor_of") + ' ' + totalPages;
993993
navDiv.appendChild(pageNum);
994994

995995
var next = _doc.createElement('span');
@@ -1015,7 +1015,7 @@ _global.HTMLCSAuditor = new function()
10151015
}
10161016

10171017
pageNum.innerHTML = '';
1018-
pageNum.appendChild(document.createTextNode(_global.HTMLCS.getTranslation("auditor_page") + ' ' + _page + ' ' + _global.HTMLCS.getTranslation("auditor_of") + ' ' + totalPages));
1018+
pageNum.appendChild(document.createTextNode(HTMLCS.getTranslation("auditor_page") + ' ' + _page + ' ' + HTMLCS.getTranslation("auditor_of") + ' ' + totalPages));
10191019

10201020
var issueList = _doc.querySelectorAll('.HTMLCS-issue-list')[0];
10211021
issueList.style.marginLeft = ((_page - 1) * -300) + 'px';
@@ -1034,7 +1034,7 @@ _global.HTMLCSAuditor = new function()
10341034
}
10351035

10361036
pageNum.innerHTML = '';
1037-
pageNum.appendChild(document.createTextNode(_global.HTMLCS.getTranslation("auditor_page") + ' ' + _page + ' ' + _global.HTMLCS.getTranslation("auditor_of") + ' ' + totalPages));
1037+
pageNum.appendChild(document.createTextNode(HTMLCS.getTranslation("auditor_page") + ' ' + _page + ' ' + HTMLCS.getTranslation("auditor_of") + ' ' + totalPages));
10381038

10391039
var issueList = _doc.querySelectorAll('.HTMLCS-issue-list')[0];
10401040
issueList.style.marginLeft = ((_page - 1) * -300) + 'px';
@@ -2189,3 +2189,5 @@ _global.HTMLCSAuditor = new function()
21892189
};
21902190

21912191
};
2192+
2193+
module.exports.HTMLCSAuditor = HTMLCSAuditor;

Gruntfile.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function (grunt) {
1616
footer: grunt.file.read('Contrib/Build/umd-footer.js')
1717
},
1818
files: {
19-
'build/HTMLCS.js': ['Translations/*.js', 'Standards/**/*.js', 'HTMLCS.js', 'HTMLCS.Util.js', 'Contrib/PhantomJS/runner.js', 'Auditor/HTMLCSAuditor.js']
19+
'build/HTMLCS.js': ['Translations/*.js', 'Standards/all.js', 'HTMLCS.js', 'HTMLCS.Util.js', 'Contrib/PhantomJS/runner.js', 'Auditor/HTMLCSAuditor.js']
2020
}
2121
},
2222
dist: {
@@ -25,7 +25,7 @@ module.exports = function (grunt) {
2525
footer: grunt.file.read('Contrib/Build/umd-footer.js')
2626
},
2727
files: {
28-
'build/HTMLCS.js': ['Translations/*.js', 'Standards/**/*.js', 'HTMLCS.js', 'HTMLCS.Util.js', 'Contrib/PhantomJS/runner.js', 'Auditor/HTMLCSAuditor.js']
28+
'build/HTMLCS.js': ['Translations/*.js', 'Standards/all.js', 'HTMLCS.js', 'HTMLCS.Util.js', 'Contrib/PhantomJS/runner.js', 'Auditor/HTMLCSAuditor.js']
2929
}
3030
},
3131
bookmarklet: {
@@ -34,7 +34,7 @@ module.exports = function (grunt) {
3434
footer: grunt.file.read('Contrib/Build/umd-footer.js')
3535
},
3636
files: {
37-
'build/HTMLCS.js': ['Translations/*.js', 'Standards/**/*.js', 'HTMLCS.js', 'HTMLCS.Util.js', 'Contrib/PhantomJS/runner.js', 'Auditor/Auditor_with_beacon.js']
37+
'build/HTMLCS.js': ['Translations/*.js', 'Standards/all.js', 'HTMLCS.js', 'HTMLCS.Util.js', 'Contrib/PhantomJS/runner.js', 'Auditor/Auditor_with_beacon.js']
3838
}
3939
}
4040
},
@@ -72,8 +72,24 @@ module.exports = function (grunt) {
7272
require('load-grunt-tasks')(grunt);
7373

7474
grunt.registerTask('default', ['eslint']);
75-
grunt.registerTask('build', ['uglify:dist', 'copy:dist']);
76-
grunt.registerTask('build-bookmarklet', ['uglify:bookmarklet', 'copy:dist']);
75+
grunt.registerTask('build', ['exportVars', 'uglify:dist', 'copy:dist']);
76+
grunt.registerTask('build-bookmarklet', ['exportVars', 'uglify:bookmarklet', 'copy:dist']);
7777

78-
return grunt.registerTask('build-debug', ['uglify:debug', 'copy:dist']);
78+
grunt.registerTask('exportVars', function() {
79+
var catted = '';
80+
81+
grunt.file.expand({ filter: 'isFile' }, 'Standards/WCAG2AAA/**/**/**/*.js')
82+
.forEach(function(file) {
83+
catted += grunt.file.read(file) + '\n';
84+
var parts = file.split("/"),
85+
varName = "HTMLCS_" + parts.slice(1).join('_').replace(/[.]js$/, "");
86+
if(varName.match(/_ruleset$/))
87+
varName = varName.replace(/_ruleset$/, "");
88+
catted += "module.exports." + varName + " = " + varName + ";\n";
89+
}
90+
);
91+
grunt.file.write('Standards/all.js', catted, { encoding: 'utf8' })
92+
});
93+
94+
return grunt.registerTask('build-debug', ['exportVars', 'uglify:debug', 'copy:dist']);
7995
};

HTMLCS.Util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* +--------------------------------------------------------------------+
1111
*
1212
*/
13-
_global.HTMLCS.util = function() {
13+
HTMLCS.util = function() {
1414
var self = {};
1515

1616
/**

HTMLCS.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
*
1212
*/
1313

14-
_global.HTMLCS = new function()
14+
var HTMLCS = new function()
1515
{
16+
var translation = _global.translation;
1617
var _standards = {};
1718
var _sniffs = [];
1819
var _tags = {};
@@ -32,6 +33,18 @@ _global.HTMLCS = new function()
3233
// The current language to use.
3334
this.lang = 'en';
3435

36+
this.setCurrentSniff = function( sniff ){
37+
_currentSniff = sniff;
38+
};
39+
40+
this.setStandard = function( standard ){
41+
_standard = standard;
42+
};
43+
44+
this.setCurrentGuideLine = function( guideline ){
45+
46+
};
47+
3548
/**
3649
* Loads the specified standard and run the sniffs.
3750
*
@@ -59,7 +72,7 @@ _global.HTMLCS = new function()
5972
}
6073

6174
// Set a language to use.
62-
var languages = Object.keys(_global.translation);
75+
var languages = Object.keys(translation);
6376
if (language && languages.indexOf(language) !== -1) {
6477
this.lang = language;
6578
}
@@ -628,3 +641,5 @@ _global.HTMLCS = new function()
628641
}
629642
};
630643
};
644+
645+
module.exports.HTMLCS = HTMLCS;

Standards/Section508/Sniffs/A.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*/
1313

14-
_global.HTMLCS_Section508_Sniffs_A = {
14+
var HTMLCS_Section508_Sniffs_A = {
1515
/**
1616
* Determines the elements to register for processing.
1717
*

Standards/Section508/Sniffs/B.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*/
1313

14-
_global.HTMLCS_Section508_Sniffs_B = {
14+
var HTMLCS_Section508_Sniffs_B = {
1515
/**
1616
* Determines the elements to register for processing.
1717
*

Standards/Section508/Sniffs/C.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*/
1313

14-
_global.HTMLCS_Section508_Sniffs_C = {
14+
var HTMLCS_Section508_Sniffs_C = {
1515
/**
1616
* Determines the elements to register for processing.
1717
*

Standards/Section508/Sniffs/D.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*/
1313

14-
_global.HTMLCS_Section508_Sniffs_D = {
14+
var HTMLCS_Section508_Sniffs_D = {
1515
/**
1616
* Determines the elements to register for processing.
1717
*
@@ -57,7 +57,7 @@ _global.HTMLCS_Section508_Sniffs_D = {
5757
*/
5858
testPresentationMarkup: function(top)
5959
{
60-
_global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1.testPresentationMarkup(top);
60+
HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1.testPresentationMarkup(top);
6161
},
6262

6363
testHeadingOrder: function(top) {

0 commit comments

Comments
 (0)