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
|</div>
script( src!="#{h5ai}config.js" )
script( src!="#{h5ai}js/scripts.js" )
|</body></html>
|</div></body></html>

View File

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

View File

@ -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": "正體中文"
}
};
}

View File

@ -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));

View File

@ -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" )

View File

@ -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);