Difference between revisions of "MediaWiki:Common.js"

1,923 bytes added ,  04:48, 1 November 2010
no edit summary
Line 360: Line 360:
// --------------------------------------------------------  
// --------------------------------------------------------  
addOnloadHook(function () {    if (wgAction != 'edit' && wgCanonicalNamespace != 'Special' && wgAction != 'history' && wgAction != 'delete' && wgAction != 'watch' && wgAction      != 'unwatch' && wgAction != 'protect' && wgAction != 'markpatrolled' && wgAction != 'rollback' && document.URL.indexOf('diff=') <= 0    && document.URL.indexOf('oldid=') <=0)    { var hist; var url;    if (!(hist = document.getElementById('ca-history') )) return;    if (!(url = hist.getElementsByTagName('a')[0] )) return;    if (!(url = url.href )) return;    addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'),                    'purge', 'ca-purge', 'Purge server cache for this page', '0'); } });
addOnloadHook(function () {    if (wgAction != 'edit' && wgCanonicalNamespace != 'Special' && wgAction != 'history' && wgAction != 'delete' && wgAction != 'watch' && wgAction      != 'unwatch' && wgAction != 'protect' && wgAction != 'markpatrolled' && wgAction != 'rollback' && document.URL.indexOf('diff=') <= 0    && document.URL.indexOf('oldid=') <=0)    { var hist; var url;    if (!(hist = document.getElementById('ca-history') )) return;    if (!(url = hist.getElementsByTagName('a')[0] )) return;    if (!(url = url.href )) return;    addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'),                    'purge', 'ca-purge', 'Purge server cache for this page', '0'); } });
/*gotten from http://grifkuba.org/MotherEarthBoundWiki/index.php?title=MediaWiki:Common.js on 11/1/2010*/
/*
=== DOM creation ===
<pre>*/
/**
* Create a new DOM node for the current document.
*    Basic usage:  var mySpan = newNode('span', "Hello World!")
*    Supports attributes and event handlers*: var mySpan = newNode('span', {style:"color: red", focus: function(){alert(this)}, id:"hello"}, "World, Hello!")
*    Also allows nesting to create trees: var myPar = newNode('p', newNode('b',{style:"color: blue"},"Hello"), mySpan)
*
* *event handlers, there are some issues with IE6 not registering event handlers on some nodes that are not yet attached to the DOM,
* it may be safer to add event handlers later manually.
**/
function newNode(tagname){
  var node = document.createElement(tagname);
 
  for( var i=1;i<arguments.length;i++ ){
   
    if(typeof arguments[i] == 'string'){ //Text
      node.appendChild( document.createTextNode(arguments[i]) );
     
    }else if(typeof arguments[i] == 'object'){
     
      if(arguments[i].nodeName){ //If it is a DOM Node
        node.appendChild(arguments[i]);
       
      }else{ //Attributes (hopefully)
        for(var j in arguments[i]){
          if(j == 'class'){ //Classname different because...
            node.className = arguments[i][j];
           
          }else if(j == 'style'){ //Style is special
            node.style.cssText = arguments[i][j];
           
          }else if(typeof arguments[i][j] == 'function'){ //Basic event handlers
            try{ node.addEventListener(j,arguments[i][j],false); //W3C
            }catch(e){try{ node.attachEvent('on'+j,arguments[i][j],"Language"); //MSIE
            }catch(e){ node['on'+j]=arguments[i][j]; }}; //Legacy
         
          }else{
            node.setAttribute(j,arguments[i][j]); //Normal attributes
          }
        }
      }
    }
  }
 
  return node;
}
/*</pre>