# File lib/ruby-prof/call_stack_printer.rb, line 321
    def print_java_script
      @output.puts "<script type=\"text/javascript\">\n/*\nCopyright (C) 2005,2009  Stefan Kaes\nskaes@railsexpress.de\n*/\n\nfunction rootNode() {\nreturn currentThread;\n}\n\nfunction hideUL(node) {\nvar lis = node.childNodes\nvar l = lis.length;\nfor (var i=0; i < l ; i++ ) {\nhideLI(lis[i]);\n}\n}\n\nfunction showUL(node) {\nvar lis = node.childNodes;\nvar l = lis.length;\nfor (var i=0; i < l ; i++ ) {\nshowLI(lis[i]);\n}\n}\n\nfunction findUlChild(li){\nvar ul = li.childNodes[2];\nwhile (ul && ul.nodeName != \"UL\") {\nul = ul.nextSibling;\n}\nreturn ul;\n}\n\nfunction isLeafNode(li) {\nvar img = li.firstChild;\nreturn (img.src.indexOf('empty.png') > -1);\n}\n\nfunction hideLI(li) {\nif (isLeafNode(li))\nreturn;\n\nvar img = li.firstChild;\nimg.src = 'plus.png';\n\nvar ul = findUlChild(li);\nif (ul) {\nul.style.display = 'none';\nhideUL(ul);\n}\n}\n\nfunction showLI(li) {\nif (isLeafNode(li))\nreturn;\n\nvar img = li.firstChild;\nimg.src = 'minus.png';\n\nvar ul = findUlChild(li);\nif (ul) {\nul.style.display = 'block';\nshowUL(ul);\n}\n}\n\nfunction toggleLI(li) {\nvar img = li.firstChild;\nif (img.src.indexOf(\"minus.png\")>-1)\nhideLI(li);\nelse {\nif (img.src.indexOf(\"plus.png\")>-1)\nshowLI(li);\n}\n}\n\nfunction aboveThreshold(text, threshold) {\nvar match = text.match(/\\d+[.,]\\d+/);\nreturn (match && parseFloat(match[0].replace(/,/, '.'))>=threshold);\n}\n\nfunction setThresholdLI(li, threshold) {\nvar img = li.firstChild;\nvar text = img.nextSibling;\nvar ul = findUlChild(li);\n\nvar visible = aboveThreshold(text.nodeValue, threshold) ? 1 : 0;\n\nvar count = 0;\nif (ul) {\ncount = setThresholdUL(ul, threshold);\n}\nif (count>0) {\nimg.src = 'minus.png';\n}\nelse {\nimg.src = 'empty.png';\n}\nif (visible) {\nli.style.display = 'block'\n}\nelse {\nli.style.display = 'none'\n}\nreturn visible;\n}\n\nfunction setThresholdUL(node, threshold) {\nvar lis = node.childNodes;\nvar l = lis.length;\n\nvar count = 0;\nfor ( var i = 0; i < l ; i++ ) {\ncount = count + setThresholdLI(lis[i], threshold);\n}\n\nvar visible = (count > 0) ? 1 : 0;\nif (visible) {\nnode.style.display = 'block';\n}\nelse {\nnode.style.display = 'none';\n}\nreturn visible;\n}\n\nfunction toggleChildren(img, event) {\nevent.cancelBubble=true;\n\nif (img.src.indexOf('empty.png') > -1)\nreturn;\n\nvar minus = (img.src.indexOf('minus.png') > -1);\n\nif (minus) {\nimg.src = 'plus.png';\n}\nelse\nimg.src = 'minus.png';\n\nvar li = img.parentNode;\nvar ul = findUlChild(li);\nif (ul) {\nif (minus)\nul.style.display = 'none';\nelse\nul.style.display = 'block';\n}\nif (minus)\nmoveSelectionIfNecessary(li);\n}\n\nfunction showChildren(li) {\nvar img = li.firstChild;\nif (img.src.indexOf('empty.png') > -1)\nreturn;\nimg.src = 'minus.png';\n\nvar ul = findUlChild(li);\nif (ul) {\nul.style.display = 'block';\n}\n}\n\nfunction setThreshold() {\nvar tv = document.getElementById(\"threshold\").value;\nif (tv.match(/[0-9]+([.,][0-9]+)?/)) {\nvar f = parseFloat(tv.replace(/,/, '.'));\nvar threads = document.getElementsByName(\"thread\");\nvar l = threads.length;\nfor ( var i = 0; i < l ; i++ ) {\nsetThresholdUL(threads[i], f);\n}\nvar p = selectedNode;\nwhile (p && p.style.display=='none')\np=p.parentNode.parentNode;\nif (p && p.nodeName==\"LI\")\nselectNode(p);\n}\nelse {\nalert(\"Please specify a decimal number as threshold value!\");\n}\n}\n\nfunction collapseAll(event) {\nevent.cancelBubble=true;\nvar threads = document.getElementsByName(\"thread\");\nvar l = threads.length;\nfor ( var i = 0; i < l ; i++ ) {\nhideUL(threads[i]);\n}\nselectNode(rootNode(), null);\n}\n\nfunction expandAll(event) {\nevent.cancelBubble=true;\nvar threads = document.getElementsByName(\"thread\");\nvar l = threads.length;\nfor ( var i = 0; i < l ; i++ ) {\nshowUL(threads[i]);\n}\n}\n\nfunction toggleHelp(node) {\nvar help = document.getElementById(\"help\");\nif (node.value == \"Show Help\") {\nnode.value = \"Hide Help\";\nhelp.style.display = 'block';\n}\nelse {\nnode.value = \"Show Help\";\nhelp.style.display = 'none';\n}\n}\n\nvar selectedNode = null;\nvar selectedColor = null;\nvar selectedThread = null;\n\nfunction descendentOf(a,b){\nwhile (a!=b && b!=null)\nb=b.parentNode;\nreturn (a==b);\n}\n\nfunction moveSelectionIfNecessary(node){\nif (descendentOf(node, selectedNode))\nselectNode(node, null);\n}\n\nfunction selectNode(node, event) {\nif (event) {\nevent.cancelBubble = true;\nthread = findThread(node);\nselectThread(thread);\n}\nif (selectedNode) {\nselectedNode.style.background = selectedColor;\n}\nselectedNode = node;\nselectedColor = node.style.background;\nselectedNode.style.background = \"red\";\nselectedNode.scrollIntoView();\nwindow.scrollBy(0,-400);\n}\n\nfunction moveUp(){\nvar p = selectedNode.previousSibling;\nwhile (p && p.style.display == 'none')\np = p.previousSibling;\nif (p && p.nodeName == \"LI\") {\nselectNode(p, null);\n}\n}\n\nfunction moveDown(){\nvar p = selectedNode.nextSibling;\nwhile (p && p.style.display == 'none')\np = p.nextSibling;\nif (p && p.nodeName == \"LI\") {\nselectNode(p, null);\n}\n}\n\nfunction moveLeft(){\nvar p = selectedNode.parentNode.parentNode;\nif (p && p.nodeName==\"LI\") {\nselectNode(p, null);\n}\n}\n\nfunction moveRight(){\nif (!isLeafNode(selectedNode)) {\nshowChildren(selectedNode);\nvar ul = findUlChild(selectedNode);\nif (ul) {\nselectNode(ul.firstChild, null);\n}\n}\n}\n\nfunction moveForward(){\nif (isLeafNode(selectedNode)) {\nvar p = selectedNode;\nwhile ((p.nextSibling == null || p.nextSibling.style.display=='none') && p.nodeName==\"LI\") {\np = p.parentNode.parentNode;\n}\nif (p.nodeName==\"LI\")\nselectNode(p.nextSibling, null);\n}\nelse {\nmoveRight();\n}\n}\n\nfunction isExpandedNode(li){\nvar img = li.firstChild;\nreturn(img.src.indexOf('minus.png')>-1);\n}\n\nfunction moveBackward(){\nvar p = selectedNode;\nvar q = p.previousSibling;\nwhile (q != null && q.style.display=='none')\nq = q.previousSibling;\nif (q == null) {\np = p.parentNode.parentNode;\n} else {\nwhile (!isLeafNode(q) && isExpandedNode(q)) {\nq = findUlChild(q).lastChild;\nwhile (q.style.display=='none')\nq = q.previousSibling;\n}\np = q;\n}\nif (p.nodeName==\"LI\")\nselectNode(p, null);\n}\n\nfunction moveHome() {\nselectNode(currentThread);\n}\n\nvar currentThreadIndex = null;\n\nfunction findThread(node){\nwhile (node && node.parentNode.nodeName!=\"BODY\") {\nnode = node.parentNode;\n}\nreturn node.firstChild;\n}\n\nfunction selectThread(node){\nvar threads = document.getElementsByName(\"thread\");\ncurrentThread = node;\nfor (var i=0; i<threads.length; i++) {\nif (threads[i]==currentThread.parentNode)\ncurrentThreadIndex = i;\n}\n}\n\nfunction nextThread(){\nvar threads = document.getElementsByName(\"thread\");\nif (currentThreadIndex==threads.length-1)\ncurrentThreadIndex = 0;\nelse\ncurrentThreadIndex += 1\ncurrentThread = threads[currentThreadIndex].firstChild;\nselectNode(currentThread, null);\n}\n\nfunction previousThread(){\nvar threads = document.getElementsByName(\"thread\");\nif (currentThreadIndex==0)\ncurrentThreadIndex = threads.length-1;\nelse\ncurrentThreadIndex -= 1\ncurrentThread = threads[currentThreadIndex].firstChild;\nselectNode(currentThread, null);\n}\n\nfunction switchThread(node, event){\nevent.cancelBubble = true;\nselectThread(node.nextSibling.firstChild);\nselectNode(currentThread, null);\n}\n\nfunction handleKeyEvent(event){\nvar code = event.charCode ? event.charCode : event.keyCode;\nvar str = String.fromCharCode(code);\nswitch (str) {\ncase \"a\": moveLeft();  break;\ncase \"s\": moveDown();  break;\ncase \"d\": moveRight(); break;\ncase \"w\": moveUp();    break;\ncase \"f\": moveForward(); break;\ncase \"b\": moveBackward(); break;\ncase \"x\": toggleChildren(selectedNode.firstChild, event); break;\ncase \"*\": toggleLI(selectedNode); break;\ncase \"n\": nextThread(); break;\ncase \"h\": moveHome(); break;\ncase \"p\": previousThread(); break;\n}\n}\ndocument.onkeypress=function(event){ handleKeyEvent(event) };\n\nwindow.onload=function(){\nvar images = document.getElementsByTagName(\"img\");\nfor (var i=0; i<images.length; i++) {\nvar img = images[i];\nif (img.className == \"toggle\") {\nimg.onclick = function(event){ toggleChildren(this, event); };\n}\n}\nvar divs = document.getElementsByTagName(\"div\");\nfor (i=0; i<divs.length; i++) {\nvar div = divs[i];\nif (div.className == \"thread\")\ndiv.onclick = function(event){ switchThread(this, event) };\n}\nvar lis = document.getElementsByTagName(\"li\");\nfor (var i=0; i<lis.length; i++) {\nlis[i].onclick = function(event){ selectNode(this, event); };\n}\nvar threads = document.getElementsByName(\"thread\");\ncurrentThreadIndex = 0;\ncurrentThread = threads[0].firstChild;\nselectNode(currentThread, null);\n}\n</script>\n"
    end