Jump to content

User:Zocky/utils.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Zocky (talk | contribs) at 13:02, 1 November 2005. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
///////////////
//Easy XML insertion
////////////////

//// el (tagname, arg1,val1,arg2,val2,...,child1,child2...)

  function el ()
  {
    var res;
    var i;

    if (el.arguments.length>0)
    {
      res = document.createElement(el.arguments[0]);
      i=1;
      while (i < el.arguments.length)
      {
        if ( typeof(el.arguments[i]) == "string" )
        {
          i++;
          if ( typeof(el.arguments[i])== "string" || typeof(el.arguments[i])=="number")
          {
            res.setAttribute(el.arguments[i-1],el.arguments[i]);
            i++;
          }
          else
          {
            alert ("el: Argument "+ el.arguments[i-1] +" specified, but no value provided.")
            return undef;
          }
        }
        else break;
      }
      
      while (i < el.arguments.length)
      {
        if (typeof(el.arguments[i])=='object')
        {
          res.appendChild(el.arguments[i]);
          i++
        }
        else
        {
          alert ("el: Useless argument "+ el.arguments[i-1] +" provided.")
          return undef;
        }
      }
    }
    else
    {
      alert ("el: Missing element name.")
      return undef;
    }
    return res;
  }

  function tx(s)
  {
    return document.createTextNode(s);
  }

  function add_stuff(p,e)
  {
    document.getElementById(p).appendChild(e);
  }