From 9c414c92e20f823c8ffd4ed3c4569bc3ec85316e Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sun, 8 Jun 2014 19:18:16 +0200 Subject: [PATCH] Clean code. --- src/_h5ai/client/js/inc/ext/custom.js | 46 +++++++++++--------------- src/_h5ai/server/php/inc/class-app.php | 3 +- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/_h5ai/client/js/inc/ext/custom.js b/src/_h5ai/client/js/inc/ext/custom.js index 7d116740..1be3fcdd 100644 --- a/src/_h5ai/client/js/inc/ext/custom.js +++ b/src/_h5ai/client/js/inc/ext/custom.js @@ -9,43 +9,37 @@ modulejs.define('ext/custom', ['_', '$', 'core/settings', 'core/server', 'core/e server.request({action: 'get', custom: true, customHref: item.absHref}, function (response) { - var h, f; + var has_header, has_footer, data, content; if (response) { + resource.loadMarkdown(function (md) { - if (response.custom.header) { - if (response.custom.header_type === 'md') { - resource.loadMarkdown(function (md) { + data = response.custom; - if (md) { - $('#content-header').html(md.toHTML(response.custom.header)).stop().slideDown(200); - } - }); - } else { - $('#content-header').html(response.custom.header).stop().slideDown(200); + if (data.header) { + content = data.header; + if (md && data.header_type === 'md') { + content = md.toHTML(content); + } + $('#content-header').html(content).stop().slideDown(200); + has_header = true; } - h = true; - } - if (response.custom.footer) { - if (response.custom.footer_type === 'md') { - resource.loadMarkdown(function (md) { - - if (md) { - $('#content-footer').html(md.toHTML(response.custom.footer)).stop().slideDown(200); - } - }); - } else { - $('#content-footer').html(response.custom.footer).stop().slideDown(200); + if (data.footer) { + content = data.footer; + if (md && data.footer_type === 'md') { + content = md.toHTML(content); + } + $('#content-footer').html(content).stop().slideDown(200); + has_footer = true; } - f = true; - } + }); } - if (!h) { + if (!has_header) { $('#content-header').stop().slideUp(200); } - if (!f) { + if (!has_footer) { $('#content-footer').stop().slideUp(200); } }); diff --git a/src/_h5ai/server/php/inc/class-app.php b/src/_h5ai/server/php/inc/class-app.php index a822dfb5..3b5ee777 100644 --- a/src/_h5ai/server/php/inc/class-app.php +++ b/src/_h5ai/server/php/inc/class-app.php @@ -4,6 +4,7 @@ class App { private static $RE_DELIMITER = "|"; private static $ICON_EXTS = array("svg", "png", "jpg"); + private static $CUSTOM_EXTS = array("html", "md"); private $options; @@ -269,7 +270,7 @@ class App { private function read_custom_file($path, $name, &$content, &$type) { - foreach (array("html", "md") as $ext) { + foreach (APP::$CUSTOM_EXTS as $ext) { $file = "$path/" . FILE_PREFIX . ".$name.$ext"; if (is_readable($file)) { $content = file_get_contents($file);