mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-06-05 01:13:40 -04:00
More changes in js.
This commit is contained in:
parent
318fefbbfd
commit
abb9b7bd0e
14 changed files with 597 additions and 543 deletions
|
@ -97,62 +97,6 @@ modulejs.define('core/ajax', ['$', 'amplify', 'base64', 'core/resource'], functi
|
|||
});
|
||||
},
|
||||
|
||||
getThumbSrc = function (data, callback) {
|
||||
|
||||
$.ajax({
|
||||
url: resource.api(),
|
||||
data: {
|
||||
action: 'getthumbsrc',
|
||||
type: data.type,
|
||||
href: data.href,
|
||||
mode: data.mode,
|
||||
width: data.width,
|
||||
height: data.height
|
||||
},
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
success: function (json) {
|
||||
|
||||
if (json.code === 0) {
|
||||
callback(json.absHref);
|
||||
}
|
||||
callback();
|
||||
},
|
||||
error: function () {
|
||||
|
||||
callback();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getThumbSrcSmall = function (type, href, callback) {
|
||||
|
||||
getThumbSrc(
|
||||
{
|
||||
type: type,
|
||||
href: href,
|
||||
mode: 'square',
|
||||
width: 16,
|
||||
height: 16
|
||||
},
|
||||
callback
|
||||
);
|
||||
},
|
||||
|
||||
getThumbSrcBig = function (type, href, callback) {
|
||||
|
||||
getThumbSrc(
|
||||
{
|
||||
type: type,
|
||||
href: href,
|
||||
mode: 'rational',
|
||||
width: 100,
|
||||
height: 48
|
||||
},
|
||||
callback
|
||||
);
|
||||
},
|
||||
|
||||
getHtml = function (url, callback) {
|
||||
|
||||
$.ajax({
|
||||
|
@ -176,8 +120,6 @@ modulejs.define('core/ajax', ['$', 'amplify', 'base64', 'core/resource'], functi
|
|||
getChecks: getChecks,
|
||||
getEntries: getEntries,
|
||||
getArchive: getArchive,
|
||||
getThumbSrcSmall: getThumbSrcSmall,
|
||||
getThumbSrcBig: getThumbSrcBig,
|
||||
getHtml: getHtml
|
||||
};
|
||||
});
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
|
||||
modulejs.define('core/refresh', ['_', 'core/mode', 'core/ajax', 'model/entry'], function (_, mode, ajax, Entry) {
|
||||
modulejs.define('core/refresh', ['_', 'core/server', 'model/entry'], function (_, server, Entry) {
|
||||
|
||||
var parseJson = function (entry, json) {
|
||||
|
||||
var found = {};
|
||||
|
||||
_.each(json, function (jsonEntry) {
|
||||
_.each(json.entries, function (jsonEntry) {
|
||||
|
||||
found[jsonEntry.absHref] = true;
|
||||
Entry.get(jsonEntry.absHref, jsonEntry.time, jsonEntry.size, jsonEntry.status, jsonEntry.content);
|
||||
|
@ -18,16 +18,18 @@ modulejs.define('core/refresh', ['_', 'core/mode', 'core/ajax', 'model/entry'],
|
|||
});
|
||||
},
|
||||
|
||||
refresh = function () {
|
||||
|
||||
if (mode.id !== 'php') {
|
||||
return;
|
||||
}
|
||||
refresh = function (callback) {
|
||||
|
||||
var entry = Entry.get();
|
||||
ajax.getEntries(entry.absHref, 1, function (json) {
|
||||
|
||||
server.request({action: 'get', entries: true, entriesHref: entry.absHref, entriesWhat: 1}, function (json) {
|
||||
|
||||
if (json) {
|
||||
parseJson(entry, json);
|
||||
}
|
||||
if (_.isFunction(callback)) {
|
||||
callback(entry);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
108
src/_h5ai/client/js/inc/core/server.js
Normal file
108
src/_h5ai/client/js/inc/core/server.js
Normal file
|
@ -0,0 +1,108 @@
|
|||
|
||||
modulejs.define('core/server', ['$', '_', 'config', 'base64'], function ($, _, config, base64) {
|
||||
|
||||
var server = _.extend({}, config.server, {
|
||||
|
||||
request: function (data, callback) {
|
||||
|
||||
if (!server.apiHref) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: server.apiHref,
|
||||
data: data,
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
success: function (json) {
|
||||
|
||||
callback(json);
|
||||
},
|
||||
error: function () {
|
||||
|
||||
callback();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
requestArchive: function (data, callback) {
|
||||
|
||||
if (!server.apiHref) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: server.apiHref,
|
||||
data: {
|
||||
action: 'archive',
|
||||
execution: data.execution,
|
||||
format: data.format,
|
||||
hrefs: data.hrefs
|
||||
},
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
beforeSend: function (xhr) {
|
||||
|
||||
if (data.user) {
|
||||
xhr.setRequestHeader('Authorization', 'Basic ' + base64.encode(data.user + ':' + data.password));
|
||||
}
|
||||
},
|
||||
success: function (json) {
|
||||
|
||||
callback(json);
|
||||
},
|
||||
error: function () {
|
||||
|
||||
callback();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
requestThumb: function (data, callback) {
|
||||
|
||||
server.request({
|
||||
action: 'getthumbsrc',
|
||||
type: data.type,
|
||||
href: data.href,
|
||||
mode: data.mode,
|
||||
width: data.width,
|
||||
height: data.height
|
||||
}, function (json) {
|
||||
|
||||
callback(json && json.code === 0 ? json.absHref : null);
|
||||
});
|
||||
},
|
||||
|
||||
requestThumbSmall: function (type, href, callback) {
|
||||
|
||||
server.requestThumb(
|
||||
{
|
||||
type: type,
|
||||
href: href,
|
||||
mode: 'square',
|
||||
width: 16,
|
||||
height: 16
|
||||
},
|
||||
callback
|
||||
);
|
||||
},
|
||||
|
||||
requestThumbBig: function (type, href, callback) {
|
||||
|
||||
server.requestThumb(
|
||||
{
|
||||
type: type,
|
||||
href: href,
|
||||
mode: 'rational',
|
||||
width: 100,
|
||||
height: 48
|
||||
},
|
||||
callback
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return server;
|
||||
});
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
modulejs.define('ext/mode', ['_', '$', 'core/mode', 'core/settings'], function (_, $, mode, allsettings) {
|
||||
modulejs.define('ext/mode', ['_', '$', 'core/settings', 'core/server'], function (_, $, allsettings, server) {
|
||||
|
||||
var settings = _.extend({
|
||||
enabled: false,
|
||||
|
@ -14,18 +14,18 @@ modulejs.define('ext/mode', ['_', '$', 'core/mode', 'core/settings'], function (
|
|||
|
||||
var info = '';
|
||||
|
||||
if (mode.id) {
|
||||
info += mode.id;
|
||||
if (server.backend) {
|
||||
info += server.backend;
|
||||
}
|
||||
if (settings.display > 0 && mode.serverName) {
|
||||
info += (info ? ' on ' : '') + mode.serverName;
|
||||
if (settings.display > 0 && server.name) {
|
||||
info += (info ? ' on ' : '') + server.name;
|
||||
}
|
||||
if (settings.display > 1 && mode.serverVersion) {
|
||||
info += (info ? '-' : '') + mode.serverVersion;
|
||||
if (settings.display > 1 && server.version) {
|
||||
info += (info ? '-' : '') + server.version;
|
||||
}
|
||||
|
||||
if (info) {
|
||||
$('#h5ai-reference').append(' (' + info + ')');
|
||||
$('#bottombar .left').append('<span id="server-mode"> (' + info + ') </span>');
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/entry', 'core/event', 'core/ajax'], function (_, allsettings, entry, event, ajax) {
|
||||
modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/entry', 'core/event', 'core/server'], function (_, allsettings, entry, event, server) {
|
||||
|
||||
var settings = _.extend({
|
||||
enabled: false,
|
||||
|
@ -24,13 +24,13 @@ modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/entry', 'core/eve
|
|||
}
|
||||
|
||||
if (type) {
|
||||
ajax.getThumbSrcSmall(type, entry.absHref, function (src) {
|
||||
server.requestThumbSmall(type, entry.absHref, function (src) {
|
||||
|
||||
if (src) {
|
||||
entry.$extended.find('.icon.small img').addClass('thumb').attr('src', src);
|
||||
}
|
||||
});
|
||||
ajax.getThumbSrcBig(type, entry.absHref, function (src) {
|
||||
server.requestThumbBig(type, entry.absHref, function (src) {
|
||||
|
||||
if (src) {
|
||||
entry.$extended.find('.icon.big img').addClass('thumb').attr('src', src);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
modulejs.define('h5ai-info', ['$', 'core/ajax'], function ($, ajax) {
|
||||
modulejs.define('h5ai-info', ['$', 'core/server'], function ($, server) {
|
||||
|
||||
var setCheckResult = function (id, result) {
|
||||
|
||||
|
@ -14,7 +14,7 @@ modulejs.define('h5ai-info', ['$', 'core/ajax'], function ($, ajax) {
|
|||
|
||||
init = function () {
|
||||
|
||||
ajax.getChecks(function (json) {
|
||||
server.request({action: 'get', checks: true}, function (json) {
|
||||
|
||||
if (json) {
|
||||
$('.test').each(function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue