Welcome to the adventure

Creating new CSS stylesheets with Javascript

Friday April 27, 2007

This isn’t documented anywhere as far as I can tell, and it took me a long time to figure out, so I thought I’d write it down.

I want to create a new CSS stylesheet, apply it to a document, and dynamically fill its contents.

In Mozilla/Firefox, Safari, and Opera, you can create a style sheet DOM node, fill its contents, and insert it into the head of your document like this:

var styleText = "body{background-color:blue;}";
var head=document.getElementsByTagName("head")[0];
var styleNode = document.createElement("style");
styleNode.appendChild(document.createTextNode(styleText));
head.append(styleNode);

IE doesn’t allow you to append style nodes to the head of your document. Instead, you can use the IE-only createStyleSheet, and set its cssText property:

var styleText = "body{background-color:blue;}";
var s = document.createStyleSheet("");
s.cssText=styleText;

Three easy ways to crash Safari

Thursday April 26, 2007

This is what happens when you don’t dogfood your own tools, as these bugs should become evident five seconds after you start using the Safari logger. *Rage, hate*

This is in the version that ships with OSX 10.4.9 (Safari 419.3).

<html><head>

<script>
// Other logging apis support multiple arguments to log. Safari doesn't
// accept multiple arguments. Why throw an error, when you can just segfault?
console.log(1,2);
</script>

</head><body/></html>

<html><head>

<script>
// why does this alias cause a crash?
log=console.log;
log("hey");
</script>

</head><body/></html>

<html><head>

<script>
// This happens often, e.g. if I mistakenly tried to log
// "document.head" (also undefined). Sometimes it just
// makes the logging window into a zombie, where it's non-responsive.
// Othertimes it crashes
console.log(undefined);
</script>

</head><body/></html>

How to add a feature

Friday April 6, 2007

Dabble DB added a cool feature this weekend to their web application: the ability to upload your company logo and customize the site’s color scheme to match the logo.

The way it’s implemented is a bit different than you’d expect, and it’s a great example of how to write software. After uploading your logo, instead of forcing you to customize all of the site’s colors yourself, their software uses color theory to pick out some workable colors from your logo, including a font color that keeps text readable. You don’t even have to think about it.

They’ve added a rich feature that requires no extra interaction from the user. That is elegance.

InstallPad hits the international press

Tuesday April 3, 2007

InstallPad got a 3 page spread in the February issue of Computer!Totaal, a Dutch IT magazine. Sweet! This magazine is pretty. I liked how they used little InstallPad logos for bullet points.

Now, if it could only get some domestic press…

cover.jpg

Read Dutch? I don’t =/

1st.jpg3rd.jpg