summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/res/smw/util/ext.smw.modal.js
blob: 017504f5931850717fa7c8faa69097d2ca200c50 (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
/**
 * @see https://www.w3schools.com/howto/howto_css_modals.asp
 *
 * @license GNU GPL v2+
 * @since 3.0
 *
 * @author mwjames
 */

/*global jQuery, mediaWiki, mw */
( function ( $, mw ) {

	'use strict';

	$( document ).ready( function() {

		$( '.smw-modal-link' ).removeClass( 'is-disabled' );

		// Iterate over available nav links onClick
		$( '.smw-modal-link' ).on( "click", function( event ) {

			var that = this;

			// Avoid visual disruption on the parameter list (uses a fading field
			// display with the help of an ::after element) and override the element
			// for the time the modal window is displayed
			var parameterList = $( '.options-parameter-list' );
			parameterList.removeClass( 'options-parameter-list' );
			parameterList.addClass( 'options-parameter-list-plain' );

			// Find the content ID
			var id = $( this ).data( 'id' );

			// Get the modal
			var modal = document.getElementById( id );

			// When the user clicks the button, open the modal
			modal.style.display = "block";

			$( '#' + id + ' .smw-modal-close' ).on( "click", function( event ) {
				modal.style.display = "none";
				parameterList.removeClass( 'options-parameter-list-plain' );
				parameterList.addClass( 'options-parameter-list' );
			} );

			// When the user clicks anywhere outside of the modal, close it
			window.onclick = function( e ) {

				var isClickInside = that.contains( e.target );

				if ( e.target == modal || ( isClickInside === false && modal.contains( e.target ) === false ) ) {
					modal.style.display = "none";
					parameterList.removeClass( 'options-parameter-list-plain' );
					parameterList.addClass( 'options-parameter-list' );
				}
			}

			event.preventDefault();
		} );

	} );

}( jQuery, mediaWiki ) );