Adds ajax abstraction. Refactors global dependencies.

This commit is contained in:
Lars Jung 2012-07-13 17:57:02 +02:00
parent 018a574d5e
commit 64640ada83
31 changed files with 245 additions and 167 deletions

View file

@ -1,5 +1,5 @@
modulejs.define('model/entry', ['jQuery', 'core/types'], function ($, types) {
modulejs.define('model/entry', ['_', 'core/types', 'core/ajax'], function (_, types, ajax) {
var domain = document.domain,
location = document.location.pathname.replace(/[^\/]*$/, ''),
@ -56,25 +56,13 @@ modulejs.define('model/entry', ['jQuery', 'core/types'], function ($, types) {
},
reContentType = /^text\/html;h5ai=/,
ajaxRequest = function (self, parser, callback) {
$.ajax({
url: self.absHref,
type: parser ? 'GET' : 'HEAD',
complete: function (xhr) {
ajax.getStatus(self.absHref, parser, function (response) {
if (xhr.status === 200 && reContentType.test(xhr.getResponseHeader('Content-Type'))) {
self.status = 'h5ai';
if (parser) {
parser.parse(self.absHref, xhr.responseText);
}
} else {
self.status = xhr.status;
}
callback(self);
self.status = response.status;
if (parser && response.status === 'h5ai') {
parser.parse(self.absHref, response.content);
}
});
},