From b649cd15195c343b1f6825d7749f56330474520b Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Mon, 17 Sep 2012 22:37:20 +0200 Subject: [PATCH] Cleans config to pure json. --- src/_h5ai/apache/h5ai-footer.html.jade | 9 +------ src/_h5ai/apache/h5ai-header.html.jade | 2 ++ src/_h5ai/{config.js => config.json} | 7 +++--- src/_h5ai/js/scripts.js | 34 ++++++++++++++++---------- src/_h5ai/php/h5ai-index.php.jade | 1 - src/_h5ai/php/inc/H5ai.php | 8 +++--- 6 files changed, 30 insertions(+), 31 deletions(-) rename src/_h5ai/{config.js => config.json} (99%) diff --git a/src/_h5ai/apache/h5ai-footer.html.jade b/src/_h5ai/apache/h5ai-footer.html.jade index cf6d4d71..4b4a411d 100644 --- a/src/_h5ai/apache/h5ai-footer.html.jade +++ b/src/_h5ai/apache/h5ai-footer.html.jade @@ -1,10 +1,3 @@ -- var h5ai = "/_h5ai/" - // generated code ends here -| - -script( src!="#{h5ai}config.js" ) -script( src!="#{h5ai}js/scripts.js" ) - -| +| diff --git a/src/_h5ai/apache/h5ai-header.html.jade b/src/_h5ai/apache/h5ai-header.html.jade index 68cd5d78..d64e4bcf 100644 --- a/src/_h5ai/apache/h5ai-header.html.jade +++ b/src/_h5ai/apache/h5ai-header.html.jade @@ -39,5 +39,7 @@ div#bottombar.clearfix span.right span.center + script( src!="#{h5ai}js/scripts.js" ) + |
// The following code was generated by Apache's autoindex module. It is not valid HTML5, but gets removed from the DOM tree as soon as possible. The actual page should render as valid HTML5. diff --git a/src/_h5ai/config.js b/src/_h5ai/config.json similarity index 99% rename from src/_h5ai/config.js rename to src/_h5ai/config.json index dafa14cd..245da50e 100644 --- a/src/_h5ai/config.js +++ b/src/_h5ai/config.json @@ -3,11 +3,10 @@ {{pkg.url}} Configuration -options, types and localization +options, types and langs */ -var H5AI_CONFIG = { - +{ "options": { /* @@ -431,4 +430,4 @@ var H5AI_CONFIG = { "zh-cn": "简体中文", "zh-tw": "正體中文" } -}; +} diff --git a/src/_h5ai/js/scripts.js b/src/_h5ai/js/scripts.js index 84933bb7..bf6a96b3 100644 --- a/src/_h5ai/js/scripts.js +++ b/src/_h5ai/js/scripts.js @@ -21,20 +21,28 @@ // @include "inc/**/*.js" - $(function () { - /*global H5AI_CONFIG, amplify, Base64, jQuery, Modernizr, moment, _ */ + $.ajax({ + url: $('script[src$="/js/scripts.js"]').attr('src').replace(/\/js\/scripts.js$/, '/config.json'), + complete: function (data) { - // `jQuery`, `moment` and `underscore` are itself functions, - // so they have to be wrapped to not be handled as constructors. - modulejs.define('config', H5AI_CONFIG); - modulejs.define('amplify', amplify); - modulejs.define('base64', Base64); - modulejs.define('$', function () { return jQuery; }); - modulejs.define('modernizr', Modernizr); - modulejs.define('moment', function () { return moment; }); - modulejs.define('_', function () { return _; }); + var config = JSON.parse(data.responseText.replace(/\/\*[\s\S]*?\*\/|\/\/.*?(\n|$)/g, '')); - modulejs.require($('body').attr('id')); - }); + $(function () { + /*global amplify, Base64, jQuery, Modernizr, moment, _ */ + + // `jQuery`, `moment` and `underscore` are itself functions, + // so they have to be wrapped to not be handled as constructors. + modulejs.define('config', config); + modulejs.define('amplify', amplify); + modulejs.define('base64', Base64); + modulejs.define('$', function () { return jQuery; }); + modulejs.define('modernizr', Modernizr); + modulejs.define('moment', function () { return moment; }); + modulejs.define('_', function () { return _; }); + + modulejs.require($('body').attr('id')); + }); + }} + ); }(jQuery)); diff --git a/src/_h5ai/php/h5ai-index.php.jade b/src/_h5ai/php/h5ai-index.php.jade index 250ac430..d8030fdc 100644 --- a/src/_h5ai/php/h5ai-index.php.jade +++ b/src/_h5ai/php/h5ai-index.php.jade @@ -62,5 +62,4 @@ html.no-js( lang="en" ) div#data-php-no-js-fallback.hideOnJs !{fallback} - script( src!="#{h5ai}config.js" ) script( src!="#{h5ai}js/scripts.js" ) diff --git a/src/_h5ai/php/inc/H5ai.php b/src/_h5ai/php/inc/H5ai.php index b94defbb..c31a1a08 100644 --- a/src/_h5ai/php/inc/H5ai.php +++ b/src/_h5ai/php/inc/H5ai.php @@ -28,10 +28,8 @@ class H5ai { $str = file_exists($file) ? file_get_contents($file) : ""; - // remove comments and change expression to pure json - $str = preg_replace("/\/\*.*?\*\//s", "", $str); - $str = preg_replace("/^.*H5AI_CONFIG\s*=\s*/s", "", $str); - $str = preg_replace("/;.*/s", "", $str); + // remove comments to get pure json + $str = preg_replace("/\/\*.*?\*\/|\/\/.*?(\n|$)/s", "", $str); $config = json_decode($str, true); return $config; @@ -63,7 +61,7 @@ class H5ai { $this->ignore_patterns = $H5AI_CONFIG["IGNORE_PATTERNS"]; $this->index_files = $H5AI_CONFIG["INDEX_FILES"]; - $this->config = H5ai::load_config($this->h5aiAbsPath . "/config.js"); + $this->config = H5ai::load_config($this->h5aiAbsPath . "/config.json"); $this->options = $this->config["options"]; $this->h5aiAbsHref = H5ai::normalize_path($this->options["h5aiAbsHref"], true);