From cd77ffa6b6c888af6257bcac8326c7293104ea22 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 21 Apr 2014 15:06:19 -0700 Subject: [PATCH] Api Explorer - add syntax highlighting --- templates/CRM/Admin/Page/APIExplorer.js | 12 ++++++++++-- templates/CRM/Admin/Page/APIExplorer.tpl | 13 +++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/templates/CRM/Admin/Page/APIExplorer.js b/templates/CRM/Admin/Page/APIExplorer.js index a800d45c33..444453fb4a 100644 --- a/templates/CRM/Admin/Page/APIExplorer.js +++ b/templates/CRM/Admin/Page/APIExplorer.js @@ -8,6 +8,12 @@ fieldTpl = _.template($('#api-param-tpl').html()), chainTpl = _.template($('#api-chain-tpl').html()); + function prettyPrint() { + if (window.prettyPrint) { + window.prettyPrint(); + } + } + function addField(name) { $('#api-params').append($(fieldTpl({name: name || ''}))); var $row = $('tr:last-child', '#api-params'); @@ -241,8 +247,9 @@ q.smarty = '{* Smarty API only works with get actions *}'; } $.each(q, function(type, val) { - $('#api-' + type).text(val); + $('#api-' + type).removeClass('prettyprinted').text(val); }); + prettyPrint(); } function submit(e) { @@ -272,7 +279,8 @@ type: action.indexOf('get') < 0 ? 'POST' : 'GET', dataType: 'text' }).done(function(text) { - $('#api-result').text(text); + $('#api-result').addClass('prettyprint linenums').removeClass('prettyprinted').text(text); + prettyPrint(); }); } diff --git a/templates/CRM/Admin/Page/APIExplorer.tpl b/templates/CRM/Admin/Page/APIExplorer.tpl index 38484f6dd1..1ecbaf983d 100644 --- a/templates/CRM/Admin/Page/APIExplorer.tpl +++ b/templates/CRM/Admin/Page/APIExplorer.tpl @@ -26,7 +26,6 @@ + +
@@ -111,14 +112,14 @@
- - - - + + + +
{ts}Code{/ts}
Rest
Smarty
Php
Javascript
Rest
Smarty
Php
Javascript
-
+
 {ts}The result of api calls are displayed in this area.{/ts}
 
-- 2.25.1