Custom d3 typewriter tween

HTML

<svg height="30" width="500">
    <text x="250" y="15" fill="black" text-anchor="middle" font-size="16px">Intro text - click mouse on this text</text>
</svg>

JavaScript

/* See http://stackoverflow.com/questions/21567336/d3-text-transitioning-in-typewriter-style */

var i = 0;
var data = [
    'Lorem ipsum dolor sit amet, consectetur adipisicing elit,',
    'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
    'Ut enim ad minim veniam, quis nostrud exercitation',
    'ullamco laboris nisi ut aliquip ex ea commodo consequat.',
    'Duis aute irure dolor in reprehenderit',
    'in voluptate velit esse cillum dolore eu fugiat nulla pariatur.',
    'Excepteur sint occaecat cupidatat non proident,',
    'sunt in culpa qui officia deserunt mollit anim id est laborum.'];

d3.select('svg').on("mousedown", function () {
    transition();
});

function transition() {
    d3.select('text').transition()
        .duration(5000)
        .ease("linear")
        .tween("text", function () {
            var newText = data[i];
            var textLength = newText.length;
            return function (t) {
                this.textContent = newText.slice(0, 
                                   Math.round( t * textLength) );
            };
        });
    
    i = (i + 1) % data.length;
}