Skip to content

Commit

Permalink
Fixed #11353, added support for passive touch events.
Browse files Browse the repository at this point in the history
  • Loading branch information
raf18seb committed Jul 20, 2020
1 parent 226365c commit fec46b1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
17 changes: 15 additions & 2 deletions js/Core/Globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,19 @@ typeof win !== 'undefined' ?
doc.createElementNS &&
!!doc.createElementNS(SVG_NS, 'svg').createSVGRect), isMS = /(edge|msie|trident)/i.test(userAgent) && !glob.opera, isFirefox = userAgent.indexOf('Firefox') !== -1, isChrome = userAgent.indexOf('Chrome') !== -1, hasBidiBug = (isFirefox &&
parseInt(userAgent.split('Firefox/')[1], 10) < 4 // issue #38
);
), noop = function () { },
// Checks whether the browser supports passive events, (#11353).
checkPassiveEvents = function () {
var supportsPassive = false;
var opts = Object.defineProperty({}, 'passive', {
get: function () {
supportsPassive = true;
}
});
glob.addEventListener('testPassive', noop, opts);
glob.removeEventListener('testPassive', noop, opts);
return supportsPassive;
};
var H = {
product: 'Highcharts',
version: '@product.version@',
Expand All @@ -46,10 +58,11 @@ var H = {
chartCount: 0,
seriesTypes: {},
symbolSizes: {},
supportPassiveEvents: checkPassiveEvents(),
svg: svg,
win: glob,
marginNames: ['plotTop', 'marginRight', 'marginBottom', 'plotLeft'],
noop: function () { },
noop: noop,
/**
* Theme options that should get applied to the chart. In module mode it
* might not be possible to change this property because of read-only
Expand Down
6 changes: 5 additions & 1 deletion js/Core/Utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -2187,8 +2187,12 @@ var addEvent = H.addEvent = function (el, type, fn, options) {
el.series.chart.runTrackerClick = true;
}
// Handle DOM events
// If the browser supports passive events, add it to improve performance
// on touch events (#11353).
if (addEventListener) {
addEventListener.call(el, type, fn, false);
addEventListener.call(el, type, fn, H.supportPassiveEvents ? {
passive: type.indexOf('touch') !== -1, capture: false
} : false);
}
if (!events[type]) {
events[type] = [];
Expand Down
22 changes: 20 additions & 2 deletions ts/Core/Globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ declare global {
const symbolSizes: Dictionary<SizeObject>;
const win: GlobalWindow;
const seriesTypes: SeriesTypesDictionary;
const supportPassiveEvents: boolean;
const svg: boolean;
const version: string;
let theme: (Options|undefined);
Expand Down Expand Up @@ -166,7 +167,23 @@ var glob = ( // @todo UMD variable named `window`, and glob named `win`
hasBidiBug = (
isFirefox &&
parseInt(userAgent.split('Firefox/')[1], 10) < 4 // issue #38
);
),
noop = function (): void {},
// Checks whether the browser supports passive events, (#11353).
checkPassiveEvents = function (): boolean {
let supportsPassive = false;

const opts = Object.defineProperty({}, 'passive', {
get: function (): void {
supportsPassive = true;
}
});

glob.addEventListener('testPassive', noop, opts);
glob.removeEventListener('testPassive', noop, opts);

return supportsPassive;
};

var H: typeof Highcharts = {
product: 'Highcharts',
Expand All @@ -185,10 +202,11 @@ var H: typeof Highcharts = {
chartCount: 0,
seriesTypes: {} as Highcharts.SeriesTypesDictionary,
symbolSizes: {},
supportPassiveEvents: checkPassiveEvents(),
svg: svg,
win: glob,
marginNames: ['plotTop', 'marginRight', 'marginBottom', 'plotLeft'],
noop: function (): void {},
noop: noop,

/**
* Theme options that should get applied to the chart. In module mode it
Expand Down
6 changes: 5 additions & 1 deletion ts/Core/Utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3025,8 +3025,12 @@ const addEvent = H.addEvent = function<T> (
}

// Handle DOM events
// If the browser supports passive events, add it to improve performance
// on touch events (#11353).
if (addEventListener) {
addEventListener.call(el, type, fn, false);
addEventListener.call(el, type, fn, H.supportPassiveEvents ? {
passive: type.indexOf('touch') !== -1, capture: false
} : false);
}

if (!events[type]) {
Expand Down

0 comments on commit fec46b1

Please sign in to comment.