plugins/content/templates/user/debug_console_js.stpl

Summary

Maintainability
Test Coverage
{css()}
#debug_console pre {
    color: #ccc;
    background: black;
    font-weight: bold;
    font-family: inherit;
    margin: 0;
    display: inline-block;
    width: auto;
    padding: 2px;
    border: 0;
}
#debug_console #debug_exec_time {
    float:left;
    display:block;
    padding-left: 20px;
    padding-right: 20px;
}
{/css}

{js()} jquery-cookie {/js}

{jquery()}
    // Needed for debug console
    $("table.debug_item a[data-hidden-toggle]", "#debug_console").on("click", function(e){
        e.preventDefault();
        var _this = $(this)
        var _parent = _this.closest("tr")
        var _name = _this.data("hidden-toggle")
        var _hidden = _parent.find("[data-hidden-name='" + _name + "']")
        _hidden.toggle();
//        console.log(_this, _parent, _name, _hidden)
    })
    $(".btn-toggle", "#debug_console").on("click", function(e){
        e.preventDefault();
        var _this = $(this)
        var _toggle_what_id = _this.data("hidden-toggle")
        if (_toggle_what_id) {
            $('#' + _toggle_what_id).toggle();
        }
        console.log(_this, _toggle_what_id)
    })
    try {
        // Needed for debug console
        $("ul.nav-tabs li a", "#debug_console").on("click", function(){
            $.cookie('debug_tabs_active', $(this).attr("href").substring(1), {path: '/'}); // Remove # at the beginning
        })
    } catch (e) { console.log(e); }
{/jquery}

{if_true(conf.DEBUG_CONSOLE_POPUP)}
    {css()} #debug_console{display:none;} {/css}

    {jquery()}

    var debug_window_name = "yf_debug_frame"
    var debug_console_use_iframe = false;
    var debug_console_head = [ ];
    // Allow to override JS, CSS as array of html elements strings
// TODO: replace .yf_core with more generic method, maybe just include all scripts
    if (typeof debug_console_override_head == "object") {
        $.each(debug_console_override_head, function(i, _html){
            debug_console_head.push( _html )
        })
        // Add debug console specific .yf_core items, not all, as in other case
        $('.yf_core', '#debug_console').each(function(){
            debug_console_head.push( $(this).clone(true)[0].outerHTML )
        })
    } else {
        $('.yf_core').each(function(){
            debug_console_head.push( $(this).clone(true)[0].outerHTML )
        })
    }
    if (debug_console_use_iframe) {
// TODO: need to do popup div display of tab contents in this mode
        $('<iframe src="about:blank" id="' + debug_window_name + '" style="position:fixed; bottom:0; height:10%; width:100%; border:0;" border="0"></iframe>').appendTo("body");
        var debug_frame = $("iframe#dbgif")[0]
    } else {
        var debug_frame = window.open('', debug_window_name, 'width=800,height=600,location=no,menubar=no,status=no,top=100,left=100,titlebar=no,toolbar=no')
    }
    // We need the iframe document object, different browsers different ways
    if (typeof debug_frame != 'undefined') {
        var frame_doc = debug_frame.document;
    } else {
        console.error('Debug console popup: debug_frame not created, maybe popup blocker killed it');
    }
    if (typeof frame_doc != 'undefined') {
        if (debug_frame.contentDocument) {
            frame_doc = debug_frame.contentDocument;
        } else if (debug_frame.contentWindow) {
            frame_doc = debug_frame.contentWindow.document;
        }
        // We open the document of the empty frame and we write desired content.
        frame_doc.open();
        // Copy JS, CSS from original frame
        $.each(debug_console_head, function(i, _html){
            frame_doc.writeln( _html )
        })
        frame_doc.writeln( $("#debug_console").clone(true)[0].outerHTML );
        frame_doc.close();
        $("#debug_console").hide().remove()
    } else {
        console.error('Debug console popup: cannot access frame document');
    }

    {/jquery}
{/if}