Skip to content

Instantly share code, notes, and snippets.

@webhat
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webhat/9655726 to your computer and use it in GitHub Desktop.
Save webhat/9655726 to your computer and use it in GitHub Desktop.
A Pen by Daniel W. Crompton.
<body>
<div id='course_list'></div>
</body>
(function ($) {
var url = 'https://marketplace.oplerno.com/teachers.json';
$.ajax({
type: 'GET',
url: url,
async: false,
contentType: "application/jsonp",
dataType: 'jsonp',
success: function (data, status) {
populate(data);
}
});
})(jQuery);
function populate(teachers, status) {
$(teachers).each(function (i) {
if ((typeof this.first_name == 'undefined') && (typeof this.last_name == 'undefined'))
return;
fn = $("<div class='course' />");
title = $("<div class='title' />");
fullname = $("<div class='first_name last_name' />");
desc = $("<div class='course_description' />");
email = $("<a href=''>Email the instructor</a>");
email.attr('href', 'mailto:' + this.first_name[0] + '' + this.last_name + '@oplerno.com')
fullname.text(text(this, 'first_name') + " " + text(this, 'last_name'));
desc.text(text(this, 'description'));
fn.append(title, fullname, desc, email);
$('#course_list').prepend(fn);
});
function text(_this, field) {
return (typeof _this[field] != 'undefined' ? _this[field] : "")
}
}
#course_list {
float:left;
width:auto;
height:auto;
}
.course_description {
margin-bottom: 20px;
}
.course {
margin: 20px 0px 20px;
border-bottom: 1px solid #000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment