Christian Heilmann

You are currently browsing the archives for the General category.

Archive for the ‘General’ Category

dconstruct 2006 review

Saturday, September 9th, 2006

Yesterday I went to dconstruct in Brighton (thanks to Andy Budd who got me a last minute ticket) and all in all I can say it was a massive success (missing the last tube on the way home and having someone throw up next to me on the night bus was less of a success though). If you haven’t been to Brighton, go now, it is simply a beautiful quaint little town. Anyways, about dconstruct: (more…)

The future is hybrids – how JavaScript can purify pure CSS solutions

Monday, September 4th, 2006

Over the last few months there were more and more requests on mailing lists and articles published how you can achieve functionality with pure CSS that was traditionally achieved with JavaScript. This post will explain why that is an interesting concept, but hopefully make you aware of the benefits of JavaScript enhanced solutions versus pure CSS solutions.

I have to thank a lot of people I asked in the research for this, foremost James Edwards, John Resig and Andrew Dupont. I’ve also given a short presentation – PDF -96KB on the same topic at the Barcamp in London last weekend.

First of all let’s investigate how pure CSS solutions became so popular. (more…)

Barcamp London

Sunday, September 3rd, 2006

Just finished the first day at Barcamp London (it feels very odd to be in the office during the weekend and not working on products). I had very much fun and met some interesting new faces while hearing good presentations of seasoned presenters. My personal contribution so far was a quick talk I knocked together on the tube towards barcamp about JavaScript versus CSS and there will be a follow-up article/blog post on this soon. For now, you can download the PDF of the talk – 96KB but without the dancing and singing it is only half the fun.

I am too knackered now to write more, so stay tuned :-)

[tags]BarCamp, BarCampLondon, BarCampLondon06[/tags]

On vacation now

Friday, August 25th, 2006

I am now on vacation till next Friday to go to Paris. No comments will make it through, but I promise to answer what accumulates.

Shortening strings to a fixed length in JavaScript

Friday, August 25th, 2006

I have this function I’ve used for quite a long time to shorten a string to a fixed amount of characters without breaking in between words:

function constrain(str,n){
var words = str.split(' ');
var resultstr = '';
for(var i = 0; i < words.length; i++ ){
if((resultstr + words[i] + ' ').length>=n){
resultstr += '…';
break;
}
resultstr += words[i] + ' ';
}
return resultstr;
}
ately that it can get really slow with massive strings in Internet Explorer. This is a well-known issue and the solution is to use arrays instead of concatenating strings.

This made me realise how convoluted the above example is and that it is much easier to do the same with an array:

function constrain(str,n){
if(str.length > n){
var s = str.substr(0, n);
var words = s.split(' ');
words[words.length-1] = '';
str = words.join(' ') + '…'
}
return str;
}

You send a string and the amount of characters wanted as parameters and the function returns the string with the right lenght followed by a “...”.

Another way to work around the MSIE issue of slow concatenation is to use thea string builder.

[tags]string concatenation webdevtrick[/tags]