From ede2316f53aab1f823cd2f3e57abf284fd60b56f Mon Sep 17 00:00:00 2001
From: Lars Jung <lrsjng@gmail.com>
Date: Wed, 19 Sep 2012 23:59:53 +0200
Subject: [PATCH] Cleans code.

---
 src/_h5ai/config.json   |  2 +-
 src/_h5ai/js/scripts.js | 50 +++++++++++++++++++++++------------------
 2 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/src/_h5ai/config.json b/src/_h5ai/config.json
index 245da50e..2afb5d93 100644
--- a/src/_h5ai/config.json
+++ b/src/_h5ai/config.json
@@ -198,7 +198,7 @@ options, types and langs
 
 		/* [all]
 		Adds Piwik tracker javascript code.
-		baseURL without protocol
+		"baseURL" without protocol
 		*/
 		"piwik-analytics": {
 			"enabled": false,
diff --git a/src/_h5ai/js/scripts.js b/src/_h5ai/js/scripts.js
index b5078066..ce8afac7 100644
--- a/src/_h5ai/js/scripts.js
+++ b/src/_h5ai/js/scripts.js
@@ -25,8 +25,6 @@
 		globalConfigHref = $scriptTag.attr('src').replace(/scripts.js$/, '../config.json'),
 		localConfigHref = $scriptTag.data('config') || './_h5ai.config.json',
 
-		ajaxOpts = {dataType: 'text'},
-
 		parse = function (response) {
 
 			return response.replace ? JSON.parse(response.replace(/\/\*[\s\S]*?\*\/|\/\/.*?(\n|$)/g, '')) : {};
@@ -40,6 +38,33 @@
 			});
 		},
 
+		loadConfig = function (callback) {
+
+			var ajaxOpts = {
+					dataType: 'text'
+				},
+				config = {
+					options: {},
+					types: {},
+					langs: {}
+				};
+
+			$.ajax(globalConfigHref, ajaxOpts).always(function (g) {
+
+				extendLevel1(config, parse(g));
+				if (localConfigHref === 'ignore') {
+					callback(config);
+					return;
+				}
+
+				$.ajax(localConfigHref, ajaxOpts).always(function (l) {
+
+					extendLevel1(config, parse(l));
+					callback(config);
+				});
+			});
+		},
+
 		run = function (config) {
 			/*global amplify, Base64, jQuery, Modernizr, moment, _ */
 
@@ -57,27 +82,8 @@
 
 				modulejs.require($('body').attr('id'));
 			});
-		},
-
-		config = {
-			options: {},
-			types: {},
-			langs: {}
 		};
 
-	$.ajax(globalConfigHref, ajaxOpts).always(function (g) {
-
-		extendLevel1(config, parse(g));
-		if (localConfigHref === 'ignore') {
-			run(config);
-			return;
-		}
-
-		$.ajax(localConfigHref, ajaxOpts).always(function (l) {
-
-			extendLevel1(config, parse(l));
-			run(config);
-		});
-	});
+	loadConfig(run);
 
 }(jQuery));