OER Glue
by dandiebolt
HTML
<script src="https://github.com/jquery/jquery-tmpl/raw/master/jquery.tmpl.min.js"></script>
<script src="https://www.quickbase.com/db/befe2yy7d?a=dbpage&pagename=jsonpath-0.8.0.js"></script>
<script id="template1" type="text/x-jquery-tmpl">
Page Title: <b>${data.title}</b><br/>
${attr.id}<br/>
<a href="${data.attr.href}" target="_blank">URL</a><br/>
<hr/>
</script>
<script id="template2" type="text/x-jquery-tmpl">
<textarea cols="80" rows="15">${script}</textarea>
action=${action}<br/>
url=${url}<br/>
id=${id}<br/>
xpath=${xpath}<br/>
<hr/>
</script>
<h1>Course Tree</h1>
<hr/>
<div id="info1"></div>
<hr/>
<hr/>
<h1>Page Scripts</h1>
<hr/>
<div id="info2"></div>
JavaScript
// YQL Query
// SELECT *
// FROM json
// WHERE url="http://www.oerglue.com/courses/my-test-course.json"
// YQL Console Permalink
// http://developer.yahoo.com/yql/console/?q=select%20*%20from%20json%20where%20url%3D%22http%3A%2F%2Fwww.oerglue.com%2Fcourses%2Fmy-test-course.json%22&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
// YQL Query (JSON Response)
// http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3D%22http%3A%2F%2Fwww.oerglue.com%2Fcourses%2Fmy-test-course.json%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=cbfunc
var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3D%22http%3A%2F%2Fwww.oerglue.com%2Fcourses%2Fmy-test-course.json%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
var xscript, xuncompiled_script, xaction, xurl, xid, xxpath;
$.ajax({
url: url,
dataType: 'jsonp',
success: function(data) {
var course_tree=data.query.results.json.course_tree;
var page_scripts=data.query.results.json.page_scripts;
$("#template1").tmpl(course_tree).appendTo("#info1");
var data_arr=[];
$.each(page_scripts,function(key,val) {
xscript=jsonPath(val, "$..script");
xuncompiled_script=jsonPath(val, "$..uncompiled_script");
xaction=jsonPath(val, "$..action");
xurl=jsonPath(val, "$..url");
xid=jsonPath(val, "$..id");
xxpath=jsonPath(val, "$..xpath");
data_arr.push({script: xscript,
uncompiled_script: xuncompiled_script,
action: xaction,
url: xurl,
id: xid,
xpath: xxpath});
});
$("#template2").tmpl(data_arr).appendTo("#info2");
}
});