diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..2cb7d2a2 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +**/*.js diff --git a/Auditor/HTMLCSAuditor.css b/Auditor/HTMLCSAuditor.css index df76c8d0..d5f4ab54 100644 --- a/Auditor/HTMLCSAuditor.css +++ b/Auditor/HTMLCSAuditor.css @@ -219,6 +219,13 @@ #HTMLCS-wrapper .HTMLCS-summary-right { text-align: right; + color: #000; + font-size: 1.35em; + line-height: 2.1em; + text-overflow: ellipsis; + text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3); + white-space: nowrap; + cursor: pointer; } #HTMLCS-wrapper .HTMLCS-outer-wrapper { @@ -902,6 +909,49 @@ opacity: 0.4; } + + +#HTMLCS-wrapper #HTMLCS-settings-download { + background-color: #3A3940; + border: 1px solid #2B2B2B; + border-radius: 0.3em 0.3em 0.3em 0.3em; + box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 0 rgba(255, 255, 255, 0.15), 0 -1.4em 1.6em rgba(0, 0, 0, 0.4) inset; + color: #FFF; + cursor: pointer; + font-size: 1.9em; + line-height: 3em; + position: relative; + text-shadow: 0 -1px 0 #000; + -moz-transition: opacity 0.3s ease; + -webkit-transition: opacity 0.3s ease; + opacity: 1; + text-align: center; +} + +#HTMLCS-wrapper #HTMLCS-settings-download:after { + background: url("Images/HTMLCS-tools.png") no-repeat scroll 0 -108px transparent; + content: ""; + height: 14px; + margin-top: -7px; + position: absolute; + right: 1em; + top: 50%; + width: 9px; +} + +#HTMLCS-wrapper #HTMLCS-settings-download:hover { + background-color: #2B2B2B; +} + +#HTMLCS-wrapper.HTMLCS-processing #HTMLCS-settings-download, +#HTMLCS-wrapper #HTMLCS-settings-download.disabled { + cursor: default; + filter: alpha(opacity=40); + opacity: 0.4; +} + + + #HTMLCS-wrapper .HTMLCS-button.disabled { cursor: default; filter: alpha(opacity=30); diff --git a/Auditor/HTMLCSAuditor.js b/Auditor/HTMLCSAuditor.js index 331ecc2c..a5bd5c6c 100644 --- a/Auditor/HTMLCSAuditor.js +++ b/Auditor/HTMLCSAuditor.js @@ -230,6 +230,7 @@ _global.HTMLCSAuditor = new function() var rightPane = _doc.createElement('div'); rightPane.className = _prefix + 'summary-right'; + rightPane.onclick = _global.downloadHTMLCS; summary.appendChild(rightPane); var leftContents = []; @@ -290,7 +291,7 @@ _global.HTMLCSAuditor = new function() lineage.appendChild(lineageTotalsItem); leftPane.appendChild(lineage); - rightPane.appendChild(_doc.createTextNode(String.fromCharCode(160))); + rightPane.appendChild(_doc.createTextNode('CSV')); return summary; }; diff --git a/HTMLCS.Util.js b/HTMLCS.Util.js index ddc1c13a..32678068 100644 --- a/HTMLCS.Util.js +++ b/HTMLCS.Util.js @@ -13,6 +13,13 @@ _global.HTMLCS.util = function() { var self = {}; + /** + * Work around a bug in FileSaver.js + * + * https://github.com/eligrey/FileSaver.js/issues/475 + */ + window.module = window.module || {}; + /** * Trim off excess spaces on either side. * diff --git a/HTMLCS.js b/HTMLCS.js index cb75a5c0..8dea7119 100755 --- a/HTMLCS.js +++ b/HTMLCS.js @@ -11,6 +11,45 @@ * */ + + /** + * Runs the sniffs and downloads the results to a text file + * + */ +_global.downloadHTMLCS = function () { + + function q(s) { + return '"' + (s || "").toString().replace(/"/g, '""') + '"'; + } + + function elementToString(element) { + if(!element) { + return ""; + } + var html = element.outerHTML; + if (!html) { + return ""; + } + if (html.length > 100) { + return html.substring(0, 100) + "..."; + } + return html; + } + + HTMLCS.run(function() { + + var header = '"Type", Code","Message","Element","Data"'; + var body = this.getMessages().map(function (m) { + return [m.type, q(m.code), q(m.msg), q(elementToString(m.element)), q(m.data)].join(",") + }).join("\n"); + var csvContents = header + "\n" + body; + + var filename = "HTML_Codesniffer" + Math.random() + ".csv"; + + saveAs(new Blob([csvContents], { type: "text/plain;charset=utf-8" }), filename); + }) +} + _global.HTMLCS = new function() { var _standards = {}; @@ -22,8 +61,9 @@ _global.HTMLCS = new function() var _messages = []; var _msgOverrides = {}; + /* - Message type constants. + Message type constants. */ this.ERROR = 1; this.WARNING = 2; @@ -243,6 +283,7 @@ _global.HTMLCS = new function() * @returns {Array} Array of message objects. */ this.getMessages = function() { + return _messages.concat([]); }; diff --git a/Translations/en.js b/Translations/en.js index 7665513c..65175751 100644 --- a/Translations/en.js +++ b/Translations/en.js @@ -9,6 +9,7 @@ _global.translation['en'] = { ,"auditor_select_types" : 'Select the types of issues to include in the report' ,"auditor_home" : 'Home' ,"auditor_view_report" : 'View Report' + ,"auditor_download_report": 'Download Report' ,"auditor_report" : 'Report' ,"auditor_back_to_report" : 'Back to Report' ,"auditor_previous_issue" : 'Previous Issue' diff --git a/gruntfile.coffee b/gruntfile.coffee index 8ed1e277..e7163430 100644 --- a/gruntfile.coffee +++ b/gruntfile.coffee @@ -27,7 +27,8 @@ module.exports = (grunt)-> 'HTMLCS.js' 'HTMLCS.Util.js' 'Contrib/PhantomJS/runner.js' - 'Auditor/HTMLCSAuditor.js' + 'Auditor/HTMLCSAuditor.js', + 'node_modules/file-saver/dist/FileSaver.js' ] dist: options: @@ -40,7 +41,8 @@ module.exports = (grunt)-> 'HTMLCS.js' 'HTMLCS.Util.js' 'Contrib/PhantomJS/runner.js' - 'Auditor/HTMLCSAuditor.js' + 'Auditor/HTMLCSAuditor.js', + 'node_modules/file-saver/dist/FileSaver.js' ], bookmarklet: options: @@ -53,7 +55,8 @@ module.exports = (grunt)-> 'HTMLCS.js' 'HTMLCS.Util.js' 'Contrib/PhantomJS/runner.js' - 'Auditor/Auditor_with_beacon.js' + 'Auditor/Auditor_with_beacon.js', + 'node_modules/file-saver/dist/FileSaver.js' ], copy: diff --git a/package.json b/package.json index 07ee319c..a4be1d18 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ }, "homepage": "http://squizlabs.github.io/HTML_CodeSniffer/", "dependencies": { + "file-saver": "^2.0.0-rc.3", "grunt": "^1.0.0", "grunt-contrib-copy": "^1.0.0", "grunt-contrib-jshint": "^1.0.0", @@ -28,4 +29,4 @@ "devDependencies": { "grunt-contrib-uglify": "^2.3.0" } -} \ No newline at end of file +}