Skip to content

Cleanup old code that was there to support the Internet Explorer #7251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/7251_change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Cleanup remaining code that was there to support the Internet Explorer [[#7251](https://github.com/plotly/plotly.js/pull/7251)]
5 changes: 0 additions & 5 deletions src/components/modebar/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ modeBarButtons.toImage = {

Lib.notifier(_(gd, 'Taking snapshot - this may take a few seconds'), 'long');

if(opts.format !== 'svg' && Lib.isIE()) {
Lib.notifier(_(gd, 'IE only supports svg. Changing format to svg.'), 'long');
opts.format = 'svg';
}

['filename', 'width', 'height', 'scale'].forEach(function(key) {
if(key in toImageButtonOptions) {
opts[key] = toImageButtonOptions[key];
Expand Down
3 changes: 0 additions & 3 deletions src/css/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ a {
@include vendor('user-select', none);
}

//Required for IE11. Other browsers set this by default.
svg { overflow: hidden; }

svg a { fill: $color-brand-primary; }
svg a:hover { fill: #3c6dc5; }

Expand Down
4 changes: 0 additions & 4 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,6 @@ lib.containsAny = function(s, fragments) {
return false;
};

lib.isIE = function() {
return typeof window.navigator.msSaveBlob !== 'undefined';
};

var IS_SAFARI_REGEX = /Version\/[\d\.]+.*Safari/;
lib.isSafari = function() {
return IS_SAFARI_REGEX.test(window.navigator.userAgent);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ exports.sorterDes = function(a, b) { return b - a; };
*/
exports.distinctVals = function(valsIn) {
var vals = valsIn.slice(); // otherwise we sort the original array...
vals.sort(exports.sorterAsc); // undefined listed in the end - also works on IE11
vals.sort(exports.sorterAsc); // undefined listed in the end

var last;
for(last = vals.length - 1; last > -1; last--) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/supports_pixelated_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function supportsPixelatedImage() {
_supportsPixelated = false;

// @see https://github.com/plotly/plotly.js/issues/6604
var unsupportedBrowser = Lib.isIE() || Lib.isSafari() || Lib.isIOS();
var unsupportedBrowser = Lib.isSafari() || Lib.isIOS();

if(window.navigator.userAgent && !unsupportedBrowser) {
var declarations = Array.from(constants.CSS_DECLARATIONS).reverse();
Expand Down
2 changes: 1 addition & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ plots.addLinks = function(gd) {

// If text's width is bigger than the layout
// Check that text is a child node or document.body
// because otherwise IE/Edge might throw an exception
// because otherwise Edge might throw an exception
// when calling getComputedTextLength().
// Apparently offsetParent is null for invisibles.
if(document.body.contains(text) && text.getComputedTextLength() >= (fullLayout.width - 20)) {
Expand Down
9 changes: 0 additions & 9 deletions src/snapshot/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ function downloadImage(gd, opts) {
reject(new Error('Snapshotting already in progress.'));
}

// see comments within svgtoimg for additional
// discussion of problems with IE
// can now draw to canvas, but CORS tainted canvas
// does not allow toDataURL
// svg format will work though
if(Lib.isIE() && opts.format !== 'svg') {
reject(new Error(helpers.MSG_IE_BAD_FORMAT));
}

if(_gd) _gd._snapshotInProgress = true;
var promise = toImage(gd, opts);

Expand Down
10 changes: 0 additions & 10 deletions src/snapshot/filesaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ function fileSaver(url, name, format) {
var blob;
var objectUrl;

// IE 10+ (native saveAs)
if(Lib.isIE()) {
// At this point we are only dealing with a decoded SVG as
// a data URL (since IE only supports SVG)
blob = helpers.createBlob(url, 'svg');
window.navigator.msSaveBlob(blob, name);
blob = null;
return resolve(name);
}

if(canUseSaveLink) {
blob = helpers.createBlob(url, format);
objectUrl = helpers.createObjectURL(blob);
Expand Down
2 changes: 0 additions & 2 deletions src/snapshot/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,3 @@ function fixBinary(b) {
}

exports.IMAGE_URL_PREFIX = /^data:image\/\w+;base64,/;

exports.MSG_IE_BAD_FORMAT = 'Sorry IE does not support downloading from canvas. Try {format:\'svg\'} instead.';
13 changes: 0 additions & 13 deletions src/snapshot/svgtoimg.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,6 @@ function svgToImg(opts) {
var svg = opts.svg;
var format = opts.format || 'png';

// IE only support svg
if(Lib.isIE() && format !== 'svg') {
var ieSvgError = new Error(helpers.MSG_IE_BAD_FORMAT);
reject(ieSvgError);
// eventually remove the ev
// in favor of promises
if(!opts.promise) {
return ev.emit('error', ieSvgError);
} else {
return promise;
}
}

var canvas = opts.canvas;
var scale = opts.scale || 1;
var w0 = opts.width || 300;
Expand Down
26 changes: 0 additions & 26 deletions src/snapshot/tosvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,6 @@ module.exports = function toSVG(gd, format, scale) {
.attr('stroke-width', 0);
}

// fix for IE namespacing quirk?
// http://stackoverflow.com/questions/19610089/unwanted-namespaces-on-svg-markup-when-using-xmlserializer-in-javascript-with-ie
svg.node().setAttributeNS(xmlnsNamespaces.xmlns, 'xmlns', xmlnsNamespaces.svg);
svg.node().setAttributeNS(xmlnsNamespaces.xmlns, 'xmlns:xlink', xmlnsNamespaces.xlink);

if(format === 'svg' && scale) {
svg.attr('width', scale * width);
svg.attr('height', scale * height);
Expand All @@ -161,26 +156,5 @@ module.exports = function toSVG(gd, format, scale) {
// Fix quotations around font strings and gradient URLs
s = s.replace(DUMMY_REGEX, '\'');

// Do we need this process now that IE9 and IE10 are not supported?

// IE is very strict, so we will need to clean
// svg with the following regex
// yes this is messy, but do not know a better way
// Even with this IE will not work due to tainted canvas
// see https://github.com/kangax/fabric.js/issues/1957
// http://stackoverflow.com/questions/18112047/canvas-todataurl-working-in-all-browsers-except-ie10
// Leave here just in case the CORS/tainted IE issue gets resolved
if(Lib.isIE()) {
// replace double quote with single quote
s = s.replace(/"/gi, '\'');
// url in svg are single quoted
// since we changed double to single
// we'll need to change these to double-quoted
s = s.replace(/(\('#)([^']*)('\))/gi, '(\"#$2\")');
// font names with spaces will be escaped single-quoted
// we'll need to change these to double-quoted
s = s.replace(/(\\')/gi, '\"');
}

return s;
};
32 changes: 1 addition & 31 deletions tasks/test_syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,13 @@ function assertJasmineSuites() {

/*
* tests about the contents of source (and lib) files:
* - check that we don't have any features that break in IE
* - check that we don't use getComputedStyle unexpectedly
* - check that require statements use lowercase (to match assertFileNames)
* or match the case of the source file
*/
function assertSrcContents() {
var logs = [];

// These are forbidden in IE *only in SVG* but since
// that's 99% of what we do here, we'll forbid them entirely
// until there's some HTML use case where we need them.
// (not sure what we'd do then, but we'd think of something!)
var IE_SVG_BLACK_LIST = ['innerHTML', 'parentElement', 'children'];

// Forbidden in IE in any context
var IE_BLACK_LIST = ['classList'];

// require'd built-in modules
var BUILTINS = ['events'];

Expand All @@ -122,28 +112,8 @@ function assertSrcContents() {
// look for .classList
if(node.type === 'MemberExpression') {
var source = node.source();
var parts = source.split('.');
var lastPart = parts[parts.length - 1];

if(source === 'Math.sign') {
logs.push(file + ' : contains Math.sign (IE failure)');
} else if(source === 'window.getComputedStyle') {
if(source === 'window.getComputedStyle') {
getComputedStyleCnt++;
} else if(IE_BLACK_LIST.indexOf(lastPart) !== -1) {
logs.push(file + ' : contains .' + lastPart + ' (IE failure)');
} else if(IE_SVG_BLACK_LIST.indexOf(lastPart) !== -1) {
// add special case for sunburst, icicle and treemap where we use 'children'
// off the d3-hierarchy output
var dirParts = path.dirname(file).split(path.sep);
var filename = dirParts[dirParts.length - 1];
var isSunburstOrIcicleOrTreemap =
filename === 'sunburst' ||
filename === 'icicle' ||
filename === 'treemap';
var isLinkedToObject = ['pt', 'd', 'parent', 'node'].indexOf(parts[parts.length - 2]) !== -1;
if(!(isSunburstOrIcicleOrTreemap && isLinkedToObject)) {
logs.push(file + ' : contains .' + lastPart + ' (IE failure in SVG)');
}
}
} else if(node.type === 'Identifier' && node.source() === 'getComputedStyle') {
if(node.parent.source() !== 'window.getComputedStyle') {
Expand Down
34 changes: 0 additions & 34 deletions test/jasmine/assets/unpolyfill.js

This file was deleted.

2 changes: 0 additions & 2 deletions test/jasmine/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ if(isFullSuite) {
}

var pathToCustomMatchers = path.join(__dirname, 'assets', 'custom_matchers.js');
var pathToUnpolyfill = path.join(__dirname, 'assets', 'unpolyfill.js');
var pathToSaneTopojsonDist = path.join(__dirname, '..', '..', 'node_modules', 'sane-topojson', 'dist');
var pathToMathJax2 = path.join(__dirname, '..', '..', 'node_modules', 'mathjax-v2');
var pathToMathJax3 = path.join(__dirname, '..', '..', 'node_modules', 'mathjax-v3');
Expand Down Expand Up @@ -189,7 +188,6 @@ func.defaultConfig = {
// N.B. the rest of this field is filled below
files: [
pathToCustomMatchers,
pathToUnpolyfill,
// available to fetch from /base/node_modules/mathjax-v2/
// more info: http://karma-runner.github.io/3.0/config/files.html
{pattern: pathToMathJax2 + '/**', included: false, watched: false, served: true},
Expand Down
48 changes: 0 additions & 48 deletions test/jasmine/tests/download_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,54 +86,6 @@ describe('Plotly.downloadImage', function() {
})
.then(done, done.fail);
}, LONG_TIMEOUT_INTERVAL);

it('should produce the right SVG output in IE', function(done) {
// mock up IE behavior
spyOn(Lib, 'isIE').and.callFake(function() { return true; });
spyOn(slzProto, 'serializeToString').and.callFake(function() {
return serializeToString.apply(this, arguments)
.replace(/(\(#)([^")]*)(\))/gi, '(\"#$2\")');
});
var savedBlob;
window.navigator.msSaveBlob = function(blob) { savedBlob = blob; };

var expectedStart = '<svg class=\'main-svg\' xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\'';
var plotClip = /clip-path='url\("#clip[0-9a-f]{6}xyplot"\)/;
var legendClip = /clip-path=\'url\("#legend[0-9a-f]{6}"\)/;

Plotly.newPlot(gd, textchartMock.data, textchartMock.layout)
.then(function(gd) {
savedBlob = undefined;
return Plotly.downloadImage(gd, {
format: 'svg',
height: 300,
width: 300,
filename: 'plotly_download'
});
})
.then(function() {
if(savedBlob === undefined) {
fail('undefined saveBlob');
}

return new Promise(function(resolve, reject) {
var reader = new FileReader();
reader.onloadend = function() {
var res = reader.result;

expect(res.substr(0, expectedStart.length)).toBe(expectedStart);
expect(res.match(plotClip)).not.toBe(null);
expect(res.match(legendClip)).not.toBe(null);

resolve();
};
reader.onerror = function(e) { reject(e); };

reader.readAsText(savedBlob);
});
})
.then(done, done.fail);
}, LONG_TIMEOUT_INTERVAL);
});

function downloadTest(gd, format) {
Expand Down
4 changes: 1 addition & 3 deletions test/jasmine/tests/lib_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1853,9 +1853,7 @@ describe('Test lib.js:', function() {
-Number.MAX_VALUE, -Number.MIN_VALUE
];

if(!Lib.isIE()) {
vals.push(Number.EPSILON, -Number.EPSILON);
}
vals.push(Number.EPSILON, -Number.EPSILON);

vals.forEach(function(v) {
expect(Lib.cleanNumber(v)).toBe(v);
Expand Down
22 changes: 0 additions & 22 deletions test/jasmine/tests/svg_text_utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,28 +349,6 @@ describe('svg+text utils', function() {
expect(i).toBe(355);
});

it('decodes arbitrary decimal and hex number entities (IE case)', function() {
// IE does not have String.fromCodePoint
String.fromCodePoint = undefined;
expect(String.fromCodePoint).toBeUndefined();

var i = 0;
for(var n = 33; n < 0x10FFFF; n = Math.round(n * 1.03)) {
var node = mockTextSVGElement(
'&#x' + n.toString(16) +
'; = &#' + n.toString() +
'; = &#x' + n.toString(16).toUpperCase() + ';'
);
var char = stringFromCodePoint(n);
expect(node.text()).toBe(char + ' = ' + char + ' = ' + char, n);
i++;
}
// not really necessary to assert this, but we tested 355 characters,
// weighted toward the low end but continuing all the way to the
// end of the unicode definition
expect(i).toBe(355);
});

it('does not decode entities prematurely', function() {
var testCases = [
'&lt;b>not bold</b&gt;',
Expand Down