./helpers/add-jquery-events
Add jQuery’s special events to the global registry.
addJQueryEvents(jQuery)
Parameters
- jQuery
{jQuery}
:Your instance of jQuery.
Returns
{function}
:
The callback to remove the jQuery events from the registry.
const $ = require("jquery");
const addJQueryEvents = require("can-dom-events/helpers/add-jquery-events");
const domEvents = require("can-dom-events");
// Require another module that registers itself with jQuery.event.special,
// e.g. jQuery++ registers events such as draginit, dragmove, etc.
const removeJQueryEvents = addJQueryEvents($);
// Listen for an event in code; this might also be accomplished through a
// can-stache-binding such as <li on:draginit="listener()">
domEvents.addEventListener(listItemElement, "draginit", function listener() {
// Will fire after a jQuery draginit event has been fired
});
// Some other code that fires a jQuery event; this will probably be in the
// package you’re using…
$(listItemElement).trigger("draginit");
// Later in your code… ready to stop listening for those jQuery events? Call
// the function returned by addJQueryEvents()
removeJQueryEvents();