Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8f26981
Showing
6 changed files
with
643 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
function initializeWithSpew(spew) { | ||
|
||
const scraper = new InferScraper.Scraper(spew); | ||
|
||
/* Highlight bubble constants. */ | ||
const hMargin = 2; | ||
const wMargin = 2; | ||
const border = 4; | ||
|
||
function removeBubble() { | ||
var bubble = $("#bubble"); | ||
var el = $("#" + bubble.attr("under")); | ||
|
||
bubble.remove(); | ||
|
||
el.removeAttr("style"); | ||
el.addClass("clickableTypeset"); | ||
el.click(clickSourceTypeset); | ||
var kids = el.find("span"); | ||
kids.addClass("clickableTypeset"); | ||
kids.click(clickSourceTypeset); | ||
} | ||
|
||
/* |el| is the element to show the bubble around. */ | ||
function showBubble(el) { | ||
if (el.length === 0) | ||
return; | ||
|
||
/* Remove the old bubble. */ | ||
removeBubble(); | ||
|
||
/* Make a new bubble. */ | ||
var id = el.attr("id"); | ||
el.after("<div id=\"bubble\" under=\"" + id + "\" class=\"bubble\"></div>"); | ||
/* Position it. */ | ||
var bubble = $("#bubble"); | ||
var offset = el.offset(); | ||
var h = el.height(); | ||
var w = el.width(); | ||
var codeLeft = $("#code").offset().left; | ||
bubble.css({ height: (h + 2 * hMargin) + "px", | ||
width: (w + 2 * wMargin) + "px", | ||
left: (offset.left - wMargin - border - codeLeft) + "px", | ||
top: (offset.top - hMargin - border) + "px" }); | ||
bubble.show(); | ||
|
||
el.css({ position: "relative", "z-index": 1000 }); | ||
el.removeClass("clickableTypeset"); | ||
el.unbind("click"); | ||
var kids = el.find("span"); | ||
kids.removeClass("clickableTypeset"); | ||
kids.unbind("click"); | ||
} | ||
|
||
function listTypes(id, selected) { | ||
var types = []; | ||
var c; | ||
for (var t in scraper.typesets[id].types) { | ||
c = (t === selected ? "selected" : "unselected"); | ||
types.push("<li class=\"" + c + "\">" + t + "</li>"); | ||
} | ||
return "<ul class=\"set\">" + types.join("") + "</ul>"; | ||
} | ||
|
||
function showTypesetAsCurrent(id) { | ||
var el = $("#typeset"); | ||
el.html("<h3>" + id + "</h3>"); | ||
el.append(listTypes(id)); | ||
el.addClass("highlight"); | ||
$("#typeset li").click(clickType); | ||
$("#path").html(""); | ||
} | ||
|
||
function clickSourceTypeset(e) { | ||
/* | ||
* The typeset spans may be deeply nested. We don't propagate up the | ||
* DOM and only handle the innermost span. | ||
*/ | ||
var el = $(this); | ||
var id = el.attr("id"); | ||
|
||
showTypesetAsCurrent(id); | ||
showBubble(el); | ||
|
||
e.stopPropagation(); | ||
} | ||
|
||
function toggleClickable(el, klass, f) { | ||
var prev = $("." + klass); | ||
prev.click(f); | ||
prev.removeClass(klass); | ||
el.addClass(klass); | ||
el.unbind("click"); | ||
} | ||
|
||
function clickTypeset(e) { | ||
var el = $(this); | ||
$(".notFound").removeClass(".notFound"); | ||
toggleClickable(el, "highlight", clickTypeset); | ||
showBubble($("#" + el.children("h3").html())); | ||
} | ||
|
||
function clickType(e) { | ||
toggleClickable($(this), "selected", clickType); | ||
|
||
var el = $("#path"); | ||
var type = $(this).html().replace("<", "<").replace(">", ">"); | ||
var pobj = scraper.pathOf($("#typeset > h3").html(), type); | ||
var path = pobj.path; | ||
var id; | ||
|
||
el.html(""); | ||
if (path) { | ||
for (var i = 0; i < path.length; i++) { | ||
id = path[i].source; | ||
el.append("<div class=\"subset\" title=\"" + path[i].kind + "\">⊆</div>"); | ||
el.append("<div class=\"superset\">" + | ||
"<h3>" + id + "<h3>" + listTypes(id, type) + | ||
"</div>"); | ||
} | ||
} | ||
|
||
switch (pobj.origin) { | ||
case InferScraper.DYNAMIC_ORIGIN: | ||
el.append("<div id=\"origin\">…which was determined dynamically</div>"); | ||
break; | ||
|
||
case InferScraper.STATIC_ORIGIN: | ||
el.append("<div id=\"origin\">…which was determined statically</div>"); | ||
break; | ||
|
||
default: | ||
el.append("<div id=\"origin\">...and the trail runs cold</div>"); | ||
break; | ||
} | ||
|
||
$("#path .superset").click(clickTypeset); | ||
} | ||
|
||
function reset() { | ||
$("#typeset").html(""); | ||
$("#typeset").removeClass("highlight"); | ||
$("#path").html(""); | ||
|
||
removeBubble(); | ||
} | ||
|
||
/* Setup up the spans to have the right classes. */ | ||
var codespans = $("#code span"); | ||
codespans.addClass("clickableTypeset"); | ||
codespans.click(clickSourceTypeset); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>$title</title> | ||
<link href="$data_path/screen.css" media="screen,projection" rel="stylesheet" type="text/css"> | ||
</head> | ||
<body> | ||
<div id="content"> | ||
<div id="spew"> | ||
<section id="typeset"></section> | ||
<section id="path"></section> | ||
</div> | ||
<div id="code">$code</div> | ||
</div> | ||
<script type="application/javascript" src="$data_path/jquery-1.6.2.min.js"></script> | ||
<script type="application/javascript" src="$data_path/inferscraper.js"></script> | ||
<script type="application/javascript" src="$data_path/app.js"></script> | ||
<script type="application/javascript"> | ||
initializeWithSpew("$spew"); | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.