This is a migrated thread and some comments may be shown as answers.

RadContextMenu Ipad

2 Answers 74 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Rodrigo
Top achievements
Rank 1
Rodrigo asked on 10 Nov 2012, 02:35 PM
Hello,

I have a radcontextmenu that targets a RadDock and I'm trying to make the right click work for ipad. I saw the implementation in a radtree, but I'm trying to adopt it without success.

Thanks,

Rod

function pageLoad() {
                var isMobileSafari = (navigator.userAgent.search(/like\sMac\sOS\sX;.*Mobile\/\S+/) != -1)
                if (isMobileSafari) {
                    var ctx = document.getElementById("<%= RadDock1.ClientID "%>);
                    ctx.addEventListener('touchstart', handleTouchStart, false);
                    ctx.addEventListener('touchend', handleTouchEnd, false);
                }
            }
 
            var lastContext = null;
            var longTouchID = 0;
            var menuShown = false;
 
            function longTouch() {
                longTouchID = 0;
                menuShown = true;
 
                var ctx = document.getElementById("<%= radMenu1.ClientID "%>);
                ctx.show();
            }
 
            function handleTouchStart(e) {
                longTouchID = setTimeout(longTouch, 1000);
            }
 
            function handleClick(e) {
                if (menuShown) {
                    menuShown = false;
                    document.body.removeEventListener('click', handleClick, true);
                    e.stopPropagation();
                    e.preventDefault();
                }
            }
 
            function handleTouchEnd(e) {
                if (longTouchID != 0)
                    clearTimeout(longTouchID);
                if (menuShown) {
                    document.body.addEventListener('click', handleClick, true);
                    e.preventDefault();
                }
            }

2 Answers, 1 is accepted

Sort by
0
AMS
Top achievements
Rank 1
answered on 20 Nov 2012, 06:58 AM
you are not closing your quotes properly:
var ctx = document.getElementById("<%= RadDock1.ClientID %>"); write this line

0
AMS
Top achievements
Rank 1
answered on 20 Nov 2012, 07:04 AM
I am getting the error in the Telerik code:

tree._contextMenu[undefined] is not a function. Its probably due to this line:

 var lastContext = null; 

Anybody to give suggestion/help?

<script type="text/javascript"  language="javascript">
    function ClientMouseOver(sender, e) {
        var contextMenu = $find("<%= completedContextMenu.ClientID %>");
 
        if ((!e.relatedTarget) || (!$telerik.isDescendantOrSelf(contextMenu.get_element(), e.relatedTarget))) {
            contextMenu.show(e);
        }
 
        $telerik.cancelRawEvent(e);
    }
 
    function pageLoad() {
        if (document.getElementById('<%= hdnVisited.ClientID %>').value == "") {
            var popup = $find('<%= pnlMessagePopup.ClientID %>');
            if (popup != null) {
                popup.show();
                document.getElementById('<%= hdnVisited.ClientID %>').value = "visited";
            }
        }
 
        // for context menu
        if ($telerik.isMobileSafari) {
                        //var treeArea = $telerik.$($find('tvCompletedCourses').get_element())[0];
            var treeArea = document.getElementById('<%= tvCompletedCourses.ClientID %>');
            alert(treeArea);
            treeArea.addEventListener('touchstart', handleTouchStart, false);
            treeArea.addEventListener('touchend', handleTouchEnd, false);
        }
 
 
    }
 
    function closePopup() {
        var popup = $find('<%= pnlMessagePopup.ClientID %>');
        if (popup != null) {
            popup.close();
        }
    }
 
    var lastContext = null;
    var longTouchID = 0;
    var menuShown = false;
 
    function longTouch() {
        longTouchID = 0;
        menuShown = true;
 
        var tree = document.getElementById('<%= tvCompletedCourses.ClientID %>');
        tree._contextMenu(lastContext);
    }
 
    function handleTouchStart(e) {
        lastContext = e;
        lastContext.button = 2;
        lastContext.target = e.originalTarget;
        lastContext.eventMapTarget = lastContext.target;
        lastContext.pageX = e.changedTouches[0].pageX;
        lastContext.pageY = e.changedTouches[0].pageY;
        lastContext.clientX = e.changedTouches[0].clientX;
        lastContext.clientY = e.changedTouches[0].clientY;
        longTouchID = setTimeout(longTouch, 1000);
    }
 
    function handleClick(e) {
        if (menuShown) {
            menuShown = false;
            document.body.removeEventListener('click', handleClick, true);
            e.stopPropagation();
            e.preventDefault();
        }
    }
 
    function handleTouchEnd(e) {
        if (longTouchID != 0)
            clearTimeout(longTouchID);
 
        if (menuShown) {
            document.body.addEventListener('click', handleClick, true);
            e.preventDefault();
        }
    }
 
</script>
Tags
Menu
Asked by
Rodrigo
Top achievements
Rank 1
Answers by
AMS
Top achievements
Rank 1
Share this question
or