diff --git a/js/functions.js b/js/functions.js index be2f17439b..90c5d0ec7b 100644 --- a/js/functions.js +++ b/js/functions.js @@ -1945,6 +1945,57 @@ function PMA_highlightSQL($base) }); } +/** + * Updates an element containing code. + * + * @param jQuery Object $base base element which contains the raw and the + * highlighted code. + * + * @param string htmlValue code in HTML format, displayed if code cannot be + * highlighted + * + * @param string rawValue raw code, used as a parameter for highlighter + * + * @return bool whether content was updated or not + */ +function PMA_updateCode($base, htmlValue, rawValue) +{ + var $code = $base.find('code'); + if ($code.length == 0) { + return false; + } + + // Determines the type of the content and appropriate CodeMirror mode. + var type = '', mode = ''; + if ($code.hasClass('json')) { + type = 'json'; + mode = 'application/json'; + } else if ($code.hasClass('sql')) { + type = 'sql'; + mode = 'text/x-mysql'; + } else if ($code.hasClass('xml')) { + type = 'xml'; + mode = 'application/xml'; + } else { + return false; + } + + // Element used to display unhighlighted code. + var $notHighlighted = $('
' + htmlValue + ''); + + // Tries to highlight code using CodeMirror. + if (typeof CodeMirror != 'undefined') { + var $highlighted = $(''); + CodeMirror.runMode(rawValue, mode, $highlighted[0]); + $notHighlighted.hide(); + $code.html('').append($notHighlighted, $highlighted[0]); + } else { + $code.html('').append($notHighlighted); + } + + return true; +} + /** * Show a message on the top of the page for an Ajax request * diff --git a/js/makegrid.js b/js/makegrid.js index 58ab633491..a7f06e5f72 100644 --- a/js/makegrid.js +++ b/js/makegrid.js @@ -640,32 +640,41 @@ function PMA_makegrid(t, enableResize, enableReorder, enableVisib, enableGridEdi $this_field.addClass('null'); } else { $this_field.removeClass('null'); - var new_html = data.isNeedToRecheck + var value = data.isNeedToRecheck ? data.truncatableFieldValue : $this_field.data('value'); + // Truncates the text. + $this_field.removeClass('truncated'); + if (PMA_commonParams.get('pftext') === 'P' && value.length > g.maxTruncatedLen) { + $this_field.addClass('truncated'); + value = value.substring(0, g.maxTruncatedLen) + '...'; + } + //Add