• Jump To … +
    breakpoints.js date-parse.js jquery.breakpoints.js jquery.calcRestrainedPos.js jquery.clientRect.js jquery.contentSize.js jquery.cookies.js jquery.css.js jquery.customEvent.js jquery.delimitedString.js jquery.disableEvent.js jquery.hostIframe.js jquery.hoverDelay.js jquery.htmlEncode.js jquery.imageSize.js jquery.isVisibleKeyCode.js jquery.menu.js jquery-menu-exampleskin.js jquery.modalDialog.deviceFixes.js jquery.modalDialog.getSettings.js jquery.modalDialog.header.js jquery.modalDialog.history.js jquery.modalDialog.js jquery.modalDialog.unobtrusive.js jquery.modalDialog.userAgent.js jquery.modalDialogContent.header.js jquery.modalDialogContent.js jquery.msAjax.js jquery.ns.js jquery.partialLoad.js jquery.postMessage.js jquery.proxyAll.js jquery.queryString.js jquery.richTooltip.js jquery.scrollAnchor.js jquery.uncomment.js jquery.url.js pointy.gestures.js pointy.js
  • jquery.customEvent.js

  • ¶
    (function ($) {
  • ¶

    Utility class to manage multiple callbacks.

  • ¶
    • {object} host: The object owning the event
    • {string} eventType: The event type (i.e. “close”, open”)
        $.CustomEvent = function (host, eventType) {
            this._host = host;
            this.eventType = eventType;
            this._callbacks = new $.Callbacks();
        };
  • ¶

    Triggers the event, and returns a jQuery.Event object.

  • ¶
    • {object} data: Any data that should appended to the event object
    • {object} host: Defines “this” in handlers. If not specified, the default host object is used.
        $.CustomEvent.prototype.fire = function (data, host) {
            var evt = new $.Event(this.eventType);
            $.extend(evt, data);
            evt.data = $.extend({}, evt.data, data);
    
            this._callbacks.fireWith(host || this._host, [evt]);
    
            return evt;
        };
  • ¶

    Assigns an event handler

  • ¶
    • {Function} callback: The event handler
        $.CustomEvent.prototype.add = function (callback) {
            if (callback) {
                this._callbacks.add(callback);
            }
        };
  • ¶
    • {Function} callback: The event handler
        $.CustomEvent.prototype.one = function (callback) {
            if (!callback) {
                return;
            }
    
            var me = this;
    
            var wrapper = $.proxy(function () {
                try {
                    callback.apply(this, arguments);
                } finally {
                    me.remove(wrapper);
                }
    
            }, this);
    
            this.add(wrapper);
        };
  • ¶

    Assigns an event handler

    • {Function} callback: The event handler
        $.CustomEvent.prototype.remove = function (callback) {
            if (callback) {
                this._callbacks.remove(callback);
            }
        };
  • ¶

    Removes all event handlers

        $.CustomEvent.prototype.empty = function () {
            this._callbacks.empty();
        };
  • ¶

    Utility for adding an event to an object more tersely

  • ¶
    • {object} host: The object owning the event
    • {string} eventType: The event type (i.e. “close”, open”)
        $.CustomEvent.create = function (host, eventType) {
            var onEventType = "on" + eventType;
            var evt = new $.CustomEvent(host, eventType);
            host[onEventType] = evt;
            return evt;
        };
    
    })(jQuery);