Browse Source

added details tag in UI

Piotr Labudda 7 năm trước cách đây
mục cha
commit
8119fafd85
1 tập tin đã thay đổi với 23 bổ sung0 xóa
  1. 23 0
      SE/se-lib/UI.php

+ 23 - 0
SE/se-lib/UI.php

@@ -783,4 +783,27 @@ class UI {
 		UI::dol(); // UI::dol must include Theme::footer();
 	}
 
+	public static function startDetails($opts, $summaryChildrens) {
+		$attrs = array_reduce(array_keys($opts), function ($ret, $optionKey) use ($opts) {
+			$option = $opts[$optionKey];
+			if (false !== strpos($optionKey, '.')) {
+				list($mainKey, $attrName) = explode('.', $optionKey, 2);
+				$ret[$mainKey][$attrName] = $option;
+			} else {
+				$ret['details'][$optionKey] = $option;
+			}
+			return $ret;
+		}, [
+			'details' => [],
+			'summary' => [],
+			'content' => [],
+		]);
+		return '<details' . ( empty($attrs['details']) ? '' : ' ' . self::hAttributes($attrs['details']) ) . '>' .
+			'<summary' . ( empty($attrs['summary']) ? '' : ' ' . self::hAttributes($attrs['summary']) ) . '>' . self::hChildrens($summaryChildrens) . '</summary>' . "\n" .
+			'<div' . ( empty($attrs['content']) ? '' : ' ' . self::hAttributes($attrs['content']) ) . '>' . "\n";
+	}
+	public static function endDetails() {
+		return '</div></details>';
+	}
+
 }