[Pkg-javascript-commits] [knowl.js] 01/02: Initial commit.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Feb 5 23:25:31 UTC 2016


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository knowl.js.

commit 4e752e2c4891b6eaf82814905cf3490da3318f8f
Author: Doug Torrance <dtorrance at piedmont.edu>
Date:   Thu Feb 4 23:10:41 2016 -0500

    Initial commit.
---
 knowl.js       | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 knowlstyle.css | 117 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 289 insertions(+)

diff --git a/knowl.js b/knowl.js
new file mode 100644
index 0000000..840c825
--- /dev/null
+++ b/knowl.js
@@ -0,0 +1,172 @@
+/* 
+ * Knowl - Feature Demo for Knowls
+ * Copyright (C) 2011  Harald Schilly
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * 4/11/2012 Modified by David Guichard to allow inline knowl code.
+ * Sample use:
+ *      This is an <a knowl="" class="internal" 
+ *      value="Hello World!">inline knowl.</a>
+ */
+
+/*  8/14/14  Modified by David Farmer to allow knowl content to be
+ *  taken from the element with a given id.
+ *
+ * The syntax is <a knowl="" class="id-ref" refid="proofSS">Proof</a>
+ */
+ 
+/* javascript code for the knowl features 
+ * global counter, used to uniquely identify each knowl-output element
+ * that's necessary because the same knowl could be referenced several times
+ * on the same page */
+var knowl_id_counter = 0;
+ 
+function knowl_click_handler($el) {
+  // the knowl attribute holds the id of the knowl
+  var knowl_id = $el.attr("knowl");
+  // the uid is necessary if we want to reference the same content several times
+  var uid = $el.attr("knowl-uid");
+  var output_id = '#knowl-output-' + uid; 
+  var $output_id = $(output_id);
+  // create the element for the content, insert it after the one where the 
+  // knowl element is included (e.g. inside a <h1> tag) (sibling in DOM)
+  var idtag = "id='"+output_id.substring(1) + "'";
+  var kid   = "id='kuid-"+ uid + "'";
+  // if we already have the content, toggle visibility
+  if ($output_id.length > 0) {
+     $("#kuid-"+uid).slideToggle("fast");
+     $el.toggleClass("active");
+ 
+  // otherwise download it or get it from the cache
+  } else { 
+    var knowl = "<div class='knowl-output' "+kid+"><div class='knowl'><div class='knowl-content' " +idtag+ ">loading '"+knowl_id+"'</div><div class='knowl-footer'>"+knowl_id+"</div></div></div>";
+    
+    // check, if the knowl is inside a td or th in a table. otherwise assume its
+    // properly sitting inside a <div> or <p>
+    if($el.parent().is("td") || $el.parent().is("th") ) {
+      // assume we are in a td or th tag, go 2 levels up
+      var cols = $el.parent().parent().children().length;
+      $el.parents().eq(1).after(
+      // .parents().eq(1) was formerly written as .parent().parent()
+          "<tr><td colspan='"+cols+"'>"+knowl+"</td></tr>");
+    } else if ($el.parent().is("li")) {
+      $el.parent().after(knowl);
+    } 
+    // the following is implemented stupidly, but I had to do it quickly.
+    // someone please replace it with an appropriate loop -- DF
+    // the '.is("p")' is for the first paragraph of a theorem or proof
+    //also, after you close the knowl, it still has a shaded background
+    else if ($el.parent().parent().is("li")) {
+      $el.parent().parent().after(knowl);
+    } 
+    else if ($el.parent().css('display') == "block" || $el.parent().is("p")) {
+             $el.parent().after(knowl);
+    } else if ($el.parent().parent().css('display') == "block" || $el.parent().parent().is("p")) {
+             $el.parent().parent().after(knowl);
+    } else {
+     $el.parent().parent().parent().after(knowl);
+    }
+ 
+//else {
+//      // $el.parent().after(knowl);
+//      var theparents=$el.parents();
+//      var ct=0;
+//     while (theparents[ct] != "block" && ct<2) 
+//       ct++;
+//      ct=0;
+//      //$el.parents().eq(ct).after(knowl);
+//      $el.parents().eq(ct).after(theparents[1]);
+//    }
+   
+    // "select" where the output is and get a hold of it 
+    var $output = $(output_id);
+    var $knowl = $("#kuid-"+uid);
+    $output.addClass("loading");
+    $knowl.hide();
+    // DRG: inline code
+    if ($el.attr("class") == 'internal') {
+      $output.html($el.attr("value"));
+      $knowl.hide();
+      $el.addClass("active");
+      if(window.MathJax == undefined) {
+            $knowl.slideDown("slow");
+      }  else {
+        $knowl.addClass("processing");
+        MathJax.Hub.Queue(['Typeset', MathJax.Hub, $output.get(0)]);
+        MathJax.Hub.Queue([ function() { $knowl.removeClass("processing"); $knowl.slideDown("slow"); }]);
+      }
+    } 
+    else if ($el.attr("class") == 'id-ref') {
+     //get content from element with the given id
+      $output.html($("#".concat($el.attr("refid"))).html());
+      $knowl.hide();
+      $el.addClass("active");
+      if(window.MathJax == undefined) {
+            $knowl.slideDown("slow");
+      }  else {
+        $knowl.addClass("processing");
+        MathJax.Hub.Queue(['Typeset', MathJax.Hub, $output.get(0)]);
+        MathJax.Hub.Queue([ function() { $knowl.removeClass("processing"); $knowl.slideDown("slow"); }]);
+      }
+    }
+    else {
+    // Get code from server.
+    $output.load(knowl_id,
+     function(response, status, xhr) { 
+      $knowl.removeClass("loading");
+      if (status == "error") {
+        $el.removeClass("active");
+        $output.html("<div class='knowl-output error'>ERROR: " + xhr.status + " " + xhr.statusText + '</div>');
+        $output.show();
+      } else if (status == "timeout") {
+        $el.removeClass("active");
+        $output.html("<div class='knowl-output error'>ERROR: timeout. " + xhr.status + " " + xhr.statusText + '</div>');
+        $output.show();
+      } else {
+        $knowl.hide();
+        $el.addClass("active");
+      }
+      // if we are using MathJax, then we reveal the knowl after it has finished rendering the contents
+      if(window.MathJax == undefined) {
+            $knowl.slideDown("slow");
+      }  else {
+        $knowl.addClass("processing");
+        MathJax.Hub.Queue(['Typeset', MathJax.Hub, $output.get(0)]);
+        MathJax.Hub.Queue([ function() { $knowl.removeClass("processing"); $knowl.slideDown("slow"); }]);
+      }
+     }); 
+    }
+  }
+} //~~ end click handler for *[knowl] elements
+
+/** register a click handler for each element with the knowl attribute 
+ * @see jquery's doc about 'live'! the handler function does the 
+ *  download/show/hide magic. also add a unique ID, 
+ *  necessary when the same reference is used several times. */
+$(function() {
+  // $("*[knowl]").live({
+    $("body").on("click", "*[knowl]", function(evt) {
+//  click: function(evt) {
+      evt.preventDefault();
+      var $knowl = $(this);
+      if(!$knowl.attr("knowl-uid")) {
+        $knowl.attr("knowl-uid", knowl_id_counter);
+        knowl_id_counter++;
+      }
+      knowl_click_handler($knowl, evt);
+//    }
+  });
+});
+
diff --git a/knowlstyle.css b/knowlstyle.css
new file mode 100644
index 0000000..ce49b63
--- /dev/null
+++ b/knowlstyle.css
@@ -0,0 +1,117 @@
+/** page wide defs for knowls, the *[knowl] is a selector for
+ *  all elements, that have a knowl attribute set to any value */
+.knowl-content {
+  padding: 10px 10px 0 10px;
+  border-bottom-left-radius: 10px;
+  -moz-border-radius-bottomleft: 10px;
+}
+.knowl-content h1 {
+  margin: 0px 0px 10px 0px;
+}
+.knowl-content h2 {
+  margin: 0px 0px 5px 0px;
+}
+
+/* next defninition is needed to over-ride the default, which is the
+   default font size, which is 16pt */
+.knowl p {
+  margin-bottom: 0;
+  margin-top: 10px;
+}
+
+
+*[knowl] {
+  display: inline;
+  border-bottom: 1px dotted #00a;
+  color: #00a;
+  cursor: pointer;
+  border-radius: 0;
+  -webkit-border-radius: 0;
+  -moz-border-radius: 0;
+  margin: 3px 0 0 0;
+}
+*[knowl]:hover,
+*[knowl].active {
+/*
+  border-bottom: 2px solid #aaf;
+*/
+  border-bottom: 1px solid #aaf;
+  background: #ddf;
+  color: #006;
+/* no point in these being different when hovering
+  padding: 0;
+  margin: 0 0 0 0;
+  border-top-left-radius: 3px;
+  -moz-border-radius-topleft: 3px;
+  border-top-right-radius: 3px;
+  -moz-border-radius-topright: 3px;
+*/
+}
+
+
+div > *[knowl], p > *[knowl] {
+  position: relative;
+}
+
+.knowl-error {
+   color: red;
+   border-bottom: 0;
+}
+.knowl-output {
+  background: #eef;
+  border-left: 10px solid #ddf;
+  border-right: 10px solid #ddf;
+  border-bottom: 10px solid #ddf;
+  border-bottom-left-radius: 10px;
+  -moz-border-radius-bottomleft: 10px;
+  border-bottom-right-radius: 10px;
+  -moz-border-radius-bottomright: 10px;
+  display: none;
+  padding: 0px;
+  margin-top: 10px;
+  margin-bottom: 0px;
+  margin-right: 0px;
+}
+.knowl-output .knowl-output,
+.knowl-output .knowl-output.loading {
+ margin-left: 0;
+ margin-right: 0;
+}
+.knowl-output.loading {
+ color: grey;
+ font-style: italic;
+ font-size: small;
+}
+.knowl-output h1, .knowl-output h2 {
+  margin: 5px 0;
+}
+.knowl-output h1 {
+  color: #006;
+}
+.knowl-output h2 {
+  color: #006;
+}
+.knowl-output a { display: inline; }
+
+.knowl-footer {
+  position: relative;
+  bottom: -10px;
+  font-size: x-small;
+  background: #ddf;
+  color: grey;
+  padding: 1px 0 1px 10px;
+  margin:  0 0 0 0;
+}
+.knowl-footer a {
+  color: #006;
+}
+.knowl-footer a:hover {
+  background: none;
+  color: #88f;
+}
+
+.knowl-output.processing {
+  display:block!important;
+  height:0pt;
+  overflow:hidden;
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/knowl.js.git



More information about the Pkg-javascript-commits mailing list