bufanliu / custom-context-menu

Automatically exported from code.google.com/p/custom-context-menu
Other
0 stars 0 forks source link

Update request for Chrome Browser support #25

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Recent change in Chrome Browser has caused the library to fail on it. Here is 
an updated code:

/**
 *
 * Copyright 2007-2012
 *
 * Paulius Uza
 * http://www.uza.lt
 *
 * Dan Florio
 * http://www.polygeek.com
 *
 * Jaroslav Danilov
 * http://jds-transparency.com
 *
 * Project website:
 * http://code.google.com/p/custom-context-menu/
 *
 * --
 * RightClick for Flash Player.
 * Version 0.6.3
 */
var RightClick = {

    /**
     *  Constructor
     */
    init:function (object, container) {
        this.FlashObjectID = object;
        this.FlashContainerID = container;
        this.Cache = this.FlashObjectID;
        if (window.addEventListener) {
            document.oncontextmenu = function (ev) {
                RightClick.killEvents(ev);
            };
            window.addEventListener("mouseup", this.onGeckoMouse, true);
        } else {
            document.oncontextmenu = function () {
                if (window.event.srcElement.id == RightClick.FlashObjectID)
                    return false;
                RightClick.Cache = "nan";
            };
            document.getElementById(this.FlashContainerID).onmouseup = function () {
                document.getElementById(RightClick.FlashContainerID).releaseCapture();
            };
            document.getElementById(this.FlashContainerID).onmousedown = RightClick.onIEMouse;
        }
    },

    /**
     * GECKO / WEBKIT event overkill
     * @param {Object} eventObject
     */
    killEvents:function (eventObject) {
        if (eventObject) {
            if (eventObject.stopPropagation) eventObject.stopPropagation();
            if (eventObject.preventDefault)  eventObject.preventDefault();
            if (eventObject.preventCapture)  eventObject.preventCapture();
            if (eventObject.preventBubble)   eventObject.preventBubble();
        }
    },

    /**
     * GECKO / WEBKIT call right click
     * @param {Object} ev
     */
    onGeckoMouse:function (ev) {
        if (ev.button != 0) {
            RightClick.killEvents(ev);
            if (ev.target.id == RightClick.FlashObjectID && RightClick.Cache == RightClick.FlashObjectID) {
                RightClick.call();
            }
            RightClick.Cache = ev.target.id;
        }
    },

    /**
     * IE call right click
     */
    onIEMouse:function () {
        if (event.button > 1) {
            if (window.event.srcElement.id == RightClick.FlashObjectID && RightClick.Cache == RightClick.FlashObjectID) {
                RightClick.call();
            }
            document.getElementById(RightClick.FlashContainerID).setCapture();
            if (window.event.srcElement.id)
                RightClick.Cache = window.event.srcElement.id;
        }
    },

    /**
     * Main call to Flash External Interface
     */
    call:function () {
        document.getElementById(this.FlashObjectID).rightClick();
    }
}

Original issue reported on code.google.com by jaroslav...@gmail.com on 7 Aug 2012 at 5:00

GoogleCodeExporter commented 8 years ago
Notice the call has been added:
        ...
        if (window.addEventListener) {
            document.oncontextmenu = function (ev) {
                RightClick.killEvents(ev);
            };
        ...
in order to fix the issue.

Original comment by jaroslav...@gmail.com on 7 Aug 2012 at 5:01