Permalink
Browse files

added sub concepts and expand

  • Loading branch information...
1 parent b6dc9e6 commit dcfe5c85aa55c296ec20a474d580ae8d55e2841f mhausenblas committed Feb 29, 2012
Showing with 81 additions and 13 deletions.
  1. +39 −5 sandbox/schema-org-nav/rdfa.css
  2. +2 −2 sandbox/schema-org-nav/rdfa.html
  3. +40 −6 sandbox/schema-org-nav/schema-org-nav.js
@@ -1,3 +1,7 @@
+body {
+ padding: 5px;
+}
+
span.h {
padding-left: 0px;
font-weight: bold;
@@ -9,24 +13,39 @@ span {
}
#nav {
- position: absolute;
+ font-family: Helvetica;
+ position: fixed;
right: 10px;
top: 10px;
+ border: 1px solid #e0e0e0;
+ background: #f0f0f0;
display: none;
}
#nav-output {
- position: absolute;
+ font-family: Helvetica;
+ position: fixed;
right: 10px;
top: 10px;
- font-size: 90%;
border: 1px solid #e0e0e0;
- padding: 10px;
- width: 200px;
background: #f0f0f0;
+ padding: 10px;
+ width: 300px;
display: none;
}
+#nav-output h3 {
+ font-size: 90%;
+ border-bottom: 1px solid #e0e0e0;
+ padding: 5px;
+}
+
+#nav-output div {
+ font-size: 80%;
+ padding: 2px;
+}
+
+
#explore {
color: #00e;
cursor: pointer;
@@ -41,4 +60,19 @@ span {
}
.lnk {
+ margin: 10px;
+}
+
+.lnk span {
+ width: 200px;
+}
+
+.lnk span.expand {
+ font-size: 100%;
+ border: 1px solid #e0e0e0;
+ width: 10px;
+ float: left;
+ margin-right: 5px;
+ cursor: pointer;
+ padding: 0 0 0 2px;
}
@@ -13,7 +13,7 @@
xmlns:doap="http://usefulinc.com/ns/doap#">
<head>
<title>RDFa Lite Reflection</title>
- <link rel="stylesheet" href="rdfa.css">
+ <link rel="stylesheet" href="rdfa.css" />
</head>
<body>
@@ -3216,7 +3216,7 @@
<!-- local libs to boost performance: -->
<script src="lib/jquery.min.js"></script>
- <script src="lib/jquery-ui.min.js"></script>
+ <!-- <script src="lib/jquery-ui.min.js"></script> -->
<script src="lib/jquery.rdfquery.rdfa.min-1.0.js"></script>
<script src="schema-org-nav.js"></script>
</body>
@@ -1,13 +1,12 @@
var SCHEMA_ORG_BASE = 'http://schema.org/';
-var rdf;
+var rdf; // see http://code.google.com/p/rdfquery/wiki/RdfPlugin for documentation
var num_triples = 0;
$(function() {
- // init - see http://code.google.com/p/rdfquery/wiki/RdfPlugin for documentation
rdf = $('div').rdf(); // extract all RDFa markup from any div
all_triples(rdf, false); // generic processing of all triples; currently just counts it
- $('#nav').slideDown('slow');
-
+ show_nav();
+
$('#explore').click(function() {
render_toplevel_things(rdf);
hide_nav();
@@ -18,9 +17,39 @@ $(function() {
$('#'+targetID).css('border', '1px solid #ff3333');
// return true;
});
+
+ $(".lnk .expand").live("click", function(){
+ var conceptID = $(this).attr('id').toString().substring('expand___'.length);
+ render_concept(rdf, conceptID, 'Thing');
+ });
+
});
-function render_toplevel_things(rdf, do_log){
+
+function render_concept(rdf, conceptID, parentID){
+ var things = []; // the things (direct sub-classes of concept)
+
+ $('#subconcepts').html('<h3>' + parentID + ' : ' + conceptID + "</h3>");
+
+ rdf
+ .prefix('rdfs', 'http://www.w3.org/2000/01/rdf-schema#')
+ .where('?s rdfs:subClassOf <http://schema.org/'+ conceptID + '>')
+ .each(function () {
+ if($.inArray(this.s.value, things) == -1){ // not already in the seen list, remember each subject only once
+ things.push(this.s.value);
+ }
+ });
+ // present things in alphabetical order
+ things.sort();
+ for(i=0; i < things.length; i++){
+ var t = things[i].toString().substring(SCHEMA_ORG_BASE.length);
+ var t_id = '__'+ t;
+ $('<div class="dynanchor" id="' + t_id + '" >&middot;</div>').insertBefore('div[about|="'+ things[i] + '"]'); // find the div and add an @id before
+ $('#subconcepts').append('<div class="lnk"><span class="expand" id="expand_' + t_id + '" title="expand this concept">&laquo;</span><span><a href="#' + t_id +'">' + t + '</a></span></div>'); // build result
+ }
+}
+
+function render_toplevel_things(rdf){
var toplevel_things = []; // the top level things (direct sub-classes of schema:Thing)
$('#nav-output').html('<h3>Top-level concepts</h3>');
$('#nav-output').slideDown('slow');
@@ -38,14 +67,19 @@ function render_toplevel_things(rdf, do_log){
var t = toplevel_things[i].toString().substring(SCHEMA_ORG_BASE.length);
var t_id = '__'+ t;
$('<div class="dynanchor" id="' + t_id + '" >&middot;</div>').insertBefore('div[about|="'+ toplevel_things[i] + '"]'); // find the div and add an @id before
- $('#nav-output').append('<div class="lnk"><a href="#' + t_id +'">' + t + '</a></div>'); // build result
+ $('#nav-output').append('<div class="lnk"><span class="expand" id="expand_' + t_id + '" title="expand this concept">&laquo;</span><span><a href="#' + t_id +'">' + t + '</a></span></div>'); // build result
}
+ $('#nav-output').append('<div id="subconcepts" />');
}
function hide_nav(){
$('#nav').slideUp('fast');
}
+function show_nav(){
+ $('#nav').slideDown('slow');
+}
+
function all_triples(rdf, do_log){
rdf
.where('?s ?p ?o')

0 comments on commit dcfe5c8

Please sign in to comment.