summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Reinert <mail@jreinert.com>2015-05-01 22:28:54 +0200
committerFlorian Pritz <bluewind@xinu.at>2015-05-05 12:21:27 +0200
commitda835670f796774d1f98c05dfdf7da1c7ba2655a (patch)
tree22922112e521779d76c7f2b2c418cee64a729e17
parentf7da6a0ee8c3b79deb8995e592a130a4a409dc70 (diff)
Use global appConfig js variable instead of passing it down
Initialize it in header
-rw-r--r--application/views/file/html_header.php7
-rw-r--r--application/views/header.php5
-rw-r--r--data/js/application.js5
-rw-r--r--data/js/lexer-input.js10
-rw-r--r--data/js/main.js2
5 files changed, 14 insertions, 15 deletions
diff --git a/application/views/file/html_header.php b/application/views/file/html_header.php
index 520e2482a..a5a6da99f 100644
--- a/application/views/file/html_header.php
+++ b/application/views/file/html_header.php
@@ -3,14 +3,11 @@ $force_full_html = true;
include(FCPATH."application/views/header.php"); ?>
</div><!-- .container -->
-
<script type="text/javascript">
/* <![CDATA[ */
- window.appConfig = {
- lexers: <?php echo json_encode($lexers); ?>
- }
+ window.appConfig.lexers = <?php echo json_encode($lexers); ?>;
/* ]]> */
-</script>
+<script>
<?php if (isset($error_message)) {
include 'framgents/alert-wide.php';
diff --git a/application/views/header.php b/application/views/header.php
index 27fdbb92f..89a3c8617 100644
--- a/application/views/header.php
+++ b/application/views/header.php
@@ -26,8 +26,11 @@ if (is_cli_client() && !isset($force_full_html)) {
echo '<link href="'.link_with_mtime("/data/local/favicon.png").'" rel="shortcut icon">';
}
?>
- <script>
+ <script type="text/javascript">
+ /* <![CDATA[ */
var require = { baseUrl: '/data/js' };
+ window.appConfig = {};
+ /* ]]> */
</script>
<script data-main="main" src="/data/js/vendor/require.js"></script>
</head>
diff --git a/data/js/application.js b/data/js/application.js
index 76ed5ae55..06a53854d 100644
--- a/data/js/application.js
+++ b/data/js/application.js
@@ -21,12 +21,11 @@ define(
* Gets called for every request after page load
* config contains app config attributes passed from php
*/
- onPageLoaded: function (config) {
- config = config || {};
+ onPageLoaded: function () {
Util.highlightLineFromHash();
Util.setTabwidthFromLocalStorage();
TabwidthInput.initialize();
- LexerInput.initialize(config.lexers);
+ LexerInput.initialize();
ThumbnailView.initialize();
this.configureTooltips();
this.setupToggleSelectAllEvent();
diff --git a/data/js/lexer-input.js b/data/js/lexer-input.js
index a4d3c7058..85c4a5432 100644
--- a/data/js/lexer-input.js
+++ b/data/js/lexer-input.js
@@ -11,10 +11,10 @@ define(['util', 'underscore', 'jquery-ui'], function (Util, _) {
var baseUrl = $(event.target).data('base-url');
this.switchLexer(ui.item.value, baseUrl);
},
- setupAutocomplete: function (lexers) {
+ setupAutocomplete: function () {
var lexerSource = [];
- for (var key in lexers) {
- lexerSource.push({ label: lexers[key], value: key });
+ for (var key in appConfig.lexers) {
+ lexerSource.push({ label: appConfig.lexers[key], value: key });
}
$('.lexer-form input').autocomplete({
@@ -37,8 +37,8 @@ define(['util', 'underscore', 'jquery-ui'], function (Util, _) {
}
};
var LexerInput = {
- initialize: function (lexers) {
- PrivateFunctions.setupAutocomplete(lexers);
+ initialize: function () {
+ PrivateFunctions.setupAutocomplete();
PrivateFunctions.setupEvents();
}
};
diff --git a/data/js/main.js b/data/js/main.js
index 92c016d79..5710dcb68 100644
--- a/data/js/main.js
+++ b/data/js/main.js
@@ -22,7 +22,7 @@ requirejs.config({
require(['application', 'jquery'], function (App, $) {
App.initialize();
$(document).ready(function () {
- App.onPageLoaded(window.appConfig);
+ App.onPageLoaded();
});
});
})();