mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 12:34:47 -04:00
Adds ajax abstraction. Refactors global dependencies.
This commit is contained in:
parent
018a574d5e
commit
64640ada83
31 changed files with 245 additions and 167 deletions
|
@ -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);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue