summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticResultFormats/resources/ext.srf.util.html.js
blob: 50519c9b9fa0d6a84b71647c1c6cce8700fc5225 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
 * SRF JavaScript for srf.util namespace
 *
 * @since 1.9
 * @release 0.1
 *
 * @file
 * @ingroup SRF
 *
 * @licence GNU GPL v2 or later
 * @author mwjames
 */
/*global semanticFormats:true mediaWiki:true*/
( function( $, mw, srf ) {
 'use strict';


	////////////////////////// PRIVATE OBJECTS //////////////////////////

	var html = mw.html;

	////////////////////////// PUBLIC METHODS /////////////////////////

	$.extend( srf.util.prototype, {

		html:{

			/**
			 * Returns a dropdown element
			 *
			 * e.g.
			 * options {
			 *  list: ['...', '...'],
			 *  id: 'printouts',
			 *  selectClass: 'printouts',
			 *  browser: 'firefox',
			 *  disabled: 'disabled'
			 * }
			 *
			 * @since 1.9
			 */
			dropdown: function( options ){
				// @note The dropdown size behaves differently in some browsers
				// therefore a css class is assigned for adjustments
				var dropdown = '';
				if ( typeof options.list === 'object' ) {
					$.each( options.list, function( index, text ) {
						if ( typeof text === 'object' ) {
							text = text[0];
						}
						dropdown = dropdown + html.element( 'option', { 'value': index }, text );
					} );
				}

				return html.element( 'div',{ 'class': 'select-wrap-' + options.browser || 'all' },
					new html.Raw ( html.element( 'select', {'id': options.id, 'class': options.selectClass, 'disabled': options.disabled || false },
						new html.Raw( html.element( 'option', { 'value': '' }, '' ) + dropdown ) )
					)
				);
			}
		}
	} );

} )( jQuery, mediaWiki, semanticFormats );