Executing default action on click on mobile devices

This commit is contained in:
Andreas Stöckel 2011-06-02 22:53:23 +00:00
parent a4730b3511
commit 0d66fcd9d1
2 changed files with 84 additions and 42 deletions

View File

@ -375,6 +375,25 @@ egwFnct.prototype.exec = function()
}
}
/**
* Checks whether this is currently run on a mobile browser
*/
var _egw_mobileBrowser = null;
function egwIsMobile() {
if (_egw_mobileBrowser == null)
{
var ua = navigator.userAgent;
_egw_mobileBrowser =
ua.match(/iPhone/i) || ua.match(/iPad/i) || ua.match(/iPod/) ||
ua.match(/Android/i) || ua.match(/SymbianOS/i);
}
return _egw_mobileBrowser;
}
/**
sprintf() for JavaScript 0.6

View File

@ -19,7 +19,6 @@ _egwActionClasses["popup"] = {
function egwPopupAction(_id, _handler, _caption, _icon, _onExecute, _allowOnMultiple)
{
var action = new egwAction(_id, _handler, _caption, _icon, _onExecute, _allowOnMultiple);
action.type = "popup";
action.canHaveChildren = ["popup"];
action["default"] = false;
@ -82,13 +81,11 @@ function egwPopupActionImplementation()
ai.type = "popup";
ai.doRegisterAction = function(_aoi, _callback, _context)
{
var node = _aoi.getDOMNode();
if (node)
{
node.ondblclick = function(e) {
/**
* Registers the handler for the default action
*/
ai._registerDefault = function(_node, _callback, _context) {
var defaultHandler = function(e) {
if (typeof document.selection != "undefined" && typeof document.selection.empty != "undefined")
{
document.selection.empty();
@ -104,7 +101,18 @@ function egwPopupActionImplementation()
return false;
}
node.oncontextmenu = function(e) {
if (egwIsMobile()) {
$(_node).bind('click', defaultHandler);
} else {
_node.dblclick = defaultHandler;
}
}
/**
* Registers the handler for the context menu
*/
ai._registerContext = function(_node, _callback, _context) {
var contextHandler = function(e) {
//Obtain the event object
if (!e)
{
@ -129,6 +137,21 @@ function egwPopupActionImplementation()
return false;
}
if (egwIsMobile()) {
$(_node).bind('taphold', contextHandler);
} else {
_node.oncontextmenu = contextHandler;
}
}
ai.doRegisterAction = function(_aoi, _callback, _context)
{
var node = _aoi.getDOMNode();
if (node)
{
this._registerDefault(node, _callback, _context);
this._registerContext(node, _callback, _context);
return true;
}
return false;