if (typeof(PhpDebugBar) == 'undefined') { // namespace var PhpDebugBar = {}; PhpDebugBar.$ = jQuery; } (function($) { /** * @namespace */ PhpDebugBar.Widgets = {}; var csscls = PhpDebugBar.utils.makecsscls('phpdebugbar-widgets-'); /** * Replaces spaces with   and line breaks with
* * @param {String} text * @return {String} */ var htmlize = PhpDebugBar.Widgets.htmlize = function(text) { return text.replace(/\n/g, '
').replace(/\s/g, " ") }; /** * Returns a string representation of value, using JSON.stringify * if it's an object. * * @param {Object} value * @param {Boolean} prettify Uses htmlize() if true * @return {String} */ var renderValue = PhpDebugBar.Widgets.renderValue = function(value, prettify) { if (typeof(value) !== 'string') { if (prettify) { return htmlize(JSON.stringify(value, undefined, 2)); } return JSON.stringify(value); } return value; }; /** * Highlights a block of code * * @param {String} code * @param {String} lang * @return {String} */ var highlight = PhpDebugBar.Widgets.highlight = function(code, lang) { if (typeof(code) === 'string') { if (typeof(hljs) === 'undefined') { return htmlize(code); } if (lang) { return hljs.highlight(lang, code).value; } return hljs.highlightAuto(code).value; } if (typeof(hljs) === 'object') { code.each(function(i, e) { hljs.highlightBlock(e); }); } return code; }; /** * Creates a
 element with a block of code
     *
     * @param  {String} code
     * @param  {String} lang
     * @param  {Number} [firstLineNumber] If provided, shows line numbers beginning with the given value.
     * @param  {Number} [highlightedLine] If provided, the given line number will be highlighted.
     * @return {String}
     */
    var createCodeBlock = PhpDebugBar.Widgets.createCodeBlock = function(code, lang, firstLineNumber, highlightedLine) {
        var pre = $('
').addClass(csscls('code-block'));
        // Add a newline to prevent  element from vertically collapsing too far if the last
        // code line was empty: that creates problems with the horizontal scrollbar being
        // incorrectly positioned - most noticeable when line numbers are shown.
        var codeElement = $('').text(code + '\n').appendTo(pre);

        // Add a span with a special class if we are supposed to highlight a line.  highlight.js will
        // still correctly format code even with existing markup in it.
        if ($.isNumeric(highlightedLine)) {
            if ($.isNumeric(firstLineNumber)) {
                highlightedLine = highlightedLine - firstLineNumber + 1;
            }
            codeElement.html(function (index, html) {
                var currentLine = 1;
                return html.replace(/^.*$/gm, function(line) {
                    if (currentLine++ == highlightedLine) {
                        return '' + line + '';
                    } else {
                        return line;
                    }
                });
            });
        }

        // Format the code
        if (lang) {
            pre.addClass("language-" + lang);
        }
        highlight(pre);

        // Show line numbers in a list
        if ($.isNumeric(firstLineNumber)) {
            var lineCount = code.split('\n').length;
            var $lineNumbers = $('