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
+52 -12
View File
@@ -9,7 +9,7 @@ kit.config = kit.config || {};
* @class kitConfig
*/
var defaultConfig = {
version: '2.0',
version: '2.1',
assetsPath: '',
requiredDependencies: [],
autoloadPluginList: [],
@@ -793,7 +793,7 @@ kit.config = kit.config || {};
* @param callback
* @param argArr
* @param context
* @returns {undefined}
* @return {Promise}
*/
PluginManager.prototype.exec = function (deps, callback, argArr = [], context = undefined) {
var self = this;
@@ -813,7 +813,7 @@ kit.config = kit.config || {};
argArr = [];
}
if(typeof callback !== 'function') {
return undefined;
callback = function(){};
}
if(global.config && global.config.requiredDependencies) {
@@ -823,11 +823,17 @@ kit.config = kit.config || {};
var depsPromiseCallback = self.__getDepsPromiseCallback(deps);
if(depsPromiseCallback) {
depsPromiseCallback().then(function(){
callback.apply(context, argArr);
return depsPromiseCallback().then(function(){
return new Promise(function(resolve, reject){
callback.apply(context, argArr)
resolve();
});
});
} else {
return new Promise(function(resolve, reject){
callback.apply(context, argArr)
resolve();
});
}
};
@@ -836,11 +842,20 @@ kit.config = kit.config || {};
* @see https://requirejs.org/
* @param deps
* @param callback
* @return {Promise}
*/
__proto.define = function (deps, callback) {
var self = this;
var context = this;
if(typeof deps === 'string'){
deps = [deps];
}
if(typeof callback !== 'function') {
callback = function (){};
}
var depsPromiseCallback = self.__getDepsPromiseCallback(deps);
var getArgArr = function () {
@@ -857,11 +872,17 @@ kit.config = kit.config || {};
}.bind(self);
if(depsPromiseCallback) {
depsPromiseCallback().then(function(){
return depsPromiseCallback().then(function(){
return new Promise(function(resolve, reject){
callback.apply(context, getArgArr());
resolve();
});
});
} else {
return new Promise(function(resolve, reject){
callback.apply(context, getArgArr())
resolve();
});
}
};
@@ -870,8 +891,9 @@ kit.config = kit.config || {};
*
* @param {(string|string[])} deps
* @param {function} callback
* @return {Promise}
*/
__proto.ready = function(deps, callback = undefined) {
__proto.ready = function(deps = [], callback = undefined) {
var self = this;
if(typeof deps === 'function') {
callback = deps;
@@ -880,19 +902,28 @@ kit.config = kit.config || {};
if(typeof 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) {
var promise;
var self = this;
context = context || this;
if (/complete|interactive|loaded/.test(document.readyState)) {
promise = new Promise(function(resolve, reject){
fn.apply(context, args);
resolve();
});
} else {
promise = new Promise(function(resolve, reject){
document.addEventListener("DOMContentLoaded", function () {
fn.apply(context, args);
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 {function} callback
*/
__proto.loaded = function(deps, callback = undefined) {
__proto.loaded = function(deps = [], callback = undefined) {
var self = this;
if(typeof deps === 'function') {
callback = deps;
@@ -910,19 +941,28 @@ kit.config = kit.config || {};
if(typeof 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) {
var promise;
var self = this;
context = context || this;
if (/complete|interactive|loaded/.test(document.readyState)) {
promise = new Promise(function(resolve, reject){
fn.apply(context, args);
resolve();
});
} else {
promise = new Promise(function(resolve, reject){
window.addEventListener("load", function () {
fn.apply(context, args);
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");?>
<?
if(\Bitrix\Main\Loader::includeModule('wt.core')) {
<?php
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([
'kit:config',
'kit:flex-kit',
@@ -12,11 +16,14 @@ if(\Bitrix\Main\Loader::includeModule('wt.core')) {
'kit:theme',
])->render();
}
/**
* @global CMain $APPLICATION
*/
$APPLICATION->ShowHead();
?>
<div class="kit-wrapper">
<div class="flex-list" style="--col-count: 3">
<div class="flex-list-item"><?
<div class="flex-list-item"><?php
service()->templater()->render('kit:input', [
'TYPE' => 'text',
'HINT' => '',
@@ -25,7 +32,7 @@ $APPLICATION->ShowHead();
'LABEL' => 'value = дв ковычки',
]); ?>
</div>
<div class="flex-list-item"><?
<div class="flex-list-item"><?php
service()->templater()->render('kit:input', [
'TYPE' => 'text',
'HINT' => '',
@@ -34,7 +41,7 @@ $APPLICATION->ShowHead();
'LABEL' => 'value = одинарные ковычки',
]); ?>
</div>
<div class="flex-list-item"><?
<div class="flex-list-item"><?php
service()->templater()->render('kit:input', [
'TYPE' => 'text',
'HINT' => '',
@@ -43,7 +50,7 @@ $APPLICATION->ShowHead();
'LABEL' => 'value = спецсимволы',
]); ?>
</div>
<div class="flex-list-item"><?
<div class="flex-list-item"><?php
service()->templater()->render('kit:input', [
'TYPE' => 'text',
'HINT' => '',
@@ -52,7 +59,7 @@ $APPLICATION->ShowHead();
'LABEL' => 'value = лев пр слеши, лев пр стрелки, дв од кав',
]); ?>
</div>
<div class="flex-list-item"><?
<div class="flex-list-item"><?php
service()->templater()->render('kit:input', [
'TYPE' => 'text',
'HINT' => '',