diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/res/smw/special.search/search.namespace.js')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/res/smw/special.search/search.namespace.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/res/smw/special.search/search.namespace.js b/www/wiki/extensions/SemanticMediaWiki/res/smw/special.search/search.namespace.js new file mode 100644 index 00000000..21659b0e --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/res/smw/special.search/search.namespace.js @@ -0,0 +1,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 ); |