treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Can Someone Explain This?

  • Hi, just got E Text Editor after 2 years using dreamweaver (i'm very exited).
    Anyway I am working my way through its snippets section and customising them for personal preference etc, when i got to this one, and i have no idea what it does...
    Its Called: PHP Error Catching Javascript
    and it creates this code;

    <script type="text/javascript" charset="utf-8">
    /* <![CDATA[ */ function scanErrors() {

    bolds = document.getElementsByTagName('b');

    for (index = 0; index < bolds.length; index++) {

    if (bolds[index].innerText.match('(Strict Standards|Warning|Notice|(Parse|Fatal) error)')) {

    current_node = bolds[index].previousSibling.previousSibling;
    wrapper = document.createElement('div');
    wrapper.className = 'php_error_wrapper';
    wrapper_parent = current_node.parentNode;
    wrapper_parent.appendChild(wrapper);

    for (child = 0; child < 7; child++) {

    if (current_node.tagName == 'A') child -= 2;
    next_node = current_node.nextSibling; wrapper.appendChild(current_node);
    if (!(current_node = next_node)) break;
    }

    link = document.createElement('a');
    link.href = 'txmt://open?url=file://' + bolds[index-0+1].innerText + '&line=' + bolds[index-0+2].innerText;
    link.innerText = '[Open in TextMate]'; wrapper.appendChild(document.createTextNode(' '));
    wrapper.appendChild(link);

    }
    }
    }

    var currentload = window.onload; if (typeof window.onload != 'function') {
    window.onload = scanErrors;
    } else {
    window.onload = function(){ currentload(); scanErrors();

    }

    } /* ]]> */ </script>



    Any Ideas? Many Thanks, Chris



    *EDIT: Cleaned it up :) - Rob *
  • Hey Chris, I'm not sure if I'm any help but it looks like its going through some file finding all the b nodes (HTML bolds) and if any of them match PHP specific keywords then it builds a link with E Text Editor? so I guess you can jump to error? If thats the case thats cool, cause I hate debugging client side code in-browser and not translate to my editor...