2013-06-06 23:14:11 +00:00
|
|
|
/*!
|
2013-06-25 00:41:01 +00:00
|
|
|
* VisualEditor UserInterface MWMediaSearchWidget class.
|
2013-06-06 23:14:11 +00:00
|
|
|
*
|
2015-01-08 23:54:03 +00:00
|
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
2013-06-06 23:14:11 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-06-25 00:41:01 +00:00
|
|
|
* Creates an ve.ui.MWMediaSearchWidget object.
|
2013-06-06 23:14:11 +00:00
|
|
|
*
|
|
|
|
* @class
|
2013-10-09 20:09:59 +00:00
|
|
|
* @extends OO.ui.SearchWidget
|
2013-06-06 23:14:11 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-06-06 23:14:11 +00:00
|
|
|
* @param {number} [size] Vertical size of thumbnails
|
|
|
|
*/
|
2013-06-25 00:41:01 +00:00
|
|
|
ve.ui.MWMediaSearchWidget = function VeUiMWMediaSearchWidget( config ) {
|
2014-11-21 13:00:50 +00:00
|
|
|
// Configuration initialization
|
2013-09-20 07:09:06 +00:00
|
|
|
config = ve.extendObject( {
|
2014-08-22 20:50:48 +00:00
|
|
|
placeholder: ve.msg( 'visualeditor-media-input-placeholder' )
|
2013-09-20 07:09:06 +00:00
|
|
|
}, config );
|
2013-06-06 23:14:11 +00:00
|
|
|
|
|
|
|
// Parent constructor
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.SearchWidget.call( this, config );
|
2013-06-06 23:14:11 +00:00
|
|
|
|
|
|
|
// Properties
|
2015-02-04 00:32:46 +00:00
|
|
|
this.providers = {};
|
2015-02-02 22:15:52 +00:00
|
|
|
this.searchValue = '';
|
2015-02-04 00:32:46 +00:00
|
|
|
this.resourceQueue = new ve.dm.MWMediaResourceQueue( {
|
|
|
|
limit: 20,
|
2015-02-07 01:35:34 +00:00
|
|
|
threshold: 10
|
2015-02-04 00:32:46 +00:00
|
|
|
} );
|
|
|
|
|
2013-06-25 00:41:01 +00:00
|
|
|
this.queryTimeout = null;
|
2015-02-04 00:32:46 +00:00
|
|
|
this.itemCache = {};
|
2014-09-05 05:21:12 +00:00
|
|
|
this.promises = [];
|
2015-02-04 00:32:46 +00:00
|
|
|
this.lang = config.lang || 'en';
|
|
|
|
this.$panels = config.$panels;
|
|
|
|
|
|
|
|
// Masonry fit properties
|
|
|
|
this.rows = [];
|
|
|
|
this.rowHeight = config.rowHeight || 200;
|
|
|
|
this.queryMediaQueueCallback = this.queryMediaQueue.bind( this );
|
2015-01-16 17:11:13 +00:00
|
|
|
this.layoutQueue = [];
|
2014-09-18 19:49:22 +00:00
|
|
|
this.numItems = 0;
|
2015-04-16 19:14:27 +00:00
|
|
|
this.currentItemCache = [];
|
|
|
|
|
|
|
|
this.resultsSize = {};
|
2014-09-18 19:49:22 +00:00
|
|
|
|
|
|
|
this.selected = null;
|
|
|
|
|
2015-02-04 00:32:46 +00:00
|
|
|
this.noItemsMessage = new OO.ui.LabelWidget( {
|
|
|
|
label: ve.msg( 'visualeditor-dialog-media-noresults' ),
|
|
|
|
classes: [ 've-ui-mwMediaSearchWidget-noresults' ]
|
|
|
|
} );
|
|
|
|
this.noItemsMessage.toggle( false );
|
2014-05-13 06:27:18 +00:00
|
|
|
|
2013-06-06 23:14:11 +00:00
|
|
|
// Events
|
2014-07-08 22:33:32 +00:00
|
|
|
this.$results.on( 'scroll', this.onResultsScroll.bind( this ) );
|
2015-02-04 00:32:46 +00:00
|
|
|
this.$query.append( this.noItemsMessage.$element );
|
2014-09-18 19:49:22 +00:00
|
|
|
this.results.connect( this, {
|
|
|
|
add: 'onResultsAdd',
|
|
|
|
remove: 'onResultsRemove'
|
|
|
|
} );
|
2013-06-06 23:14:11 +00:00
|
|
|
|
2015-04-16 19:14:27 +00:00
|
|
|
this.resizeHandler = ve.debounce( this.afterResultsResize.bind( this ), 500 );
|
|
|
|
|
2013-06-06 23:14:11 +00:00
|
|
|
// Initialization
|
2013-11-01 19:45:59 +00:00
|
|
|
this.$element.addClass( 've-ui-mwMediaSearchWidget' );
|
2013-06-06 23:14:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.inheritClass( ve.ui.MWMediaSearchWidget, OO.ui.SearchWidget );
|
2013-06-06 23:14:11 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2015-04-16 19:14:27 +00:00
|
|
|
/**
|
|
|
|
* Respond to window resize and check if the result display should
|
|
|
|
* be updated.
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaSearchWidget.prototype.afterResultsResize = function () {
|
|
|
|
var items = this.currentItemCache,
|
|
|
|
value = this.query.getValue();
|
|
|
|
|
|
|
|
if (
|
|
|
|
items.length > 0 &&
|
|
|
|
(
|
|
|
|
this.resultsSize.width !== this.$results.width() ||
|
|
|
|
this.resultsSize.height !== this.$results.height()
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
this.resetRows();
|
|
|
|
this.itemCache = {};
|
|
|
|
this.processQueueResults( items, value );
|
|
|
|
if ( this.results.getItems().length > 0 ) {
|
|
|
|
this.lazyLoadResults();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cache the size
|
|
|
|
this.resultsSize = {
|
|
|
|
width: this.$results.width(),
|
|
|
|
height: this.$results.height()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Teardown the widget; disconnect the window resize event.
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaSearchWidget.prototype.teardown = function () {
|
|
|
|
$( window ).off( 'resize', this.resizeHandler );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the widget; activate the resize event.
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaSearchWidget.prototype.setup = function () {
|
|
|
|
$( window ).on( 'resize', this.resizeHandler );
|
|
|
|
};
|
2013-12-16 12:09:54 +00:00
|
|
|
/**
|
2015-02-04 00:32:46 +00:00
|
|
|
* Query all sources for media.
|
|
|
|
*
|
|
|
|
* @method
|
2013-12-16 12:09:54 +00:00
|
|
|
*/
|
2015-02-04 00:32:46 +00:00
|
|
|
ve.ui.MWMediaSearchWidget.prototype.queryMediaQueue = function () {
|
|
|
|
var search = this,
|
|
|
|
value = this.query.getValue();
|
|
|
|
|
|
|
|
if ( value === '' ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.query.pushPending();
|
|
|
|
search.noItemsMessage.toggle( false );
|
|
|
|
|
2015-02-07 01:35:34 +00:00
|
|
|
this.resourceQueue.setParams( { gsrsearch: value } );
|
2015-02-04 00:32:46 +00:00
|
|
|
this.resourceQueue.get( 20 )
|
|
|
|
.then( function ( items ) {
|
|
|
|
if ( items.length > 0 ) {
|
|
|
|
search.processQueueResults( items, value );
|
2015-04-16 19:14:27 +00:00
|
|
|
search.currentItemCache = search.currentItemCache.concat( items );
|
2015-02-04 00:32:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
search.query.popPending();
|
|
|
|
search.noItemsMessage.toggle( search.results.getItems().length === 0 );
|
|
|
|
if ( search.results.getItems().length > 0 ) {
|
|
|
|
search.lazyLoadResults();
|
|
|
|
}
|
|
|
|
|
|
|
|
} );
|
2013-12-16 12:09:54 +00:00
|
|
|
};
|
|
|
|
|
2015-01-15 18:50:30 +00:00
|
|
|
/**
|
2015-02-04 00:32:46 +00:00
|
|
|
* Process the media queue giving more items
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Object[]} items Given items by the media queue
|
2015-01-15 18:50:30 +00:00
|
|
|
*/
|
2015-02-04 00:32:46 +00:00
|
|
|
ve.ui.MWMediaSearchWidget.prototype.processQueueResults = function ( items ) {
|
|
|
|
var i, len, title,
|
|
|
|
resultWidgets = [],
|
2015-02-07 01:35:34 +00:00
|
|
|
inputSearchQuery = this.query.getValue(),
|
|
|
|
queueSearchQuery = this.resourceQueue.getSearchQuery();
|
2015-02-04 00:32:46 +00:00
|
|
|
|
2015-02-07 01:35:34 +00:00
|
|
|
if ( inputSearchQuery === '' || queueSearchQuery !== inputSearchQuery ) {
|
2015-02-04 00:32:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = 0, len = items.length; i < len; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
title = new mw.Title( items[ i ].title ).getMainText();
|
2015-02-04 00:32:46 +00:00
|
|
|
// Do not insert duplicates
|
|
|
|
if ( !Object.prototype.hasOwnProperty.call( this.itemCache, title ) ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
this.itemCache[ title ] = true;
|
2015-02-04 00:32:46 +00:00
|
|
|
resultWidgets.push(
|
|
|
|
new ve.ui.MWMediaResultWidget( {
|
2015-08-19 17:33:02 +00:00
|
|
|
data: items[ i ],
|
2015-02-12 01:07:44 +00:00
|
|
|
rowHeight: this.rowHeight,
|
|
|
|
maxWidth: this.results.$element.width() / 3,
|
|
|
|
minWidth: 30,
|
|
|
|
rowWidth: this.results.$element.width()
|
2015-02-04 00:32:46 +00:00
|
|
|
} )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.results.addItems( resultWidgets );
|
|
|
|
|
2015-01-15 18:50:30 +00:00
|
|
|
};
|
|
|
|
|
2013-06-06 23:14:11 +00:00
|
|
|
/**
|
2015-02-04 00:32:46 +00:00
|
|
|
* Handle search value change
|
2013-06-06 23:14:11 +00:00
|
|
|
*
|
|
|
|
* @param {string} value New value
|
|
|
|
*/
|
2015-02-02 22:15:52 +00:00
|
|
|
ve.ui.MWMediaSearchWidget.prototype.onQueryChange = function ( value ) {
|
2015-11-20 19:48:55 +00:00
|
|
|
var trimmed = value.trim();
|
2015-02-02 22:15:52 +00:00
|
|
|
|
|
|
|
if ( trimmed === this.searchValue ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.searchValue = trimmed;
|
2013-06-06 23:14:11 +00:00
|
|
|
|
2013-06-25 00:41:01 +00:00
|
|
|
// Parent method
|
2015-02-02 22:15:52 +00:00
|
|
|
OO.ui.SearchWidget.prototype.onQueryChange.apply( this, arguments );
|
2013-06-25 00:41:01 +00:00
|
|
|
|
2013-06-06 23:14:11 +00:00
|
|
|
// Reset
|
2015-02-04 00:32:46 +00:00
|
|
|
this.itemCache = {};
|
2015-04-16 19:14:27 +00:00
|
|
|
this.currentItemCache = [];
|
2015-02-04 00:32:46 +00:00
|
|
|
this.resetRows();
|
|
|
|
|
|
|
|
// Empty the results queue
|
|
|
|
this.layoutQueue = [];
|
|
|
|
|
|
|
|
// Change resource queue query
|
2015-02-07 01:35:34 +00:00
|
|
|
this.resourceQueue.setParams( { gsrsearch: this.searchValue } );
|
2013-06-06 23:14:11 +00:00
|
|
|
|
|
|
|
// Queue
|
2013-06-25 00:41:01 +00:00
|
|
|
clearTimeout( this.queryTimeout );
|
2015-02-04 00:32:46 +00:00
|
|
|
this.queryTimeout = setTimeout( this.queryMediaQueueCallback, 350 );
|
2013-06-06 23:14:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle results scroll events.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} e Scroll event
|
|
|
|
*/
|
2013-06-25 00:41:01 +00:00
|
|
|
ve.ui.MWMediaSearchWidget.prototype.onResultsScroll = function () {
|
2013-06-06 23:14:11 +00:00
|
|
|
var position = this.$results.scrollTop() + this.$results.outerHeight(),
|
2015-01-15 18:50:30 +00:00
|
|
|
threshold = this.results.$element.outerHeight() - this.rowHeight * 3;
|
|
|
|
|
|
|
|
// Check if we need to ask for more results
|
2013-06-25 00:41:01 +00:00
|
|
|
if ( !this.query.isPending() && position > threshold ) {
|
2015-02-04 00:32:46 +00:00
|
|
|
this.queryMediaQueue();
|
2013-06-06 23:14:11 +00:00
|
|
|
}
|
2015-01-15 18:50:30 +00:00
|
|
|
|
|
|
|
this.lazyLoadResults();
|
2013-06-06 23:14:11 +00:00
|
|
|
};
|
|
|
|
|
2015-01-15 18:50:30 +00:00
|
|
|
/**
|
|
|
|
* Lazy-load the images that are visible.
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaSearchWidget.prototype.lazyLoadResults = function () {
|
|
|
|
var i, elementTop,
|
|
|
|
items = this.results.getItems(),
|
|
|
|
resultsScrollTop = this.$results.scrollTop(),
|
|
|
|
position = resultsScrollTop + this.$results.outerHeight();
|
2015-02-04 00:32:46 +00:00
|
|
|
|
2015-01-15 18:50:30 +00:00
|
|
|
// Lazy-load results
|
|
|
|
for ( i = 0; i < items.length; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
elementTop = items[ i ].$element.position().top;
|
|
|
|
if ( elementTop <= position && !items[ i ].hasSrc() ) {
|
2015-01-15 18:50:30 +00:00
|
|
|
// Load the image
|
2015-08-19 17:33:02 +00:00
|
|
|
items[ i ].lazyLoad();
|
2015-01-15 18:50:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-09-05 05:21:12 +00:00
|
|
|
|
2014-09-18 19:49:22 +00:00
|
|
|
/**
|
|
|
|
* Reset all the rows; destroy the jQuery elements and reset
|
|
|
|
* the rows array.
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaSearchWidget.prototype.resetRows = function () {
|
|
|
|
var i, len;
|
|
|
|
|
|
|
|
for ( i = 0, len = this.rows.length; i < len; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
this.rows[ i ].$element.remove();
|
2014-09-18 19:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.rows = [];
|
2015-04-16 19:14:27 +00:00
|
|
|
this.itemCache = {};
|
2014-09-18 19:49:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find an available row at the end. Either we will need to create a new
|
|
|
|
* row or use the last available row if it isn't full.
|
2015-02-04 00:32:46 +00:00
|
|
|
*
|
2014-09-18 19:49:22 +00:00
|
|
|
* @return {number} Row index
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaSearchWidget.prototype.getAvailableRow = function () {
|
2015-02-12 01:07:44 +00:00
|
|
|
var row;
|
2014-09-18 19:49:22 +00:00
|
|
|
|
|
|
|
if ( this.rows.length === 0 ) {
|
|
|
|
row = 0;
|
|
|
|
} else {
|
|
|
|
row = this.rows.length - 1;
|
|
|
|
}
|
|
|
|
|
2015-08-19 17:33:02 +00:00
|
|
|
if ( !this.rows[ row ] ) {
|
2014-09-18 19:49:22 +00:00
|
|
|
// Create new row
|
2015-08-19 17:33:02 +00:00
|
|
|
this.rows[ row ] = {
|
2014-09-18 19:49:22 +00:00
|
|
|
isFull: false,
|
|
|
|
width: 0,
|
|
|
|
items: [],
|
2015-04-09 23:47:15 +00:00
|
|
|
$element: $( '<div>' )
|
2014-09-18 19:49:22 +00:00
|
|
|
.addClass( 've-ui-mwMediaResultWidget-row' )
|
|
|
|
.css( {
|
|
|
|
overflow: 'hidden'
|
|
|
|
} )
|
|
|
|
.data( 'row', row )
|
|
|
|
.attr( 'data-full', false )
|
|
|
|
};
|
|
|
|
// Append to results
|
2015-08-19 17:33:02 +00:00
|
|
|
this.results.$element.append( this.rows[ row ].$element );
|
|
|
|
} else if ( this.rows[ row ].isFull ) {
|
2014-09-18 19:49:22 +00:00
|
|
|
row++;
|
|
|
|
// Create new row
|
2015-08-19 17:33:02 +00:00
|
|
|
this.rows[ row ] = {
|
2014-09-18 19:49:22 +00:00
|
|
|
isFull: false,
|
|
|
|
width: 0,
|
|
|
|
items: [],
|
2015-04-09 23:47:15 +00:00
|
|
|
$element: $( '<div>' )
|
2014-09-18 19:49:22 +00:00
|
|
|
.addClass( 've-ui-mwMediaResultWidget-row' )
|
|
|
|
.css( {
|
|
|
|
overflow: 'hidden'
|
|
|
|
} )
|
|
|
|
.data( 'row', row )
|
|
|
|
.attr( 'data-full', false )
|
|
|
|
};
|
|
|
|
// Append to results
|
2015-08-19 17:33:02 +00:00
|
|
|
this.results.$element.append( this.rows[ row ].$element );
|
2014-09-18 19:49:22 +00:00
|
|
|
}
|
2015-02-12 01:07:44 +00:00
|
|
|
|
2014-09-18 19:49:22 +00:00
|
|
|
return row;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Respond to add results event in the results widget.
|
|
|
|
* Override the way SelectWidget and GroupElement append the items
|
|
|
|
* into the group so we can append them in groups of rows.
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2014-09-18 19:49:22 +00:00
|
|
|
* @param {ve.ui.MWMediaResultWidget[]} items An array of item elements
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaSearchWidget.prototype.onResultsAdd = function ( items ) {
|
2015-01-16 17:11:13 +00:00
|
|
|
var search = this;
|
|
|
|
|
|
|
|
// Add method to a queue; this queue will only run when the widget
|
|
|
|
// is visible
|
|
|
|
this.layoutQueue.push( function () {
|
2015-02-12 01:07:44 +00:00
|
|
|
var i, j, ilen, jlen, itemWidth, row, effectiveWidth,
|
|
|
|
resizeFactor,
|
|
|
|
maxRowWidth = search.results.$element.width() - 15;
|
2015-01-16 17:11:13 +00:00
|
|
|
|
|
|
|
// Go over the added items
|
|
|
|
row = search.getAvailableRow();
|
|
|
|
for ( i = 0, ilen = items.length; i < ilen; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
itemWidth = items[ i ].$element.outerWidth( true );
|
2015-02-12 01:07:44 +00:00
|
|
|
|
2015-01-16 17:11:13 +00:00
|
|
|
// Add items to row until it is full
|
2015-08-19 17:33:02 +00:00
|
|
|
if ( search.rows[ row ].width + itemWidth >= maxRowWidth ) {
|
2015-01-16 17:11:13 +00:00
|
|
|
// Mark this row as full
|
2015-08-19 17:33:02 +00:00
|
|
|
search.rows[ row ].isFull = true;
|
|
|
|
search.rows[ row ].$element.attr( 'data-full', true );
|
2015-02-12 01:07:44 +00:00
|
|
|
|
|
|
|
// Find the resize factor
|
2015-08-19 17:33:02 +00:00
|
|
|
effectiveWidth = search.rows[ row ].width;
|
2015-02-12 01:07:44 +00:00
|
|
|
resizeFactor = maxRowWidth / effectiveWidth;
|
|
|
|
|
2015-08-19 17:33:02 +00:00
|
|
|
search.rows[ row ].$element.attr( 'data-effectiveWidth', effectiveWidth );
|
|
|
|
search.rows[ row ].$element.attr( 'data-resizeFactor', resizeFactor );
|
|
|
|
search.rows[ row ].$element.attr( 'data-row', row );
|
2015-02-12 01:07:44 +00:00
|
|
|
|
|
|
|
// Resize all images in the row to fit the width
|
2015-08-19 17:33:02 +00:00
|
|
|
for ( j = 0, jlen = search.rows[ row ].items.length; j < jlen; j++ ) {
|
|
|
|
search.rows[ row ].items[ j ].resizeThumb( resizeFactor );
|
2015-01-16 17:11:13 +00:00
|
|
|
}
|
2015-02-12 01:07:44 +00:00
|
|
|
|
2015-01-16 17:11:13 +00:00
|
|
|
// find another row
|
|
|
|
row = search.getAvailableRow();
|
2014-09-18 19:49:22 +00:00
|
|
|
}
|
2015-02-12 01:07:44 +00:00
|
|
|
|
2015-12-09 16:47:13 +00:00
|
|
|
// Add the cumulative
|
2015-08-19 17:33:02 +00:00
|
|
|
search.rows[ row ].width += itemWidth;
|
2015-02-12 01:07:44 +00:00
|
|
|
|
|
|
|
// Store reference to the item and to the row
|
2015-08-19 17:33:02 +00:00
|
|
|
search.rows[ row ].items.push( items[ i ] );
|
|
|
|
items[ i ].setRow( row );
|
2015-02-12 01:07:44 +00:00
|
|
|
|
2015-01-16 17:11:13 +00:00
|
|
|
// Append the item
|
2015-08-19 17:33:02 +00:00
|
|
|
search.rows[ row ].$element.append( items[ i ].$element );
|
2014-09-18 19:49:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-16 17:11:13 +00:00
|
|
|
// If we have less than 4 rows, call for more images
|
|
|
|
if ( search.rows.length < 4 ) {
|
2015-02-04 00:32:46 +00:00
|
|
|
search.queryMediaQueue();
|
2015-01-16 17:11:13 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
this.runLayoutQueue();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run layout methods from the queue only if the element is visible.
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaSearchWidget.prototype.runLayoutQueue = function () {
|
|
|
|
var i, len;
|
|
|
|
|
|
|
|
if ( this.$element.is( ':visible' ) ) {
|
|
|
|
for ( i = 0, len = this.layoutQueue.length; i < len; i++ ) {
|
|
|
|
this.layoutQueue.pop()();
|
|
|
|
}
|
2014-09-18 19:49:22 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Respond to removing results event in the results widget.
|
|
|
|
* Clear the relevant rows.
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2014-09-18 19:49:22 +00:00
|
|
|
* @param {OO.ui.OptionWidget[]} items Removed items
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaSearchWidget.prototype.onResultsRemove = function ( items ) {
|
|
|
|
if ( items.length > 0 ) {
|
|
|
|
// In the case of the media search widget, if any items are removed
|
|
|
|
// all are removed (new search)
|
|
|
|
this.resetRows();
|
2015-04-16 19:14:27 +00:00
|
|
|
this.currentItemCache = [];
|
2014-09-18 19:49:22 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set language for the search results.
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2014-09-18 19:49:22 +00:00
|
|
|
* @param {string} lang Language
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaSearchWidget.prototype.setLang = function ( lang ) {
|
|
|
|
this.lang = lang;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get language for the search results.
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string} lang Language
|
2014-09-18 19:49:22 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWMediaSearchWidget.prototype.getLang = function () {
|
|
|
|
return this.lang;
|
|
|
|
};
|