Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Change some variable names, optimize row generation.
  • Loading branch information
conzett committed Feb 3, 2012
1 parent 21246ac commit 20eebbb
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions grid-checker.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
var gridChecker = function (ColumnWidth, ColumnMargin, LineHeight, InnerPadding, Target) {
var gridChecker = function (ColumnWidth, ColumnMargin, RowHeight, InnerPadding, Target) {
'use strict';

var container,
column,
inner,
line,
row,
s,
i,
t,
columnNumber,
lineNumber,
rowNumber,
rowContainer,
target = document.getElementById(Target) || document.getElementsByTagName('body')[0];

columnNumber = parseInt(target.offsetWidth / (ColumnWidth + ColumnMargin), 10);
lineNumber = parseInt(window.innerHeight / LineHeight, 10);
rowNumber = parseInt(window.innerHeight / RowHeight, 10);

s = 'height: 100%;';
s += 'position: absolute;';
Expand Down Expand Up @@ -54,22 +55,26 @@ var gridChecker = function (ColumnWidth, ColumnMargin, LineHeight, InnerPadding,

s = "position: absolute;";
s += 'width: 100%;';
s += 'height: ' + LineHeight + 'px;';
s += 'z-index: 90;';
s += 'opacity: .2;';
s += 'filter:alpha(opacity=20);';

for (i = 0; i < lineNumber; i += 1) {
line = document.createElement('div');
line.className = "gc-row";
t = s;
t += 'top: ' + (i * LineHeight) + 'px;';
t += 'background-color: ';
rowContainer = document.createElement('div');
rowContainer.setAttribute('class', 'gc-row-container');
rowContainer.setAttribute('style', s);

s = 'height: ' + RowHeight + 'px;';

row = document.createElement('div');
row.className = "gc-row";

for (i = 0; i < rowNumber; i += 1) {
t = s + 'background-color: ';
t += (i % 2 === 0) ? 'blue' : 'white';
t += ';';
line.setAttribute('style', t);
container.appendChild(line.cloneNode(true));
row.setAttribute('style', t);
rowContainer.appendChild(row.cloneNode(true));
}

container.appendChild(rowContainer);
target.appendChild(container);
};

0 comments on commit 20eebbb

Please sign in to comment.