Use own location as API href.

This commit is contained in:
Lars Jung 2015-05-13 01:16:21 +02:00
parent 0f72db1961
commit 4f83c95d20
3 changed files with 15 additions and 31 deletions

View file

@ -1,28 +1,22 @@
modulejs.define('boot', ['$'], function ($) {
modulejs.define('boot', ['$', 'core/server'], function ($, server) {
if ($('html').hasClass('no-browser')) {
return;
}
var module = $('script[data-module]').data('module');
var data = {action: 'get', setup: true, options: true, types: true, theme: true, langs: true};
var href;
var data = {action: 'get', setup: true, options: true, types: true};
if (module === 'index') {
href = '.';
data.theme = true;
data.langs = true;
} else if (module === 'info') {
data.refresh = true;
href = 'index.php';
} else {
return;
}
$.ajax({
url: href,
data: data,
type: 'post',
dataType: 'json'
}).done(function (config) {
server.request(data, function (config) {
modulejs.define('config', config);
$(function () { modulejs.require('main/' + module); });

View file

@ -1,9 +1,9 @@
modulejs.define('core/server', ['_', '$', 'core/location'], function (_, $, location) {
modulejs.define('core/server', ['_', '$'], function (_, $) {
function request(data, callback) {
$.ajax({
url: location.getAbsHref(),
url: '?',
data: data,
type: 'post',
dataType: 'json'
@ -20,8 +20,7 @@ modulejs.define('core/server', ['_', '$', 'core/location'], function (_, $, loca
function formRequest(data) {
var $form = $('<form method="post" style="display:none;"/>')
.attr('action', location.getAbsHref());
var $form = $('<form method="post" action="?" style="display:none;"/>');
_.each(data, function (val, key) {

View file

@ -1,4 +1,4 @@
modulejs.define('main/info', ['$', 'config'], function ($, config) {
modulejs.define('main/info', ['$', 'config', 'core/server'], function ($, config, server) {
var testsTemp =
'<ul id="tests">';
@ -106,33 +106,24 @@ modulejs.define('main/info', ['$', 'config'], function ($, config) {
);
}
function request(data) {
function reload() {
$.ajax({
url: 'index.php',
type: 'post',
dataType: 'json',
data: data
})
.always(function () {
window.location.reload();
});
window.location.reload();
}
function onLogin() {
request({
server.request({
action: 'login',
pass: $('#pass').val()
});
}, reload);
}
function onLogout() {
request({
server.request({
action: 'logout'
});
}, reload);
}
function onKeydown(event) {