将数据传递到自定义控制台

时间:2012-08-05 23:50:26

标签: javascript jquery

我一直在做一个小项目,并试图让我自己的调试控制台有点东西,我可以自定义我需要的东西,而不是使用firebug ..到目前为止,我有我需要的两个部分工作但不要工作。我有一个脚本会报告鼠标输入和点击的内容,它直接打印到我设置的DIV窗口,然后昨天遇到了我真正喜欢的JQuery控制台,我删除了所有我没做过的事情。我需要它在它自己的工作正常,但不知道如何将数据从我的其他方法传递到那个,我编译了基本的东西,试图让它工作...它可能是一些简单的事情与我LOL而且我可能会让自己感到困惑并使其变得更难,然后才需要

如果有人能提供帮助那就太棒了

JsFiddle

1 个答案:

答案 0 :(得分:1)

在休息一天后坐下来实际上捣乱了一段时间,阅读Trip的评论LOL我决定只是通过这件事并清理它就好像它正在工作并取出了几十个联合国 - 需要的功能和包装我需要的主要内容到一个包含所有内容的功能,并确保我没有使用多个变量来避免冲突和一些调整我得到它的工作..所以我的结论从它有很多功能我删除了我不需要的东西后剩下的。继承人的工作代码,只是因为某人正在寻找像这样的东西

JsFiddle

非常感谢Trip指出所有正在使用的方法

    function clock(){
    var dayarray        = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    var montharray        = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
    var suffix             = "AM";    

    var currentTime    = new Date();
    var hours         = currentTime.getHours();
    var minutes     = currentTime.getMinutes();
    var mydate        = new Date();
    var year        = mydate.getFullYear();
    var day            = mydate.getDay();
    var month        = mydate.getMonth();
    var daym        = mydate.getDate();

    if(hours >= 12){
        suffix = "PM";
        hours = hours - 12;
    }
    if(hours == 0){
        hours = 12;
    }
    if(minutes < 10){
        minutes = "0" + minutes
    }
    if(daym<10){
        daym="0"+daym
    }

    //alert(hours);
    return [hours, minutes, suffix, month, day, year, dayarray, montharray];
}
$('#consolex').click(function() { loadConsole(); });
var xD;

function loadConsole(){
if (document.forms[0].console.checked) {
        // if CHECKED than LOAD Console
            if (window.twd_console) {
                window.twd_console.toggle();
            } else {
                function init($) {
                    function HistoryManager() {
                        this.curr = -1;
                        this.entries = [];
                    };
                    HistoryManager.prototype = {
                        push: function(item) {
                            if (this.entries.length && this.entries[0] == item) return;
                            if (item.match(/^\s*$/)) return;
                            this.entries.unshift(item);
                            this.curr = -1;
                        },
                        scroll: function(direction) {
                            var moveTo = this.curr + (direction == 'prev' ? 1 : -1);
                            if (moveTo >= 0 && moveTo < this.entries.length) {
                                this.curr = moveTo;
                                return this.entries[this.curr];
                            } else if (moveTo == -1) {
                                this.curr = moveTo;
                                return '';
                            } else {
                                return null;
                            }
                        }
                    };
                    var toolbar = 'hello';
                    var context = {},
                        history = new HistoryManager(),
                        $drag = $('<div/>').css({
                            backgroundColor: '#e0e0e0',
                            border: '1px solid #a0a0a0',
                            fontSize: '11px',
                            fontFamily: 'sans-serif',
                            lineHeight: 1,
                            padding: '5px',
                            marginBottom: '7px',
                            cursor: 'pointer',
                            textAlign: 'right'
                        }).html(toolbar),
                        $log = $('<div/>').css({
                            fontSize: '11px',
                            fontFamily: 'monospace',
                            color: 'white',
                            marginBottom: '7px',
                            height: '155px',
                            overflow: 'auto',
                            border: '1px solid #a0a0a0',
                            padding: '5px',
                            textAlign: 'left'
                        }),
                        $dummy = $('<div/>');

                    xD = function append(text, act, tag, id, color) {
                        var aX = ' »    ', // Bullet
                        bX = '['+ clock()[0]+':'+clock()[1]+':'+clock()[2]+']  ', // Timestamp
                        cX = '  ERROR  ', //ERROR
                        dX = '  Location  ', //Location of ERROR
                        eX = '  ID Location  ', //ID Location
                        fX = '  Cause  '; //Cause of ERROR
                        $log.append($('<div/>').css({
                            'color': color || 'black',
                            margin: 0,
                            padding: 0
                        }).text(aX).append(bX).append(text).append(act).append(tag).append(id));
                        $log[0].scrollTop = $log[0].scrollHeight;
                    };

                    $(document).mousemove(function(evt) {
                        if (dragging) $container.css({
                            left: evt.pageX - dragging[0],
                            top: evt.pageY - dragging[1]
                        });
                    });

                    var pos = ($.browser.msie && $.browser.version < 7) ? 'absolute' : 'fixed';

                    var $container = $('<div/>').css({
                        backgroundColor: 'white',
                        padding: '7px',
                        position: pos,
                        opacity: 0.9,
                        top: '10px',
                        right: '10px',
                        width: '550px',
                        height: '200px',
                        border: '1px solid #000',
                        zIndex: 99999
                    }).appendTo(document.body);

                    $container.append($drag).append($log);

                    //xD('jQuery initialised!', 'green');
                    //xD('(using jQuery version ' + $.fn.jquery + ')');
                    //xD('jQuery initialised!', 'green');
                    //xD('(using jQuery version ' + $.fn.jquery + ')');
                    //xD('jQuery initialised!', 'green');
                    //xD('(using jQuery version ' + $.fn.jquery + ')');
                    //xD('jQuery initialised!', 'green');
                    //xD('(using jQuery version ' + $.fn.jquery + ')');

                    window.twd_console = $container;

                };

                if (typeof jQuery == 'undefined' || !jQuery.fn.jquery.match(/^1\.7/)) {
                    var e = document.createElement('script'),
                        jq = null;
                    e.onload = function() {
                        jq = jQuery;
                        jQuery.noConflict(true);
                        init(jq);
                    };
                    e.setAttribute('type', 'text/javascript');
                    e.setAttribute('src', 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js');
                    document.body.appendChild(e);
                } else {
                    init(jQuery);
                }
            }
    } else if (!document.forms[0].console.checked) {
        window.twd_console.hide();
    }    
    mouse(true);
}
        function mouse(bol){
            var d = $("*", document.body);

            if(bol){              
                // Cancel mousedown.
                d.mousedown(function(event) {
                    var x = $(this).get(0),
                    y = x.tagName,
                    z = x.id;
                    switch (event.which) {
                        case 1:
                            //alert('Left mouse button click: ' + x.tagName);

                            xD(x.tagName, '  Left mouse button  ','  '+ x.tagName+'  ','  '+ x.id+'  ', 'purple');
                            //xD(x.id, 'red');
                            break;
                        case 2:
                            //alert('Middle mouse button click: ' + x.tagName);
                            xD(x.tagName, '  Centermouse button  ', x.tagName, x.id, 'purple');
                            break;
                        case 3:
                            //alert('Right mouse button click: ' + x.tagName);
                            xD(x.tagName, '  Right mouse button  ', x.tagName, x.id, 'purple');
                            return null;
                            break;
                        default:
                            xD(x.tagName, '  mouse UNKNOWN  ', x.tagName, x.id, 'purple');
                    }
                });
                // Transfer focus, if already open.
                d.mouseenter(function(event) {
                    var x = $(this).get(0),
                    y = x.tagName,
                    z = x.id;
                   // $('#window').append('mouse entered' + x.tagName + '<br />');
                    try{
                        xD(y, '  Mouse Entered  ', y, z, 'blue');
                    //xD(y, 'blue');
                    }catch(err){
                        alert(err);
                }
                });            
            }
        };