Removed ?json in favor of X-Ajax
This commit is contained in:
parent
a4f7c80fe2
commit
2a6f047c28
7 changed files with 67 additions and 36 deletions
|
@ -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';
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 = $('<ul>');
|
||||
$.each(data.tags, function(i, tag)
|
||||
|
|
|
@ -15,7 +15,7 @@ function scrolled()
|
|||
if (pageNext != null && pageNext != pageDone)
|
||||
{
|
||||
$(document).data('page-done', pageNext);
|
||||
$.get(pageNext, [], function(response)
|
||||
$.get(pageNext).success(function(response)
|
||||
{
|
||||
var dom = $(response);
|
||||
var nextPage = dom.find('.paginator .next:not(.disabled) a').attr('href');
|
||||
|
|
|
@ -12,9 +12,9 @@ $(function()
|
|||
aDom.addClass('inactive');
|
||||
|
||||
var enable = !aDom.parents('.post').hasClass('tagged');
|
||||
var url = $(this).attr('href') + '?json';
|
||||
var url = $(this).attr('href');
|
||||
url = url.replace('_enable_', enable ? '1' : '0');
|
||||
$.post(url).success(function(data)
|
||||
postJSON({ url: url }).success(function(data)
|
||||
{
|
||||
aDom.removeClass('inactive');
|
||||
aDom.parents('.post').removeClass('tagged');
|
||||
|
|
|
@ -90,7 +90,7 @@ $(function()
|
|||
}
|
||||
|
||||
var postDom = posts.first();
|
||||
var url = postDom.find('form').attr('action') + '?json';
|
||||
var url = postDom.find('form').attr('action');
|
||||
var fd = new FormData(postDom.find('form').get(0));
|
||||
|
||||
fd.append('file', postDom.data('file'));
|
||||
|
@ -104,7 +104,6 @@ $(function()
|
|||
processData: false,
|
||||
contentType: false,
|
||||
dataType: 'json',
|
||||
type: 'POST',
|
||||
success: function(data)
|
||||
{
|
||||
postDom.slideUp(function()
|
||||
|
@ -125,7 +124,7 @@ $(function()
|
|||
}
|
||||
};
|
||||
|
||||
$.ajax(ajaxData);
|
||||
postJSON(ajaxData);
|
||||
}
|
||||
|
||||
function uploadFinished()
|
||||
|
@ -204,7 +203,8 @@ $(function()
|
|||
if (matches = url.match(/watch.*?=([a-zA-Z0-9_-]+)/))
|
||||
{
|
||||
postDom.find('.file-name strong').text(url);
|
||||
$.getJSON('http://gdata.youtube.com/feeds/api/videos/' + matches[1] + '?v=2&alt=jsonc', function(data)
|
||||
var url = 'http://gdata.youtube.com/feeds/api/videos/' + matches[1] + '?v=2&alt=jsonc';
|
||||
getJSON({ url: url }).success(function(data)
|
||||
{
|
||||
postDom.find('.file-name strong')
|
||||
.text(data.data.title);
|
||||
|
|
|
@ -67,7 +67,7 @@ $(function()
|
|||
|
||||
$('.comments.unit a.simple-action').data('callback', 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');
|
||||
|
@ -76,7 +76,7 @@ $(function()
|
|||
|
||||
$('#sidebar a.simple-action').data('callback', function()
|
||||
{
|
||||
$.get(window.location.href, function(data)
|
||||
$.get(window.location.href).success(function(data)
|
||||
{
|
||||
$('#sidebar').replaceWith($(data).find('#sidebar'));
|
||||
$('body').trigger('dom-update');
|
||||
|
@ -97,7 +97,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 ajaxData =
|
||||
|
@ -112,7 +112,7 @@ $(function()
|
|||
{
|
||||
disableExitConfirmation();
|
||||
|
||||
$.get(window.location.href, function(data)
|
||||
$.get(window.location.href).success(function(data)
|
||||
{
|
||||
$('#sidebar').replaceWith($(data).find('#sidebar'));
|
||||
$('#edit-token').replaceWith($(data).find('#edit-token'));
|
||||
|
@ -132,7 +132,7 @@ $(function()
|
|||
}
|
||||
};
|
||||
|
||||
$.ajax(ajaxData);
|
||||
postJSON(ajaxData);
|
||||
});
|
||||
|
||||
Mousetrap.bind('a', function()
|
||||
|
|
Loading…
Reference in a new issue