Connexions Course II

by dandiebolt

HTML

<script src="https://github.com/jquery/jquery-tmpl/raw/master/jquery.tmpl.min.js"></script>
<link rel="stylesheet" href="http://cnx.org/extjs/resources/css/ext-all.css">
<link rel="stylesheet" href="http://cnx.org/cnx-styles/newlook/document.css">
<link rel="stylesheet" href="http://cnx.org/cnx-styles/newlook/print.css">
<h1>Select a ConneXions Module</h1>
<select id="module" name="module">
    <option value="m0050">The Sampling Theorem</option>
    <option value="m0051">Amplitude Quantization</option>
    <option value="m0052">Summary of Series and Parallel Combination Rules</option>
    <option value="m0053">Dependent Sources</option>
    <option value="m0054">Using Operational Amplifiers</option>
    <option value="m0055">Inverting Amplifier</option>
    <option value="m0056">Inverting Amplifiers with Impedances</option>
    <option value="m0057">Designing Circuits with Operational Amplifiers</option>
    <option value="m0058">Diode Behavior</option>
    <option value="m0059">Logarithmic Amplifier</option>
</select>

<br/><hr/><br/>

<h1>Title Extracted From XML Representation</h1>
<div id="title"></div>

<br/><hr/><br/>

<h1>Client Side XML Representation</h1>
<textarea id="xml" cols="70" rows="100"></textarea>

JavaScript

function updateModule(course)  {
    var query = "";
    query += "SELECT * ";
    query += "FROM xml ";
    query += "WHERE url='http://cnx.org/content/" + course + "/latest/source' ";
    //console.log("query=" + query);

    var yql = "";
    yql += "http://query.yahooapis.com/v1/public/yql?q=";
    yql += encodeURIComponent(query);
    yql += "&format=xml";
    yql += "&callback=?";
    //console.log("yql=" + yql);

    $.getJSON(yql,function(data) {
        //console.dir(data.results[0]);
        $course = $(data.results[0]);
        
        title=$course.find("title:first").html();
        if (title === null) {
            $("#title").html("This course has no title in the XML Representation!");
        } else {
            $("#title").html(title);
        }
        $("#xml").val(data.results[0]);
    });
}

$("#module").change(function(){
    var course = $(this).val();
    updateModule(course);
    
});

updateModule($("#module option:first").val());