diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/src/Utils/HtmlModal.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/src/Utils/HtmlModal.php | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/src/Utils/HtmlModal.php b/www/wiki/extensions/SemanticMediaWiki/src/Utils/HtmlModal.php new file mode 100644 index 00000000..b8b99997 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/src/Utils/HtmlModal.php @@ -0,0 +1,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' + ], + '×' + ) . $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; + } + +} |