Refactor js init sequence.

This commit is contained in:
Lars Jung 2015-04-18 00:38:28 +02:00
parent b1b5e37ab6
commit 5f2a7985d8
5 changed files with 34 additions and 33 deletions

View file

@ -0,0 +1,30 @@
modulejs.define('boot', ['$'], function ($) {
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 url;
if (module === 'index') {
url = '.';
} else if (module === 'info') {
data.updatecmds = true;
url = 'server/php/index.php';
} else {
return;
}
$.ajax({
url: url,
data: data,
type: 'POST',
dataType: 'json'
}).done(function (config) {
modulejs.define('config', config);
$(function () { modulejs.require('main/' + module); });
});
});

View file

@ -1,4 +1,4 @@
modulejs.define('main', ['_', 'core/event'], function (_, event) {
modulejs.define('main/index', ['_', 'core/event'], function (_, event) {
modulejs.require('view/ensure');
modulejs.require('view/items');

View file

@ -1,4 +1,4 @@
modulejs.define('info', ['$', 'config'], function ($, config) {
modulejs.define('main/info', ['$', 'config'], function ($, config) {
var testsTemp =
'<ul id="tests">';

View file

@ -10,7 +10,6 @@
'use strict';
var win = window;
modulejs.define('$', function () { return win.jQuery; });
modulejs.define('_', function () { return win._; });
modulejs.define('marked', function () { return win.marked; });
@ -19,33 +18,5 @@
// @include "inc/**/*.js"
var $ = win.jQuery;
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 url;
if (module === 'main') {
url = '.';
} else if (module === 'info') {
data.updatecmds = true;
url = 'server/php/index.php';
} else {
return;
}
$.ajax({
url: url,
data: data,
type: 'POST',
dataType: 'json'
}).done(function (config) {
modulejs.define('config', config);
$(function () { modulejs.require(module); });
});
modulejs.require('boot');
}());

View file

@ -16,7 +16,7 @@ head
link( rel="shortcut icon", href!="#{app_href}client/images/favicon/favicon-16-32.ico" )
link( rel="apple-touch-icon-precomposed", type="image/png", href!="#{app_href}client/images/favicon/favicon-152.png" )
link( rel="stylesheet", href!="#{app_href}client/css/styles.css" )
script( src!="#{app_href}client/js/scripts.js", data-module="main" )
script( src!="#{app_href}client/js/scripts.js", data-module="index" )
body