summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/res/smw/special.search/search.namespace.js
blob: 21659b0e36cbe7661f93ebc892e12c41b82162f2 (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
65
66
67
68
69
70
71
72
73
/*!
 * @license GNU GPL v2+
 * @since  3.0
 *
 * @author mwjames
 */
( function( $, mw, smw ) {
	'use strict';

	/**
	 * Namespace form in Special:Search
	 *
	 * @since 3.0
	 */
	var namespace = function() {

		/**
		 * Copied from mediawiki.special.search.js in order to have the NS
		 * button to work without #powersearch
		 */
		var $checkboxes = $( '#search input[id^=mw-search-ns]' );

		// JS loaded enable all fields
		$( ".is-disabled" ).removeClass( 'is-disabled' );

		$( document ).on( "click", "#mw-search-toggleall", function() {
			$checkboxes.prop( 'checked', true );
		} );

		$( document ).on( "click", "#mw-search-togglenone", function(){
			$checkboxes.prop( 'checked', false );
		} );

		// When saving settings, use the proper request method (POST instead of GET).
		$( this ).on( "change", "#mw-search-powersearch-remember", function() {
			this.form.method = this.checked ? 'post' : 'get';
		} ).trigger( 'change' );

		var nsList = $( '#mw-search-ns' ).css( 'display' ) !== 'none' ? mw.msg( 'smw-search-hide' ) : mw.msg( 'smw-search-show' );

		/**
		 * Append hide/show button to the NS section
		 */
		$( '#smw-search-togglensview' ).append(
			$( '<input>' ).attr( 'type', 'button' )
				.attr( 'id', 'smw-togglensview' )
				.prop( 'value', nsList )
				.click( function ( event ) {

					// We carry the hidden `ns-list` on a submit so the status
					// of the prevsious acion is retained to either show or hide
					// the section
					if ( $( '#mw-search-ns' ).css( 'display' ) !== 'none' ) {
						$( 'input[name=ns-list]' ).attr( 'value', 1 );
						event.target.value = mw.msg( 'smw-search-show' );
						$( '#mw-search-ns' ).css( 'display', 'none' );
					} else {
						event.target.value = mw.msg( 'smw-search-hide' );
						$( 'input[name=ns-list]' ).attr( 'value', 0 );
						$( '#mw-search-ns' ).css( 'display', 'block' );
					}
				} )
		)

	};

	// Only load when it is Special:Search and the search type supports
	// https://www.semantic-mediawiki.org/wiki/Help:SMWSearch
	if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == 'Search' && mw.config.get( 'wgSearchType' ) == 'SMWSearch' ) {
		smw.load( namespace );
	};

} )( jQuery, mediaWiki, semanticMediaWiki );