User:Subh83/JavaScriptTools/refRightclickMenu.js

/**************************************************** * Created by Subhrajit Bhattacharya [[User:Subh83]] * * Licensed under GNU-GPL v3.0

/****************************************************
* Created by Subhrajit Bhattacharya [[User:Subh83]] *
* Licensed under GNU-GPL v3.0                       *
*****************************************************/

if (typeof(RightClickMenuKey)=='undefined') RightClickMenuKey = ''; // 'shift', 'alt', 'ctrl' or ''

if (typeof(UserSubh83_utils1)=='undefined') importScript("User:Subh83/JavaScriptTools/utils1.js");


function getRefMenuHTML(refname) {
    var refRawname = refname.split("#")[1];
    var theLI = document.getElementById(refRawname);
    if (theLI)
        var theAs = theLI.getElementsByTagName('a');

    // Generate the HTML
    var oddeven = ['odd','even'];
    var ret = "<div class='rightclickmenu'> " +
                  "<span class='heading'>" + refRawname + "</span><span class='summary'><br/>" + theLI.innerHTML + 
                  "</span><hr/><div class='items'>";
    var j = 0;
    for (var i=0; i<theAs.length; i++) {
        if ( theAs[i].className.toString().indexOf("external") >= 0 && theAs[i].className.toString().indexOf("text") >= 0 ) {
            ret += "<div class='menuitem "+oddeven[j%2]+"'><a href=\""+theAs[i].href+"\" target='_blank'>" + theAs[i].href +"</a></div>";
            j++;
        }
    }
    ret += "</div></div>";
 
    return ret;
}

function showRefMenu(e)
{
    if (!e) var e = window.event;
    var rightclick;
    if (e.which) rightclick = (e.which == 3);
    else if (e.button) rightclick = (e.button == 2);
 
    var targ;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // Safari bug
        targ = targ.parentNode;
 
    var keyPressed = true;
    if (RightClickMenuKey=='' && (e.shiftKey || e.ctrlKey || e.altKey)) keyPressed = false;
    else if (RightClickMenuKey=='shift' && !e.shiftKey) keyPressed = false;
    else if (RightClickMenuKey=='ctrl' && !e.ctrlKey) keyPressed = false;
    else if (RightClickMenuKey=='alt' && !e.altKey) keyPressed = false;
 
    var refrightclickmenu = document.getElementById("refrightclickmenu");
    if (!refrightclickmenu) {
        alert("Unable to locate rightclick-menu!");
        return;
    }
    if (rightclick && keyPressed && targ.tagName.toLowerCase()=="a") {
        refrightclickmenu.innerHTML = getRefMenuHTML(targ.href);
        setMenuPosition (e, refrightclickmenu);
        refrightclickmenu.style.zIndex = "10000";
        refrightclickmenu.style.display = "block";
        return false;
    }
    else 
        refrightclickmenu.style.display = "none";
}

var onRefMenu = false;
$( function () {
 
    // Add right-click menu to each ref link
    var refSups = document.getElementsByTagName("sup");
    if (refSups && refSups.length>0)
        for (var i=0; i<refSups.length; i++) 
            if (refSups[i].getAttribute("class") == "reference") {
                refSups[i].getElementsByTagName('a')[0].onmouseup = showRefMenu;
                refSups[i].getElementsByTagName('a')[0].oncontextmenu = showRefMenu;
            }
    AppendHandlerToEvent( "document.onmousedown", 
                          function() { if(!onRefMenu) document.getElementById('refrightclickmenu').style.display='none'; } );

    var refrightclickmenu = document.createElement("div");
    refrightclickmenu.setAttribute("id", "refrightclickmenu");
    refrightclickmenu.setAttribute("display", "none");
    var theBody = document.getElementsByTagName("body")[0];
    theBody.insertBefore(refrightclickmenu, theBody.childNodes[0]);

    document.getElementById('refrightclickmenu').onmouseover = function() { onRefMenu = true; };
    document.getElementById('refrightclickmenu').onmouseout = function() { onRefMenu = false; };
});

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.