views:

107

answers:

1

I'm working on a project in Ruby right now that is essentially a web-app. We like the format of web-apps and some of the natural agile advantages we have building for the web. However, we want to be able to package our application and distribute it in a standalone format.

Ideally, we would like to essentially make a .app package for Mac and a .exe for Windows that just opens a Webkit view, connects to our server and renders the HTML we serve it.

Not so hard so far, though this is a little beyond our current expertise (especially the Windows development) but all surmountable.

The issue is that we'd like to enable right-clicking, as you can in the iTunes store (which is a Webkit view that has custom events for right-clicks). We want to give our right-clicks special meaning in our application, too, and have it act context sensitive.

What do we do? Where can we even start?

Thanks!

+1  A: 

Do you want to do this from your webapp or from your native app side?

If you're doing this from a Cocoa app, you can just implement the webView:contextMenuItemsForElement:defaultMenuItems: WebUIDelegate method and return an array of custom NSMenuItem's corresponding to your custom actions.

If you want to do this from the web app itself, you can add an event listener for the "contextmenu" event like so:

document.addEventListener("contextmenu", function(event) {
    event.preventDefault();
    console.log("My spiffy custom right click menu here!");
}, false);

You need to be aware though, that if you use the above code in your webapp, you can't modify the browser's native right click menu, just replace it with your own custom creation.

Matt Lilek
Great! I'm going to have to dive into Obj-C, but it looks like it'll be worth it, and relatively simple to implement. Thanks!
Isaac Hodes