From 11c375069069c5e4b3b5402500dc45a7ca2075fb Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Tue, 5 May 2015 21:53:23 +0200 Subject: [PATCH] Refactor custom API. --- src/_h5ai/client/js/inc/ext/custom.js | 21 +++++++++++---------- src/_h5ai/server/php/inc/class-app.php | 12 ++++-------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/_h5ai/client/js/inc/ext/custom.js b/src/_h5ai/client/js/inc/ext/custom.js index 2faebee5..26427c22 100644 --- a/src/_h5ai/client/js/inc/ext/custom.js +++ b/src/_h5ai/client/js/inc/ext/custom.js @@ -12,26 +12,27 @@ modulejs.define('ext/custom', ['_', '$', 'marked', 'core/event', 'core/server', server.request({action: 'get', custom: item.absHref}, function (response) { + var custom = response && response.custom; var hasHeader; var hasFooter; - var data; - var content; - if (response) { - data = response.custom; + if (custom) { + var header = custom.header; + var footer = custom.footer; + var content; - if (data.header) { - content = data.header; - if (data.headerType === 'md') { + if (header.content) { + content = header.content; + if (header.type === 'md') { content = marked(content); } $header.html(content).stop().slideDown(duration); hasHeader = true; } - if (data.footer) { - content = data.footer; - if (data.footerType === 'md') { + if (footer.content) { + content = footer.content; + if (footer.type === 'md') { content = marked(content); } $footer.html(content).stop().slideDown(duration); diff --git a/src/_h5ai/server/php/inc/class-app.php b/src/_h5ai/server/php/inc/class-app.php index 6686f42b..43345c81 100644 --- a/src/_h5ai/server/php/inc/class-app.php +++ b/src/_h5ai/server/php/inc/class-app.php @@ -340,10 +340,8 @@ class App { if (!$this->get_option("custom.enabled", false)) { return array( - "header" => null, - "headerType" => null, - "footer" => null, - "footerType" => null + "header" => array("content" => null, "type" => null), + "footer" => array("content" => null, "type" => null) ); } @@ -377,10 +375,8 @@ class App { } return array( - "header" => $header, - "headerType" => $header_type, - "footer" => $footer, - "footerType" => $footer_type + "header" => array("content" => $header, "type" => $header_type), + "footer" => array("content" => $footer, "type" => $footer_type) ); }