diff --git a/js/src/functions.js b/js/src/functions.js index 449e1e8ba4..ce9532f20c 100644 --- a/js/src/functions.js +++ b/js/src/functions.js @@ -1730,6 +1730,28 @@ Functions.highlightSql = function ($base) { }); }; +/** + * Applies JSON syntax highlighting transformation using CodeMirror + * + * @param {JQuery} $base base element which contains the JSON code blocks + */ +Functions.highlightJson = function ($base) { + var $elm = $base.find('code.json'); + $elm.each(function () { + var $json = $(this); + var $pre = $json.find('pre'); + /* We only care about visible elements to avoid double processing */ + if ($pre.is(':visible')) { + var $highlight = $('
'); + $json.append($highlight); + if (typeof CodeMirror !== 'undefined' && typeof CodeMirror.runMode === 'function') { + CodeMirror.runMode($json.text(), 'application/json', $highlight[0]); + $pre.hide(); + } + } + }); +}; + /** * Updates an element containing code. * diff --git a/js/src/sql.js b/js/src/sql.js index 28e090c5c1..1180842d0f 100644 --- a/js/src/sql.js +++ b/js/src/sql.js @@ -675,6 +675,7 @@ AJAX.registerOnload('sql.js', function () { .html(data.message) .trigger('makeGrid'); Functions.highlightSql($sqlqueryresults); + Functions.highlightJson($sqlqueryresults); }); // end $.post() }); // end displayOptionsForm handler diff --git a/js/src/transformations/json.js b/js/src/transformations/json.js index 4326a2eda3..4e2383656e 100644 --- a/js/src/transformations/json.js +++ b/js/src/transformations/json.js @@ -2,16 +2,5 @@ * JSON syntax highlighting transformation plugin */ AJAX.registerOnload('transformations/json.js', function () { - var $elm = $('#page_content').find('code.json'); - $elm.each(function () { - var $json = $(this); - var $pre = $json.find('pre'); - /* We only care about visible elements to avoid double processing */ - if ($pre.is(':visible')) { - var $highlight = $(''); - $json.append($highlight); - CodeMirror.runMode($json.text(), 'application/json', $highlight[0]); - $pre.hide(); - } - }); + Functions.highlightJson($('#page_content')); });