mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-28 05:54:48 -04:00
Adds experimental support for local config files.
This commit is contained in:
parent
bcc9f21fc1
commit
df208faf25
5 changed files with 88 additions and 21 deletions
|
@ -58,7 +58,8 @@ To create an fresh zipball run
|
|||
* PHP ignore patterns might include paths now
|
||||
* adds optional binary prefixes for file sizes
|
||||
* improves filter: autofocus on keypress, clear on `ESC`
|
||||
* add ctrl-click file selection
|
||||
* adds ctrl-click file selection
|
||||
* adds Piwik analytics support
|
||||
* temp download packages are now stored in the `_h5ai/cache` and deleted as soon as possible
|
||||
* localization now in separate files
|
||||
* updates translations
|
||||
|
|
|
@ -7,6 +7,9 @@ modulejs.define('parser/generic-json', ['_', '$', 'core/mode', 'core/settings',
|
|||
mode.serverName = json.serverName;
|
||||
mode.serverVersion = json.serverVersion;
|
||||
|
||||
if (!settings.custom) {
|
||||
settings.custom = {};
|
||||
}
|
||||
if (_.has(json, 'customHeader')) {
|
||||
settings.custom.header = json.customHeader;
|
||||
}
|
||||
|
|
|
@ -21,13 +21,26 @@
|
|||
|
||||
// @include "inc/**/*.js"
|
||||
|
||||
$.ajax({
|
||||
url: $('script[src$="scripts.js"]').attr('src').replace(/scripts.js$/, '../config.json'),
|
||||
complete: function (data) {
|
||||
var $scriptTag = $('script[src$="scripts.js"]'),
|
||||
globalConfigHref = $scriptTag.attr('src').replace(/scripts.js$/, '../config.json'),
|
||||
localConfigHref = $scriptTag.data('config') || './_h5ai.config.json',
|
||||
|
||||
var config = JSON.parse(data.responseText.replace(/\/\*[\s\S]*?\*\/|\/\/.*?(\n|$)/g, ''));
|
||||
ajaxOpts = {dataType: 'text'},
|
||||
|
||||
$(function () {
|
||||
parse = function (response) {
|
||||
|
||||
return response.replace ? JSON.parse(response.replace(/\/\*[\s\S]*?\*\/|\/\/.*?(\n|$)/g, '')) : {};
|
||||
},
|
||||
|
||||
extendLevel1 = function (a, b) {
|
||||
|
||||
$.each(b, function (key) {
|
||||
|
||||
$.extend(a[key], b[key]);
|
||||
});
|
||||
},
|
||||
|
||||
run = function (config) {
|
||||
/*global amplify, Base64, jQuery, Modernizr, moment, _ */
|
||||
|
||||
// `jQuery`, `moment` and `underscore` are itself functions,
|
||||
|
@ -40,9 +53,31 @@
|
|||
modulejs.define('moment', function () { return moment; });
|
||||
modulejs.define('_', function () { return _; });
|
||||
|
||||
$(function () {
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
}(jQuery));
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
- var h5ai = "<?php echo $h5aiAbsHref; ?>"
|
||||
- var json = "<?php if (!$isHeadRequest) { echo $h5ai->getGenericJson(); }?>"
|
||||
- var fallback = "<?php if (!$isHeadRequest) { echo $h5ai->getNoJsFallback(); }?>"
|
||||
- var config = "<?php if (!$isHeadRequest) { echo $h5ai->getCustomConfig(); }?>"
|
||||
|
||||
doctype 5
|
||||
//if lt IE 9
|
||||
|
@ -62,4 +63,4 @@ html.no-js( lang="en" )
|
|||
|
||||
div#data-php-no-js-fallback.hideOnJs !{fallback}
|
||||
|
||||
script( src!="#{h5ai}js/scripts.js" )
|
||||
script( src!="#{h5ai}js/scripts.js", data-config!="#{config}" )
|
||||
|
|
|
@ -26,13 +26,28 @@ class H5ai {
|
|||
|
||||
private static final function load_config($file) {
|
||||
|
||||
$str = file_exists($file) ? file_get_contents($file) : "";
|
||||
if (!file_exists($file)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$str = file_get_contents($file);
|
||||
|
||||
// remove comments to get pure json
|
||||
$str = preg_replace("/\/\*.*?\*\/|\/\/.*?(\n|$)/s", "", $str);
|
||||
$config = json_decode($str, true);
|
||||
|
||||
return $config;
|
||||
return json_decode($str, true);
|
||||
}
|
||||
|
||||
|
||||
private static final function merge_config($a, $b) {
|
||||
|
||||
$result = array_merge(array(), $a);
|
||||
|
||||
foreach ($b as $key => $value) {
|
||||
$result[$key] = array_merge($result[$key], $b[$key]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
@ -61,7 +76,8 @@ class H5ai {
|
|||
$this->ignore_patterns = $H5AI_CONFIG["IGNORE_PATTERNS"];
|
||||
$this->index_files = $H5AI_CONFIG["INDEX_FILES"];
|
||||
|
||||
$this->config = H5ai::load_config($this->h5aiAbsPath . "/config.json");
|
||||
$this->config = array("options" => array(), "types" => array(), "langs" => array());
|
||||
$this->config = H5ai::merge_config($this->config, H5ai::load_config($this->h5aiAbsPath . "/config.json"));
|
||||
$this->options = $this->config["options"];
|
||||
|
||||
$this->h5aiAbsHref = H5ai::normalize_path($this->options["h5aiAbsHref"], true);
|
||||
|
@ -69,6 +85,9 @@ class H5ai {
|
|||
|
||||
$this->absHref = H5ai::normalize_path(preg_replace('/[^\\/]*$/', '', getenv("REQUEST_URI")), true);
|
||||
$this->absPath = $this->getAbsPath($this->absHref);
|
||||
|
||||
$this->config = H5ai::merge_config($this->config, H5ai::load_config($this->absPath . "/_h5ai.config.json"));
|
||||
$this->options = $this->config["options"];
|
||||
}
|
||||
|
||||
|
||||
|
@ -285,6 +304,14 @@ class H5ai {
|
|||
}
|
||||
|
||||
|
||||
public function getCustomConfig() {
|
||||
|
||||
$config = "_h5ai.config.json";
|
||||
$config = $this->fileExists($config ? $this->absPath . "/" . $config : "ignore") ? $config : "ignore";
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
public function getEntries($absHref, $content) {
|
||||
|
||||
$folder = Entry::get($this, $this->getAbsPath($absHref), $absHref);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue