mirror of
https://github.com/seigler/dash-docs
synced 2025-07-27 01:36:13 +00:00
Avoid direct use of e.type
Some browsers need us to use window.event
This commit is contained in:
parent
09acaafbb0
commit
11c484c858
2 changed files with 24 additions and 19 deletions
21
js/base.js
21
js/base.js
|
@ -25,11 +25,16 @@ if (!e) var e = window.event;
|
||||||
(e.preventDefault) ? e.preventDefault() : e.returnValue = false;
|
(e.preventDefault) ? e.preventDefault() : e.returnValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEventTarget(e) {
|
function getEvent(e, a) {
|
||||||
// Return target DOM node on which the event is triggered.
|
// Return requested event property.
|
||||||
// Ex. getEventTarget(event);
|
// Ex. var target = getEvent(event, 'target');
|
||||||
if (!e) var e = window.event;
|
e = (e) ? e : window.event;
|
||||||
return (e.target && e.target.nodeType == 3) ? e.target.parentNode : (e.target) ? e.target : e.srcElement;
|
switch (a) {
|
||||||
|
case 'type':
|
||||||
|
return e.type;
|
||||||
|
case 'target':
|
||||||
|
return (e.target && e.target.nodeType == 3) ? e.target.parentNode : (e.target) ? e.target : e.srcElement;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStyle(a, b) {
|
function getStyle(a, b) {
|
||||||
|
@ -99,7 +104,7 @@ var timeout = 1000,
|
||||||
// Cancel click events on different targets within timeframe.
|
// Cancel click events on different targets within timeframe.
|
||||||
// This avoids accidental clicks when the page is scrolled or updated due to the 300ms click event delay on mobiles.
|
// This avoids accidental clicks when the page is scrolled or updated due to the 300ms click event delay on mobiles.
|
||||||
removeEvent(document.body, 'click', wrongClickListener);
|
removeEvent(document.body, 'click', wrongClickListener);
|
||||||
if (!clickReady() && getEventTarget(e) != t) cancelEvent(e);
|
if (!clickReady() && getEvent(e, 'target') != t) cancelEvent(e);
|
||||||
},
|
},
|
||||||
setClickTimeout = function() {
|
setClickTimeout = function() {
|
||||||
// Update timeout during which click events will be blocked.
|
// Update timeout during which click events will be blocked.
|
||||||
|
@ -111,7 +116,7 @@ var timeout = 1000,
|
||||||
return (ti === null || ti === '' || parseInt(ti, 10) < new Date().getTime());
|
return (ti === null || ti === '' || parseInt(ti, 10) < new Date().getTime());
|
||||||
};
|
};
|
||||||
// Apply appropriate actions according to each event type.
|
// Apply appropriate actions according to each event type.
|
||||||
switch (e.type) {
|
switch (getEvent(e, 'type')) {
|
||||||
case 'touchstart':
|
case 'touchstart':
|
||||||
// Save initial touchstart coordinates and listen for touchend events and accidental click events.
|
// Save initial touchstart coordinates and listen for touchend events and accidental click events.
|
||||||
var x = e.changedTouches[0].pageX,
|
var x = e.changedTouches[0].pageX,
|
||||||
|
@ -145,7 +150,7 @@ onTouchClick(e, show);
|
||||||
|
|
||||||
function mobileMenuHover(e) {
|
function mobileMenuHover(e) {
|
||||||
// Prevent mobile menu to shrink on hover to prevent accidental clicks on other entries.
|
// Prevent mobile menu to shrink on hover to prevent accidental clicks on other entries.
|
||||||
var t = getEventTarget(e),
|
var t = getEvent(e, 'target'),
|
||||||
fn = (t.parentNode.className.indexOf('hover') === -1) ? addClass : removeClass,
|
fn = (t.parentNode.className.indexOf('hover') === -1) ? addClass : removeClass,
|
||||||
initHover = function() {
|
initHover = function() {
|
||||||
if (t.nodeName != 'A') return;
|
if (t.nodeName != 'A') return;
|
||||||
|
|
22
js/main.js
22
js/main.js
|
@ -119,7 +119,7 @@ return false;
|
||||||
|
|
||||||
function loadYoutubeVideo(e) {
|
function loadYoutubeVideo(e) {
|
||||||
// Load Youtube video on target node on click.
|
// Load Youtube video on target node on click.
|
||||||
var t = getEventTarget(e),
|
var t = getEvent(e, 'target'),
|
||||||
nd = document.createElement('IFRAME');
|
nd = document.createElement('IFRAME');
|
||||||
while (t.getAttribute('data-youtubeurl') === null || t.getAttribute('data-youtubeurl') === '') t = t.parentNode;
|
while (t.getAttribute('data-youtubeurl') === null || t.getAttribute('data-youtubeurl') === '') t = t.parentNode;
|
||||||
nd.src = t.getAttribute('data-youtubeurl');
|
nd.src = t.getAttribute('data-youtubeurl');
|
||||||
|
@ -148,7 +148,7 @@ setTimeout(function() {
|
||||||
|
|
||||||
function boxShow(e) {
|
function boxShow(e) {
|
||||||
// Display the box content when the user click a box on the "Secure your wallet" page.
|
// Display the box content when the user click a box on the "Secure your wallet" page.
|
||||||
var t = getEventTarget(e);
|
var t = getEvent(e, 'target');
|
||||||
while (t.nodeName != 'DIV') t = t.parentNode;
|
while (t.nodeName != 'DIV') t = t.parentNode;
|
||||||
expandBox(t);
|
expandBox(t);
|
||||||
cancelEvent(e);
|
cancelEvent(e);
|
||||||
|
@ -156,7 +156,7 @@ cancelEvent(e);
|
||||||
|
|
||||||
function faqShow(e) {
|
function faqShow(e) {
|
||||||
// Display the content of a question in the FAQ at user request.
|
// Display the content of a question in the FAQ at user request.
|
||||||
var t = getEventTarget(e);
|
var t = getEvent(e, 'target');
|
||||||
while (t.nodeType != 1 || t.nodeName != 'DIV') t = t.nextSibling;
|
while (t.nodeType != 1 || t.nodeName != 'DIV') t = t.nextSibling;
|
||||||
expandBox(t);
|
expandBox(t);
|
||||||
cancelEvent(e);
|
cancelEvent(e);
|
||||||
|
@ -164,7 +164,7 @@ cancelEvent(e);
|
||||||
|
|
||||||
function materialShow(e) {
|
function materialShow(e) {
|
||||||
// Display more materials on the "Press center" page at user request.
|
// Display more materials on the "Press center" page at user request.
|
||||||
var t = getEventTarget(e),
|
var t = getEvent(e, 'target'),
|
||||||
p = t;
|
p = t;
|
||||||
while (p.nodeType != 1 || p.nodeName != 'DIV') p = p.parentNode;
|
while (p.nodeType != 1 || p.nodeName != 'DIV') p = p.parentNode;
|
||||||
expandBox(p);
|
expandBox(p);
|
||||||
|
@ -173,7 +173,7 @@ cancelEvent(e);
|
||||||
|
|
||||||
function librariesShow(e) {
|
function librariesShow(e) {
|
||||||
// Display more open source projects on the "Development" page at user request.
|
// Display more open source projects on the "Development" page at user request.
|
||||||
var t = getEventTarget(e),
|
var t = getEvent(e, 'target'),
|
||||||
p = t;
|
p = t;
|
||||||
while (p.nodeType != 1 || p.nodeName != 'UL') p = p.parentNode;
|
while (p.nodeType != 1 || p.nodeName != 'UL') p = p.parentNode;
|
||||||
expandBox(p);
|
expandBox(p);
|
||||||
|
@ -294,14 +294,14 @@ init();
|
||||||
|
|
||||||
function updateIssue(e) {
|
function updateIssue(e) {
|
||||||
// Update GitHub issue link pre-filled with current page location.
|
// Update GitHub issue link pre-filled with current page location.
|
||||||
var t = getEventTarget(e);
|
var t = getEvent(e, 'target');
|
||||||
t.href = 'https://github.com/bitcoin-dot-org/bitcoin.org/issues/new?body=' + encodeURIComponent('Location: ' + window.location.href.toString() + "\n\n");
|
t.href = 'https://github.com/bitcoin-dot-org/bitcoin.org/issues/new?body=' + encodeURIComponent('Location: ' + window.location.href.toString() + "\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateSource(e){
|
function updateSource(e){
|
||||||
// Update GitHub source file link pre-filled with current page location.
|
// Update GitHub source file link pre-filled with current page location.
|
||||||
if (!document.getElementsByClassName) return;
|
if (!document.getElementsByClassName) return;
|
||||||
var t = getEventTarget(e),
|
var t = getEvent(e, 'target'),
|
||||||
nodes = document.getElementsByClassName('sourcefile'),
|
nodes = document.getElementsByClassName('sourcefile'),
|
||||||
pageoffset = Math.max(0, getPageYOffset() + 100),
|
pageoffset = Math.max(0, getPageYOffset() + 100),
|
||||||
windowy = getWindowY(),
|
windowy = getWindowY(),
|
||||||
|
@ -340,7 +340,7 @@ if (sessionStorage.getItem('develdocdisclaimerclose') === '1') disclaimerClose()
|
||||||
|
|
||||||
function walletMenuListener(e) {
|
function walletMenuListener(e) {
|
||||||
// Listen for events on the wallet menu.
|
// Listen for events on the wallet menu.
|
||||||
var t = getEventTarget(e),
|
var t = getEvent(e, 'target'),
|
||||||
walletSelectPlatform = function() {
|
walletSelectPlatform = function() {
|
||||||
if (t.nodeName != 'A') return;
|
if (t.nodeName != 'A') return;
|
||||||
if (t.parentNode.className.indexOf('active') !== -1) walletShowPlatform(t.getAttribute('data-walletcompat'));
|
if (t.parentNode.className.indexOf('active') !== -1) walletShowPlatform(t.getAttribute('data-walletcompat'));
|
||||||
|
@ -352,7 +352,7 @@ onTouchClick(e, walletSelectPlatform);
|
||||||
|
|
||||||
function walletListener(e) {
|
function walletListener(e) {
|
||||||
// Listen for events on wallets.
|
// Listen for events on wallets.
|
||||||
var t = getEventTarget(e),
|
var t = getEvent(e, 'target'),
|
||||||
walletShow = function() {
|
walletShow = function() {
|
||||||
// Show wallet on click on mobile or desktop.
|
// Show wallet on click on mobile or desktop.
|
||||||
if (t.id == 'wallets') return;
|
if (t.id == 'wallets') return;
|
||||||
|
@ -482,10 +482,10 @@ function makeEditable(e) {
|
||||||
// An easter egg that makes the page editable when user click on the page and hold their mouse button for one second.
|
// An easter egg that makes the page editable when user click on the page and hold their mouse button for one second.
|
||||||
// This trick allows translators and writers to preview their work.
|
// This trick allows translators and writers to preview their work.
|
||||||
if (!e) var e = window.event;
|
if (!e) var e = window.event;
|
||||||
switch (e.type) {
|
switch (getEvent(e, 'type')) {
|
||||||
case 'mousedown':
|
case 'mousedown':
|
||||||
if ((e.which && e.which == 3) || (e.button && e.button == 2)) return;
|
if ((e.which && e.which == 3) || (e.button && e.button == 2)) return;
|
||||||
var t = getEventTarget(e);
|
var t = getEvent(e, 'target');
|
||||||
while (t.parentNode) {
|
while (t.parentNode) {
|
||||||
if (getStyle(t, 'overflow') == 'auto' || getStyle(t, 'overflow-y') == 'auto' || getStyle(t, 'overflow-x') == 'auto') return;
|
if (getStyle(t, 'overflow') == 'auto' || getStyle(t, 'overflow-y') == 'auto' || getStyle(t, 'overflow-x') == 'auto') return;
|
||||||
t = t.parentNode;
|
t = t.parentNode;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue