diff options
author | Heather Miller <heather.miller@epfl.ch> | 2011-08-02 02:56:05 +0000 |
---|---|---|
committer | Heather Miller <heather.miller@epfl.ch> | 2011-08-02 02:56:05 +0000 |
commit | 6f1552568c2668ab02f56f77b5de5a68258bf304 (patch) | |
tree | f58ecdfe841c65d0f24781af4ebc1825e118a380 /src | |
parent | 74062e352955afa6869636d84035011e3518d7d4 (diff) | |
download | scala-6f1552568c2668ab02f56f77b5de5a68258bf304.tar.gz scala-6f1552568c2668ab02f56f77b5de5a68258bf304.tar.bz2 scala-6f1552568c2668ab02f56f77b5de5a68258bf304.zip |
Merged enhancements made to scaladoc filter pan...
Merged enhancements made to scaladoc filter panel by Ruediger Keller.
Enhancements include faster filtering, automatically focused text input
field, improved searching (no regex syntax, so now its possible to
search for members like ++). No review.
Diffstat (limited to 'src')
3 files changed, 125 insertions, 92 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/html/page/Template.scala b/src/compiler/scala/tools/nsc/doc/html/page/Template.scala index ccc40013f1..bc2fc61d0b 100644 --- a/src/compiler/scala/tools/nsc/doc/html/page/Template.scala +++ b/src/compiler/scala/tools/nsc/doc/html/page/Template.scala @@ -80,34 +80,34 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { { signature(tpl, true) } { memberToCommentHtml(tpl, true) } - <div id="template"> - - <div id="mbrsel"> - <div id='textfilter'><span class='pre'/><span class='input'><input type='text' accesskey='/'/></span><span class='post'/></div> - { if (tpl.linearizationTemplates.isEmpty) NodeSeq.Empty else - <div id="order"> - <span class="filtertype">Ordering</span> - <ol><li class="alpha in"><span>Alphabetic</span></li><li class="inherit out"><span>By inheritance</span></li></ol> - </div> - } - { if (tpl.linearizationTemplates.isEmpty) NodeSeq.Empty else - <div id="ancestors"> - <span class="filtertype">Inherited</span> - <ol><li class="hideall out"><span>Hide All</span></li> - <li class="showall in"><span>Show all</span></li></ol> - <ol id="linearization">{ - (tpl :: tpl.linearizationTemplates) map { wte => <li class="in" name={ wte.qualifiedName }><span>{ wte.name }</span></li> } - }</ol> - </div> - } - { - <div id="visbl"> - <span class="filtertype">Visibility</span> - <ol><li class="public in"><span>Public</span></li><li class="all out"><span>All</span></li></ol> + <div id="mbrsel"> + <div id='textfilter'><span class='pre'/><span class='input'><input type='text' accesskey='/'/></span><span class='post'/></div> + { if (tpl.linearizationTemplates.isEmpty) NodeSeq.Empty else + <div id="order"> + <span class="filtertype">Ordering</span> + <ol><li class="alpha in"><span>Alphabetic</span></li><li class="inherit out"><span>By inheritance</span></li></ol> </div> - } - </div> + } + { if (tpl.linearizationTemplates.isEmpty) NodeSeq.Empty else + <div id="ancestors"> + <span class="filtertype">Inherited</span> + <ol><li class="hideall out"><span>Hide All</span></li> + <li class="showall in"><span>Show all</span></li></ol> + <ol id="linearization">{ + (tpl :: tpl.linearizationTemplates) map { wte => <li class="in" name={ wte.qualifiedName }><span>{ wte.name }</span></li> } + }</ol> + </div> + } + { + <div id="visbl"> + <span class="filtertype">Visibility</span> + <ol><li class="public in"><span>Public</span></li><li class="all out"><span>All</span></li></ol> + </div> + } + </div> + <div id="template"> + <div id="allMembers"> { if (constructors.isEmpty) NodeSeq.Empty else <div id="constructors" class="members"> <h3>Instance Constructors</h3> @@ -142,7 +142,9 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { <ol>{ deprValueMembers map (memberToHtml(_)) }</ol> </div> } + </div> + <div id="inheritedMembers"> { NodeSeq fromSeq (for ((superTpl, superType) <- (tpl.linearizationTemplates zip tpl.linearizationTypes)) yield <div class="parent" name={ superTpl.qualifiedName }> @@ -161,6 +163,7 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage { </div> ) } + </div> </div> diff --git a/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.css b/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.css index 84c2d6bfc0..441f6153e9 100644 --- a/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.css +++ b/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.css @@ -227,7 +227,7 @@ dl.attributes > dd { height: 18px; } -#template > div.parent > h3 { +#inheritedMembers > div.parent > h3 { background-color: #dadada; /* border:1px solid #6f6f6f; border-left:0; @@ -243,7 +243,7 @@ dl.attributes > dd { font-size: 12pt; } -#template > div.parent > h3 * { +#inheritedMembers > div.parent > h3 * { color: white; } diff --git a/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.js b/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.js index 0d2e373811..09437063c2 100644 --- a/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.js +++ b/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.js @@ -16,20 +16,29 @@ $(document).ready(function(){ $("#linearization li").filter(function(){ return isHiddenClass($(this).attr("name")); }).removeClass("in").addClass("out"); + + // Pre-filter members filter(); + // Member filter box var input = $("#textfilter input"); input.bind("keyup", function(event) { - if (event.keyCode == 27) { // escape - input.attr("value", ""); - } - filter(); + if (event.keyCode == 27) + input.val(""); // escape key + filter(true); }); - input.focus(function(event) { input.select(); }); - $("#textfilter > .post").click(function(){ + input.focus(function(event) { + input.select(); + }); + $("#textfilter > .post").click(function() { $("#textfilter input").attr("value", ""); filter(); }); + $(document).keydown(function() { + if (document.activeElement != $("#textfilter input")[0]) + $("#textfilter input").focus(); + }); + $("#textfilter input").focus(); $("#linearization li").click(function(){ if ($(this).hasClass("in")) { @@ -162,12 +171,13 @@ function orderInherit() { function initInherit() { // parents is a map from fully-qualified names to the DOM node of parent headings. var parents = new Object(); - $("#template > div.parent").each(function(){ + $("#inheritedMembers > div.parent").each(function(){ parents[$(this).attr("name")] = $(this); }); - // $("#types > ol > li").each(function(){ - var qualName = $(this).attr("name"); + var mbr = $(this); + this.mbrText = mbr.find("> .fullcomment .cmt").text(); + var qualName = mbr.attr("name"); var owner = qualName.slice(0, qualName.indexOf("#")); var name = qualName.slice(qualName.indexOf("#") + 1); var parent = parents[owner]; @@ -177,11 +187,15 @@ function initInherit() { parent.append("<div class='types members'><h3>Type Members</h3><ol></ol></div>"); types = $("> .types > ol", parent); } - types.append($(this).clone()); + var clone = mbr.clone(); + clone[0].mbrText = this.mbrText; + types.append(clone); } }); $("#values > ol > li").each(function(){ - var qualName = $(this).attr("name"); + var mbr = $(this); + this.mbrText = mbr.find("> .fullcomment .cmt").text(); + var qualName = mbr.attr("name"); var owner = qualName.slice(0, qualName.indexOf("#")); var name = qualName.slice(qualName.indexOf("#") + 1); var parent = parents[owner]; @@ -191,70 +205,86 @@ function initInherit() { parent.append("<div class='values members'><h3>Value Members</h3><ol></ol></div>"); values = $("> .values > ol", parent); } - values.append($(this).clone()); + var clone = mbr.clone(); + clone[0].mbrText = this.mbrText; + values.append(clone); } }); - $("#template > div.parent").each(function(){ + $("#inheritedMembers > div.parent").each(function() { if ($("> div.members", this).length == 0) { $(this).remove(); }; }); - $("#template > div.parent").each(function(){ - $(this).hide(); - }); }; -function filter() { - var query = $("#textfilter input").attr("value").toLowerCase(); +function filter(scrollToMember) { + var query = $.trim($("#textfilter input").val()).toLowerCase(); + query = query.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&").replace(/\s+/g, "|"); var queryRegExp = new RegExp(query, "i"); - var inheritHides = null - if ($("#order > ol > li.inherit").hasClass("in")) { - inheritHides = $("#linearization > li:gt(0)"); + var privateMembersHidden = $("#visbl > ol > li.public").hasClass("in"); + var orderingAlphabetic = $("#order > ol > li.alpha").hasClass("in"); + var hiddenSuperclassElements = orderingAlphabetic ? $("#linearization > li.out") : $("#linearization > li:gt(0)"); + var hiddenSuperclasses = hiddenSuperclassElements.map(function() { + return $(this).attr("name"); + }).get(); + + var hideInheritedMembers; + + if(orderingAlphabetic) { + $("#inheritedMembers").hide(); + hideInheritedMembers = true; + $("#allMembers > .members").each(filterFunc); } else { - inheritHides = $("#linearization > li.out"); + $("#inheritedMembers").show(); + hideInheritedMembers = true; + $("#allMembers > .members").each(filterFunc); + hideInheritedMembers = false; + $("#inheritedMembers > .parent > .members").each(filterFunc); } - var outOwners = - inheritHides.map(function(){ - var r = $(this).attr("name"); - return r - }).get(); - var prtVisbl = $("#visbl > ol > li.all").hasClass("in"); - $(".members > ol > li").each(function(){ - var vis1 = $(this).attr("visbl"); - var qualName1 = $(this).attr("name"); - //var name1 = qualName1.slice(qualName1.indexOf("#") + 1); - var showByOwned = true; - if ($(this).parents(".parent").length == 0) { - // owner filtering must not happen in "inherited from" member lists - var ownerIndex = qualName1.indexOf("#"); - if (ownerIndex < 0) { ownerIndex = qualName1.lastIndexOf("."); } - var owner1 = qualName1.slice(0, ownerIndex); - for (out in outOwners) { - if (outOwners[out] == owner1) { - showByOwned = false; - }; - }; - }; - var showByVis = true; - if (vis1 == "prt") { - showByVis = prtVisbl; - }; - var showByName = true; - if (query != "") { - var content = $(this).attr("name") + $("> .fullcomment .cmt", this).text(); - showByName = queryRegExp.test(content); - }; - if (showByOwned && showByVis && showByName) { - $(this).show(); + + + function filterFunc() { + var membersVisible = false; + var members = $(this); + members.find("> ol > li").each(function() { + var mbr = $(this); + if (privateMembersHidden && mbr.attr("visbl") == "prt") { + mbr.hide(); + return; } - else { - $(this).hide(); - }; - }); - $(".members").each(function(){ - $(this).show(); - if ($(" > ol > li:visible", this).length == 0) { $(this).hide(); } - }); - return false + var name = mbr.attr("name"); + // Owner filtering must not happen in "inherited from" member lists + if (hideInheritedMembers) { + var ownerIndex = name.indexOf("#"); + if (ownerIndex < 0) { + ownerIndex = name.lastIndexOf("."); + } + var owner = name.slice(0, ownerIndex); + for (var i = 0; i < hiddenSuperclasses.length; i++) { + if (hiddenSuperclasses[i] == owner) { + mbr.hide(); + return; + } + } + } + if (query && !(queryRegExp.test(name) || queryRegExp.test(this.mbrText))) { + mbr.hide(); + return; + } + mbr.show(); + membersVisible = true; + }); + + if (membersVisible) + members.show(); + else + members.hide(); + }; + + if (scrollToMember) { + window.scrollTo(0, $("#mbrsel").offset().top); + } + + return false; }; function windowTitle() |