MediaWiki:Vector.js: Różnice pomiędzy wersjami

Z High School DxD Wiki
Skocz do:nawigacji, wyszukiwania
m
Linia 7: Linia 7:
  
  
 
+
Sidebar = {
/* Sidebar */
+
getItem: function(name) {
// Para editar los elementos del sidebar, cambiar [[MediaWiki:Monobook.js/Sidebar.js]]
+
return $('#n-' + encodeURIComponent(name.replace(/ /g, '-')).replace(/%/g, '.'));
window.wgSidebar = (window.wgSidebar||{});
+
},
importScript('MediaWiki:Vector.js/Sidebar.js');
+
+
/*
+
* MonobookSidebar v1.1: Permite definir submenús para elementos del Sidebar de MonoBook, agregando clases
+
* especiales al pasar con el puntero por encima para permitir el efecto en todos los navegadores.
+
*
+
* Copyright (C) 2010  Jesús Martínez Novo ([[User:Ciencia Al Poder]])
+
*
+
* This program is free software; you can redistribute it and/or modify
+
*  it under the terms of the GNU General Public License as published by
+
*  the Free Software Foundation; either version 2 of the License, or
+
(at your option) any later version
+
*/
+
MonobookSidebar = {
+
re_s: / /g,
+
re_p: /%/g,
+
loadedMenus: [],
+
 
init: function() {
 
init: function() {
if (!window.wgSidebar) return;
+
if (!window.wgSidebar)
 +
return;
 +
 
for (var menu in wgSidebar) {
 
for (var menu in wgSidebar) {
var item = document.getElementById(MonobookSidebar.getId(menu));
+
var item = this.getItem(menu);
if (!item) continue;
+
var menuId = $(item).parents().get(2).id;
+
this.buildSubmenu(item, wgSidebar[menu]);
// Check it's a valid portlet item
+
if (!menuId || menuId == '') continue;
+
// Generate menu hierarchy
+
MonobookSidebar.buildSubmenu(item, wgSidebar[menu]);
+
// Set events
+
MonobookSidebar.setEvents(menuId);
+
 
}
 
}
 +
 +
 
},
 
},
buildSubmenu: function(el, arr) {
+
var ul = document.createElement('ul');
+
ul.className = 'sub-menu';
+
buildSubmenu: function(menu, items)
for (var i = 0; i < arr.length; i++) {
+
{
var li = document.createElement('li');
+
var ul = $('<ul>');
if (typeof arr[i] == 'string') {
+
var a = MonobookSidebar.linkFromText(arr[i]);
+
menu.addClass('submenu');
li.appendChild(a);
+
} else {
+
for (var i in items)
for (var menukey in arr[i]) {
+
{
a = MonobookSidebar.linkFromText(menukey);
+
var item = items[i];
li.appendChild(a);
+
var li = $('<li>');
MonobookSidebar.buildSubmenu(li, arr[i][menukey]);
+
 +
if (typeof item === 'string')
 +
{
 +
var link = this.getLink(item);
 +
li.append(link);
 +
ul.append(li);
 +
}
 +
else if(typeof item === 'object')
 +
{
 +
for (var j in item)
 +
{
 +
var link = this.getLink(j);
 +
li.append(link);
 +
ul.append(li);
 +
this.buildSubmenu(li, item[j]);
 
}
 
}
}
+
} else continue;
ul.appendChild(li);
+
 +
$(menu).on('mouseover', 'a', function() {
 +
var parent = $(this).parent('li');
 +
var pos = parent.position();
 +
 +
$(this).next().css({display:'block', left: parent.width()+pos.left, top: pos.top});
 +
//parent.addClass('hover');
 +
}).on('mouseout', 'a', function() {
 +
 +
var submenu = $(this).next('ul');
 +
if(submenu.is(':visible'))
 +
{
 +
submenu.css({display: 'none'});
 +
}
 +
console.log(submenu.is(':visible'));
 +
//
 +
});
 
}
 
}
el.appendChild(ul);
+
el.className = 'with-sub-menu';
+
menu.append(ul);
var em = document.createElement('em');
+
em.appendChild(document.createTextNode('\u203A'));
+
el.firstChild.appendChild(em);
+
 
},
 
},
setEvents: function(menuId) {
+
getLink: function(txt, has_submenu)
for (var i = 0; i < MonobookSidebar.loadedMenus; i++) {
+
{
if (MonobookSidebar.loadedMenus[i] == menuId) return;
+
var pos = txt.indexOf('|');
 +
var article = '';
 +
var caption = '';
 +
 +
if (pos > 0)
 +
{
 +
article = txt.substr(0, pos);
 +
caption = txt.substr(pos + 1);
 
}
 
}
$('#'+menuId).children().eq(1).children().eq(0).bind('mouseover',MonobookSidebar.mouseover).bind('mouseout',MonobookSidebar.mouseout);
+
else
MonobookSidebar.loadedMenus.push(menuId);
+
{
},
+
article = txt;
mouseover: function(e) {
+
caption = txt;
var target = e.target;
+
while (target.tagName.toLowerCase() != 'div') {
+
if (target.tagName.toLowerCase() == 'a') {
+
target = target.parentNode;
+
}
+
if (target.tagName.toLowerCase() == 'li') {
+
$(target).addClass('hover');
+
}
+
target = target.parentNode;
+
 
}
 
}
},
+
mouseout: function(e) {
+
var href = '';
var target = e.target;
+
while (target.tagName.toLowerCase() != 'div') {
+
if (article.length > 7 && article.substr(0,7) == 'http://')
if (target.tagName.toLowerCase() == 'a') {
+
{
target = target.parentNode;
+
href = article;
}
+
if (target.tagName.toLowerCase() == 'li') {
+
$(target).removeClass('hover');
+
}
+
target = target.parentNode;
+
 
}
 
}
},
+
else
linkFromText: function(txt) {
+
{
var article = '', caption = '', sepPos = txt.indexOf('|');
+
article = encodeURIComponent(article.replace(/ /g, '_'));
if (sepPos > 0) {
+
href = wgArticlePath.replace('$1',article);
article = txt.substr(0, sepPos);
+
caption = txt.substr(sepPos+1);
+
} else {
+
article = caption = txt;
+
 
}
 
}
var a = document.createElement('a');
+
if (article.length > 7 && article.substr(0,7) == 'http://') {
+
return '<a href="' + article + '">' + caption  + '</a>';
a.setAttribute('href',article);
+
} else {
+
article = encodeURIComponent(article.replace(MonobookSidebar.re_s, '_'));
+
a.setAttribute('href',wgArticlePath.replace('$1',article));
+
}
+
a.appendChild(document.createTextNode(caption));
+
return a;
+
},
+
getId: function(name) {
+
return 'n-' + encodeURIComponent(name.replace(MonobookSidebar.re_s, '-')).replace(MonobookSidebar.re_p, '.');
+
 
}
 
}
};
+
}
/* </pre> */
+
 
 +
//$(function(){Sidebar.init();});

Wersja z 20:44, 12 lip 2013

$(function(){
if ($.browser.mozilla)
{
$('#left-navigation, #right-navigation').css('top', '10.8em');
}
});


Sidebar = {
	getItem: function(name) {
		return $('#n-' + encodeURIComponent(name.replace(/ /g, '-')).replace(/%/g, '.'));
	},
	init: function() {
		if (!window.wgSidebar)
			return;
		
		for (var menu in wgSidebar) {
			var item = this.getItem(menu);
			
			this.buildSubmenu(item, wgSidebar[menu]);
		}
		
		
	},
	
	
	buildSubmenu: function(menu, items)
	{
		var ul = $('<ul>');
		
		menu.addClass('submenu');
		
		for (var i in items)
		{
			var item = items[i];
			var li = $('<li>');
			
			if (typeof item === 'string')
			{
				var link = this.getLink(item);
				li.append(link);
				ul.append(li);
			}
			else if(typeof item === 'object')
			{
				for (var j in item)
				{
					var link = this.getLink(j);
					li.append(link);
					ul.append(li);
					this.buildSubmenu(li, item[j]);
				}
			} else continue;
			
			$(menu).on('mouseover', 'a', function() {
				var parent = $(this).parent('li');
				var pos = parent.position();
			
				$(this).next().css({display:'block', left: parent.width()+pos.left, top: pos.top});
				//parent.addClass('hover');
			}).on('mouseout', 'a', function() {
			
				var submenu = $(this).next('ul');
				if(submenu.is(':visible'))
				{
					submenu.css({display: 'none'});
				}
				console.log(submenu.is(':visible'));
				//
			});
		}
		
		menu.append(ul);
	},
	getLink: function(txt, has_submenu)
	{
		var pos = txt.indexOf('|');
		var article = '';
		var caption = '';
		
		if (pos > 0)
		{
			article = txt.substr(0, pos);
			caption = txt.substr(pos + 1);
		}
		else
		{
			article = txt;
			caption = txt;
		}
		
		var href = '';
		
		if (article.length > 7 && article.substr(0,7) == 'http://')
		{
			href = article;
		}
		else
		{
			article = encodeURIComponent(article.replace(/ /g, '_'));
			href = wgArticlePath.replace('$1',article);
		}
		
		return '<a href="' + article + '">' + caption  + '</a>';
	}
}

//$(function(){Sidebar.init();});
Źródło „https://hsdxd.usermd.net/w/index.php?title=MediaWiki:Vector.js&oldid=151