Cleans config to pure json.

This commit is contained in:
Lars Jung 2012-09-17 22:37:20 +02:00
parent 0e05e6d0a1
commit b649cd1519
6 changed files with 30 additions and 31 deletions

View file

@ -1,10 +1,3 @@
- var h5ai = "/_h5ai/"
// generated code ends here // generated code ends here
|</div> |</div></body></html>
script( src!="#{h5ai}config.js" )
script( src!="#{h5ai}js/scripts.js" )
|</body></html>

View file

@ -39,5 +39,7 @@ div#bottombar.clearfix
span.right span.right
span.center span.center
script( src!="#{h5ai}js/scripts.js" )
|<div id="data-apache-autoindex" class="hideOnJs"> |<div id="data-apache-autoindex" class="hideOnJs">
// 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. // 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.

View file

@ -3,11 +3,10 @@
{{pkg.url}} {{pkg.url}}
Configuration Configuration
options, types and localization options, types and langs
*/ */
var H5AI_CONFIG = { {
"options": { "options": {
/* /*
@ -431,4 +430,4 @@ var H5AI_CONFIG = {
"zh-cn": "简体中文", "zh-cn": "简体中文",
"zh-tw": "正體中文" "zh-tw": "正體中文"
} }
}; }

View file

@ -21,20 +21,28 @@
// @include "inc/**/*.js" // @include "inc/**/*.js"
$(function () { $.ajax({
/*global H5AI_CONFIG, amplify, Base64, jQuery, Modernizr, moment, _ */ url: $('script[src$="/js/scripts.js"]').attr('src').replace(/\/js\/scripts.js$/, '/config.json'),
complete: function (data) {
// `jQuery`, `moment` and `underscore` are itself functions, var config = JSON.parse(data.responseText.replace(/\/\*[\s\S]*?\*\/|\/\/.*?(\n|$)/g, ''));
// 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 _; });
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)); }(jQuery));

View file

@ -62,5 +62,4 @@ html.no-js( lang="en" )
div#data-php-no-js-fallback.hideOnJs !{fallback} div#data-php-no-js-fallback.hideOnJs !{fallback}
script( src!="#{h5ai}config.js" )
script( src!="#{h5ai}js/scripts.js" ) script( src!="#{h5ai}js/scripts.js" )

View file

@ -28,10 +28,8 @@ class H5ai {
$str = file_exists($file) ? file_get_contents($file) : ""; $str = file_exists($file) ? file_get_contents($file) : "";
// remove comments and change expression to pure json // remove comments to get pure json
$str = preg_replace("/\/\*.*?\*\//s", "", $str); $str = preg_replace("/\/\*.*?\*\/|\/\/.*?(\n|$)/s", "", $str);
$str = preg_replace("/^.*H5AI_CONFIG\s*=\s*/s", "", $str);
$str = preg_replace("/;.*/s", "", $str);
$config = json_decode($str, true); $config = json_decode($str, true);
return $config; return $config;
@ -63,7 +61,7 @@ class H5ai {
$this->ignore_patterns = $H5AI_CONFIG["IGNORE_PATTERNS"]; $this->ignore_patterns = $H5AI_CONFIG["IGNORE_PATTERNS"];
$this->index_files = $H5AI_CONFIG["INDEX_FILES"]; $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->options = $this->config["options"];
$this->h5aiAbsHref = H5ai::normalize_path($this->options["h5aiAbsHref"], true); $this->h5aiAbsHref = H5ai::normalize_path($this->options["h5aiAbsHref"], true);