Skip to content

Commit

Permalink
Fixed bug with image stats
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJaredWilcurt committed Mar 6, 2017
1 parent 5431c9e commit 4f007de
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 46 deletions.
82 changes: 41 additions & 41 deletions _scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function runApp () {

var fs = require('fs-extra');
var path = require('path');
var stat = require('folder-stat');
var base64Img = require('base64-img');
var appData = nw.App.dataPath;
var temp = path.join(appData, 'temp');
Expand Down Expand Up @@ -427,60 +426,61 @@ function runApp () {

$('#imageAltsModal .modal-footer .btn').click(function () {
if (!$(this).hasClass('disabled')) {
$('#imageAltsModal').slideUp('slow');

var allData = JSON.parse($('#imagealts').val());

var imagesWithDescriptiveAltText = 0;
var altTagsUnder100Characters = 0;
var totalImages = window.imgAltsParsed.length;
var imagesUnder100KB = 0;
var totalFileSizeInBytes = 0;
var imagesLoaded = 0;

window.confirmedImages.forEach(function (img) {
if (img) {
imagesWithDescriptiveAltText = imagesWithDescriptiveAltText + 1;
}
});

var altTagsUnder100Characters = 0;
allData.forEach(function (img) {
if (img.alt.length <= 100) {
altTagsUnder100Characters = altTagsUnder100Characters + 1;
for (var i = 0, len = window.imgAltsParsed.length; i < len; i++) {
window.imgAltsParsed[i].size = 0;
var imgPath = window.imgAltsParsed[i].path;
var imgAlt = window.imgAltsParsed[i].alt;

if (imgPath && imgPath.length > 1) {
window.imgAltsParsed[i].size = fs.statSync(imgPath).size;
}
});

var imagesUnder100KB = 0;
var totalFileSizeInBytes = 0;
var imagesLoaded = 0;
var size = window.imgAltsParsed[i].size;

stat(path.join(nw.App.dataPath, 'temp'), function (err, stats, files) {
if (err) {
// eslint-disable-next-line no-console
console.log(err);
if (size <= (100 * 1024)) {
imagesUnder100KB = imagesUnder100KB + 1;
}
if (stats) {
stats.forEach(function (file) {
if (file.size <= (100 * 1024)) {
imagesUnder100KB = imagesUnder100KB + 1;
}
totalFileSizeInBytes = totalFileSizeInBytes + file.size;
});
imagesLoaded = files.length;
totalFileSizeInBytes = totalFileSizeInBytes + size;

if (size > 0) {
imagesLoaded = imagesLoaded + 1;
}

window.imageStats = {
'totalImages': allData.length,
'descriptive': imagesWithDescriptiveAltText,
'nondescriptive': allData.length - imagesWithDescriptiveAltText,
'under100Char': altTagsUnder100Characters,
'under100KB': imagesUnder100KB,
'imagesLoaded': imagesLoaded,
'totalFileSizeInBytes': totalFileSizeInBytes,
'totalFileSizeInKB': Math.round((totalFileSizeInBytes / 1024) * 10) / 10,
'descriptivePercent': Math.round((imagesWithDescriptiveAltText / allData.length) * 100),
'under100CharPercent': Math.round((altTagsUnder100Characters / allData.length) * 100),
'under100KBPercent': Math.round((imagesUnder100KB / allData.length) * 100),
'imagesLoadedPercent': Math.round((imagesLoaded / allData.length) * 100)
};
if (imgAlt.length <= 100) {
altTagsUnder100Characters = altTagsUnder100Characters + 1;
}
}

runPa11y();
});
window.imageStats = {
'totalImages': totalImages,
'descriptive': imagesWithDescriptiveAltText,
'nondescriptive': totalImages - imagesWithDescriptiveAltText,
'under100Char': altTagsUnder100Characters,
'under100KB': imagesUnder100KB,
'imagesLoaded': imagesLoaded,
'totalFileSizeInBytes': totalFileSizeInBytes,
'totalFileSizeInKB': Math.round((totalFileSizeInBytes / 1024) * 10) / 10,
'descriptivePercent': Math.round((imagesWithDescriptiveAltText / totalImages) * 100),
'under100CharPercent': Math.round((altTagsUnder100Characters / totalImages) * 100),
'under100KBPercent': Math.round((imagesUnder100KB / totalImages) * 100),
'imagesLoadedPercent': Math.round((imagesLoaded / totalImages) * 100)
};

$('#imageAltsModal').slideUp('slow');
runPa11y();
}
});

Expand Down
10 changes: 6 additions & 4 deletions index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,12 @@ <h3 class="panel-title">About <span class="applicationTitle">Koa11y</span></h3>
This program will load an invisible (headless) browser and go to the URL you've supplied to test the page for accessibility issues. Then it outputs any issues to a file.
</p>
<p>
<span class="applicationTitle">Koa11y</span> created by <span class="authorName">The Jared Wilcurt</span><br />
<a href="http://thejaredwilcurt.github.io/Koa11y" class="external-link">Visit the Koa11y website.</a><br />
For more information visit: <a href="http://pa11y.org" class="external-link">Pa11y.org</a>.<br />
Koala Logo designed by <a href="mailto:[email protected]" title="[email protected]" class="external-link">Charlotte Schmidt</a>.
<span class="applicationTitle">Koa11y</span> was created by The Jared Wilcurt.<br />
Koa11y uses Pa11y under the hood to automate checking your page for issues. For more information visit: <a href="http://pa11y.org" class="external-link">Pa11y.org</a>.<br />
Koala Logo designed by <a href="mailto:[email protected]" title="[email protected]" class="external-link">Charlotte Schmidt</a>.<br /><br />
<div class="text-center">
<a href="http://thejaredwilcurt.github.io/Koa11y" class="external-link">Visit the Koa11y website.</a>
</div>
</p>
</div>

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"pa11y": "4.1.1",
"phantomjs-prebuilt": "^2.1.14",
"json2csv": "3.7.3",
"folder-stat": "^1.0.1",
"base64-img": "^1.0.3",
"fs-extra": "^0.30.x",
"semver": "^5.3.x"
Expand Down

0 comments on commit 4f007de

Please sign in to comment.