Utilisateur:CreatixEA/monobook.js/wpObjets.js

Un article de Wikipédia, l'encyclopédie libre.

Note : Après avoir publié la page, vous devrez forcer son rechargement pour voir les changements : Mozilla / Konqueror / Firefox : Shift-Ctrl-R, Internet Explorer / Opera : Ctrl-F5, Safari : Cmd-R.

/* <pre><nowiki> */
	/** wpMonobook
	  * It handles basic functions
	  */
	function wpMonobook ()
	{
		this.publishList = new Array();
		this.initList = new Array();
 
		this.addToPublish = function (obj) { this.publishList.push(obj); }
		this.addToInit = function (obj) { this.initList.push(obj); }
 
		this.init = function()
		{
			for (var i = 0; i < this.initList.length; i ++) { this.initList[i].init(); }
 
			this.addEvent(window, 'load', wpPublish);
		}
 
		this.publish = function ()
		{
			for (var i = 0; i < this.publishList.length; i++) { this.publishList[i].publish(); }
		}
 
		this.addEvent = function(obj, event, func)
		{
			if (obj.addEventListener) { obj.addEventListener(event, func, false); }
			else if (window.attachEvent) { obj.attachEvent('on' + event, func); }
		}
 
		this.changeFormSummary = function (text)
		{
			var summary = document.getElementById('wpSummary');
			if (!summary) return;
 
			summary.value = text;
		}
 
		this.include = function (URL)
		{
			document.write ('<script language="JavaScript" src="' + URL + '"></script>');
		}
	}
 
	// wpPublish launches the publication of all objects
	function wpPublish() { myMonobook.publish(); }
 
	// myMonobook is the instance of wpMonobook
	var myMonobook = new wpMonobook();
 
	/** wpTab
	  * It manages the tabs
	  */
	function wpTab (id)
	{
		this.id = id;
		this.group = null;
		this.Links = new Array();
 
		myMonobook.addToInit(this);
 
		this.init = function()
		{
			this.group = document.createElement('li');
			this.group.id = this.id;
 
			myMonobook.addToPublish(this);
		}
 
		this.addTab = function (label, URL)
		{
			var newLink = document.createElement('a');
			newLink.href = URL;
			newLink.innerHTML = label;
 
			this.Links.push(newLink);
		}
 
		this.publish = function()
		{
			var ul = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
			if (ul)
			{
				for (var i = 0; i < this.Links.length; i++) { this.group.appendChild(this.Links[i]); }
				ul.appendChild(this.group);
			}
		}
	}
 
	/**
	  * wpNav
	  * It manages the navigation links
	  */
	wpNavSerial = 0;
	function wpNav (label, navgroup)
	{
		this.id = (++wpNavSerial);
		this.label = label;
		this.group = null;
		this.block = null;
		if (!navgroup) { this.navgroup = 0; } else { this.navgroup = navgroup; }
		this.Links = new Array();
 
		myMonobook.addToInit(this);
 
		this.fireClick = function(E)
		{
			var reg = new RegExp('wpNavGrp-([0-9]+)', 'gi');
			var id = reg.exec(E.target.id)[1];
 
			var block = document.getElementById('wpNavBlock-' + id);
			if (block) block.style.display = 'block';
		}
 
		this.init = function()
		{
			this.group = document.createElement('li');
			this.group.id = 'wpNavGrp-' + this.id;
			this.group.style.cursor = 'pointer';
			this.group.innerHTML = this.label + '<sup>*</sup>';
			myMonobook.addEvent(this.group, 'click', this.fireClick);
 
			this.block = document.createElement('ul');
			this.block.id = 'wpNavBlock-' + this.id;
			this.block.style.display = 'none';
 
			this.group.appendChild(this.block);
 
			myMonobook.addToPublish(this);
		}
 
		this.addLink = function (label, URL)
		{
			var newLink = document.createElement('a');
			newLink.innerHTML = label;
			newLink.href = URL;
 
			this.Links.push(newLink);
		}
 
		this.publish = function()
		{
			for (var i = 0; i < this.Links.length; i++)
			{
				var newLi = document.createElement('li');
				newLi.appendChild(this.Links[i]);
 
				this.block.appendChild(newLi);
			}
 
			var uls = document.getElementById('p-navigation').getElementsByTagName('ul');
			uls[this.navgroup].appendChild(this.group);
		}
	}
 
	/**
	  * wpToolbar
	  * It manages the toolbar in edit mode
	  */
	function wpToolbar ()
	{
		this.toolbar = null;
		this.Links = new Array();
 
		myMonobook.addToInit(this);
 
		this.init = function() { myMonobook.addToPublish(this); }
 
		this.addLink = function (name, insertion, Image)
		{
			var newLink = document.createElement('a');
			newLink.href = 'javascript: insertTags("", "' + insertion + '", ""); myMonobook.changeFormSummary("' + name + '");';
 
			var newImg = document.createElement('img');
			newImg.src = Image;
			newLink.appendChild(newImg);
 
			this.Links.push(newLink);
		}
 
		this.publish = function()
		{
			var toolbar = document.getElementById('toolbar');
			if (!toolbar) return;
 
			for (var i = 0; i < this.Links.length; i ++) { toolbar.appendChild(this.Links[i]); }
		}
	}
 
	// myToolbar is the instance of wpToolbar
	var myToolbar = new wpToolbar();
 
/* </nowiki></pre> */