MediaWiki:Common.js: Difference between revisions
| No edit summary | No edit summary | ||
| Line 2: | Line 2: | ||
| (function ($, mw) { | (function ($, mw) { | ||
| 	$.getScript('https://code.jquery.com/jquery-migrate-3.0.0.min.js', function() {}); | |||
| 	var fn = function () { | |||
| 		var cats = mw.config.get('wgCategories'), newClasses; | |||
| 		if (cats) { | |||
| 			newClasses = $.map(cats, function (el) { | |||
| 				return 'cat-' + encodeURIComponent(el.replace(/[ .]/g, '_')).replace(/%/g, '_'); | |||
| 			}).join(' '); | |||
| 			$(document.body).addClass(newClasses); | |||
| 		} | |||
| 	}; | |||
| 	if (document.body) { | |||
| 		fn(); | |||
| 	} else { | |||
| 		$(fn); | |||
| 	} | |||
| 	mw.loader.using( 'ext.bootstrap' ).then( function () { | |||
| 		$( '.menu-item-docs-' + glang ).show(); | |||
| 		$( '.menu-item-tasks-' + glang ).show(); | |||
| 		$( '.menu-item-progress-' + glang ).show(); | |||
| 		if ( $( '#org_actions' ).length || $( '#progress_list' ).length ) { | |||
| 			console.log( 'heps2' ) | |||
| 			$( '#domains' ).selectpicker(); | |||
| 			console.log( 'heps' ) | |||
| 			$( '#years' ).selectpicker(); | |||
| 			$( '#row_grouping' ).selectpicker(); | |||
| 			$( '#col_grouping' ).selectpicker(); | |||
| 			$( '#domains' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) { | |||
| 				updateActionView() | |||
| 			} ); | |||
| 			$( '#years' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) { | |||
| 				updateActionView() | |||
| 			} ); | |||
| 			$( '#actors' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) { | |||
| 				window.scrollTo( 0, 0 ) | |||
| 				updateActionView() | |||
| 			} ); | |||
| 			$( '#row_grouping' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) { | |||
| 				window.scrollTo( 0, 0 ) | |||
| 				updateActionView() | |||
| 			} ); | |||
| 			$( '#col_grouping' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) { | |||
| 				window.scrollTo( 0, 0 ) | |||
| 				updateActionView() | |||
| 			} ); | |||
| 			$( '#orgs' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) { | |||
| 				window.scrollTo( 0, 0 ) | |||
| 				updateActionView() | |||
| 			} ); | |||
| 			// select all as by default | |||
| 			console.log( 'heps' ) | |||
| 			$( '#domains' ).selectpicker( 'selectAll' ); | |||
| 			console.log( 'heps' ) | |||
| 			$( '#years' ).selectpicker( 'selectAll' ); | |||
| 			var searchBox = $( '#searchtxt' ) | |||
| 			$( searchBox ).on( 'keypress', function ( e ) { | |||
| 				if ( e.which == 13 ) { | |||
| 					console.log( 'test' ) | |||
| 					nextMatch() | |||
| 					$( '#nextMatch' ).focus() | |||
| 				} | |||
| 			} ); | |||
| 			fetch_data( glang ).then( updateActionView ) | |||
| 		} | |||
| if( | 		if ( $( '#overview_actions' ).length ) { | ||
| 			console.log( 'heps' ) | |||
| 			$( '#domains' ).selectpicker(); | |||
| 			const queryString = window.location.search; | |||
| 			const urlParams = new URLSearchParams( queryString ); | |||
| 			if ( urlParams.has( 'domain' ) ) { | |||
| 				var selectedDomain = urlParams.get( 'domain' ) | |||
| 				$( '#domains' ).selectpicker( 'val', selectedDomain ) | |||
| 			} else { | |||
| 				$( '#domains' ).selectpicker( 'selectAll' ); | |||
| 			} | |||
| 			console.log( 'heps' ) | |||
| 			$( '#years' ).selectpicker(); | |||
| 			$( '#row_grouping' ).selectpicker(); | |||
| 			$( '#col_grouping' ).selectpicker(); | |||
| 			$( '#domains' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) { | |||
| 				updateActionView() | |||
| 			} ); | |||
| 			$( '#years' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) { | |||
| 				updateActionView() | |||
| 			} ); | |||
| 			$( '#actors' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) { | |||
| 				window.scrollTo( 0, 0 ) | |||
| 				updateActionView() | |||
| 			} ); | |||
| 			$( '#row_grouping' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) { | |||
| 				window.scrollTo( 0, 0 ) | |||
| 				updateActionView() | |||
| 			} ); | |||
| 			$( '#col_grouping' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) { | |||
| 				window.scrollTo( 0, 0 ) | |||
| 				updateActionView() | |||
| 			} ); | |||
| 			// select all as by default | |||
| 			console.log( 'heps' ) | |||
| 			console.log( 'heps' ) | |||
| 			$( '#years' ).selectpicker( 'selectAll' ); | |||
| 			var searchBox = $( '#searchtxt' ) | |||
| 			$( searchBox ).on( 'keypress', function ( e ) { | |||
| 				if ( e.which == 13 ) { | |||
| 					console.log( 'test' ) | |||
| 					nextMatch() | |||
| 					$( '#nextMatch' ).focus() | |||
| 				} | |||
| 			} ); | |||
| 			fetch_data( glang ).then( updateActionView ) | |||
| 		} | |||
| 	} ); | |||
Revision as of 18:26, 25 February 2024
var glang = mw.config.get( 'wgPageContentLanguage' );
(function ($, mw) {
	$.getScript('https://code.jquery.com/jquery-migrate-3.0.0.min.js', function() {});
	var fn = function () {
		var cats = mw.config.get('wgCategories'), newClasses;
		if (cats) {
			newClasses = $.map(cats, function (el) {
				return 'cat-' + encodeURIComponent(el.replace(/[ .]/g, '_')).replace(/%/g, '_');
			}).join(' ');
			$(document.body).addClass(newClasses);
		}
	};
	if (document.body) {
		fn();
	} else {
		$(fn);
	}
	mw.loader.using( 'ext.bootstrap' ).then( function () {
		$( '.menu-item-docs-' + glang ).show();
		$( '.menu-item-tasks-' + glang ).show();
		$( '.menu-item-progress-' + glang ).show();
		if ( $( '#org_actions' ).length || $( '#progress_list' ).length ) {
			console.log( 'heps2' )
			$( '#domains' ).selectpicker();
			console.log( 'heps' )
			$( '#years' ).selectpicker();
			$( '#row_grouping' ).selectpicker();
			$( '#col_grouping' ).selectpicker();
			$( '#domains' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) {
				updateActionView()
			} );
			$( '#years' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) {
				updateActionView()
			} );
			$( '#actors' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) {
				window.scrollTo( 0, 0 )
				updateActionView()
			} );
			$( '#row_grouping' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) {
				window.scrollTo( 0, 0 )
				updateActionView()
			} );
			$( '#col_grouping' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) {
				window.scrollTo( 0, 0 )
				updateActionView()
			} );
			$( '#orgs' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) {
				window.scrollTo( 0, 0 )
				updateActionView()
			} );
			// select all as by default
			console.log( 'heps' )
			$( '#domains' ).selectpicker( 'selectAll' );
			console.log( 'heps' )
			$( '#years' ).selectpicker( 'selectAll' );
			var searchBox = $( '#searchtxt' )
			$( searchBox ).on( 'keypress', function ( e ) {
				if ( e.which == 13 ) {
					console.log( 'test' )
					nextMatch()
					$( '#nextMatch' ).focus()
				}
			} );
			fetch_data( glang ).then( updateActionView )
		}
		if ( $( '#overview_actions' ).length ) {
			console.log( 'heps' )
			$( '#domains' ).selectpicker();
			const queryString = window.location.search;
			const urlParams = new URLSearchParams( queryString );
			if ( urlParams.has( 'domain' ) ) {
				var selectedDomain = urlParams.get( 'domain' )
				$( '#domains' ).selectpicker( 'val', selectedDomain )
			} else {
				$( '#domains' ).selectpicker( 'selectAll' );
			}
			console.log( 'heps' )
			$( '#years' ).selectpicker();
			$( '#row_grouping' ).selectpicker();
			$( '#col_grouping' ).selectpicker();
			$( '#domains' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) {
				updateActionView()
			} );
			$( '#years' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) {
				updateActionView()
			} );
			$( '#actors' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) {
				window.scrollTo( 0, 0 )
				updateActionView()
			} );
			$( '#row_grouping' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) {
				window.scrollTo( 0, 0 )
				updateActionView()
			} );
			$( '#col_grouping' ).on( 'changed.bs.select', function ( e, clickedIndex, isSelected, previousValue ) {
				window.scrollTo( 0, 0 )
				updateActionView()
			} );
			// select all as by default
			console.log( 'heps' )
			console.log( 'heps' )
			$( '#years' ).selectpicker( 'selectAll' );
			var searchBox = $( '#searchtxt' )
			$( searchBox ).on( 'keypress', function ( e ) {
				if ( e.which == 13 ) {
					console.log( 'test' )
					nextMatch()
					$( '#nextMatch' ).focus()
				}
			} );
			fetch_data( glang ).then( updateActionView )
		}
	} );
})(jQuery, mw);
$('body.page-Special_FormEdit_Progress #firstHeading').text('Uusi edistysaskel');
$('body.page-Special_FormEdit_Progress #wpSave > button').text('Tallenna');
$('#searchform').append('<input type="hidden" value="default" name="profile" /><input type="hidden" value="' + glang + '" name="uselang" />');