This commit is contained in:
2026-02-15 19:38:58 +03:00
parent f21144ae53
commit 08389f091b
15 changed files with 135 additions and 30 deletions
+61 -21
View File
@@ -9,7 +9,7 @@ kit.config = kit.config || {};
* @class kitConfig * @class kitConfig
*/ */
var defaultConfig = { var defaultConfig = {
version: '2.0', version: '2.1',
assetsPath: '', assetsPath: '',
requiredDependencies: [], requiredDependencies: [],
autoloadPluginList: [], autoloadPluginList: [],
@@ -793,7 +793,7 @@ kit.config = kit.config || {};
* @param callback * @param callback
* @param argArr * @param argArr
* @param context * @param context
* @returns {undefined} * @return {Promise}
*/ */
PluginManager.prototype.exec = function (deps, callback, argArr = [], context = undefined) { PluginManager.prototype.exec = function (deps, callback, argArr = [], context = undefined) {
var self = this; var self = this;
@@ -813,7 +813,7 @@ kit.config = kit.config || {};
argArr = []; argArr = [];
} }
if(typeof callback !== 'function') { if(typeof callback !== 'function') {
return undefined; callback = function(){};
} }
if(global.config && global.config.requiredDependencies) { if(global.config && global.config.requiredDependencies) {
@@ -823,11 +823,17 @@ kit.config = kit.config || {};
var depsPromiseCallback = self.__getDepsPromiseCallback(deps); var depsPromiseCallback = self.__getDepsPromiseCallback(deps);
if(depsPromiseCallback) { if(depsPromiseCallback) {
depsPromiseCallback().then(function(){ return depsPromiseCallback().then(function(){
callback.apply(context, argArr); return new Promise(function(resolve, reject){
callback.apply(context, argArr)
resolve();
});
}); });
} else { } else {
callback.apply(context, argArr) return new Promise(function(resolve, reject){
callback.apply(context, argArr)
resolve();
});
} }
}; };
@@ -836,11 +842,20 @@ kit.config = kit.config || {};
* @see https://requirejs.org/ * @see https://requirejs.org/
* @param deps * @param deps
* @param callback * @param callback
* @return {Promise}
*/ */
__proto.define = function (deps, callback) { __proto.define = function (deps, callback) {
var self = this; var self = this;
var context = this; var context = this;
if(typeof deps === 'string'){
deps = [deps];
}
if(typeof callback !== 'function') {
callback = function (){};
}
var depsPromiseCallback = self.__getDepsPromiseCallback(deps); var depsPromiseCallback = self.__getDepsPromiseCallback(deps);
var getArgArr = function () { var getArgArr = function () {
@@ -857,11 +872,17 @@ kit.config = kit.config || {};
}.bind(self); }.bind(self);
if(depsPromiseCallback) { if(depsPromiseCallback) {
depsPromiseCallback().then(function(){ return depsPromiseCallback().then(function(){
callback.apply(context, getArgArr()); return new Promise(function(resolve, reject){
callback.apply(context, getArgArr());
resolve();
});
}); });
} else { } else {
callback.apply(context, getArgArr()) return new Promise(function(resolve, reject){
callback.apply(context, getArgArr())
resolve();
});
} }
}; };
@@ -870,8 +891,9 @@ kit.config = kit.config || {};
* *
* @param {(string|string[])} deps * @param {(string|string[])} deps
* @param {function} callback * @param {function} callback
* @return {Promise}
*/ */
__proto.ready = function(deps, callback = undefined) { __proto.ready = function(deps = [], callback = undefined) {
var self = this; var self = this;
if(typeof deps === 'function') { if(typeof deps === 'function') {
callback = deps; callback = deps;
@@ -880,19 +902,28 @@ kit.config = kit.config || {};
if(typeof callback !== 'function') { if(typeof callback !== 'function') {
callback = function (){}; callback = function (){};
} }
self.__ready(self.exec, [deps, callback], self); return self.__ready(self.exec, [deps, callback], self);
}; };
__proto.__ready = function(fn, args = [], context = window) { __proto.__ready = function(fn, args = [], context = window) {
var promise;
var self = this; var self = this;
context = context || this; context = context || this;
if (/complete|interactive|loaded/.test(document.readyState)) { if (/complete|interactive|loaded/.test(document.readyState)) {
fn.apply(context, args); promise = new Promise(function(resolve, reject){
} else {
document.addEventListener("DOMContentLoaded", function () {
fn.apply(context, args); fn.apply(context, args);
}.bind(this)); resolve();
});
} else {
promise = new Promise(function(resolve, reject){
document.addEventListener("DOMContentLoaded", function () {
resolve();
}.bind(this));
}).then(function(){
return fn.apply(context, args);
});
} }
return promise;
}; };
/** /**
@@ -901,7 +932,7 @@ kit.config = kit.config || {};
* @param {(string|string[])} deps * @param {(string|string[])} deps
* @param {function} callback * @param {function} callback
*/ */
__proto.loaded = function(deps, callback = undefined) { __proto.loaded = function(deps = [], callback = undefined) {
var self = this; var self = this;
if(typeof deps === 'function') { if(typeof deps === 'function') {
callback = deps; callback = deps;
@@ -910,19 +941,28 @@ kit.config = kit.config || {};
if(typeof callback !== 'function') { if(typeof callback !== 'function') {
callback = function (){}; callback = function (){};
} }
self.__loaded(self.exec, [deps, callback], self); return self.__loaded(self.exec, [deps, callback], self);
}; };
__proto.__loaded = function(fn, args = [], context = window) { __proto.__loaded = function(fn, args = [], context = window) {
var promise;
var self = this; var self = this;
context = context || this; context = context || this;
if (/complete|interactive|loaded/.test(document.readyState)) { if (/complete|interactive|loaded/.test(document.readyState)) {
fn.apply(context, args); promise = new Promise(function(resolve, reject){
} else {
window.addEventListener("load", function () {
fn.apply(context, args); fn.apply(context, args);
}.bind(this)); resolve();
});
} else {
promise = new Promise(function(resolve, reject){
window.addEventListener("load", function () {
resolve();
}.bind(this));
}).then(function(){
return fn.apply(context, args);
});
} }
return promise;
}; };
/** /**
+1 -1
View File
File diff suppressed because one or more lines are too long
Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

+58
View File
@@ -0,0 +1,58 @@
<script type="text/javascript" src="../assets/core/core.plugins.config.js"></script>
<script type="text/javascript" src="../assets/core/core.js"></script>
<script>
console.log('exec 1');
kit.exec('jquery', function () {
console.log('exec 3');
}).then(function(){
console.log('exec 4');
});
console.log('exec 2');
console.log('ready 1');
kit.ready('menu', function () {
console.log('ready 3');
}).then(function(){
console.log('ready 4');
});
console.log('ready 2');
console.log('loaded 1');
kit.loaded('Tooltip', function () {
console.log('loaded 3');
}).then(function(){
console.log('loaded 4');
});
console.log('loaded 2');
console.log('define 1');
kit.loaded().then(function(){
kit.define('Popover', function (Popover) {
console.log('define 3', Popover);
}).then(function(){
console.log('define 4');
});
});
console.log('define 2');
(new Promise(function(resolve, reject){
console.log('Promise 1');
resolve();
})).then(function(){
console.log('Promise 3');
});
console.log('Promise 2');
</script>
<div class="kit-wrapper">
<div class="kit-logger"></div>
</div>
<?php
echo str_repeat('<div></div>', 100000);
+15 -8
View File
@@ -1,6 +1,10 @@
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");?> <?php
<?
if(\Bitrix\Main\Loader::includeModule('wt.core')) { use Bitrix\Main\Loader;
require($_SERVER['DOCUMENT_ROOT']. '/bitrix/modules/main/include/prolog_before.php');?>
<?php
if(Loader::includeModule('wt.core')) {
app()->service()->assets()->setPlugins([ app()->service()->assets()->setPlugins([
'kit:config', 'kit:config',
'kit:flex-kit', 'kit:flex-kit',
@@ -12,11 +16,14 @@ if(\Bitrix\Main\Loader::includeModule('wt.core')) {
'kit:theme', 'kit:theme',
])->render(); ])->render();
} }
/**
* @global CMain $APPLICATION
*/
$APPLICATION->ShowHead(); $APPLICATION->ShowHead();
?> ?>
<div class="kit-wrapper"> <div class="kit-wrapper">
<div class="flex-list" style="--col-count: 3"> <div class="flex-list" style="--col-count: 3">
<div class="flex-list-item"><? <div class="flex-list-item"><?php
service()->templater()->render('kit:input', [ service()->templater()->render('kit:input', [
'TYPE' => 'text', 'TYPE' => 'text',
'HINT' => '', 'HINT' => '',
@@ -25,7 +32,7 @@ $APPLICATION->ShowHead();
'LABEL' => 'value = дв ковычки', 'LABEL' => 'value = дв ковычки',
]); ?> ]); ?>
</div> </div>
<div class="flex-list-item"><? <div class="flex-list-item"><?php
service()->templater()->render('kit:input', [ service()->templater()->render('kit:input', [
'TYPE' => 'text', 'TYPE' => 'text',
'HINT' => '', 'HINT' => '',
@@ -34,7 +41,7 @@ $APPLICATION->ShowHead();
'LABEL' => 'value = одинарные ковычки', 'LABEL' => 'value = одинарные ковычки',
]); ?> ]); ?>
</div> </div>
<div class="flex-list-item"><? <div class="flex-list-item"><?php
service()->templater()->render('kit:input', [ service()->templater()->render('kit:input', [
'TYPE' => 'text', 'TYPE' => 'text',
'HINT' => '', 'HINT' => '',
@@ -43,7 +50,7 @@ $APPLICATION->ShowHead();
'LABEL' => 'value = спецсимволы', 'LABEL' => 'value = спецсимволы',
]); ?> ]); ?>
</div> </div>
<div class="flex-list-item"><? <div class="flex-list-item"><?php
service()->templater()->render('kit:input', [ service()->templater()->render('kit:input', [
'TYPE' => 'text', 'TYPE' => 'text',
'HINT' => '', 'HINT' => '',
@@ -52,7 +59,7 @@ $APPLICATION->ShowHead();
'LABEL' => 'value = лев пр слеши, лев пр стрелки, дв од кав', 'LABEL' => 'value = лев пр слеши, лев пр стрелки, дв од кав',
]); ?> ]); ?>
</div> </div>
<div class="flex-list-item"><? <div class="flex-list-item"><?php
service()->templater()->render('kit:input', [ service()->templater()->render('kit:input', [
'TYPE' => 'text', 'TYPE' => 'text',
'HINT' => '', 'HINT' => '',