Skip to content

Commit

Permalink
Merge pull request #19620 from apache/fix/toolbox/saveAsImage
Browse files Browse the repository at this point in the history
fix(toolbox): use `typeof` operator rather than `isFunction` util to detect if `MouseEvent` object is supported
  • Loading branch information
Ovilia committed Feb 20, 2024
2 parents 031a908 + 385a817 commit 706b74b
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/component/toolbox/feature/SaveAsImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
* under the License.
*/

/* global Uint8Array, document */
/* global window, Uint8Array, document */

import env from 'zrender/src/core/env';
import { ToolboxFeature, ToolboxFeatureOption } from '../featureManager';
import { ZRColor } from '../../../util/types';
import GlobalModel from '../../../model/Global';
import ExtensionAPI from '../../../core/ExtensionAPI';
import { isFunction } from 'zrender/src/core/util';

export interface ToolboxSaveAsImageFeatureOption extends ToolboxFeatureOption {
icon?: string
Expand All @@ -42,8 +41,6 @@ export interface ToolboxSaveAsImageFeatureOption extends ToolboxFeatureOption {
lang?: string[]
}

/* global window, document */

class SaveAsImage extends ToolboxFeature<ToolboxSaveAsImageFeatureOption> {

onclick(ecModel: GlobalModel, api: ExtensionAPI) {
Expand All @@ -61,7 +58,7 @@ class SaveAsImage extends ToolboxFeature<ToolboxSaveAsImageFeatureOption> {
});
const browser = env.browser;
// Chrome, Firefox, New Edge
if (isFunction(MouseEvent) && (browser.newEdge || (!browser.ie && !browser.edge))) {
if (typeof MouseEvent === 'function' && (browser.newEdge || (!browser.ie && !browser.edge))) {
const $a = document.createElement('a');
$a.download = title + '.' + type;
$a.target = '_blank';
Expand Down

0 comments on commit 706b74b

Please sign in to comment.