From 0ed123136f71e68f29aea3775651b731da5cd011 Mon Sep 17 00:00:00 2001 From: Hao Sun Date: Wed, 29 Mar 2023 09:35:43 +0800 Subject: [PATCH] * zin: refactor --- zin/core/context.class.php | 27 ++++++++++++++++++++++++--- zin/core/context.func.php | 15 ++++++++++----- zin/core/h.func.php | 5 ----- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/zin/core/context.class.php b/zin/core/context.class.php index 7d696a8f29..df41184084 100644 --- a/zin/core/context.class.php +++ b/zin/core/context.class.php @@ -12,6 +12,7 @@ namespace zin; require_once dirname(__DIR__) . DS . 'utils' . DS . 'dataset.class.php'; +require_once dirname(__DIR__) . DS . 'utils' . DS . 'flat.func.php'; require_once 'portal.class.php'; class context extends \zin\utils\dataset @@ -74,7 +75,8 @@ class context extends \zin\utils\dataset public function addJSCall() { - $code = call_user_func_array('h::createJsCallCode', func_get_args()); + $code = call_user_func_array('\zin\h::createJsCallCode', func_get_args()); + \a(array('code', $code, $this->getJsList())); return $this->addToList('jsCall', $code); } @@ -97,13 +99,32 @@ class context extends \zin\utils\dataset public static function js(/* string ...$code */) { $context = static::current(); - call_user_func_array(array($context, 'addJS'), func_get_args()); + call_user_func_array(array($context, 'addJS'), \zin\utils\flat(func_get_args())); + } + + public static function jsCall(/* string ...$code */) + { + $context = static::current(); + call_user_func_array(array($context, 'addJSCall'), func_get_args()); + } + + + public static function jsVar($name, $value) + { + $context = static::current(); + $context->addJSVar($name, $value); } public static function css(/* string ...$code */) { $context = static::current(); - call_user_func_array(array($context, 'addCSS'), func_get_args()); + call_user_func_array(array($context, 'addCSS'), \zin\utils\flat(func_get_args())); + } + + public static function import(/* string ...$files */) + { + $context = static::current(); + call_user_func_array(array($context, 'addImport'), func_get_args()); } /** diff --git a/zin/core/context.func.php b/zin/core/context.func.php index 70a3a475b9..5d7a770644 100644 --- a/zin/core/context.func.php +++ b/zin/core/context.func.php @@ -18,22 +18,27 @@ function portal(/* string $name, mixed ...$children */) call_user_func_array('\zin\context::portal', func_get_args()); } -function pageJS() +function js() { call_user_func_array('\zin\context::js', func_get_args()); } -function pageCSS() +function jsCall() { - call_user_func_array('\zin\context::css', func_get_args()); + call_user_func_array('\zin\context::jsCall', func_get_args()); } -function pageJSVar() +function jsVar() { call_user_func_array('\zin\context::jsVar', func_get_args()); } -function pageImport() +function css() +{ + call_user_func_array('\zin\context::css', func_get_args()); +} + +function import() { call_user_func_array('\zin\context::import', func_get_args()); } diff --git a/zin/core/h.func.php b/zin/core/h.func.php index 5098662945..227364a55c 100644 --- a/zin/core/h.func.php +++ b/zin/core/h.func.php @@ -42,9 +42,4 @@ function li() {return call_user_func_array('\zin\h::li', func_get_args()); function input() {return call_user_func_array('\zin\h::input', func_get_args());} function textarea() {return call_user_func_array('\zin\h::textarea', func_get_args());} -function js() {return call_user_func_array('\zin\h::js', func_get_args());} -function jsVar() {return call_user_func_array('\zin\h::jsVar', func_get_args());} -function jsCall() {return call_user_func_array('\zin\h::jsCall', func_get_args());} function jsRaw() {return call_user_func_array('\zin\h::jsRaw', func_get_args());} -function css() {return call_user_func_array('\zin\h::css', func_get_args());} -function import() {return call_user_func_array('\zin\h::import', func_get_args());}