Skip to content

Commit 565cbfc

Browse files
return jquery event handler return value even when no node events present
1 parent e027310 commit 565cbfc

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

shelly/plotlyjs/static/plotlyjs/src/events.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ var Events = {
7373
* Now run all the node style event handlers
7474
*/
7575
var ev = plotObj._ev;
76-
if (!ev) return;
76+
if (!ev) return jQueryHandlerValue;
7777

7878
var handlers = ev._events[event];
79-
if (!handlers) return;
79+
if (!handlers) return jQueryHandlerValue;
8080

8181
/*
8282
* handlers can be function or an array of functions

shelly/plotlyjs/static/plotlyjs/tests/events_test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,59 @@ describe('Events', function () {
100100
expect(result).toBe('pong');
101101
});
102102

103+
it('triggers jQuery handlers when no node events initialized', function() {
104+
var eventBaton = 0;
105+
106+
Events.init(plotDiv);
107+
108+
$(plotDiv).bind('ping', function() {
109+
eventBaton++;
110+
return 'ping';
111+
});
112+
113+
/*
114+
* This will not be called
115+
*/
116+
plotDiv.on('pong', function() {
117+
eventBaton++;
118+
return 'ping';
119+
});
120+
121+
$(plotDiv).bind('ping', function() {
122+
eventBaton++;
123+
return 'pong';
124+
});
125+
126+
var result = Events.triggerHandler(plotDiv, 'ping');
127+
128+
expect(eventBaton).toBe(2);
129+
expect(result).toBe('pong');
130+
});
131+
132+
it('triggers jQuery handlers when no matching node events bound', function() {
133+
var eventBaton = 0;
134+
135+
$(plotDiv).bind('ping', function() {
136+
eventBaton++;
137+
return 'ping';
138+
});
139+
140+
$(plotDiv).bind('ping', function() {
141+
eventBaton++;
142+
return 'ping';
143+
});
144+
145+
$(plotDiv).bind('ping', function() {
146+
eventBaton++;
147+
return 'pong';
148+
});
149+
150+
var result = Events.triggerHandler(plotDiv, 'ping');
151+
152+
expect(eventBaton).toBe(3);
153+
expect(result).toBe('pong');
154+
});
155+
103156

104157
it('triggers jQuery + nodejs handlers and returns last jQuery value', function() {
105158
var eventBaton = 0;

0 commit comments

Comments
 (0)