From 873bb38694be953e5cfc28f172cad3561b9c1d51 Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Wed, 19 Aug 2015 13:40:12 -0400 Subject: [PATCH] Export event helpers on videojs object --- src/js/video.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/js/video.js b/src/js/video.js index 22c22daafc..60111ffce3 100644 --- a/src/js/video.js +++ b/src/js/video.js @@ -5,6 +5,7 @@ import document from 'global/document'; import * as setup from './setup'; import Component from './component'; import EventTarget from './event-target'; +import * as Events from './utils/events.js'; import Player from './player'; import plugin from './plugins.js'; import mergeOptions from '../../src/js/utils/merge-options.js'; @@ -428,6 +429,50 @@ videojs.parseUrl = Url.parseUrl; */ videojs.EventTarget = EventTarget; +/** + * Add an event listener to element + * It stores the handler function in a separate cache object + * and adds a generic handler to the element's event, + * along with a unique id (guid) to the element. + * + * @param {Element|Object} elem Element or object to bind listeners to + * @param {String|Array} type Type of event to bind to. + * @param {Function} fn Event listener. + * @method on + */ +videojs.on = Events.on; + +/** + * Trigger a listener only once for an event + * + * @param {Element|Object} elem Element or object to + * @param {String|Array} type Name/type of event + * @param {Function} fn Event handler function + * @method one + */ +videojs.one = Events.one; + +/** + * Removes event listeners from an element + * + * @param {Element|Object} elem Object to remove listeners from + * @param {String|Array=} type Type of listener to remove. Don't include to remove all events from element. + * @param {Function} fn Specific listener to remove. Don't include to remove listeners for an event type. + * @method off + */ +videojs.off = Events.off; + +/** + * Trigger an event for an element + * + * @param {Element|Object} elem Element to trigger an event on + * @param {Event|Object|String} event A string (the type) or an event object with a type attribute + * @param {Object} [hash] data hash to pass along with the event + * @return {Boolean=} Returned only if default was prevented + * @method trigger + */ +videojs.trigger = Events.trigger; + // REMOVING: We probably should add this to the migration plugin // // Expose but deprecate the window[componentName] method for accessing components // Object.getOwnPropertyNames(Component.components).forEach(function(name){