diff --git a/public_html/dispatch.php b/public_html/dispatch.php index 5bcfe3f2..1ca0ffb2 100644 --- a/public_html/dispatch.php +++ b/public_html/dispatch.php @@ -42,8 +42,8 @@ $context->simpleActionName = null; Assets::setTitle(Core::getConfig()->main->title); $context->handleExceptions = false; -$context->json = isset($_GET['json']); -$context->layoutName = $context->json +$context->layoutName + = isset($_SERVER['HTTP_X_AJAX']) ? 'layout-json' : 'layout-normal'; $context->viewName = ''; @@ -87,7 +87,7 @@ catch (SimpleException $e) catch (Exception $e) { \Chibi\Util\Headers::setCode(400); - Messenger::message($e->getMessage()); + Messenger::message($e->getMessage(), false); $context->transport->exception = $e; $context->transport->queries = \Chibi\Database::getLogs(); $context->viewName = 'error-exception'; diff --git a/public_html/media/js/comment-edit.js b/public_html/media/js/comment-edit.js index 5023067f..c8a3d920 100644 --- a/public_html/media/js/comment-edit.js +++ b/public_html/media/js/comment-edit.js @@ -20,7 +20,7 @@ $(function() formDom.addClass('inactive'); formDom.find(':input').attr('readonly', true); - var url = formDom.attr('action') + '?json'; + var url = formDom.attr('action'); var fd = new FormData(formDom[0]); var preview = false; @@ -36,7 +36,6 @@ $(function() data: fd, processData: false, contentType: false, - type: 'POST', success: function(data) { @@ -51,7 +50,7 @@ $(function() formDom.find('.preview').hide(); var cb = function() { - $.get(window.location.href, function(data) + $.get(window.location.href).success(function(data) { $('.comments-wrapper').replaceWith($(data).find('.comments-wrapper')); $('body').trigger('dom-update'); @@ -84,7 +83,7 @@ $(function() } }; - $.ajax(ajaxData); + postJSON(ajaxData); }); $('.comment .edit a').bindOnce('edit-comment', 'click', function(e) @@ -100,7 +99,7 @@ $(function() if (formDom.length == 0) { - $.get($(this).attr('href'), function(data) + $.get($(this).attr('href')).success(function(data) { var otherForm = $(data).find('form.edit-comment'); otherForm.hide(); diff --git a/public_html/media/js/core.js b/public_html/media/js/core.js index 9b6d338a..d029c3e4 100644 --- a/public_html/media/js/core.js +++ b/public_html/media/js/core.js @@ -32,6 +32,24 @@ function rememberLastSearchQuery() } //core functionalities, prototypes +function getJSON(data) +{ + if (typeof(data.headers) === 'undefined') + data.headers = {}; + data.headers['X-Ajax'] = '1'; + data.type = 'GET'; + return $.ajax(data); +}; + +function postJSON(data) +{ + if (typeof(data.headers) === 'undefined') + data.headers = {}; + data.headers['X-Ajax'] = '1'; + data.type = 'POST'; + return $.ajax(data); +}; + $.fn.hasAttr = function(name) { return this.attr(name) !== undefined; @@ -83,8 +101,8 @@ $(function() return; aDom.addClass('inactive'); - var url = $(this).attr('href') + '?json'; - $.post(url).success(function(data) + var url = $(this).attr('href'); + postJSON({ url: url }).success(function(data) { if (aDom.hasAttr('data-redirect-url')) window.location.href = aDom.attr('data-redirect-url'); @@ -173,21 +191,26 @@ function split(val) function retrieveTags(searchTerm, cb) { - var options = { search: searchTerm }; - $.getJSON('/tags-autocomplete?json', options, function(data) + var options = { - var tags = $.map(data.tags.slice(0, 15), function(tag) + url: '/tags-autocomplete', + data: { search: searchTerm } + }; + getJSON(options) + .success(function(data) { - var ret = + var tags = $.map(data.tags.slice(0, 15), function(tag) { - label: tag.name + ' (' + tag.count + ')', - value: tag.name, - }; - return ret; - }); + var ret = + { + label: tag.name + ' (' + tag.count + ')', + value: tag.name, + }; + return ret; + }); - cb(tags); - }); + cb(tags); + }); } $(function() @@ -249,8 +272,17 @@ function attachTagIt(target) { var targetTagit = ui.tag.parents('.tagit'); var context = target.tagit('assignedTags'); - options = { context: context, tag: ui.tagLabel }; - if (targetTagit.siblings('.related-tags:eq(0)').data('for') == options.tag) + var options = + { + url: '/tags-related', + data: + { + context: context, + tag: ui.tagLabel + } + }; + + if (targetTagit.siblings('.related-tags:eq(0)').data('for') == options.data.tag) { targetTagit.siblings('.related-tags').slideUp(function() { @@ -259,7 +291,7 @@ function attachTagIt(target) return; } - $.getJSON('/tags-related?json', options, function(data) + getJSON(options).success(function(data) { var list = $('