Skip to content

Commit 8c828e7

Browse files
committed
Correct event namespace filtering
1 parent b711780 commit 8c828e7

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

inst/www/shared/shiny.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,11 +3309,23 @@
33093309
sendOutputHiddenStateDebouncer.immediateCall();
33103310
});
33113311

3312+
// Given a namespace and a handler function, return a function that invokes
3313+
// the handler only when e's namespace matches. For example, if the
3314+
// namespace is "bs", it would match when e.namespace is "bs" or "bs.tab".
3315+
// If the namespace is "bs.tab", it would match for "bs.tab", but not "bs".
33123316
function filterEventsByNamespace(namespace, handler) {
3317+
namespace = namespace.split(".");
3318+
33133319
return function(e) {
3314-
if (e.namespace.indexOf(namespace) === 0) {
3315-
handler.apply(this, arguments);
3320+
var eventNamespace = e.namespace.split(".");
3321+
3322+
// If any of the namespace strings aren't present in this event, quit.
3323+
for (var i=0; i<namespace.length; i++) {
3324+
if (eventNamespace.indexOf(namespace[i]) === -1)
3325+
return;
33163326
}
3327+
3328+
handler.apply(this, arguments);
33173329
};
33183330
}
33193331

@@ -3326,10 +3338,10 @@
33263338
var bs3classes = ['modal', 'dropdown', 'tab', 'tooltip', 'popover', 'collapse'];
33273339
$.each(bs3classes, function(idx, classname) {
33283340
$('body').on('shown.bs.' + classname + '.sendImageSize', '*',
3329-
filterEventsByNamespace('bs.', sendImageSize));
3341+
filterEventsByNamespace('bs', sendImageSize));
33303342
$('body').on('shown.bs.' + classname + '.sendOutputHiddenState ' +
33313343
'hidden.bs.' + classname + '.sendOutputHiddenState',
3332-
'*', filterEventsByNamespace('bs.', sendOutputHiddenState));
3344+
'*', filterEventsByNamespace('bs', sendOutputHiddenState));
33333345
});
33343346

33353347
// This is needed for Bootstrap 2 compatibility and for non-Bootstrap

0 commit comments

Comments
 (0)