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')) { if ($('html').hasClass('no-browser')) {
return; return;
} }
var module = $('script[data-module]').data('module'); var module = $('script[data-module]').data('module');
var data = {action: 'get', setup: true, options: true, types: true, theme: true, langs: true}; var data = {action: 'get', setup: true, options: true, types: true};
var href;
if (module === 'index') { if (module === 'index') {
href = '.'; data.theme = true;
data.langs = true;
} else if (module === 'info') { } else if (module === 'info') {
data.refresh = true; data.refresh = true;
href = 'index.php';
} else { } else {
return; return;
} }
$.ajax({ server.request(data, function (config) {
url: href,
data: data,
type: 'post',
dataType: 'json'
}).done(function (config) {
modulejs.define('config', config); modulejs.define('config', config);
$(function () { modulejs.require('main/' + module); }); $(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) { function request(data, callback) {
$.ajax({ $.ajax({
url: location.getAbsHref(), url: '?',
data: data, data: data,
type: 'post', type: 'post',
dataType: 'json' dataType: 'json'
@ -20,8 +20,7 @@ modulejs.define('core/server', ['_', '$', 'core/location'], function (_, $, loca
function formRequest(data) { function formRequest(data) {
var $form = $('<form method="post" style="display:none;"/>') var $form = $('<form method="post" action="?" style="display:none;"/>');
.attr('action', location.getAbsHref());
_.each(data, function (val, key) { _.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 = var testsTemp =
'<ul id="tests">'; '<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() { function onLogin() {
request({ server.request({
action: 'login', action: 'login',
pass: $('#pass').val() pass: $('#pass').val()
}); }, reload);
} }
function onLogout() { function onLogout() {
request({ server.request({
action: 'logout' action: 'logout'
}); }, reload);
} }
function onKeydown(event) { function onKeydown(event) {