123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- $(document).ready(function () {
- 'use strict';
- $.getJSON('http://api.github.com/users/FGM/repos' + '?callback=?', function (response) {
- var html = '';
- var items = ['<ul>'];
- $.each(response.data, function (entryIndex, entry) {
- var name = entry.name;
- var url = entry.html_url;
- items.push('<li><a href="' + url + '">' + name + '</a></li>');
- });
- items.push('</ul>');
- $('#dictionary').html(items.join(''));
- });
- $('.letter').hover(function () {
- var $this = $(this);
- if ($this.attr('title') === undefined) {
- var idSelector = '#' + this.id;
- $.ajax({
- type: 'GET',
- url: 'exercises-contentz.html',
- dataType: 'html',
- success: function (data) {
- var $fragment= $('<div />').append($.parseHTML(data)).find(idSelector);
- var title = $fragment.text().trim();
- $this.attr('title', title);
- },
- error: function (jqXHR, textStatus, errorThrown) {
- $('#dictionary').html('Sorry, but an error occurred: ' + jqXHR.status)
- .append(jqXHR.responseText);
- }
- });
- }
- });
- $('#letter-a a').click(function (event) {
- event.preventDefault();
- $.ajaxSetup({
- url: 'a.html',
- type: 'POST',
- dataType: 'html'
- });
- $.ajax({
- type: 'GET',
- success: function (data) {
- $('#dictionary').html(data);
- }
- });
- });
- $('#letter-b a').click(function (event) {
- event.preventDefault();
- $.getJSON('b.json', function (data) {
- var html = '';
- $.each(data, function (entryIndex, entry) {
- html += '<div class="entry">';
- html += '<h3 class="term">' + entry.term + '</h3>';
- html += '<div class="part">' + entry.part + '</div>';
- html += '<div class="definition">';
- html += entry.definition;
- if (entry.quote) {
- html += '<div class="quote">';
- $.each(entry.quote, function (lineIndex, line) {
- html += '<div class="quote-line">' + line + '</div>';
- });
- if (entry.author) {
- html += '<div class="quote-author">' + entry.author + '</div>';
- }
- html += '</div>';
- }
- html += '</div>';
- html += '</div>';
- });
- $('#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 = '<div class="entry">';
- html += '<h3 class="term">' + $entry.attr('term');
- html += '</h3>';
- html += '<div class="part">' + $entry.attr('part');
- html += '</div>';
- html += '<div class="definition">';
- html += $entry.find('definition').text();
- var $quote = $entry.find('quote');
- if ($quote.length) {
- html += '<div class="quote">';
- $quote.find('line').each(function () {
- html += '<div class="quote-line">';
- html += $(this).text() + '</div>';
- });
- if ($quote.attr('author')) {
- html += '<div class="quote-author">';
- html += $quote.attr('author') + '</div>';
- }
- html += '</div>';
- }
- html += '</div>';
- html += '</div>';
- $('#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 += '<div class="entry">';
- html += '<h3 class="term">' + entry.term + '</h3>';
- html += '<div class="part">' + entry.part + '</div>';
- html += '<div class="definition">';
- html += entry.definition;
- if (entry.quote) {
- html += '<div class="quote">';
- $.each(entry.quote, function (lineIndex, line) {
- html += '<div class="quote-line">' + line + '</div>';
- });
- if (entry.author) {
- html += '<div class="quote-author">' + entry.author + '</div>';
- }
- html += '</div>';
- }
- html += '</div>';
- html += '</div>';
- });
- $('#dictionary').html(html);
- });
- });
- $('#letter-h a').click(function (event) {
- event.preventDefault();
- $('#dictionary').load('h.html .entry');
- });
- var $loading = $('<div id="loading">Loading...</div>')
- .insertBefore('#dictionary');
- $(document).ajaxStart(function () {
- $loading.show();
- }).ajaxStop(function () {
- $loading.hide();
- });
- $('body').on('click', 'h3.term', function () {
- $(this).siblings('.definition').slideToggle();
- });
- });
|