Difference between revisions of "MediaWiki:Gadget-ReferenceTooltips.css"

From Harridanic
Jump to navigation Jump to search
(Undo revision 837 by Paul Herring (talk))
 
Line 1: Line 1:
// See [[mw:Reference Tooltips]]
+
/* See [[mw:Reference Tooltips]] */
+
 
window.pg || $(document).ready( function($) {
+
.referencetooltip {
+
         position: absolute;
    // Make sure we are in article, project, or help namespace
+
        list-style: none;
    if ( wgCanonicalNamespace === '' || wgCanonicalNamespace === 'Project' || wgCanonicalNamespace === 'Help' ) {
+
         list-style-image: none;
         function toggleRT(o){
+
         opacity: 0;
            mw.loader.using("jquery.cookie",function(){
+
         font-size: 10px;
                    $.cookie("RTsettings",o+"|"+ settings[1] + "|" + settings[2], {path:"/",expires:90});
+
         margin: 0;
                    location.reload();
+
        z-index: 5;
            })
+
        padding: 0;
         }
+
}
         var settings = document.cookie.split("RTsettings=")[1];
+
.referencetooltip li {
         settings = settings ? settings.split(";")[0].split("%7C") : [1, 200, +("ontouchstart" in document.documentElement)];
+
        border: #080086 2px solid;
         if( settings[0] == 0 ) {
+
        max-width: 260px;
            var footer = $("#footer-places, #f-list");
+
         padding: 10px 8px 13px 8px;
            if( footer.length === 0 ) {
+
         margin: 0px;
                    footer = $("#footer li").parent();
+
        background-color: #F7F7F7;
            }
+
         box-shadow: 2px 4px 2px rgba(0,0,0,0.3);
            footer.append($("<li>").append($("<a>").text("Enable Reference Tooltips").attr("href","javascript:(function(){})()").click(function(){toggleRT(1)})));
+
        -moz-box-shadow: 2px 4px 2px rgba(0,0,0,0.3);
            return;
+
        -webkit-box-shadow: 2px 4px 2px rgba(0,0,0,0.3);
         }
+
}
         var isTouchscreen = +settings[2],
+
.referencetooltip li+li {
            timerLength = isTouchscreen ? 0 : +settings[1],
+
        margin-left: 7px;
            settingsMenu;
+
        margin-top: -2px;
         $(".reference").each( function() {
+
        border: 0;
            var tooltipNode, hideTimer, showTimer, checkFlip = false;
+
        padding: 0;
            function findRef( h ){
+
        height: 3px;
                    h = h.firstChild.getAttribute("href"); h = h && h.split("#"); h = h && h[1];
+
        width: 0px;
                    h = h && document.getElementById( h );
+
        background-color: transparent;
                    h = h && h.nodeName == "LI" && h;
+
        box-shadow: none;
                    return h;
+
        -moz-box-shadow: none;
            }
+
        -webkit-box-shadow: none;
            function hide( refLink ){
+
        border-top: 12px #080086 solid;
                    if( tooltipNode && tooltipNode.parentNode == document.body ) {
+
        border-right: 7px transparent solid;
                            hideTimer = setTimeout( function() {
+
        border-left: 7px transparent solid;
                                    $(tooltipNode).animate({opacity: 0}, 100, function(){ document.body.removeChild( tooltipNode ) })
+
}
                            }, isTouchscreen ? 16 : 100)
+
.referencetooltip>li+li::after {
                    } else {
+
        content: '';
                            var h = findRef( refLink );
+
        border-top: 8px #F7F7F7 solid;
                            h && (h.style.border = "");
+
        border-right: 5px transparent solid;
                    }
+
        border-left: 5px transparent solid;
            }
+
        margin-top: -12px;
            function show(){
+
        margin-left: -5px;
                    if( !tooltipNode.parentNode || tooltipNode.parentNode.nodeType === 11 ){
+
        z-index: 1;
                            document.body.appendChild( tooltipNode );
+
        height: 0px;
                            checkFlip = true;
+
        width: 0px;
                    }
+
        display: block;
                    $(tooltipNode).stop().animate({opacity: 1}, 100)
+
}
                    clearTimeout( hideTimer );
+
.client-js .referencetooltip li ul li {
            }
+
        border: none;
            function openSettingsMenu(){
+
        box-shadow: none;
                    if( settingsMenu ) {
+
        -moz-box-shadow: none;
                            settingsMenu.dialog( "open" );
+
        -webkit-box-shadow: none;
                    } else {
+
        height: auto;
                            settingsMenu = $("<form>").append(
+
        width: auto;
                                    $("<button>").css("width","100%").text("Disable Reference Tooltips").button().click(function(){toggleRT(0)}),
+
        margin: auto;
                                    $("<br>"),
+
        padding: 0;
                                    $("<small>").text("Once disabled, Reference Tooltips can be re-enabled using a link in the footer of the page."),
+
        position: static;
                                    $("<hr>"),
+
}
                                    $("<label>").text("Delay before the tooltip appears (in milliseconds): ").append($("<input>").attr({"type":"number","value":settings[1],step:50,min:0,max:5000})),
+
.RTflipped {
                                    $("<br>"),
+
        padding-top: 13px;
                                    $("<span>").text("Tooltip is activated by:"),
+
}
                                    $("<label>").append(
+
.referencetooltip.RTflipped li+li {
                                            $("<input>").attr({"type":"radio", "name":"RTActivate", "checked":settings[2]==0&&"checked", "disabled":"ontouchstart" in document.documentElement&&"disabled"}),
+
        position: absolute;
                                            "hovering"
+
        top: 2px;
                                    ),
+
        border-top: 0;
                                    $("<label>").append(
+
        border-bottom: 12px #080086 solid;
                                            $("<input>").attr({"type":"radio", "name":"RTActivate", "checked":settings[2]==1&&"checked"}),
+
}
                                            "clicking"
+
.referencetooltip.RTflipped li+li::after {
                                    )
+
        border-top: 0;
                            ).submit(function(e){e.preventDefault()}).dialog({modal:true,width:500,title:"Reference Tooltips options",buttons:{"Save settings":function(){
+
        border-bottom: 8px #F7F7F7 solid;
                                    var a = this.getElementsByTagName("input"),
+
        position: absolute;
                                            b = +a[0].value;
+
        margin-top: 7px;
                                    $.cookie("RTsettings","1|"+ (b > -1 && b < 5001 ? b : settings[1]) + (a[1].checked ? "|0" : "|1"), {path:"/",expires:90});
+
}
                                    location.reload();
+
.RTsettings{
                            }}});
+
        float: right;
                    }
+
        height: 16px;
            }
+
        width: 16px;
            $(this)[ isTouchscreen ? 'click' : 'hover' ](function( e ){
+
        cursor: pointer;
                    var _this = this;
+
        background-image: url(//upload.wikimedia.org/wikipedia/commons/e/ed/Cog.png);
                    if( isTouchscreen ) {
+
        margin-top: -9px;
                            e.preventDefault();
+
        margin-right: -7px;
                            (tooltipNode && tooltipNode.parentNode == document.body) || setTimeout( function(){
+
        -webkit-transition: opacity 0.15s;
                                    $( document.body ).on("click touchstart", function( e ) {
+
        -moz-transition: opacity 0.15s;
                                            e = e || event;
+
        -o-transition: opacity 0.15s;
                                            e = e.target || e.srcElement;
+
        -ms-transition: opacity 0.15s;
                                            for( ; e && !$( e ).hasClass( "referencetooltip" ) ; )
+
        transition: opacity 0.15s;
                                                    e = e.parentNode;
+
        opacity: 0.6;
                                            if( !e ){
+
        filter: alpha(opacity=60);
                                                    clearTimeout( showTimer );
+
}
                                                    hide( _this );
+
.RTsettings:hover{
                                                    $(document.body).off("click touchstart", arguments.callee)
+
        opacity: 1;
                                            }
+
        filter: alpha(opacity=100);
                                    })
+
}
                            }, 0);
 
                    }
 
                    showTimer && clearTimeout( showTimer );
 
                    showTimer = setTimeout( function() {
 
                            var h = findRef( _this );
 
                            if( !h ){return};
 
                            if( !isTouchscreen && ( window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0 ) + $(window).height() > $( h ).offset().top + h.offsetHeight ) {
 
                                    h.style.border = "#080086 2px solid";
 
                                    return;
 
                            }
 
                            if(!tooltipNode){
 
                                    tooltipNode = document.createElement("ul");
 
                                    tooltipNode.className = "referencetooltip";
 
                                    var c = tooltipNode.appendChild( h.cloneNode( true ) );
 
                                    try {
 
                                            if( c.firstChild.nodeName != "A" ) {
 
                                                    while( c.childNodes[1].nodeName == "A" && c.childNodes[1].getAttribute( "href" ).indexOf("#cite_ref-") !== -1 ) {
 
                                                            do { c.removeChild( c.childNodes[1] ) } while ( c.childNodes[1].nodeValue == " " );
 
                                                    }
 
                                            }
 
                                    } catch (e) { mw.log(e) }
 
                                    c.removeChild( c.firstChild );
 
                                    $( tooltipNode.firstChild.insertBefore( document.createElement( "span" ), tooltipNode.firstChild.firstChild ) ).addClass("RTsettings").attr("title", "Tooltip settings").click(function(){
 
                                            mw.loader.using(["jquery.cookie","jquery.ui.dialog"], openSettingsMenu);
 
                                    })
 
                                    tooltipNode.appendChild( document.createElement( "li" ) );
 
                                    isTouchscreen || $(tooltipNode).hover(show, hide);
 
                            }
 
                            show();
 
                            var o = $(_this).offset(), oH = tooltipNode.offsetHeight;
 
                            $(tooltipNode).css({top: o.top - oH, left: o.left - 7 });
 
                            if( tooltipNode.offsetHeight > oH ) { // is it squished against the right side of the page?
 
                                    $(tooltipNode).css({left:'auto',right:0});
 
                                    tooltipNode.lastChild.style.marginLeft = (o.left - tooltipNode.offsetLeft) + "px";
 
                            }
 
                            if( checkFlip ) {
 
                                    if( o.top < tooltipNode.offsetHeight + ( window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0 ) ) { // is part of it above the top of the screen?
 
                                            $(tooltipNode).addClass("RTflipped").css({top: o.top + 12});
 
                                    } else if( tooltipNode.className === "referencetooltip RTflipped" ) { // cancel previous
 
                                            $(tooltipNode).removeClass("RTflipped");
 
                                    }
 
                                    checkFlip = false;
 
                            }
 
                    }, timerLength);
 
            }, isTouchscreen ? undefined : function(){clearTimeout(showTimer); hide(this); } )
 
 
        } );
 
 
    }
 
 
} );
 

Latest revision as of 12:33, 5 October 2012

/* See [[mw:Reference Tooltips]] */

.referencetooltip {
        position: absolute;
        list-style: none;
        list-style-image: none;
        opacity: 0;
        font-size: 10px;
        margin: 0;
        z-index: 5;
        padding: 0;
}
.referencetooltip li {
        border: #080086 2px solid;
        max-width: 260px;
        padding: 10px 8px 13px 8px;
        margin: 0px;
        background-color: #F7F7F7;
        box-shadow: 2px 4px 2px rgba(0,0,0,0.3);
        -moz-box-shadow: 2px 4px 2px rgba(0,0,0,0.3);
        -webkit-box-shadow: 2px 4px 2px rgba(0,0,0,0.3);
}
.referencetooltip li+li {
        margin-left: 7px;
        margin-top: -2px;
        border: 0;
        padding: 0;
        height: 3px;
        width: 0px;
        background-color: transparent;
        box-shadow: none;
        -moz-box-shadow: none;
        -webkit-box-shadow: none;
        border-top: 12px #080086 solid;
        border-right: 7px transparent solid;
        border-left: 7px transparent solid;
}
.referencetooltip>li+li::after {
        content: '';
        border-top: 8px #F7F7F7 solid;
        border-right: 5px transparent solid;
        border-left: 5px transparent solid;
        margin-top: -12px;
        margin-left: -5px;
        z-index: 1;
        height: 0px;
        width: 0px;
        display: block;
}
.client-js .referencetooltip li ul li {
        border: none;
        box-shadow: none;
        -moz-box-shadow: none;
        -webkit-box-shadow: none;
        height: auto;
        width: auto;
        margin: auto;
        padding: 0;
        position: static;
}
.RTflipped {
        padding-top: 13px;
}
.referencetooltip.RTflipped li+li {
        position: absolute;
        top: 2px;
        border-top: 0;
        border-bottom: 12px #080086 solid;
}
.referencetooltip.RTflipped li+li::after {
        border-top: 0;
        border-bottom: 8px #F7F7F7 solid;
        position: absolute;
        margin-top: 7px;
}
.RTsettings{
        float: right;
        height: 16px;
        width: 16px;
        cursor: pointer;
        background-image: url(//upload.wikimedia.org/wikipedia/commons/e/ed/Cog.png);
        margin-top: -9px;
        margin-right: -7px;
        -webkit-transition: opacity 0.15s;
        -moz-transition: opacity 0.15s;
        -o-transition: opacity 0.15s;
        -ms-transition: opacity 0.15s;
        transition: opacity 0.15s;
        opacity: 0.6;
        filter: alpha(opacity=60);
}
.RTsettings:hover{
        opacity: 1;
        filter: alpha(opacity=100);
}