From 6f1552568c2668ab02f56f77b5de5a68258bf304 Mon Sep 17 00:00:00 2001 From: Heather Miller Date: Tue, 2 Aug 2011 02:56:05 +0000 Subject: 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. --- .../scala/tools/nsc/doc/html/page/Template.scala | 55 +++---- .../tools/nsc/doc/html/resource/lib/template.css | 4 +- .../tools/nsc/doc/html/resource/lib/template.js | 158 ++++++++++++--------- 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) } -
- -
-
- { if (tpl.linearizationTemplates.isEmpty) NodeSeq.Empty else -
- Ordering -
  1. Alphabetic
  2. By inheritance
-
- } - { if (tpl.linearizationTemplates.isEmpty) NodeSeq.Empty else -
- Inherited -
  1. Hide All
  2. -
  3. Show all
-
    { - (tpl :: tpl.linearizationTemplates) map { wte =>
  1. { wte.name }
  2. } - }
-
- } - { -
- Visibility -
  1. Public
  2. All
+
+
+ { if (tpl.linearizationTemplates.isEmpty) NodeSeq.Empty else +
+ Ordering +
  1. Alphabetic
  2. By inheritance
- } -
+ } + { if (tpl.linearizationTemplates.isEmpty) NodeSeq.Empty else +
+ Inherited +
  1. Hide All
  2. +
  3. Show all
+
    { + (tpl :: tpl.linearizationTemplates) map { wte =>
  1. { wte.name }
  2. } + }
+
+ } + { +
+ Visibility +
  1. Public
  2. All
+
+ } +
+
+
{ if (constructors.isEmpty) NodeSeq.Empty else

Instance Constructors

@@ -142,7 +142,9 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage {
    { deprValueMembers map (memberToHtml(_)) }
} +
+
{ NodeSeq fromSeq (for ((superTpl, superType) <- (tpl.linearizationTemplates zip tpl.linearizationTypes)) yield
@@ -161,6 +163,7 @@ class Template(tpl: DocTemplateEntity) extends HtmlPage {
) } +
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("

Type Members

    "); 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("

    Value Members

      "); 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() -- cgit v1.2.3