From a57a28aeaef51fb47db15f245c840a98da59f570 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Sun, 27 Sep 2009 01:29:24 -0400 Subject: [PATCH] defer some expensive DOM fiddling --- j/dip3.js | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/j/dip3.js b/j/dip3.js index d4b6637..d81f007 100644 --- a/j/dip3.js +++ b/j/dip3.js @@ -168,32 +168,36 @@ $(document).ready(function() { var hip = {'background-color':'#eee','cursor':'default'}; var unhip = {'background-color':'inherit','cursor':'inherit'}; $("pre.code, pre.screen").each(function() { - var s = ''; - var ol = $(this).next("ol"); - var refs = $(this).find("a:not([href])"); - refs.each(function(i) { - var li = ol.find("li:nth-child(" + (i+1) + ")"); - s += "&#x" + (parseInt('2460', 16) + i).toString(16) + ";" + li.html() + ""; - }); - ol.replaceWith("" + s + "
"); - refs.each(function(i) { - var a = $(this); - var li = a.parents("pre").next("table").find("tr:nth-child(" + (i+1) + ") td:nth-child(2)"); - li.add(a).hover(function() { a.css(hip); li.css(hip); }, - function() { a.css(unhip); li.css(unhip); }); - }); - + var _this = $(this); + window.setTimeout(function() { + var s = ''; + var ol = _this.next("ol"); + var refs = _this.find("a:not([href])"); + refs.each(function(i) { + var li = ol.find("li:nth-child(" + (i+1) + ")"); + s += "&#x" + (parseInt('2460', 16) + i).toString(16) + ";" + li.html() + ""; + }); + ol.replaceWith("" + s + "
"); + refs.each(function(i) { + var a = $(this); + var li = a.parents("pre").next("table").find("tr:nth-child(" + (i+1) + ") td:nth-child(2)"); + li.add(a).hover(function() { a.css(hip); li.css(hip); }, + function() { a.css(unhip); li.css(unhip); }); + }); + }, 0); }); /* synchronized highlighting on callouts and their associated table rows */ $("table").each(function() { $(this).find("tr:gt(0)").each(function(i) { var tr = $(this); - var li = tr.parents("table").next("ol").find("li:nth-child(" + (i+1) + ")"); - if (li.length > 0) { - li.add(tr).hover(function() { tr.css(hip); li.css(hip); }, - function() { tr.css(unhip); li.css(unhip); }); - } + window.setTimeout(function() { + var li = tr.parents("table").next("ol").find("li:nth-child(" + (i+1) + ")"); + if (li.length > 0) { + li.add(tr).hover(function() { tr.css(hip); li.css(hip); }, + function() { tr.css(unhip); li.css(unhip); }); + } + }, 0); }); });