User:Jadowity/global.js

//__NOWYSIWYG__ 	function tooltips_init { var href = $('link[rel="canonical"]').attr('href') if(typeof href == 'undefined' || !href) { console.log('Tooltips: script couldn\'t find link[rel="canonical"] tag'); return false } var i = href.indexOf('/wiki/') window.tooltipsAPIpath = href.substring(0,i)+'/api.php?format=json&action=parse&disablepp=true&prop=text&title='+href.substring(i+6)+'&text=' if(typeof tooltipClasses != 'undefined') { var skin = $('#WikiaMainContent') if(!skin.length) skin = $('#mw-content-text') $(' ').appendTo(skin).hide $(' ').appendTo(skin).css({'height':'0px','min-height':'0px','visibility':'hidden','overflow':'hidden'}).append(' Lorem ipsum dolor sit amet ') tooltipClassList = []; for(classname in tooltipClasses) { tooltipClassList.push(classname) }			var links = $('.basic-tooltip, .'+tooltipClassList.join(', .')) links.each(function {				$(this).find('*').attr('title', )				$(this).mouseover(tooltips_handleMouseOver);				$(this).mouseout(tooltips_handleMouseOut);				$(this).mousemove(tooltips_handleMouseMove);				$(this).data('tooltip-contents', $(this).attr('title'))				$(this).attr('title', )			}) }	}	function tooltips_setOwnWidth { elem = $(this) if(typeof elem.data('width') != 'undefined') elem.css('width', elem.data('width')+'px') else elem.css('width', '') }	function tooltips_calcSize { elem = $(this) elem.css('position', 'absolute') var temp = elem.css('width') elem.css('width', '') elem.data('width', elem.width); elem.data('height', elem.height); elem.data('outerwidth', elem.outerWidth(true)); elem.data('outerheight', elem.outerHeight(true)); elem.css('width', elem.data('width')+'px') elem.css('position', '') elem.css('width', temp) }	function tooltips_sameWidth { if($("#tooltip-wrapper").find('.main-tooltip').length == 1) { $("#tooltip-wrapper").find('.main-tooltip').each(tooltips_setOwnWidth) } else { var width = 0; $("#tooltip-wrapper").find('.main-tooltip').each(function { width = Math.max(width, $(this).data('width')); }); $("#tooltip-wrapper").find('.main-tooltip').each(function { $(this).css('width', width+'px'); }); }	}	function tooltips_handleMouseOver(e) { window.lastKnownMousePos = [e.pageX, e.pageY] tooltips_wrapperPosition(e.pageX, e.pageY) var tip = tooltips_getTooltips($(this)) $("#tooltip-wrapper").append(tip).show tooltips_sameWidth }	function tooltips_handleMouseOut(e) { window.lastKnownMousePos = [e.pageX, e.pageY] tooltips_wrapperPosition(e.pageX, e.pageY) $("#tooltip-wrapper").hide $("#tooltip-wrapper").find('.main-tooltip').appendTo('#tooltip-storage') }	function tooltips_handleMouseMove(e) { window.lastKnownMousePos = [e.pageX, e.pageY] tooltips_wrapperPosition(e.pageX, e.pageY) }	function tooltips_wrapperPosition(mouseX, mouseY) { if (typeof tooltipOffsetY == 'undefined') var offsetY = 8 else var offsetY = tooltipOffsetY; if (typeof tooltipOffsetX == 'undefined') var offsetX = 16 else var offsetX = tooltipOffsetX; var tipH = 0 $("#tooltip-wrapper").find('.main-tooltip').each( function{ if(typeof $(this).data('outerheight') != 'undefined') tipH += $(this).data('outerheight'); }); var coordX = offsetX+mouseX var coordY = offsetY+mouseY if ($("#tooltip-wrapper").css('position') == 'fixed') { coordX = coordX-$(window).scrollLeft coordY = coordY-$(window).scrollTop coordY = Math.min(coordY, $(window).height-tipH-$('#WikiaBarWrapper').height) } else { coordY = Math.min(coordY, $(window).height-tipH-$('#WikiaBarWrapper').height+$(window).scrollTop) }		$("#tooltip-wrapper").css({left: coordX + 'px', top: coordY + 'px', right: '0px'}); }	function tooltips_getTooltips(elem) { var classes = elem.attr('class').split(' ') var result = [] for(var i=0;i<classes.length;i++) { var type = classes[i] var parameter = '' if(type == 'basic-tooltip') { if(typeof elem.data('tooltip-contents') != 'undefined') parameter = elem.data('tooltip-contents') else if(typeof elem.attr('title') != 'undefined') parameter = elem.attr('title') } else { if(tooltipClassList.indexOf(type) == -1) continue; if(typeof elem.data(type) != 'undefined') parameter = elem.data(type) else if(typeof elem.data('param') != 'undefined') parameter = elem.data('param') }			var tip = tooltips_getTooltip(type, parameter) result.push(tip[0]); }		return $(result) }	function tooltips_getTooltip(type, value) { if(type == 'basic-tooltip') { var tip = $('#tooltip-basic-tooltip') tip.html(value.replace('\\n',' '))			tip.each(tooltips_calcSize).each(tooltips_setOwnWidth) } else { var id = 'tooltip-'+type+'-'+value.replace('+', '_').replace(/[^A-Z^a-z^0-9^\-^_]/g, '-') var tip = $('#'+id) if(tip.length == 0) { tip = $(' ').attr('id', id) tip.appendTo('#tooltip-storage') tooltips_wrapperPosition(lastKnownMousePos[0], lastKnownMousePos[1]) tooltips_sameWidth var api = tooltips_getAPI(value, type) tip.attr('title', api) $.ajax({					url: api,					dataType: 'json',					context: tip,					success: function(data, textStatus, jqXHR) {						$(this).html(data['parse']['text']['*']).each(tooltips_calcSize).each(tooltips_setOwnWidth)						if($(this).find('a.new').length > 0) $(this).addClass('has-redlinks')						var images = $(this).find('img')						images.fadeTo(0, 0).one('load', function { if(waitForImages) { $(this).fadeTo(0,1); $(this).addClass('image-loaded') tip = $(this).closest('.main-tooltip') if(tip.find('img').hasClass('image-loaded')) { tip.removeClass('tooltip-loading').css('content', '').each(tooltips_calcSize) tooltips_wrapperPosition(lastKnownMousePos[0], lastKnownMousePos[1]) tooltips_sameWidth }							} else { $(this).fadeTo(100,1); }						})						if(waitForImages) {							if(images.length == 0) {								$(this).removeClass('tooltip-loading').css('content', ).each(tooltips_calcSize)							} else $(this).css('content', '\'\)						} else {							$(this).removeClass('tooltip-loading').css('content', '').each(tooltips_calcSize)						}						tooltips_wrapperPosition(lastKnownMousePos[0], lastKnownMousePos[1])						tooltips_sameWidth					}				}); }		}		return tip }	function tooltips_getAPI(name, type) { var prefix = tooltipClasses[type][0] var suffix = tooltipClasses[type][1] return tooltipsAPIpath+encodeURI(prefix+name+suffix) }	addOnloadHook(tooltips_init); //