Difference between revisions of "User:Moussekateer/vector.js"
Moussekateer (talk | contribs) m (Blanked the page) |
Moussekateer (talk | contribs) |
||
Line 1: | Line 1: | ||
− | + | $(document).ready(function(){ | |
+ | var ttCache = new Object(); | ||
+ | var urlPrefix = wgArticlePath.replace("$1",""); | ||
+ | var container = $("<div id='tooltip-container' style='position:absolute;z-index:999999;height:auto !important;padding:0px;margin:0px;max-width: 300px'></div>"); | ||
+ | var ttOffset = 10; | ||
+ | container.hide(); | ||
+ | var mouseX = 0; | ||
+ | var mouseY = 0; | ||
+ | var bodyContainer = $("#bodyContent"); | ||
+ | bodyContainer.append(container); | ||
+ | $(".backpack-link").mouseover(function(evt){ | ||
+ | var url = $(this).find("a").attr("href"); | ||
+ | if(urlPrefix == url.substr(0,urlPrefix.length)){ | ||
+ | url = url.substr(urlPrefix.length); | ||
+ | } | ||
+ | relocateTooltip(evt); | ||
+ | if(ttCache[url] != undefined){ | ||
+ | showTooltip(ttCache[url]); | ||
+ | return; | ||
+ | } | ||
+ | $.get(wgScript+"?title="+url+"&action=render",function(data){ | ||
+ | var subpage = $(data).find(".backpack-tooltip"); | ||
+ | ttCache[url] = subpage; | ||
+ | showTooltip(subpage); | ||
+ | },"html"); | ||
+ | }).mousemove(function(evt){ | ||
+ | updateCoords(evt); | ||
+ | relocateTooltip(); | ||
+ | }).mouseout(function(){ | ||
+ | container.hide(); | ||
+ | }); | ||
+ | function showTooltip(tooltipObj){ | ||
+ | container.html(tooltipObj); | ||
+ | container.css("width","auto"); | ||
+ | if(container.outerWidth() > 300) | ||
+ | container.css("width","300px"); | ||
+ | relocateTooltip(); | ||
+ | container.show(); | ||
+ | } | ||
+ | function relocateTooltip(){ | ||
+ | var lMouseX = mouseX; | ||
+ | var lMouseY = mouseY; | ||
+ | if(lMouseY + container.outerHeight() > $(window).height()+$(window).scrollTop()) | ||
+ | lMouseY = ($(window).height()+$(window).scrollTop())-container.outerHeight(); | ||
+ | if(lMouseX + container.outerWidth() > $(window).width()+$(window).scrollLeft()) | ||
+ | lMouseX = lMouseX - ((ttOffset*2) + container.outerWidth()); | ||
+ | var bodyOffset = bodyContainer.offset(); | ||
+ | lMouseX -= bodyOffset.left; | ||
+ | lMouseY -= bodyOffset.top; | ||
+ | container.css("left",lMouseX+"px").css("top",lMouseY+"px"); | ||
+ | } | ||
+ | function updateCoords(evt){ | ||
+ | mouseX = evt.pageX + ttOffset; | ||
+ | mouseY = evt.pageY + ttOffset; | ||
+ | } | ||
+ | }); |
Revision as of 19:15, 5 November 2011
$(document).ready(function(){ var ttCache = new Object(); var urlPrefix = wgArticlePath.replace("$1",""); var container = $("<div id='tooltip-container' style='position:absolute;z-index:999999;height:auto !important;padding:0px;margin:0px;max-width: 300px'></div>"); var ttOffset = 10; container.hide(); var mouseX = 0; var mouseY = 0; var bodyContainer = $("#bodyContent"); bodyContainer.append(container); $(".backpack-link").mouseover(function(evt){ var url = $(this).find("a").attr("href"); if(urlPrefix == url.substr(0,urlPrefix.length)){ url = url.substr(urlPrefix.length); } relocateTooltip(evt); if(ttCache[url] != undefined){ showTooltip(ttCache[url]); return; } $.get(wgScript+"?title="+url+"&action=render",function(data){ var subpage = $(data).find(".backpack-tooltip"); ttCache[url] = subpage; showTooltip(subpage); },"html"); }).mousemove(function(evt){ updateCoords(evt); relocateTooltip(); }).mouseout(function(){ container.hide(); }); function showTooltip(tooltipObj){ container.html(tooltipObj); container.css("width","auto"); if(container.outerWidth() > 300) container.css("width","300px"); relocateTooltip(); container.show(); } function relocateTooltip(){ var lMouseX = mouseX; var lMouseY = mouseY; if(lMouseY + container.outerHeight() > $(window).height()+$(window).scrollTop()) lMouseY = ($(window).height()+$(window).scrollTop())-container.outerHeight(); if(lMouseX + container.outerWidth() > $(window).width()+$(window).scrollLeft()) lMouseX = lMouseX - ((ttOffset*2) + container.outerWidth()); var bodyOffset = bodyContainer.offset(); lMouseX -= bodyOffset.left; lMouseY -= bodyOffset.top; container.css("left",lMouseX+"px").css("top",lMouseY+"px"); } function updateCoords(evt){ mouseX = evt.pageX + ttOffset; mouseY = evt.pageY + ttOffset; } });