/*!
- * OOjs UI v0.1.0-pre (989950a4db)
+ * OOjs UI v0.1.0-pre (d4baf57069)
* https://www.mediawiki.org/wiki/OOjs_UI
*
* Copyright 2011–2014 OOjs Team and other contributors.
* Released under the MIT license
* http://oojs.mit-license.org
*
- * Date: Fri Apr 18 2014 13:02:46 GMT-0700 (PDT)
+ * Date: Mon Apr 21 2014 12:42:04 GMT-0700 (PDT)
*/
( function ( OO ) {
/**
* Get closest scrollable container.
- *
- * @see #static-method-getClosestScrollableContainer
*/
OO.ui.Element.prototype.getClosestScrollableElementContainer = function () {
return OO.ui.Element.getClosestScrollableContainer( this.$element[0] );
/**
* Scroll element into view.
*
- * @see #static-method-scrollIntoView
* @param {Object} [config={}]
*/
OO.ui.Element.prototype.scrollElementIntoView = function ( config ) {
/**
* Bind a handler for an event on this.$element
- * @see #static-method-onDOMEvent
+ *
* @param {string} event
* @param {Function} callback
*/
/**
* Unbind a handler bound with #offDOMEvent
- * @see #static-method-offDOMEvent
+ *
* @param {string} event
* @param {Function} callback
*/
* @constructor
* @param {jQuery} $group Container node, assigned to #$group
* @param {Object} [config] Configuration options
+ * @cfg {Object.<string,string>} [aggregations] Events to aggregate, keyed by item event name
*/
OO.ui.GroupElement = function OoUiGroupElement( $group, config ) {
// Configuration
this.$group = $group;
this.items = [];
this.$items = this.$( [] );
- this.aggregateItemEvents = {};
+ this.aggregate = !$.isEmptyObject( config.aggregations );
+ this.aggregations = config.aggregations || {};
};
/* Methods */
return this.items.slice( 0 );
};
-/**
- * Add an aggregate item event.
- *
- * Aggregated events are listened to on each item and then emitted by the group under a new name,
- * and with an additional leading parameter containing the item that emitted the original event.
- * Other arguments that were emitted from the original event are passed through.
- *
- * @param {Object.<string,string|null>} events Aggregate events emitted by group, keyed by item
- * event, use null value to remove aggregation
- * @throws {Error} If aggregation already exists
- */
-OO.ui.GroupElement.prototype.aggregate = function ( events ) {
- var i, len, item, add, remove, itemEvent, groupEvent;
-
- for ( itemEvent in events ) {
- groupEvent = events[itemEvent];
-
- // Remove existing aggregated event
- if ( itemEvent in this.aggregateItemEvents ) {
- // Don't allow duplicate aggregations
- if ( groupEvent ) {
- throw new Error( 'Duplicate item event aggregation for ' + itemEvent );
- }
- // Remove event aggregation from existing items
- remove = {};
- remove[itemEvent] = this.aggregateItemEvents[itemEvent];
- for ( i = 0, len = this.items.length; i < len; i++ ) {
- this.items[i].disconnect( this, remove );
- }
- // Prevent future items from aggregating event
- delete this.aggregateItemEvents[itemEvent];
- }
-
- // Add new aggregate event
- if ( groupEvent ) {
- // Make future items aggregate event
- this.aggregateItemEvents[itemEvent] = groupEvent;
- // Add event aggregation to existing items
- for ( i = 0, len = this.items.length; i < len; i++ ) {
- item = this.items[i];
- add = {};
- add[itemEvent] = [ 'emit', groupEvent, item ];
- item.connect( this, add );
- }
- }
- }
-};
-
/**
* Add items.
*
}
}
// Add the item
- if ( !$.isEmptyObject( this.aggregateItemEvents ) ) {
+ if ( this.aggregate ) {
events = {};
- for ( event in this.aggregateItemEvents ) {
- events[event] = [ 'emit', this.aggregateItemEvents[event], item ];
+ for ( event in this.aggregations ) {
+ events[event] = [ 'emit', this.aggregations[event], item ];
}
item.connect( this, events );
}
item = items[i];
index = $.inArray( item, this.items );
if ( index !== -1 ) {
- if ( !$.isEmptyObject( this.aggregateItemEvents ) ) {
+ if ( this.aggregate ) {
item.disconnect( this );
}
item.setElementGroup( null );
// Remove all items
for ( i = 0, len = this.items.length; i < len; i++ ) {
item = this.items[i];
- if ( !$.isEmptyObject( this.aggregateItemEvents ) ) {
+ if ( this.aggregate ) {
item.disconnect( this );
}
item.setElementGroup( null );