Skip to content

Commit

Permalink
* core: export zui init helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Nov 20, 2024
1 parent 53d7345 commit e3d90a4
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/core/src/component/creator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {$, Cash} from '../cash';
import {$, Cash, Selector} from '../cash';
import {type GetLibOptions} from '../dom';
import {evalValue} from '../helpers';
import {storeData, takeData} from '../helpers/data';
Expand All @@ -16,6 +16,7 @@ export type ComponentCreateOptions = ComponentOptions & {

export type ZUIInitOptions = {
update?: boolean | 'reset';
runJS?: boolean;
beforeCreate?: BeforeCreateCallback;
onCreate?: OnCreateCallback;
};
Expand Down Expand Up @@ -330,29 +331,37 @@ function autoDestroyComponents() {
storeData(document.body, '_autoDestoryMob', mob);
}

/** Define the $.fn.zuiInit method. */
$.fn.zuiInit = function (this: Cash, options?: ZUIInitOptions) {
this.find('[zui-create],[data-zui]').each(function () {
export function init(element: Selector, options?: ZUIInitOptions) {
const $element = $(element);
$element.find('[zui-create],[data-zui]').each(function () {
if (options?.beforeCreate?.(this) === false) {
return;
}
initCreators(this, options);
});
this.find('[zui-init]').each(function () {
$element.find('[zui-init]').each(function () {
if (this.hasAttribute('z-zui-inited')) {
return;
}
this.setAttribute('z-zui-inited', '');
$.runJS(this.getAttribute('zui-init')!, ['$element', $(this)]);
});
this.find('.hide-before-init').removeClass('invisible hidden opacity-0');
this.find('.scroll-into-view').scrollIntoView();
this.find('[data-on="inited"],[zui-on-inited]').each((_, ele) => {
$element.find('.hide-before-init').removeClass('invisible hidden opacity-0');
$element.find('.scroll-into-view').scrollIntoView();
$element.find('[data-on="inited"],[zui-on-inited]').each((_, ele) => {
const $ele = $(ele);
if (!$ele.zui()) {
$ele.trigger('inited');
}
});
if (options?.runJS) {
$element.runJS();
}
}

/** Define the $.fn.zuiInit method. */
$.fn.zuiInit = function (this: Cash, options?: ZUIInitOptions) {
init(this, options);
return this;
};

Expand Down

0 comments on commit e3d90a4

Please sign in to comment.