0

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

如果有人能帮忙,那就太好了

提琴手

4

1 回答 1

1

在下班休息一天后,坐下来真正搞砸了一段时间,阅读了 Trip 的评论,哈哈,我决定只是检查一下,把它清理干净,就好像它正在工作一样,并取出了几十个不需要的功能并将我需要的主要内容包装到一个包含所有内容的函数中,并确保我没有使用多个变量来避免冲突和一些调整我让它工作..所以我的结论是在我之后还有很多函数正在删除我不需要的东西。所以这是工作代码,以防有人正在搜索这样的东西

提琴手

非常感谢 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);
                }
                });            
            }
        };
于 2012-08-09T23:24:53.300 回答