Browse files

IE7 compat

  • Loading branch information...
1 parent 69363d2 commit 73c7c9d015807e46aef61b1e743999ab58578173 @ndp committed Sep 28, 2010
Showing with 51 additions and 34 deletions.
  1. +8 −6 csster.js
  2. +36 −23 spec/core_spec.js
  3. +1 −1 src/core.js
  4. +6 −4 src/functions/color.js
View
14 csster.js
@@ -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) {
@@ -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]));
}
@@ -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];
}
@@ -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);
View
59 spec/core_spec.js
@@ -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);
+ });
});
});
+
});
+
});
View
2 src/core.js
@@ -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]));
}
View
10 src/functions/color.js
@@ -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];
}
@@ -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);

0 comments on commit 73c7c9d

Please sign in to comment.