From: Coleman Watts Date: Wed, 25 Feb 2015 03:03:47 +0000 (-0500) Subject: Improve api explorer formatting X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1080dff4af8f1c01500a113a5c7c896017f167bc;p=civicrm-core.git Improve api explorer formatting --- diff --git a/templates/CRM/Admin/Page/APIExplorer.js b/templates/CRM/Admin/Page/APIExplorer.js index 00d880fdad..5d3276e649 100644 --- a/templates/CRM/Admin/Page/APIExplorer.js +++ b/templates/CRM/Admin/Page/APIExplorer.js @@ -24,6 +24,22 @@ TEXT = ['LIKE', 'NOT LIKE'], MULTI = ['IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN']; + /** + * Call prettyPrint function and perform additional formatting + * @param ele + */ + function prettyPrint(ele) { + if (typeof window.prettyPrint === 'function') { + $(ele).removeClass('prettyprinted').addClass('prettyprint'); + + window.prettyPrint(); + + // Highlight errors in api result + $('span:contains("error_code"),span:contains("error_message")', '#api-result') + .siblings('span.str').css('color', '#B00'); + } + } + /** * Add a "fields" row * @param name @@ -512,9 +528,9 @@ q.smarty = "{* Smarty does not have a syntax for array literals; assign complex variables from php *}\n" + q.smarty; } $.each(q, function(type, val) { - $('#api-' + type).addClass('prettyprint').removeClass('prettyprinted').text(val); + $('#api-' + type).text(val); }); - prettyPrint(); + prettyPrint('#api-generated pre'); } /** @@ -552,8 +568,8 @@ type: _.includes(action, 'get') ? 'GET' : 'POST', dataType: 'text' }).done(function(text) { - $('#api-result').addClass('prettyprint').removeClass('prettyprinted').text(text); - prettyPrint(); + $('#api-result').text(text); + prettyPrint('#api-result'); }); } @@ -579,8 +595,8 @@ $('#example-result').block(); $.get(CRM.url('civicrm/ajax/apiexample', {file: entity + '/' + action})) .done(function(result) { - $('#example-result').unblock().addClass('prettyprint').removeClass('prettyprinted').text(result); - prettyPrint(); + $('#example-result').unblock().text(result); + prettyPrint('#example-result'); }); } else { $('#example-result').text($('#example-result').attr('title')); @@ -615,7 +631,7 @@ if (result.code) { $('#doc-result').append(docCodeTpl(result)); } - prettyPrint(); + prettyPrint('.api-doc-code pre'); }); } else { $('#doc-result').html($('#doc-result').attr('title')); diff --git a/templates/CRM/Admin/Page/APIExplorer.tpl b/templates/CRM/Admin/Page/APIExplorer.tpl index 3a8202f800..28e05dbef1 100644 --- a/templates/CRM/Admin/Page/APIExplorer.tpl +++ b/templates/CRM/Admin/Page/APIExplorer.tpl @@ -311,7 +311,7 @@
{ts}Source Code{/ts}
<%- file %>
-
<%- code %>
+
<%- code %>