Debian Codegraph @

resources/src/mediawiki.widgets/MediaSearch/mw.widgets.MediaSearchQueue.js

raw symbols SCIP
1 /*!
2 * MediaWiki Widgets - MediaSearchQueue class.
3 *
4 * @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7 ( function () {
8
9 /**
10 * @classdesc Media resource queue.
11 *
12 * @class
13 * @extends mw.widgets.MediaResourceQueue
14 *
15 * @constructor
16 * @description Create an instance of `mw.widgets.MediaSearchQueue`.
17 * @param {Object} [config] Configuration options
18 * @param {number} config.maxHeight The maximum height of the media, used in the
19 * search call to the API.
20 */
21 mw.widgets.MediaSearchQueue = function MwWidgetsMediaSearchQueue( config ) {
22 config = config || {};
23
24 // Parent constructor
25 mw.widgets.MediaSearchQueue.super.call( this, config );
26 };
27
28 /* Inheritance */
29 OO.inheritClass( mw.widgets.MediaSearchQueue, mw.widgets.MediaResourceQueue );
30
31 /**
32 * Override parent method to set up the providers according to
33 * the file repos.
34 *
35 * @return {jQuery.Promise} Promise that resolves when the resources are set up
36 */
37 mw.widgets.MediaSearchQueue.prototype.setup = function () {
38 return this.getFileRepos().then( ( sources ) => {
39 if ( this.providers.length === 0 ) {
40 // Set up the providers
41 for ( let i = 0, len = sources.length; i < len; i++ ) {
42 this.addProvider( new mw.widgets.MediaSearchProvider(
43 sources[ i ].apiurl,
44 {
45 name: sources[ i ].name,
46 local: sources[ i ].local,
47 scriptDirUrl: sources[ i ].scriptDirUrl,
48 userParams: {
49 gsrsearch: this.getSearchQuery()
50 },
51 staticParams: {
52 iiurlheight: this.getMaxHeight()
53 }
54 } )
55 );
56 }
57 }
58 } );
59 };
60
61 /**
62 * Set the search query.
63 *
64 * @param {string} searchQuery API search query
65 */
66 mw.widgets.MediaSearchQueue.prototype.setSearchQuery = function ( searchQuery ) {
67 this.setParams( { gsrsearch: searchQuery } );
68 };
69
70 /**
71 * Get the search query.
72 *
73 * @return {string} API search query
74 */
75 mw.widgets.MediaSearchQueue.prototype.getSearchQuery = function () {
76 return this.getParams().gsrsearch;
77 };
78 }() );