/**
 * xkcd-today - main javascript file
 *
 * @author poxip
 *
 */

// Setup Semantic UI
$(function () {
    $('.accordion').accordion();
});

var APP = {};
/**
 * A API url to the latest post.
 * @type {string}
 */
APP.XKCD_TODAY = 'http://xkcd.com/info.0.json';

/**
 * Shows loading error
 */
APP.onLoadingError = function () {
    // @TODO: @poxip
    console.error("Error while loading a post")
    $('#xkcd-content').removeClass('loading');
};

/**
 * Polls xkcd.com/info.0.json, gets the latest post and then show it.
 */
APP.getLatest = function () {
    $.get(this.XKCD_TODAY, function (data) {
        if (!data['img']) {
            this.onLoadingError();
        }

        $('#xkcd-title').text(data['safe_title']);
        $('#xkcd-alt').text(
            (data['alt'] !== "") ? data['alt'] : "No description"
        );

        var img = $('#xkcd-img')[0];
        img.src = data['img'];
        img.addEventListener('load', function() {
            $('#xkcd-content').removeClass('loading');
        });

        var postDate = new Date(data['year'], data['month'], data['day']);
        $('#xkcd-date').text(postDate.toLocaleDateString());

    }).fail(this.onLoadingError);
};

APP.getLatest();
@@ -333,117 +333,444 @@
     
-// @TODO: @poxip%0A    console.error(%22Error while loading a post%22)%0A    $('#xkcd-content').removeClass('loading'
+$('#xkcd-content').removeClass('loading');%0A    var errorMessage =%0A        '%3Cdiv class=%22ui negative message%22%3E %5C%0A            %3Ci class=%22close icon%22%3E%3C/i%3E %5C%0A        %3Cdiv class=%22header%22%3E %5C%0A        Sorry, this post cannot be loaded..:( %5C%0A        %3C/div%3E %5C%0A        %3Cp%3ETry %3Ca href=%22#reload%22%3Ereloading.%3C/a%3E%5C%0A        %3C/p%3E%3C/div%3E';%0A    $('#xkcd-content').html(errorMessage)%0A    $('%5Bhref=#reload%5D').click(function () %7B%0A        location.reload();%0A    %7D
 );%0A%7D

Add information about an error