MediaWiki:Gadget-LegacyScriptsNewNode.js

Vanuit Wiktionary, die vrye woordeboek.

Let wel: Na die wysiging is dit dalk nodig om u blaaier se kasgeheue te verfris voordat u die veranderinge sal sien:

  • Firefox / Safari: hou Shift en kliek Herlaai, of druk Ctrl-F5 of Ctrl-R (⌘-R op 'n Mac)
  • Google Chrome: Druk Ctrl-Shift-R (⌘-Shift-R op 'n Mac)
  • Internet Explorer / Edge: Hou Ctrl en kliek Refresh, of druk Ctrl-F5
  • Opera: Gaan na Kieslys → Settings (Opera → Preferences op 'n Mac) en dan na Privacy & security → Clear browsing data → Cached images and files.
//this script is deprecated do not use newNode function! use jQuery instead

/**
 * 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.
 **/
var newNode = window.newNode = 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
						newNode.addEventHandler(node, j, arguments[i][j]);
					} else {
						node.setAttribute(j, arguments[i][j]); //Normal attributes
					}
				}
			}
		}
	}
	
	node.addEventHandler = function (eventName, handler) {
		newNode.addEventHandler(this, eventName, handler);
	};
	
	return node;
};

newNode.addEventHandler = function (node, eventName, handler) {
	try {
		node.addEventListener(eventName, handler, false); //W3C
	} catch (e) {
		try {
			node.attachEvent('on' + eventName, handler, "Language"); //MSIE
		} catch (e) {
			node['on' + eventName] = handler;
		}
	} //Legacy
};