diff --git a/README.md b/README.md index 15ddae6d..b8e45f5f 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,9 @@ It profits from these great projects: * drops support for IE7+8 (simple fallback, same as no javascript) * uses History API if available (way faster browsing) * faster thumbnail generation if EXIF thumbnails available -* improves previews -* improves packaged downloads +* adds optional custom headers/footers that are propageted to all subfolders +* some fixes on previews +* speeds up packaged downloads * add line wrap and line highlighting (on hover) to text preview * new design (colors, images) * now uses `SVG` images for the interface diff --git a/src/_h5ai/client/js/inc/ext/custom.js b/src/_h5ai/client/js/inc/ext/custom.js index 33df86e8..e2cc27a2 100644 --- a/src/_h5ai/client/js/inc/ext/custom.js +++ b/src/_h5ai/client/js/inc/ext/custom.js @@ -2,25 +2,30 @@ modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server', 'core/event'], function (_, $, allsettings, server, event) { var settings = _.extend({ - enabled: false, - header: '_h5ai.header.html', - footer: '_h5ai.footer.html' + enabled: false }, allsettings.custom), onLocationChanged = function () { - $('#content-header, #content-footer').stop(true, true).slideUp(200); - server.request({action: 'get', custom: true}, function (response) { + var h, f; if (response) { if (response.custom.header) { - $('#content-header').html(response.custom.header).stop(true, true).slideDown(400); + $('#content-header').html(response.custom.header).stop().slideDown(200); + h = true; } if (response.custom.footer) { - $('#content-footer').html(response.custom.footer).stop(true, true).slideDown(400); + $('#content-footer').html(response.custom.footer).stop().slideDown(200); + f = true; } } + if (!h) { + $('#content-header').stop().slideUp(200); + } + if (!f) { + $('#content-footer').stop().slideUp(200); + } }); }, diff --git a/src/_h5ai/conf/options.json b/src/_h5ai/conf/options.json index 503f652a..90eb4d4f 100644 --- a/src/_h5ai/conf/options.json +++ b/src/_h5ai/conf/options.json @@ -32,7 +32,7 @@ Options - binaryPrefix: set to true uses 1024B=1KiB when formatting file sizes (see http://en.wikipedia.org/wiki/Binary_prefix) - indexFiles: consider folder with those files as non {{pkg.name}} folders - ignore: don't list items matching these regular expressions - - smartBrowsing: use browser history if available (no need to reload the whole page) + - smartBrowsing: use History API if available (no need to reload the whole page) - extInNewWindow: open non-h5ai links in new window/tab */ "view": { @@ -67,13 +67,16 @@ Options }, /* - Filenames of customized header and footer files to look for - in each folder. + Allow customized header and footer files. + First looks for files "_h5ai.header.html" and "_h5ai.footer.html" + in the current directory. + If not found it looks in all parent directories (starting in the + current directory) for files "_h5ai.headers.html" and "_h5ai.footers.html" + until it finds one. + Note the different filenames: header (only current) - headers (recursive)! */ "custom": { - "enabled": true, - "header": "_{{pkg.name}}.header.html", - "footer": "_{{pkg.name}}.footer.html" + "enabled": true }, /* [EXPERIMENTAL] diff --git a/src/_h5ai/server/php/inc/App.php b/src/_h5ai/server/php/inc/App.php index d391be34..1617ad4c 100644 --- a/src/_h5ai/server/php/inc/App.php +++ b/src/_h5ai/server/php/inc/App.php @@ -312,12 +312,40 @@ class App { public function get_customizations($abs_href) { - $abs_path = $this->get_abs_path($abs_href); + if (!$this->options["custom"]["enabled"]) { + return array( + "header" => null, + "footer" => null + ); + } + $abs_path = $this->get_abs_path($abs_href); $file = $abs_path . "/" . App::$FILE_PREFIX . ".header.html"; - $header = is_string($file) && file_exists($file) ? file_get_contents($file) : null; + $header = is_readable($file) ? file_get_contents($file) : null; $file = $abs_path . "/" . App::$FILE_PREFIX . ".footer.html"; - $footer = is_string($file) && file_exists($file) ? file_get_contents($file) : null; + $footer = is_readable($file) ? file_get_contents($file) : null; + + $p = $abs_path; + while ($header === null || $footer === null) { + + if ($header === null) { + $file = $p . "/" . App::$FILE_PREFIX . ".headers.html"; + $header = is_readable($file) ? file_get_contents($file) : null; + } + if ($footer === null) { + $file = $p . "/" . App::$FILE_PREFIX . ".footers.html"; + $footer = is_readable($file) ? file_get_contents($file) : null; + } + + if ($p === $this->root_abs_path) { + break; + } + $pp = normalize_path(dirname($p)); + if ($pp === $p) { + break; + } + $p = $pp; + } return array( "header" => $header,