// Generated by CoffeeScript 1.10.0 (function() { var do_search, height, redraw, result_height, results, svg, width; d3.select('#search_input').on('keyup', function() { /* if ENTER is pressed */ if (d3.event.keyCode === 13 || d3.event.which === 13) { return do_search(this.value); } }); do_search = function(query) { return d3.html("google_search.php?q=" + query, function(page) { var estimate; estimate = +(d3.select(page).select('#resultStats').text().replace(/,|\./g, '').match(/\d+/)[0]); results.push({ query: query, estimate: estimate }); return redraw(); }); }; results = []; svg = d3.select('svg'); width = svg[0][0].getBoundingClientRect().width; height = svg[0][0].getBoundingClientRect().height; result_height = 30; redraw = function() { var max, new_results_r, results_r; max = d3.max(results, function(d) { return d.estimate; }); results_r = svg.selectAll('.result').data(results); new_results_r = results_r.enter().append('a').attr('class', 'result').attr('transform', function(d, i) { return "translate(0, " + ((results.length - 2 - i) * result_height) + ")"; }).attr('xlink:href', function(d) { return "http://www.google.com/search?q=" + d.query; }); new_results_r.append('rect').attr('height', result_height - 2); new_results_r.append('text').text(function(d) { return d.query; }).attr('dy', '0.35em').attr('y', (result_height - 2) / 2).attr('x', 4); svg.selectAll('.result > rect').transition().duration(600).attr('width', function(d) { return d.estimate / max * 600; }); return results_r.transition().delay(600).duration(600).attr('transform', function(d, i) { return "translate(0, " + ((results.length - 1 - i) * result_height) + ")"; }); }; }).call(this);