|
@@ -1,6 +1,7 @@
|
|
<?php
|
|
<?php
|
|
|
|
|
|
Lib::loadClass('Theme');
|
|
Lib::loadClass('Theme');
|
|
|
|
+require_once dirname(__FILE__) . '/' . 'UITagInterface.php';
|
|
|
|
|
|
class UI {
|
|
class UI {
|
|
|
|
|
|
@@ -305,22 +306,26 @@ class UI {
|
|
}
|
|
}
|
|
|
|
|
|
public static function inlineJS($jsFile, $jsonVars = []) {
|
|
public static function inlineJS($jsFile, $jsonVars = []) {
|
|
|
|
+ echo self::hScript($jsFile, $jsonVars);
|
|
|
|
+ }
|
|
|
|
+ public static function hScript($jsFile, $jsonVars = []) {
|
|
if (!file_exists($jsFile)) throw new Exception("js file '" . basename($jsFile) . "' not exists!");
|
|
if (!file_exists($jsFile)) throw new Exception("js file '" . basename($jsFile) . "' not exists!");
|
|
- UI::startTag('script', [], "\n");
|
|
|
|
- echo "(function (global) {" . "\n";
|
|
|
|
- echo " var module = {}; module.exports = {};\n";
|
|
|
|
|
|
+ $ret = '<script>' . "\n";
|
|
|
|
+ $ret .= "(function (global) {" . "\n";
|
|
|
|
+ $ret .= " var module = {}; module.exports = {};\n";
|
|
foreach ($jsonVars as $name => $var) {
|
|
foreach ($jsonVars as $name => $var) {
|
|
- echo " var {$name} = " . json_encode($var) . ";\n";
|
|
|
|
- }
|
|
|
|
- echo file_get_contents($jsFile);
|
|
|
|
- echo "\n;\n";
|
|
|
|
- echo " if (module && module.exports && Object.keys(module.exports).length) {" . "\n";
|
|
|
|
- echo " Object.keys(module.exports).forEach(function (key) {" . "\n";
|
|
|
|
- echo " global[key] = module.exports[key];" . "\n";
|
|
|
|
- echo " })" . "\n";
|
|
|
|
- echo " }" . "\n";
|
|
|
|
- echo "})(window)" . "\n";
|
|
|
|
- UI::endTag('script', "\n");
|
|
|
|
|
|
+ $ret .= " var {$name} = " . json_encode($var) . ";\n";
|
|
|
|
+ }
|
|
|
|
+ $ret .= file_get_contents($jsFile);
|
|
|
|
+ $ret .= "\n;\n";
|
|
|
|
+ $ret .= " if (module && module.exports && Object.keys(module.exports).length) {" . "\n";
|
|
|
|
+ $ret .= " Object.keys(module.exports).forEach(function (key) {" . "\n";
|
|
|
|
+ $ret .= " global[key] = module.exports[key];" . "\n";
|
|
|
|
+ $ret .= " })" . "\n";
|
|
|
|
+ $ret .= " }" . "\n";
|
|
|
|
+ $ret .= "})(window)" . "\n";
|
|
|
|
+ $ret .= '</script>' . "\n";
|
|
|
|
+ return $ret;
|
|
}
|
|
}
|
|
public static function inlineRawJS($jsFile) {
|
|
public static function inlineRawJS($jsFile) {
|
|
if (!file_exists($jsFile)) throw new Exception("js file '" . basename($jsFile) . "' not exists!");
|
|
if (!file_exists($jsFile)) throw new Exception("js file '" . basename($jsFile) . "' not exists!");
|
|
@@ -466,6 +471,7 @@ class UI {
|
|
");
|
|
");
|
|
}
|
|
}
|
|
public static function h($tagName, $params = [], $childrens = []) {
|
|
public static function h($tagName, $params = [], $childrens = []) {
|
|
|
|
+ if (null === $tagName && empty($params)) return self::hChildrens($childrens);
|
|
$emptyTags = [];
|
|
$emptyTags = [];
|
|
$emptyTags[] = 'hr';
|
|
$emptyTags[] = 'hr';
|
|
$emptyTags[] = 'br';
|
|
$emptyTags[] = 'br';
|
|
@@ -483,8 +489,18 @@ class UI {
|
|
$emptyTags[] = 'track';
|
|
$emptyTags[] = 'track';
|
|
$emptyTags[] = 'wbr';
|
|
$emptyTags[] = 'wbr';
|
|
if (in_array($tagName, $emptyTags)) return '<' . $tagName . (empty($params) ? '' : ' ' . self::hAttributes($params)) . '/>';
|
|
if (in_array($tagName, $emptyTags)) return '<' . $tagName . (empty($params) ? '' : ' ' . self::hAttributes($params)) . '/>';
|
|
|
|
+ if ('p5:' === substr($tagName, 0, 3)) return self::hCustomTag($tagName, $params, $childrens);
|
|
return '<' . $tagName . (empty($params) ? '' : ' ' . self::hAttributes($params)) . '>' . self::hChildrens($childrens) . '</' . $tagName . '>';
|
|
return '<' . $tagName . (empty($params) ? '' : ' ' . self::hAttributes($params)) . '>' . self::hChildrens($childrens) . '</' . $tagName . '>';
|
|
}
|
|
}
|
|
|
|
+ public static function hCustomTag($tagName, $params = [], $childrens = []) {
|
|
|
|
+ if ('p5:' === substr($tagName, 0, 3)) {
|
|
|
|
+ $tagClass = "UI_" . substr($tagName, 3);
|
|
|
|
+ if (!class_exists($tagClass)) Lib::tryLoadClass($tagClass);
|
|
|
|
+ if (!class_exists($tagClass)) throw new Exception("Not implemented custom tag '{$tagName}'");
|
|
|
|
+ return $tagClass::h($tagName, $params, $childrens);
|
|
|
|
+ }
|
|
|
|
+ throw new Exception("Not implemented custom tag prefix '{$tagName}'");
|
|
|
|
+ }
|
|
public static function hAttributes($params = []) {
|
|
public static function hAttributes($params = []) {
|
|
$attr = [];
|
|
$attr = [];
|
|
if (null === $params) return '';
|
|
if (null === $params) return '';
|