$(document).ready(function () {
'use strict';
$.getJSON('http://api.github.com/users/FGM/repos' + '?callback=?', function (response) {
var html = '';
var items = ['
';
html += '
' + entry.term + '
';
html += '
' + entry.part + '
';
html += '
';
html += entry.definition;
if (entry.quote) {
html += '
';
$.each(entry.quote, function (lineIndex, line) {
html += '
' + line + '
';
});
if (entry.author) {
html += '
' + entry.author + '
';
}
html += '
';
}
html += '
';
html += '
';
});
$('#dictionary').html(html);
});
});
$('#letter-c a').click(function (event) {
event.preventDefault();
$.getScript('c.js');
});
$('#letter-d a').click(function (event) {
event.preventDefault();
$.get('d.xml', function (data) {
$('#dictionary').empty();
$(data).find('entry').each(function() {
var $entry = $(this);
var html = '';
html += '
' + $entry.attr('term');
html += '
';
html += '
' + $entry.attr('part');
html += '
';
html += '
';
html += $entry.find('definition').text();
var $quote = $entry.find('quote');
if ($quote.length) {
html += '
';
$quote.find('line').each(function () {
html += '
';
html += $(this).text() + '
';
});
if ($quote.attr('author')) {
html += '
';
html += $quote.attr('author') + '
';
}
html += '
';
}
html += '
';
html += '
';
$('#dictionary').append($(html));
});
});
});
$('#letter-e a').click(function (event) {
event.preventDefault();
var requestData = { term: $(this).text() };
$.get('e.php', requestData, function(data) {
$('#dictionary').html(data);
}).fail(function (jqXHR) {
$('#dictionary')
.html('Sorry, but an error occurred: ' + jqXHR.status)
.append(jqXHR.responseText);
});
});
$('#letter-f form').submit(function (event) {
event.preventDefault();
var formValues = $(this).serialize();
$.get('f.php', formValues, function(data) {
$('#dictionary').html(data);
});
});
var url = 'http://examples.learningjquery.com/jsonp/g.php';
$('#letter-g a').click(function (event) {
event.preventDefault();
$.getJSON(url + '?callback=?', function (data) {
var html = '';
$.each(data, function (entryIndex, entry) {
html += '';
html += '
' + entry.term + '
';
html += '
' + entry.part + '
';
html += '
';
html += entry.definition;
if (entry.quote) {
html += '
';
$.each(entry.quote, function (lineIndex, line) {
html += '
' + line + '
';
});
if (entry.author) {
html += '
' + entry.author + '
';
}
html += '
';
}
html += '
';
html += '
';
});
$('#dictionary').html(html);
});
});
$('#letter-h a').click(function (event) {
event.preventDefault();
$('#dictionary').load('h.html .entry');
});
var $loading = $('Loading...
')
.insertBefore('#dictionary');
$(document).ajaxStart(function () {
$loading.show();
}).ajaxStop(function () {
$loading.hide();
});
$('body').on('click', 'h3.term', function () {
$(this).siblings('.definition').slideToggle();
});
});