Test Long Click
by bakhshi
HTML
<div class="main"> main div</div>
CSS
.main{
width:200px;
height:200px;
background-color:blue;
border:solid 2px black;
color:white;
}
JavaScript
CoordinateCategories = {
Screen: "screen",
Client: "client",
Page: "page"
};
function getCoordinates(mouseOrTouchEvent, category) {
var coordinates = {}, xProp = category + "X", yProp = category + "Y";
var coordinateSource = mouseOrTouchEvent;
if (window.TouchEvent) {
coordinateSource = coordinateSource.originalEvent || coordinateSource;
if (coordinateSource.type.indexOf('mouse') !== 0 && coordinateSource.type.indexOf('pointer') < 0)
coordinateSource = (coordinateSource.touches && coordinateSource.touches.length > 0 ? coordinateSource.touches : coordinateSource.changedTouches)[0];
}
coordinates.x = coordinateSource[xProp];
coordinates.y = coordinateSource[yProp];
return coordinates;
}
function getScreenCoordinates(mouseOrTouchEvent) {
return getCoordinates(mouseOrTouchEvent,
CoordinateCategories.Screen);
}var RoughHoverHandler = (function () {
function RoughHoverHandler(radius) {
this.radius = radius;
this.radius *= this.radius;
}
RoughHoverHandler.prototype.Start = function (e) {
var coord = getScreenCoordinates(e);
this.startX = coord.x;
this.startY = coord.y;
};
RoughHoverHandler.prototype.Check = function (e) {
var coord = getScreenCoordinates(e);
var dx = coord.x - this.startX;
var dy = coord.y - this.startY;
return (dx * dx + dy * dy) <= this.radius;
};
return RoughHoverHandler;
})();
var LongClickHandler = (function () {
function LongClickHandler(element, longClickTime, hoverMovementThreshold, callback, immediateCallback) {
var hoverHandler = new RoughHoverHandler(hoverMovementThreshold);
var timeout, tt;
var cancelled = false;
var longClickHandler = function (e) {
if...