From 4793cee888431b41f0aaf5341e2d8c77a155e8b8 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Mon, 24 Sep 2012 11:10:12 -0400 Subject: [PATCH] Switch to Handlebars templating Benchmarks [1] show it's much faster than ICanHaz, though we will have to work to realize those gains. [1] http://jsperf.com/jquery-template-table-performance/77 (imported from commit b037a6f15e27fd49af88f814ff949811dbcd48f2) --- templates/zephyr/index.html | 11 ++++++++--- zephyr/static/js/zephyr.js | 15 +++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/templates/zephyr/index.html b/templates/zephyr/index.html index 89e34be0e8..67dd2c07a9 100644 --- a/templates/zephyr/index.html +++ b/templates/zephyr/index.html @@ -12,13 +12,18 @@ {% block customhead %} -{% icanhazjs "zephyr" %} -{% icanhazjs "subscription" %} + + + {% autoescape off %} - + diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index 07a505cf93..037c44acec 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -1,9 +1,16 @@ /*jslint browser: true, devel: true, sloppy: true, plusplus: true, nomen: true, regexp: true */ -/*global $: false, jQuery: false, ich: false, +/*global $: false, jQuery: false, Handlebars: false, zephyr_json: false, initial_pointer: false, email: false, class_list: false, instance_list: false, people_list: false */ +// Compile Handlebars templates. +var templates = {}; +$(function () { + templates.zephyr = Handlebars.compile($("#template_zephyr").html()); + templates.subscription = Handlebars.compile($("#template_subscription").html()); +}); + function register_huddle_onclick(zephyr_row, sender) { zephyr_row.find(".zephyr_sender").click(function (e) { prepare_huddle(sender); @@ -61,7 +68,7 @@ $(function () { $('#subscriptions_table tr').remove(); if (data) { $.each(data.subscriptions, function (index, name) { - $('#subscriptions_table').append(ich.subscription({subscription: name})); + $('#subscriptions_table').append(templates.subscription({subscription: name})); }); } $('#new_subscriptions').focus().select(); @@ -239,7 +246,7 @@ $(function () { success: function (resp, statusText, xhr, form) { $("#new_subscription").val(""); var name = $.parseJSON(xhr.responseText).data; - $('#subscriptions_table').prepend(ich.subscription({subscription: name})); + $('#subscriptions_table').prepend(templates.subscription({subscription: name})); class_list.push(name); $("#subscriptions-status").fadeOut(0); }, @@ -647,7 +654,7 @@ function add_to_tables(zephyr, parent, table_name) { zephyr.dom_id = table_name + zephyr.id; - var new_tr = ich.zephyr(zephyr); + var new_tr = $(templates.zephyr(zephyr)); table.append(new_tr); register_huddle_onclick(new_tr, zephyr.sender_email); }