W3C home > Mailing lists > Public > public-dap-commits@w3.org > July 2011

2009/dap/ReSpec.js/js respec.js,1.154,1.155

From: Frederick Hirsch via cvs-syncmail <cvsmail@w3.org>
Date: Thu, 14 Jul 2011 15:56:43 +0000
To: public-dap-commits@w3.org
Message-Id: <E1QhOHL-00079Z-B5@lionel-hutz.w3.org>
Update of /sources/public/2009/dap/ReSpec.js/js
In directory hutz:/tmp/cvs-serv27453/js

Modified Files:
	respec.js 
Log Message:
revision of best practices processing to (1) autodetect likely need for best practices processing, (2) generate summary of best practices if section with class id bp-summary is present

Index: respec.js
===================================================================
RCS file: /sources/public/2009/dap/ReSpec.js/js/respec.js,v
retrieving revision 1.154
retrieving revision 1.155
diff -u -d -r1.154 -r1.155
--- respec.js	4 Jul 2011 10:14:16 -0000	1.154
+++ respec.js	14 Jul 2011 15:56:41 -0000	1.155
@@ -194,8 +194,18 @@
             this.webIDL();
             this.examples();
 
+            // only process best practices if element with class
+            // practicelab found, do not slow down non best-practice
+            // docs.
+            // doBestPractices must be called before makeTOC, fjh
+            // this might not work with old browsers like IE 8
+
+            var bpnode = document.getElementsByClassName("practicelab");
+            if(bpnode.length > 0) this.doBestPractices(); 
+
             this.informative();
             this.fixHeaders();
+
             this.makeTOC();
             this.idHeaders();
 
@@ -205,8 +215,6 @@
 
             // if (this.doMicroData) this.makeMicroData();
             if (this.doRDFa) this.makeRDFa();
-            if( this.practiceNum) this.doBestPractices(); // do not
-            // slow down those who do not need it , fjh
             this.makeSectionRefs(); // allow references to sections using name for text, fjh
            this.unHTML5();
             this.removeRespec();
@@ -1349,12 +1357,38 @@
     doBestPractices: function () {
         this.practiceNum = 1;
         var spans = document.querySelectorAll("span.practicelab");
+        var contents = "<h2>Best Practices Summary</h2><ul>"
+        // scan all the best practices to number them and add handle
+        // at same time generate summary section contents if section
+        // is provided in source, using links if possible
+        //
+        // probably not the most efficient here but only used rarely, only
+        // for best practices documents that request it by putting
+        // practiceNum in config
         for (var i = 0; i < spans.length; i++) {
             var span = spans[i];
             var label = span.innerHTML;
-            span.innerHTML = "Best Practice " + this.practiceNum + ": " +  label;
+            var ref = span.getAttribute("id");
+            var handle = "Best Practice " + this.practiceNum;
+            var content =  ": " + label;
+            var item = handle + content;
+            if(!ref) {
+                contents += "<li>" + handle + content + "</li>";
+            } else {
+                contents += "<li><a href='#" + ref + "'>" + handle +
+                    "</a>" + content + "</li>";
+            }
+            span.innerHTML = item;
             this.practiceNum++;
         }
+        contents += "</ul>";
+
+        var sec = document.getElementById("bp-summary");
+        if(!sec) {
+//             alert("no bp-summary section");
+            return;
+        }
+        sec.innerHTML = contents;
     },
     
     //  <link href="section id" class="sectionRef" />
Received on Thursday, 14 July 2011 15:56:44 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 14 July 2011 15:56:45 GMT