Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag and Drop in another iframe #187

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions jquery.ui.touch-punch.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
var mouseProto = $.ui.mouse.prototype,
_mouseInit = mouseProto._mouseInit,
_mouseDestroy = mouseProto._mouseDestroy,
offset_map = [],
touchHandled;

/**
Expand All @@ -38,7 +39,10 @@
event.preventDefault();

var touch = event.originalEvent.changedTouches[0],
simulatedEvent = document.createEvent('MouseEvents');
simulatedEvent = document.createEvent('MouseEvents'),
doc, frameOffset,
offsetX = 0,
offsetY = 0;

// Initialize the simulated mouse event using the touch event's coordinates
simulatedEvent.initMouseEvent(
Expand All @@ -61,6 +65,41 @@

// Dispatch the simulated event to the target element
event.target.dispatchEvent(simulatedEvent);

if (( doc = $( event.target )[ 0 ].ownerDocument ) !== document ) {
simulatedEvent = document.createEvent('MouseEvents');

frame = (doc.defaultView || doc.parentWindow).frameElement;
frameOffset = offset_map[ frame.id ];
if ( !frameOffset ) {
frameOffset = offset_map[ frame.id ] = $( frame ).offset();
}

offsetX = frameOffset.left;
offsetY = frameOffset.top;

// Initialize the simulated mouse event using the touch event's coordinates
simulatedEvent.initMouseEvent(
simulatedType, // type
true, // bubbles
true, // cancelable
window, // view
1, // detail
touch.screenX + offsetX, // screenX
touch.screenY + offsetY, // screenY
touch.clientX + offsetX, // clientX
touch.clientY + offsetY, // clientY
false, // ctrlKey
false, // altKey
false, // shiftKey
false, // metaKey
0, // button
null // relatedTarget
);

// Dispatch the simulated event to the target element
document.dispatchEvent(simulatedEvent);
}
}

/**
Expand Down Expand Up @@ -177,4 +216,4 @@
_mouseDestroy.call(self);
};

})(jQuery);
})(jQuery);