Skip to content

Commit 71bc4ee

Browse files
authored
Merge pull request #7224 from plotly/drop-jquery-support
Drop jQuery support
2 parents 7916edf + 3931ac3 commit 71bc4ee

File tree

5 files changed

+5
-243
lines changed

5 files changed

+5
-243
lines changed

draftlogs/7224_remove.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Drop jQuery events support [[#7224](https://github.com/plotly/plotly.js/pull/7224)]

src/lib/events.js

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

3-
/* global jQuery:false */
4-
53
var EventEmitter = require('events').EventEmitter;
64

75
var Events = {
@@ -56,17 +54,7 @@ var Events = {
5654
plotObj._removeInternalListener = internalEv.removeListener.bind(internalEv);
5755
plotObj._removeAllInternalListeners = internalEv.removeAllListeners.bind(internalEv);
5856

59-
/*
60-
* We must wrap emit to continue to support JQuery events. The idea
61-
* is to check to see if the user is using JQuery events, if they are
62-
* we emit JQuery events to trigger user handlers as well as the EventEmitter
63-
* events.
64-
*/
6557
plotObj.emit = function(event, data) {
66-
if(typeof jQuery !== 'undefined') {
67-
jQuery(plotObj).trigger(event, data);
68-
}
69-
7058
ev.emit(event, data);
7159
internalEv.emit(event, data);
7260
};
@@ -77,29 +65,19 @@ var Events = {
7765
/*
7866
* This function behaves like jQuery's triggerHandler. It calls
7967
* all handlers for a particular event and returns the return value
80-
* of the LAST handler. This function also triggers jQuery's
81-
* triggerHandler for backwards compatibility.
68+
* of the LAST handler.
8269
*/
8370
triggerHandler: function(plotObj, event, data) {
84-
var jQueryHandlerValue;
8571
var nodeEventHandlerValue;
8672

87-
/*
88-
* If jQuery exists run all its handlers for this event and
89-
* collect the return value of the LAST handler function
90-
*/
91-
if(typeof jQuery !== 'undefined') {
92-
jQueryHandlerValue = jQuery(plotObj).triggerHandler(event, data);
93-
}
94-
9573
/*
9674
* Now run all the node style event handlers
9775
*/
9876
var ev = plotObj._ev;
99-
if(!ev) return jQueryHandlerValue;
77+
if(!ev) return;
10078

10179
var handlers = ev._events[event];
102-
if(!handlers) return jQueryHandlerValue;
80+
if(!handlers) return;
10381

10482
// making sure 'this' is the EventEmitter instance
10583
function apply(handler) {
@@ -129,14 +107,7 @@ var Events = {
129107
// now call the final handler and collect its value
130108
nodeEventHandlerValue = apply(handlers[i]);
131109

132-
/*
133-
* Return either the jQuery handler value if it exists or the
134-
* nodeEventHandler value. jQuery event value supersedes nodejs
135-
* events for backwards compatibility reasons.
136-
*/
137-
return jQueryHandlerValue !== undefined ?
138-
jQueryHandlerValue :
139-
nodeEventHandlerValue;
110+
return nodeEventHandlerValue;
140111
},
141112

142113
purge: function(plotObj) {

test/jasmine/assets/jquery-1.8.3.min.js

-2
This file was deleted.

test/jasmine/karma.conf.js

-5
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ if(isFullSuite) {
117117
testFileGlob = path.join(__dirname, 'tests', glob(merge(argv._).map(basename)));
118118
}
119119

120-
var pathToJQuery = path.join(__dirname, 'assets', 'jquery-1.8.3.min.js');
121120
var pathToCustomMatchers = path.join(__dirname, 'assets', 'custom_matchers.js');
122121
var pathToUnpolyfill = path.join(__dirname, 'assets', 'unpolyfill.js');
123122
var pathToSaneTopojsonDist = path.join(__dirname, '..', '..', 'node_modules', 'sane-topojson', 'dist');
@@ -318,10 +317,6 @@ func.defaultConfig = {
318317
func.defaultConfig.preprocessors[pathToCustomMatchers] = ['esbuild'];
319318
func.defaultConfig.preprocessors[testFileGlob] = ['esbuild'];
320319

321-
if(!isBundleTest) {
322-
func.defaultConfig.files.push(pathToJQuery);
323-
}
324-
325320
if(argv.virtualWebgl) {
326321
// add virtual-webgl to the top
327322
func.defaultConfig.files = [

test/jasmine/tests/events_test.js

-203
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
/* global $:false, jQuery:false */
2-
3-
/*
4-
* Note this test requires JQuery in the global scope.
5-
* we should keep it that way to keep testing our backward
6-
* compatibility with JQuery events.
7-
*/
8-
91
var Events = require('../../../src/lib/events');
102

113
describe('Events', function() {
@@ -57,19 +49,6 @@ describe('Events', function() {
5749
});
5850
});
5951

60-
it('triggers jquery events', function(done) {
61-
Events.init(plotDiv);
62-
63-
$(plotDiv).bind('ping', function(event, data) {
64-
expect(data).toBe('pong');
65-
done();
66-
});
67-
68-
setTimeout(function() {
69-
$(plotDiv).trigger('ping', 'pong');
70-
});
71-
});
72-
7352
it('mirrors events on an internal handler', function(done) {
7453
Events.init(plotDiv);
7554

@@ -139,86 +118,6 @@ describe('Events', function() {
139118
expect(result).toBe('pong');
140119
});
141120

142-
it('triggers jQuery handlers when no matching node events bound', function() {
143-
var eventBaton = 0;
144-
145-
Events.init(plotDiv);
146-
147-
$(plotDiv).bind('ping', function() {
148-
eventBaton++;
149-
return 'ping';
150-
});
151-
152-
/*
153-
* This will not be called
154-
*/
155-
plotDiv.on('pong', function() {
156-
eventBaton++;
157-
return 'ping';
158-
});
159-
160-
$(plotDiv).bind('ping', function() {
161-
eventBaton++;
162-
return 'pong';
163-
});
164-
165-
var result = Events.triggerHandler(plotDiv, 'ping');
166-
167-
expect(eventBaton).toBe(2);
168-
expect(result).toBe('pong');
169-
});
170-
171-
it('triggers jQuery handlers when no node events initialized', function() {
172-
var eventBaton = 0;
173-
174-
$(plotDiv).bind('ping', function() {
175-
eventBaton++;
176-
return 'ping';
177-
});
178-
179-
$(plotDiv).bind('ping', function() {
180-
eventBaton++;
181-
return 'ping';
182-
});
183-
184-
$(plotDiv).bind('ping', function() {
185-
eventBaton++;
186-
return 'pong';
187-
});
188-
189-
var result = Events.triggerHandler(plotDiv, 'ping');
190-
191-
expect(eventBaton).toBe(3);
192-
expect(result).toBe('pong');
193-
});
194-
195-
196-
it('triggers jQuery + nodejs handlers and returns last jQuery value', function() {
197-
var eventBaton = 0;
198-
199-
Events.init(plotDiv);
200-
201-
$(plotDiv).bind('ping', function() {
202-
eventBaton++;
203-
return 'ping';
204-
});
205-
206-
plotDiv.on('ping', function() {
207-
eventBaton++;
208-
return 'ping';
209-
});
210-
211-
$(plotDiv).bind('ping', function() {
212-
eventBaton++;
213-
return 'pong';
214-
});
215-
216-
var result = Events.triggerHandler(plotDiv, 'ping');
217-
218-
expect(eventBaton).toBe(3);
219-
expect(result).toBe('pong');
220-
});
221-
222121
it('works with *once* event handlers', function() {
223122
var eventBaton = 0;
224123

@@ -247,106 +146,4 @@ describe('Events', function() {
247146
expect(plotObj).toEqual({});
248147
});
249148
});
250-
251-
describe('when jQuery.noConflict is set, ', function() {
252-
beforeEach(function() {
253-
$.noConflict();
254-
});
255-
256-
afterEach(function() {
257-
window.$ = jQuery;
258-
});
259-
260-
it('triggers jquery events', function(done) {
261-
Events.init(plotDiv);
262-
263-
jQuery(plotDiv).bind('ping', function(event, data) {
264-
expect(data).toBe('pong');
265-
done();
266-
});
267-
268-
setTimeout(function() {
269-
jQuery(plotDiv).trigger('ping', 'pong');
270-
});
271-
});
272-
273-
it('triggers jQuery handlers when no matching node events bound', function() {
274-
var eventBaton = 0;
275-
276-
Events.init(plotDiv);
277-
278-
jQuery(plotDiv).bind('ping', function() {
279-
eventBaton++;
280-
return 'ping';
281-
});
282-
283-
/*
284-
* This will not be called
285-
*/
286-
plotDiv.on('pong', function() {
287-
eventBaton++;
288-
return 'ping';
289-
});
290-
291-
jQuery(plotDiv).bind('ping', function() {
292-
eventBaton++;
293-
return 'pong';
294-
});
295-
296-
var result = Events.triggerHandler(plotDiv, 'ping');
297-
298-
expect(eventBaton).toBe(2);
299-
expect(result).toBe('pong');
300-
});
301-
302-
it('triggers jQuery handlers when no node events initialized', function() {
303-
var eventBaton = 0;
304-
305-
jQuery(plotDiv).bind('ping', function() {
306-
eventBaton++;
307-
return 'ping';
308-
});
309-
310-
jQuery(plotDiv).bind('ping', function() {
311-
eventBaton++;
312-
return 'ping';
313-
});
314-
315-
jQuery(plotDiv).bind('ping', function() {
316-
eventBaton++;
317-
return 'pong';
318-
});
319-
320-
var result = Events.triggerHandler(plotDiv, 'ping');
321-
322-
expect(eventBaton).toBe(3);
323-
expect(result).toBe('pong');
324-
});
325-
326-
it('triggers jQuery + nodejs handlers and returns last jQuery value', function() {
327-
var eventBaton = 0;
328-
329-
Events.init(plotDiv);
330-
331-
jQuery(plotDiv).bind('ping', function() {
332-
eventBaton++;
333-
return 'ping';
334-
});
335-
336-
plotDiv.on('ping', function() {
337-
eventBaton++;
338-
return 'ping';
339-
});
340-
341-
jQuery(plotDiv).bind('ping', function() {
342-
eventBaton++;
343-
return 'pong';
344-
});
345-
346-
var result = Events.triggerHandler(plotDiv, 'ping');
347-
348-
expect(eventBaton).toBe(3);
349-
expect(result).toBe('pong');
350-
});
351-
});
352149
});

0 commit comments

Comments
 (0)