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 sprintf() for JavaScript 0.6

View File

@ -19,7 +19,6 @@ _egwActionClasses["popup"] = {
function egwPopupAction(_id, _handler, _caption, _icon, _onExecute, _allowOnMultiple) function egwPopupAction(_id, _handler, _caption, _icon, _onExecute, _allowOnMultiple)
{ {
var action = new egwAction(_id, _handler, _caption, _icon, _onExecute, _allowOnMultiple); var action = new egwAction(_id, _handler, _caption, _icon, _onExecute, _allowOnMultiple);
action.type = "popup"; action.type = "popup";
action.canHaveChildren = ["popup"]; action.canHaveChildren = ["popup"];
action["default"] = false; action["default"] = false;
@ -82,53 +81,77 @@ function egwPopupActionImplementation()
ai.type = "popup"; ai.type = "popup";
/**
* 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();
}
else if( typeof window.getSelection != "undefined")
{
var sel = window.getSelection();
sel.removeAllRanges();
}
_callback.call(_context, "default", ai);
return false;
}
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)
{
e = window.event;
}
if (_egw_active_menu)
{
_egw_active_menu.hide()
}
else
{
_xy = ai._getPageXY(e);
_callback.call(_context, _xy, ai);
}
e.cancelBubble = true;
if (e.stopPropagation)
{
e.stopPropagation();
}
return false;
}
if (egwIsMobile()) {
$(_node).bind('taphold', contextHandler);
} else {
_node.oncontextmenu = contextHandler;
}
}
ai.doRegisterAction = function(_aoi, _callback, _context) ai.doRegisterAction = function(_aoi, _callback, _context)
{ {
var node = _aoi.getDOMNode(); var node = _aoi.getDOMNode();
if (node) if (node)
{ {
node.ondblclick = function(e) { this._registerDefault(node, _callback, _context);
if (typeof document.selection != "undefined" && typeof document.selection.empty != "undefined") this._registerContext(node, _callback, _context);
{
document.selection.empty();
}
else if( typeof window.getSelection != "undefined")
{
var sel = window.getSelection();
sel.removeAllRanges();
}
_callback.call(_context, "default", ai);
return false;
}
node.oncontextmenu = function(e) {
//Obtain the event object
if (!e)
{
e = window.event;
}
if (_egw_active_menu)
{
_egw_active_menu.hide()
}
else
{
_xy = ai._getPageXY(e);
_callback.call(_context, _xy, ai);
}
e.cancelBubble = true;
if (e.stopPropagation)
{
e.stopPropagation();
}
return false;
}
return true; return true;
} }
return false; return false;