Difference between revisions of "User:RJackson/vector.js"
m (guess I don't ened this anymore) |
(Trying this tooltips thing) |
||
Line 64: | Line 64: | ||
} | } | ||
/*END UTC CLOCK*/ | /*END UTC CLOCK*/ | ||
+ | |||
+ | |||
+ | |||
+ | /* tooltips thing */ | ||
+ | $(document).ready(function(){ | ||
+ | var ttCache = new Object(); | ||
+ | var urlPrefix = wgArticlePath.replace("$1",""); | ||
+ | var ttOffset = 10; | ||
+ | var mouseX = 0; | ||
+ | var mouseY = 0; | ||
+ | var currentTooltip = ""; | ||
+ | var container = $("<div id='tooltip-container' style='position:absolute;z-index:999999;height:auto !important;max-width: 300px;color:white;text-align: center; background: #24201B; -moz-border-radius: 10px; border-radius: 10px; padding:7px 0px;'></div>"); | ||
+ | $("#bodyContent").append(container); | ||
+ | var offsetContainer = container.offsetParent(); | ||
+ | container.hide(); | ||
+ | $(".backpack-link > a[href]").mouseover(function(evt){ | ||
+ | var url = $(this).attr("href"); | ||
+ | if(urlPrefix == url.substr(0,urlPrefix.length)){ | ||
+ | url = url.substr(urlPrefix.length); | ||
+ | } | ||
+ | currentTooltip = url; | ||
+ | relocateTooltip(evt); | ||
+ | if(ttCache[url] != undefined){ | ||
+ | showTooltip(ttCache[url]); | ||
+ | return; | ||
+ | } | ||
+ | $.get(wgScript+"?title="+url+"&action=render",function(data){ | ||
+ | var subpage = $(data).find(".backpack-tooltip"); | ||
+ | if(subpage.size() == 0){ | ||
+ | subpage = "<span style='padding-left:7px;margin-right:7px;'>Unable to load tooltip for this item</span>"; | ||
+ | }else{ | ||
+ | subpage = subpage.eq(0).html(); | ||
+ | } | ||
+ | ttCache[url] = subpage; | ||
+ | if(currentTooltip == url){ | ||
+ | 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 = offsetContainer.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; | ||
+ | } | ||
+ | $(document).unload(function(){ | ||
+ | container.hide(); | ||
+ | }); | ||
+ | }); |
Revision as of 23:29, 6 November 2011
/*BEGIN UTC CLOCK Modifications: Added timerTimezoneLabel, timer now displays (TIMEZONE UTC-X) if this is set. - RJackson, Aug 19th 2011 */ /** additional monobook scripts **/ hookEvent( 'load', displayTimer ); /**** function displayTimer.js * by Patrick Westerhoff [poke] */ function displayTimer () { if ( typeof( timerDisplay ) !== 'undefined' && timerDisplay === false ) return; /* Time-zone settings */ var timerTimezone = -7; /* Leave blank for UTC */ var timerTimezoneLabel = "PDT"; /* Leave blank to display "(UTC)" or "(UTC-X)". Fill in to display "(TIMEZONE UTC-X)" */ var date; var timerParent = document.getElementById( 'p-personal' ).getElementsByTagName( 'ul' )[0]; var timerLink = document.createElement( 'a' ); var timerObj = document.createElement( 'li' ); timerLink.href = '/wiki/' + wgPageName + '?action=purge'; timerLink.title = 'Purge the server cache and update the contents of this page.' timerObj.id = 'pt-timer'; timerObj.style.textTransform = 'none'; timerObj.appendChild( timerLink ); timerParent.insertBefore( timerObj, timerParent.firstChild ); function actualizeUTC () { timerDate = new Date(); timerLink.innerHTML = ( timerDate.getUTCHours() < 10 ? '0' : '' ) + timerDate.getUTCHours() + ':' + ( timerDate.getUTCMinutes() < 10 ? '0' : '' ) + timerDate.getUTCMinutes() + ':' + ( timerDate.getUTCSeconds() < 10 ? '0' : '' ) + timerDate.getUTCSeconds() + ' (UTC)'; } function actualizeCustom () { timerDate = new Date(); timerDate.setMinutes( timerDate.getMinutes() + timerDate.getTimezoneOffset() + timerTimezone * 60 ); timerLink.innerHTML = ( timerDate.getHours() < 10 ? '0' : '' ) + timerDate.getHours() + ':' + ( timerDate.getMinutes() < 10 ? '0' : '' ) + timerDate.getMinutes() + ':' + ( timerDate.getSeconds() < 10 ? '0' : '' ) + timerDate.getSeconds() + ' (' + ( timerTimezoneLabel != null ? timerTimezoneLabel + ', ' : '' ) + 'UTC' + ( timerTimezone < 0 ? '' : '+' ) + timerTimezone + ')'; } // start if ( typeof( timerTimezone ) !== 'number' ) { actualizeUTC(); setInterval( actualizeUTC, 1000 ); } else { actualizeCustom(); setInterval( actualizeCustom, 1000 ); } } /*END UTC CLOCK*/ /* tooltips thing */ $(document).ready(function(){ var ttCache = new Object(); var urlPrefix = wgArticlePath.replace("$1",""); var ttOffset = 10; var mouseX = 0; var mouseY = 0; var currentTooltip = ""; var container = $("<div id='tooltip-container' style='position:absolute;z-index:999999;height:auto !important;max-width: 300px;color:white;text-align: center; background: #24201B; -moz-border-radius: 10px; border-radius: 10px; padding:7px 0px;'></div>"); $("#bodyContent").append(container); var offsetContainer = container.offsetParent(); container.hide(); $(".backpack-link > a[href]").mouseover(function(evt){ var url = $(this).attr("href"); if(urlPrefix == url.substr(0,urlPrefix.length)){ url = url.substr(urlPrefix.length); } currentTooltip = url; relocateTooltip(evt); if(ttCache[url] != undefined){ showTooltip(ttCache[url]); return; } $.get(wgScript+"?title="+url+"&action=render",function(data){ var subpage = $(data).find(".backpack-tooltip"); if(subpage.size() == 0){ subpage = "<span style='padding-left:7px;margin-right:7px;'>Unable to load tooltip for this item</span>"; }else{ subpage = subpage.eq(0).html(); } ttCache[url] = subpage; if(currentTooltip == url){ 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 = offsetContainer.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; } $(document).unload(function(){ container.hide(); }); });