summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/Utils/HtmlModal.php
blob: b8b999971ab29cef5762d2055b456034c4587dd2 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php

namespace SMW\Utils;

use Html;

/**
 * @license GNU GPL v2+
 * @since 3.0
 *
 * @author mwjames
 */
class HtmlModal {

	/**
	 * @since 3.0
	 *
	 * @return array
	 */
	public static function getModules() {
		return [ 'ext.smw.modal' ];
	}

	/**
	 * @since 3.0
	 *
	 * @return array
	 */
	public static function getModuleStyles() {
		return [ 'ext.smw.modal.styles' ];
	}

	/**
	 * @since 3.0
	 *
	 * @param string $html
	 * @param array $attributes
	 *
	 * @return string
	 */
	public static function link( $name, array $attributes = [] ) {

		$attributes = self::mergeAttributes(
			'smw-modal-link is-disabled',
			$attributes
		);

		return Html::rawElement(
			'span',
			$attributes,
			Html::rawElement(
				'a',
				[
					'href' => '#help',
					'rel'  => 'nofollow'
				],
				$name
			)
		);
	}

	/**
	 * @since 3.0
	 *
	 * @param string $html
	 * @param array $attributes
	 *
	 * @return string
	 */
	public static function modal( $title = '', $html = '', array $attributes = [] ) {

		$attributes = self::mergeAttributes(
			'smw-modal',
			$attributes
		);

		$title = Html::rawElement(
			'span',
			[
				'class' => 'smw-modal-title'
			],
			$title
		);

		$html = Html::rawElement(
			'div',
			[
				'class' => 'smw-modal-content'
			],
			Html::rawElement(
				'div',
				[
					'class' => 'smw-modal-header'
				],
				Html::rawElement(
					'span',
					[
						'class' => 'smw-modal-close'
					],
					'&#215;'
				) . $title
			). Html::rawElement(
				'div',
				[
					'class' => 'smw-modal-body'
				],
				$html
			) . Html::rawElement(
				'div',
				[
					'class' => 'smw-modal-footer'
				],
				''
			)
		);

		return Html::rawElement(
			'div',
			$attributes,
			$html
		);
	}

	private static function mergeAttributes( $class, $attr ) {

		$attributes = [];

		// A bit of attribute order
		if ( isset( $attr['id'] ) ) {
			$attributes['id'] = $attr['id'];
		}

		if ( isset( $attr['class'] ) ) {
			$attributes['class'] = $class . ' ' . $attr['class'];
		} else {
			$attributes['class'] = $class;
		}

		return $attributes += $attr;
	}

}