Skip to content

Commit b039346

Browse files
committed
Revert "Merge pull request #764 from nielsenb-jf/fix_child_window"
This reverts commit 85c2e20, reversing changes made to 48eec0c.
1 parent 86a77cd commit b039346

File tree

17 files changed

+76
-288
lines changed

17 files changed

+76
-288
lines changed

build/plotcss.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var Plotly = require('../src/plotly');
34
var rules = {
45
"X,X div": "font-family:'Open Sans', verdana, arial, sans-serif;margin:0;padding:0;",
56
"X input,X button": "font-family:'Open Sans', verdana, arial, sans-serif;",
@@ -53,4 +54,9 @@ var rules = {
5354
"Y .notifier-close:hover": "color:#444;text-decoration:none;cursor:pointer;"
5455
};
5556

56-
module.exports = rules;
57+
for(var selector in rules) {
58+
var fullSelector = selector.replace(/^,/,' ,')
59+
.replace(/X/g, '.js-plotly-plot .plotly')
60+
.replace(/Y/g, '.plotly-notifier');
61+
Plotly.Lib.addStyleRule(fullSelector, rules[selector]);
62+
}

src/components/dragelement/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ dragElement.init = function init(options) {
8686

8787
if(options.prepFn) options.prepFn(e, startX, startY);
8888

89-
dragCover = coverSlip(gd);
89+
dragCover = coverSlip();
9090

9191
dragCover.onmousemove = onMove;
9292
dragCover.onmouseup = onDone;
@@ -139,7 +139,7 @@ dragElement.init = function init(options) {
139139
if(options.doneFn) options.doneFn(gd._dragged, numClicks);
140140

141141
if(!gd._dragged) {
142-
var e2 = gd._document.createEvent('MouseEvents');
142+
var e2 = document.createEvent('MouseEvents');
143143
e2.initEvent('click', true, true);
144144
initialTarget.dispatchEvent(e2);
145145
}
@@ -159,8 +159,8 @@ dragElement.init = function init(options) {
159159
options.element.style.pointerEvents = 'all';
160160
};
161161

162-
function coverSlip(gd) {
163-
var cover = gd._document.createElement('div');
162+
function coverSlip() {
163+
var cover = document.createElement('div');
164164

165165
cover.className = 'dragcover';
166166
var cStyle = cover.style;
@@ -172,7 +172,7 @@ function coverSlip(gd) {
172172
cStyle.zIndex = 999999999;
173173
cStyle.background = 'none';
174174

175-
gd._document.body.appendChild(cover);
175+
document.body.appendChild(cover);
176176

177177
return cover;
178178
}

src/components/modebar/buttons.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ modeBarButtons.toImage = {
5050
click: function(gd) {
5151
var format = 'png';
5252

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

5555
if(Lib.isIE()) {
56-
Lib.notifier(gd, 'IE only supports svg. Changing format to svg.', 'long');
56+
Lib.notifier('IE only supports svg. Changing format to svg.', 'long');
5757
format = 'svg';
5858
}
5959

6060
downloadImage(gd, {'format': format})
6161
.then(function(filename) {
62-
Lib.notifier(gd, 'Snapshot succeeded - ' + filename, 'long');
62+
Lib.notifier('Snapshot succeeded - ' + filename, 'long');
6363
})
6464
.catch(function() {
65-
Lib.notifier(gd, 'Sorry there was a problem downloading your snapshot!', 'long');
65+
Lib.notifier('Sorry there was a problem downloading your snapshot!', 'long');
6666
});
6767
}
6868
};

src/components/rangeslider/create_slider.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = function createSlider(gd) {
3333
var minStart = 0,
3434
maxStart = width;
3535

36-
var slider = gd._document.createElementNS(svgNS, 'g');
36+
var slider = document.createElementNS(svgNS, 'g');
3737
helpers.setAttributes(slider, {
3838
'class': 'range-slider',
3939
'data-min': minStart,
@@ -43,7 +43,7 @@ module.exports = function createSlider(gd) {
4343
});
4444

4545

46-
var sliderBg = gd._document.createElementNS(svgNS, 'rect'),
46+
var sliderBg = document.createElementNS(svgNS, 'rect'),
4747
borderCorrect = options.borderwidth % 2 === 0 ? options.borderwidth : options.borderwidth - 1;
4848
helpers.setAttributes(sliderBg, {
4949
'fill': options.bgcolor,
@@ -56,7 +56,7 @@ module.exports = function createSlider(gd) {
5656
});
5757

5858

59-
var maskMin = gd._document.createElementNS(svgNS, 'rect');
59+
var maskMin = document.createElementNS(svgNS, 'rect');
6060
helpers.setAttributes(maskMin, {
6161
'x': 0,
6262
'width': minStart,
@@ -65,7 +65,7 @@ module.exports = function createSlider(gd) {
6565
});
6666

6767

68-
var maskMax = gd._document.createElementNS(svgNS, 'rect');
68+
var maskMax = document.createElementNS(svgNS, 'rect');
6969
helpers.setAttributes(maskMax, {
7070
'x': maxStart,
7171
'width': width - maxStart,
@@ -74,9 +74,9 @@ module.exports = function createSlider(gd) {
7474
});
7575

7676

77-
var grabberMin = gd._document.createElementNS(svgNS, 'g'),
78-
grabAreaMin = gd._document.createElementNS(svgNS, 'rect'),
79-
handleMin = gd._document.createElementNS(svgNS, 'rect');
77+
var grabberMin = document.createElementNS(svgNS, 'g'),
78+
grabAreaMin = document.createElementNS(svgNS, 'rect'),
79+
handleMin = document.createElementNS(svgNS, 'rect');
8080
helpers.setAttributes(grabberMin, { 'transform': 'translate(' + (minStart - handleWidth - 1) + ')' });
8181
helpers.setAttributes(grabAreaMin, {
8282
'width': 10,
@@ -97,9 +97,9 @@ module.exports = function createSlider(gd) {
9797
helpers.appendChildren(grabberMin, [handleMin, grabAreaMin]);
9898

9999

100-
var grabberMax = gd._document.createElementNS(svgNS, 'g'),
101-
grabAreaMax = gd._document.createElementNS(svgNS, 'rect'),
102-
handleMax = gd._document.createElementNS(svgNS, 'rect');
100+
var grabberMax = document.createElementNS(svgNS, 'g'),
101+
grabAreaMax = document.createElementNS(svgNS, 'rect'),
102+
handleMax = document.createElementNS(svgNS, 'rect');
103103
helpers.setAttributes(grabberMax, { 'transform': 'translate(' + maxStart + ')' });
104104
helpers.setAttributes(grabAreaMax, {
105105
'width': 10,
@@ -120,7 +120,7 @@ module.exports = function createSlider(gd) {
120120
helpers.appendChildren(grabberMax, [handleMax, grabAreaMax]);
121121

122122

123-
var slideBox = gd._document.createElementNS(svgNS, 'rect');
123+
var slideBox = document.createElementNS(svgNS, 'rect');
124124
helpers.setAttributes(slideBox, {
125125
'x': minStart,
126126
'width': maxStart - minStart,
@@ -137,8 +137,8 @@ module.exports = function createSlider(gd) {
137137
minVal = slider.getAttribute('data-min'),
138138
maxVal = slider.getAttribute('data-max');
139139

140-
gd._document.defaultView.addEventListener('mousemove', mouseMove);
141-
gd._document.defaultView.addEventListener('mouseup', mouseUp);
140+
window.addEventListener('mousemove', mouseMove);
141+
window.addEventListener('mouseup', mouseUp);
142142

143143
function mouseMove(e) {
144144
var delta = +e.clientX - startX,
@@ -189,8 +189,8 @@ module.exports = function createSlider(gd) {
189189
}
190190

191191
function mouseUp() {
192-
gd._document.defaultView.removeEventListener('mousemove', mouseMove);
193-
gd._document.defaultView.removeEventListener('mouseup', mouseUp);
192+
window.removeEventListener('mousemove', mouseMove);
193+
window.removeEventListener('mouseup', mouseUp);
194194
slider.style.cursor = 'auto';
195195
}
196196
});
@@ -222,8 +222,8 @@ module.exports = function createSlider(gd) {
222222

223223
function setDataRange(dataMin, dataMax) {
224224

225-
if(gd._document.defaultView.requestAnimationFrame) {
226-
gd._document.defaultView.requestAnimationFrame(function() {
225+
if(window.requestAnimationFrame) {
226+
window.requestAnimationFrame(function() {
227227
Plotly.relayout(gd, 'xaxis.range', [dataMin, dataMax]);
228228
});
229229
} else {

src/lib/index.js

+24-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ lib.log = loggersModule.log;
6565
lib.warn = loggersModule.warn;
6666
lib.error = loggersModule.error;
6767

68-
var cssModule = require('./plotcss_utils');
69-
lib.injectStyles = cssModule.injectStyles;
70-
7168
lib.notifier = require('./notifier');
7269

7370
/**
@@ -392,6 +389,30 @@ lib.removeElement = function(el) {
392389
if(elParent) elParent.removeChild(el);
393390
};
394391

392+
/**
393+
* for dynamically adding style rules
394+
* makes one stylesheet that contains all rules added
395+
* by all calls to this function
396+
*/
397+
lib.addStyleRule = function(selector, styleString) {
398+
if(!lib.styleSheet) {
399+
var style = document.createElement('style');
400+
// WebKit hack :(
401+
style.appendChild(document.createTextNode(''));
402+
document.head.appendChild(style);
403+
lib.styleSheet = style.sheet;
404+
}
405+
var styleSheet = lib.styleSheet;
406+
407+
if(styleSheet.insertRule) {
408+
styleSheet.insertRule(selector + '{' + styleString + '}', 0);
409+
}
410+
else if(styleSheet.addRule) {
411+
styleSheet.addRule(selector, styleString, 0);
412+
}
413+
else lib.warn('addStyleRule failed');
414+
};
415+
395416
lib.getTranslate = function(element) {
396417

397418
var re = /.*\btranslate\((\d*\.?\d*)[^\d]*(\d*\.?\d*)[^\d].*/,

src/lib/notifier.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ var NOTEDATA = [];
1616

1717
/**
1818
* notifier
19-
* @param {object} gd figure Object
2019
* @param {String} text The person's user name
2120
* @param {Number} [delay=1000] The delay time in milliseconds
2221
* or 'long' which provides 2000 ms delay time.
2322
* @return {undefined} this function does not return a value
2423
*/
25-
module.exports = function(gd, text, displayLength) {
24+
module.exports = function(text, displayLength) {
2625
if(NOTEDATA.indexOf(text) !== -1) return;
2726

2827
NOTEDATA.push(text);
@@ -31,7 +30,7 @@ module.exports = function(gd, text, displayLength) {
3130
if(isNumeric(displayLength)) ts = displayLength;
3231
else if(displayLength === 'long') ts = 3000;
3332

34-
var notifierContainer = d3.select(gd._document.body)
33+
var notifierContainer = d3.select('body')
3534
.selectAll('.plotly-notifier')
3635
.data([0]);
3736
notifierContainer.enter()

src/lib/plotcss_utils.js

-81
This file was deleted.

src/plot_api/plot_api.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ Plotly.plot = function(gd, data, layout, config) {
5555

5656
gd = getGraphDiv(gd);
5757

58-
// Get the document the graph div lives in, so we can make sure things like
59-
// drag covers are attached to the correct document
60-
gd._document = gd.ownerDocument || window.document;
61-
62-
// Inject the plot styles into the document where we're plotting, bails if
63-
// already styled
64-
Lib.injectStyles(gd);
65-
6658
// Events.init is idempotent and bails early if gd has already been init'd
6759
Events.init(gd);
6860

@@ -2575,12 +2567,12 @@ function plotAutoSize(gd, aobj) {
25752567
// embedded in an iframe - just take the full iframe size
25762568
// if we get to this point, with no aspect ratio restrictions
25772569
if(gd._context.fillFrame) {
2578-
newWidth = gd._document.defaultView.innerWidth;
2579-
newHeight = gd._document.defaultView.innerHeight;
2570+
newWidth = window.innerWidth;
2571+
newHeight = window.innerHeight;
25802572

25812573
// somehow we get a few extra px height sometimes...
25822574
// just hide it
2583-
gd._document.body.style.overflow = 'hidden';
2575+
document.body.style.overflow = 'hidden';
25842576
}
25852577
else if(isNumeric(context.frameMargins) && context.frameMargins > 0) {
25862578
var reservedMargins = calculateReservedMargins(gd._boundingBoxMargins),
@@ -2597,7 +2589,7 @@ function plotAutoSize(gd, aobj) {
25972589
// provide height and width for the container div,
25982590
// specify size in layout, or take the defaults,
25992591
// but don't enforce any ratio restrictions
2600-
computedStyle = gd._document.defaultView.getComputedStyle(gd);
2592+
computedStyle = window.getComputedStyle(gd);
26012593
newHeight = parseFloat(computedStyle.height) || fullLayout.height;
26022594
newWidth = parseFloat(computedStyle.width) || fullLayout.width;
26032595
}

src/plotly.js

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ var Lib = exports.Lib = require('./lib');
2626
exports.util = require('./lib/svg_text_utils');
2727
exports.Queue = require('./lib/queue');
2828

29+
// plot css
30+
require('../build/plotcss');
31+
2932
// configuration
3033
exports.MathJaxConfig = require('./fonts/mathjax_config');
3134
exports.defaultConfig = require('./plot_api/plot_config');

src/plots/cartesian/dragbox.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
305305
dragTail(zoomMode);
306306

307307
if(SHOWZOOMOUTTIP && gd.data && gd._context.showTips) {
308-
Lib.notifier(gd, 'Double-click to<br>zoom back out', 'long');
308+
Lib.notifier('Double-click to<br>zoom back out', 'long');
309309
SHOWZOOMOUTTIP = false;
310310
}
311311
}

src/plots/cartesian/set_convert.js

-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ module.exports = function setConvert(ax) {
114114

115115
if(!isFinite(ax._m) || !isFinite(ax._b)) {
116116
Lib.notifier(
117-
ax._gd,
118117
'Something went wrong with axis scaling',
119118
'long');
120119
ax._gd._replotting = false;

0 commit comments

Comments
 (0)