Comments (2)
also I still have the issue of double-popup on Firefox Android 42.0
I copied both the abbr-touch.js and the touchtap.js from your github right into the php that has all the stuff. so this is all the script code I have in there:
<script>
/**
* @license
* abbr-touch <http://github.com/Tyriar/abbr-touch>
* Copyright 2014 Daniel Imms <http://www.growingwiththeweb.com>
* Released under the MIT license <http://github.com/Tyriar/abbr-touch/blob/master/LICENSE>
*/
var abbrTouch = (function () { // eslint-disable-line no-unused-vars
"use strict";
/**
* Generates a touchtap event handler that calls the tap handler provided.
* @param {function} handler The tap handler to call.
* @returns {function}
*/
function generateTouchtapHandler(handler) {
return function (e) {
handler(e.currentTarget, e.currentTarget.title, e.customData.touchX, e.customData.touchY);
};
}
/**
* The default lightweight tap handler.
*/
function defaultOnTapHandler(target, title, touchX, touchY) { // eslint-disable-line no-unused-vars
alert(title); // eslint-disable-line no-alert
}
/**
* Attaches abbrTouch events on all abbr[title] elements within an element
* @param {HTMLElement} elementScope The element containing abbr[title]
* elements.
* @param {function} customTapHandler (Optional) A custom touchtap handler to
* be used when abbr[title] elements are touched.
*/
function init(elementScope, customTapHandler) {
if (!elementScope) {
elementScope = document;
}
var tapHandler = customTapHandler || defaultOnTapHandler;
var elements = elementScope.querySelectorAll("abbr[title]");
var touchtapHandler = generateTouchtapHandler(tapHandler);
for (var i = 0; i < elements.length; i++) {
elements[i].addEventListener("touchtap", touchtapHandler);
}
}
return init;
})();
</script>
<script>
/**
* @license
* touchtap-event <http://github.com/Tyriar/touchtap-event>
* Copyright 2014 Daniel Imms <http://www.growingwiththeweb.com>
* Released under the MIT license <http://github.com/Tyriar/touchtap-event/blob/master/LICENSE>
*/
(function () {
"use strict";
var touchTapEvent;
var isTapLength;
var tapLengthTimeout;
var startPosition = { x: -1, y: -1 };
var currentPosition = { x: -1, y: -1 };
/**
* Gets the touch object from a touch* event.
* @param {Event} e The event.
* @returns {Touch} The (first) touch object from the event.
*/
function getTouchObject(e) {
if (e.originalEvent && e.originalEvent.targetTouches) {
return e.originalEvent.targetTouches[0];
}
if (e.targetTouches) {
return e.targetTouches[0];
}
return e;
}
/**
* Gets whether two numbers are approximately equal to each other.
* @param {number} a The first number.
* @param {number} b The second number.
* @returns {Boolean}
*/
function approximatelyEqual(a, b) {
return Math.abs(a - b) < 2;
}
/**
* Handler for the touchstart event.
* @param {Event} e The touchstart event.
*/
function touchstart(e) {
var touchObject = getTouchObject(e);
startPosition.x = touchObject.pageX;
startPosition.y = touchObject.pageY;
currentPosition.x = touchObject.pageX;
currentPosition.y = touchObject.pageY;
isTapLength = true;
if (tapLengthTimeout) {
clearTimeout(tapLengthTimeout);
}
tapLengthTimeout = setTimeout(function () {
isTapLength = false;
}, 200);
}
/**
* Handler for the touchend event.
* @param {Event} e The touchend event.
*/
function touchend(e) {
if (isTapLength &&
approximatelyEqual(startPosition.x, currentPosition.x) &&
approximatelyEqual(startPosition.y, currentPosition.y)) {
touchTapEvent.customData = {
touchX: currentPosition.x,
touchY: currentPosition.y
};
e.target.dispatchEvent(touchTapEvent);
}
}
/**
* Handler for the touchmove event.
* @param {Event} e The touchmove event.
*/
function touchmove(e) {
var touchObject = getTouchObject(e);
currentPosition.x = touchObject.pageX;
currentPosition.y = touchObject.pageY;
}
/**
* Initialises the library.
*/
function init() {
touchTapEvent = document.createEvent("CustomEvent");
touchTapEvent.initEvent("touchtap", true, true);
document.addEventListener("touchstart", touchstart);
document.addEventListener("touchend", touchend);
document.addEventListener("touchcancel", touchend);
document.addEventListener("touchmove", touchmove);
}
init();
})();
</script>
<script>
abbrTouch();
</script>
from abbr-touch.
Moved to #13
from abbr-touch.
Related Issues (14)
- Make a customisable popup when tapped instead of a plain alert HOT 1
- Factor out touch event into own repo, depend on it
- Add unit tests
- Make note of special cases/issues in readme
- Use shields.io
- <abbr> wrapped in an <a> will trigger both events
- Report that abbr-touch doesn't work on mobile safari HOT 1
- Add link to working demo
- Improve wording of package description/readme
- empty popup if <i> is in abbr HOT 7
- Remove bower support HOT 1
- Handler is triggered twice in Firefox HOT 2
- Prime abbr-touch tooltip element with will-change
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from abbr-touch.