Skip to content

Commit

Permalink
IE7 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
ndp committed Sep 28, 2010
1 parent 69363d2 commit 73c7c9d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 34 deletions.
14 changes: 8 additions & 6 deletions csster.js
Expand Up @@ -4,7 +4,7 @@
//
// See http://github.com/ndp/csster
//
// Generated Mon Sep 27 23:40:59 PDT 2010
// Generated Tue Sep 28 09:31:33 PDT 2010
//
//
function isArray(object) {
Expand Down Expand Up @@ -396,7 +396,7 @@ Csster.formatSelectorAndProperties = function(selector, properties) {

var subs = p.split(',');
for (var s = 0; s < subs.length; s++) {
subs[s] = selector + (subs[s][0] == '&' ? subs[s].substr(1) : ' ' + subs[s]);
subs[s] = selector + ((subs[s].substr(0,1) == '&') ? subs[s].substr(1) : ' ' + subs[s]);
}
rules.push(Csster.formatSelectorAndProperties(subs.join(','), properties[p]));
}
Expand Down Expand Up @@ -656,10 +656,12 @@ function verticalCentering(height) {
};

String.prototype.toHexColor = function() {
if (this[0] == '#' && this.length == 7) {
if (this.substr(0, 1) == '#' && this.length == 7) {
colorCache(this)['hex'] = '' + this;
} else if (this[0] == '#' && this.length == 4) {
colorCache(this)['hex'] = '#' + this[1] + this[1] + this[2] + this[2] + this[3] + this[3];
} else if (this.substr(0, 1) == '#' && this.length == 4) {
colorCache(this)['hex'] = '#' + this.substr(1, 1) + this.substr(1, 1) +
this.substr(2, 1) + this.substr(2, 1) +
this.substr(3, 1) + this.substr(3, 1);
} else {
colorCache(this)['hex'] = HTML4_COLORS[this];
}
Expand Down Expand Up @@ -786,7 +788,7 @@ function verticalCentering(height) {
function hex2(n) {
var h = Math.round(n).toString(16);
if (h.length == 1) h = '0' + h;
return h[0] + h[1];
return h.substr(0, 1) + h.substr(1, 1);
}

var rgb = hsl2rgb(h, s, l);
Expand Down
59 changes: 36 additions & 23 deletions spec/core_spec.js
Expand Up @@ -190,41 +190,54 @@ describe("Csster", function() {

});

describe('#insertStyleElement', function() {
var originalWidth;
describe("Everything together", function() {
var logo;
beforeEach(function() {
originalWidth = document.getElementsByClassName('logo')[0].clientWidth;
});
it('should have no element style overrides for width', function() {
expect(document.getElementsByClassName('logo')[0].style.width).toEqual('');
var divs = document.getElementsByTagName('DIV');
for (var i = 0; i<divs.length; i++) {
if (divs[i].className == 'logo') {
logo = divs[i];
}
}
});
describe('inserting the stylesheet', function() {
describe('#insertStyleElement', function() {
var originalWidth;
beforeEach(function() {
Csster.insertStylesheet([{sel:'.logo',props:'font-size: 150%;'}]);
originalWidth = logo.clientWidth;
});
it('should have no element style overrides for width', function() {
expect(logo.style.width).toEqual('');
});
it('should now be wider', function() {
expect(document.getElementsByClassName('logo')[0].clientWidth).toBeGreaterThan(originalWidth);
describe('inserting the stylesheet', function() {
beforeEach(function() {
Csster.insertStylesheet([{sel:'.logo',props:'font-size: 150%;'}]);
});
it('should now be wider', function() {
expect(logo.clientWidth).toBeGreaterThan(originalWidth);
});
});
});
});

describe('#style', function() {
var originalWidth;
beforeEach(function() {
originalWidth = document.getElementsByClassName('logo')[0].clientWidth;
});
it('should have no element style overrides for width', function() {
expect(document.getElementsByClassName('logo')[0].style.width).toEqual('');
});
describe('inserting the stylesheet', function() {
describe('#style', function() {
var originalWidth;
beforeEach(function() {
Csster.style({'.logo': { fontSize: '75%'}});
originalWidth = logo.clientWidth;
});
it('should have no element style overrides for width', function() {
expect(logo.style.width).toEqual('');
});
it('should now be wider', function() {
expect(document.getElementsByClassName('logo')[0].clientWidth).toBeLessThan(originalWidth);
describe('inserting the stylesheet', function() {
beforeEach(function() {
Csster.style({'.logo': { fontSize: '75%'}});
});
it('should now be wider', function() {
expect(logo.clientWidth).toBeLessThan(originalWidth);
});
});
});

});



});
2 changes: 1 addition & 1 deletion src/core.js
Expand Up @@ -348,7 +348,7 @@ Csster.formatSelectorAndProperties = function(selector, properties) {

var subs = p.split(',');
for (var s = 0; s < subs.length; s++) {
subs[s] = selector + (subs[s][0] == '&' ? subs[s].substr(1) : ' ' + subs[s]);
subs[s] = selector + ((subs[s].substr(0,1) == '&') ? subs[s].substr(1) : ' ' + subs[s]);
}
rules.push(Csster.formatSelectorAndProperties(subs.join(','), properties[p]));
}
Expand Down
10 changes: 6 additions & 4 deletions src/functions/color.js
Expand Up @@ -33,10 +33,12 @@
};

String.prototype.toHexColor = function() {
if (this[0] == '#' && this.length == 7) {
if (this.substr(0, 1) == '#' && this.length == 7) {
colorCache(this)['hex'] = '' + this;
} else if (this[0] == '#' && this.length == 4) {
colorCache(this)['hex'] = '#' + this[1] + this[1] + this[2] + this[2] + this[3] + this[3];
} else if (this.substr(0, 1) == '#' && this.length == 4) {
colorCache(this)['hex'] = '#' + this.substr(1, 1) + this.substr(1, 1) +
this.substr(2, 1) + this.substr(2, 1) +
this.substr(3, 1) + this.substr(3, 1);
} else {
colorCache(this)['hex'] = HTML4_COLORS[this];
}
Expand Down Expand Up @@ -163,7 +165,7 @@
function hex2(n) {
var h = Math.round(n).toString(16);
if (h.length == 1) h = '0' + h;
return h[0] + h[1];
return h.substr(0, 1) + h.substr(1, 1);
}

var rgb = hsl2rgb(h, s, l);
Expand Down

0 comments on commit 73c7c9d

Please sign in to comment.