User:Hippietrail/debugportlet.js

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Note – after saving, you may have to bypass your browser’s cache to see the changes.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

/*
<pre>
*/

// output text to the debug portlet
function debugPrint( dbtxt ) {
  var p_db = document.getElementById('p-debug');

  if (p_db) p_db.style.display = 'block';

  //document.getElementById('dbTextarea').innerHTML += dbtxt;
  //document.dbForm.dbTextarea.innerHTML += dbtxt;

  //document.dbForm.dbTextarea.value += dbtxt;
  document.getElementById('dbTextarea').value += dbtxt;
}

// add a portlet for outputting debug messages
function addDebugPortlet() {

  // find the search portlet. we want to be after it
  var p_search = document.getElementById('p-search');

  if (p_search) {
    var p_db;
    var newh;
    var pbody;
    var newform;
    var newdiv;
    var newtextarea;

    p_db = document.createElement('div');
    p_db.id = 'p-debug';
    p_db.className = 'portlet';
    p_db.style.display = 'none';

    newh = document.createElement('h5');
    newh.appendChild(document.createTextNode('Debug'));
    p_db.appendChild(newh);

    pbody = document.createElement('div');
    pbody.className = 'pBody';
    p_db.appendChild(pbody);

    newform = document.createElement('form');
    newform.id = 'dbForm';
    newform.name = 'dbForm';
    pbody.appendChild(newform);

    newdiv = document.createElement('div');
    newform.appendChild(newdiv);

    newtextarea = document.createElement('textarea');
    newtextarea.id = 'dbTextarea';
    newtextarea.name = 'dbTextarea';
    //newtextarea.readOnly = 'readonly';
    newdiv.appendChild(newtextarea);

    // insert our constructed portlet between the search and toolbox portlets
    p_search.parentNode.insertBefore(p_db, p_search.nextSibling);
  }
}

/*
</pre>
*/