function news_ajax(event, count, offset, privileged) { /* * event - The click event, passed to hide the element when necessary. * count - Number of news items to fetch. * offset - Database offset for fetching news. * privilege - Gotta check your privilege (used to show/hide [Edit] on news). */ // Unbind onclick to avoid spamclicks. $(event.target).attr('onclick', 'return false;'); // Fetch news data, check for errors etc. $.get("ajax.php", { action: "news_ajax", count: count, offset: offset }) .done(function(data) { var response = $.parseJSON(data.response); if (typeof data == 'undefined' || data == null || data.status != "success" || typeof response == 'undefined' || response == null) { console.log("ERR ajax_news(" + (new Error).lineNumber + "): Unknown data or failure returned."); // Return to original paremeters, no news were added. $(event.target).attr('onclick', 'news_ajax(event, ' + count + ', ' + offset + ', ' + privileged + '); return false;'); } else { if (response.length == 0) { $(event.target).parent().remove(); } else { var targetClass = $('#more_news').prev().attr('class'); $.each(response, function() { // Create a new element, insert the news. $('#more_news').before($('
', { id: 'news' + this[0], Class: targetClass })); // I'm so happy with this condition statement. if (privileged) { $('#news' + this[0]).append(''); } else { $('#news' + this[0]).append('