mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
fix
This commit is contained in:
+66
-22
@@ -80,8 +80,11 @@ kit.config = kit.config || {};
|
||||
plugin = this.plugins[pluginId] = defaultPlugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo !!!
|
||||
*/
|
||||
if(
|
||||
this.__checkState(pluginId, stateList.installed) ||
|
||||
(this.__checkState(pluginId, stateList.installed) && typeof config.loader === 'function') ||
|
||||
(
|
||||
(plugin.stateInit.loading || this.__checkState(pluginId, stateList.loaded)) && typeof config === 'object'
|
||||
)
|
||||
@@ -96,6 +99,13 @@ kit.config = kit.config || {};
|
||||
config = plugin.config;
|
||||
config.loader = loader;
|
||||
config.type = 'loader';
|
||||
if(this.__checkState(pluginId, stateList.registered)) {
|
||||
plugin.stateInit.installing = false;
|
||||
plugin.state = stateList.registered;
|
||||
if(plugin.config.autoRequire) {
|
||||
this.require(pluginId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(typeof config === 'object') {
|
||||
@@ -152,6 +162,10 @@ kit.config = kit.config || {};
|
||||
if(!this.__checkState(pluginId, stateList.registered)) {
|
||||
plugin.state = stateList.registered;
|
||||
plugin.config.onRegister(plugin);
|
||||
var event = new CustomEvent("onRegister" + plugin.id + "Plugin", {
|
||||
"detail": {plugin: plugin}
|
||||
});
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -227,12 +241,13 @@ kit.config = kit.config || {};
|
||||
var loadNode = getFileLoadNode(src);
|
||||
if (loadNode) {
|
||||
global.config.debug && console.warn(`Скрипт ${src} уже загружен`);
|
||||
self.__ready(resolve, [loadNode]);
|
||||
// self.__ready(resolve, [loadNode]);
|
||||
resolve();
|
||||
} else {
|
||||
script = document.createElement('script');
|
||||
var script = document.createElement('script');
|
||||
script.src = '' + src + '?__pm' + (new Date()).getTime();
|
||||
script.onload = () => resolve(script);
|
||||
script.onerror = () => reject(new Error(`Ошибка загрузки скрипта ${src}`));
|
||||
script.onload = function() {resolve(script);};
|
||||
script.onerror = function() {reject(new Error(`Ошибка загрузки скрипта ${src}`));};
|
||||
document.head.append(script);
|
||||
}
|
||||
}).then(resolveCallback, rejectCallback);
|
||||
@@ -260,8 +275,9 @@ kit.config = kit.config || {};
|
||||
var loadNode = getFileLoadNode(src);
|
||||
if(loadNode){
|
||||
self.__ready(resolve, [src, true]);
|
||||
// resolve(src, true);
|
||||
} else {
|
||||
script = document.createElement('script');
|
||||
var script = document.createElement('script');
|
||||
script.src = '' + src + '?__pm' + (new Date()).getTime();
|
||||
script.onload = () => checkResolve(src, true);
|
||||
script.onerror = () => checkResolve(src, false);
|
||||
@@ -276,7 +292,8 @@ kit.config = kit.config || {};
|
||||
var loadNode = getFileLoadNode(src);
|
||||
if(loadNode) {
|
||||
global.config.debug && console.warn(`Стиль ${src} уже загружен`);
|
||||
self.__ready(resolve, [src]);
|
||||
// self.__ready(resolve, [src]);
|
||||
resolve();
|
||||
} else {
|
||||
var link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
@@ -322,14 +339,15 @@ kit.config = kit.config || {};
|
||||
}.bind(this);
|
||||
var setSkipLoadPromise = function (depsPromise) {
|
||||
|
||||
var noJsPromise, noImportPromise;
|
||||
var jsPromiseExists = true, importPromiseExists = true;
|
||||
if(configModule.js.length === 0) {
|
||||
noJsPromise = true;
|
||||
jsPromiseExists = false;
|
||||
}
|
||||
if((!configModule.module && configModule.type === 'import') || (configModule.type === 'loader' && typeof configModule.loader === 'function')) {
|
||||
noImportPromise = true;
|
||||
importPromiseExists = false;
|
||||
}
|
||||
plugin.skipLoadPromise = noImportPromise && noJsPromise && !depsPromise;
|
||||
plugin.skipLoadPromise = !importPromiseExists && !jsPromiseExists && !depsPromise;
|
||||
|
||||
return plugin.skipLoadPromise;
|
||||
}.bind(this);
|
||||
|
||||
@@ -358,6 +376,10 @@ kit.config = kit.config || {};
|
||||
plugin.state = stateList.loaded;
|
||||
plugin.skipLoadPromise = true;
|
||||
configModule.onLoad.call(plugin.module.exports);
|
||||
var event = new CustomEvent("onLoad" + plugin.id + "Plugin", {
|
||||
"detail": {plugin: plugin}
|
||||
});
|
||||
document.dispatchEvent(event);
|
||||
callback();
|
||||
}.bind(this));
|
||||
|
||||
@@ -420,20 +442,37 @@ kit.config = kit.config || {};
|
||||
}.bind(this))
|
||||
}
|
||||
}.bind(this);
|
||||
var installed = false;
|
||||
/**
|
||||
* @todo !!!
|
||||
*/
|
||||
if(plugin.config.type === moduleTypeList.loader && typeof plugin.config.loader === 'function') {
|
||||
var returnData = plugin.config.loader.bind(module.exports).call(module.exports, module, module.exports, this.require.bind(this), global);
|
||||
// var returnData = plugin.config.loader.bind(module.exports).call(module.exports, module, module.exports, this.require.bind(this), global);
|
||||
var returnData = plugin.config.loader.bind(window).call(module.exports, module, module.exports, this.require.bind(this), global);
|
||||
setGlobalExtension(pluginId, plugin.config.alias, returnData);
|
||||
|
||||
installed = true;
|
||||
} else if(plugin.config.type === moduleTypeList.import && typeof plugin.config.module === 'string') {
|
||||
setGlobalExtension(pluginId, plugin.config.alias, (typeof module.exports === 'object' && module.exports.default !== undefined)?module.exports.default:module.exports);
|
||||
installed = true;
|
||||
}
|
||||
console.log('%cPluginManager.install: plugin ' + pluginId + ' установлен', "color: green;");
|
||||
plugin.state = stateList.installed;
|
||||
if(installed){
|
||||
console.log('%cPluginManager.install: plugin ' + pluginId + ' установлен', "color: green;");
|
||||
plugin.state = stateList.installed;
|
||||
}
|
||||
|
||||
return installed;
|
||||
}.bind(this);
|
||||
|
||||
this.__exec(pluginId, function(){
|
||||
installer();
|
||||
plugin.config.onInstall.call(module.exports, plugin);
|
||||
if(!this.__checkState(pluginId, stateList.installed)) {
|
||||
if(installer()){
|
||||
plugin.config.onInstall.call(module.exports, plugin);
|
||||
var event = new CustomEvent("onInstall" + plugin.id + "Plugin", {
|
||||
"detail": {plugin: plugin}
|
||||
});
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
callback();
|
||||
}.bind(this));
|
||||
|
||||
@@ -445,6 +484,7 @@ kit.config = kit.config || {};
|
||||
* @param {string} pluginId
|
||||
* @param {callback} callback
|
||||
* @return {boolean}
|
||||
* @memberOf {kit}
|
||||
*/
|
||||
__proto.require = function (pluginId, callback) {
|
||||
|
||||
@@ -536,13 +576,13 @@ kit.config = kit.config || {};
|
||||
|
||||
__proto.__exec = function (pluginId, callback, argArr = []) {
|
||||
|
||||
var module = this.plugins[pluginId];
|
||||
var plugin = this.plugins[pluginId];
|
||||
|
||||
var exec = function(_callback, argArr){
|
||||
if(module.skipLoadPromise) {
|
||||
if(plugin.skipLoadPromise) {
|
||||
_callback.apply(this, argArr);
|
||||
} else {
|
||||
module.promise = module.promise.then(function(){
|
||||
plugin.promise = plugin.promise.then(function(){
|
||||
_callback.apply(this, argArr);
|
||||
}.bind(this));
|
||||
}
|
||||
@@ -575,9 +615,11 @@ kit.config = kit.config || {};
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {(string|string[])} deps
|
||||
* @param {function} callback
|
||||
* @memberOf kit
|
||||
*/
|
||||
__proto.ready = function(deps, callback) {
|
||||
__proto.ready = function(deps, callback = undefined) {
|
||||
if(typeof deps === 'function') {
|
||||
callback = deps;
|
||||
deps = [];
|
||||
@@ -657,7 +699,9 @@ kit.config = kit.config || {};
|
||||
global.ready = manager.ready.bind(manager);
|
||||
global.exec = manager.exec.bind(manager);
|
||||
global.require = manager.require.bind(manager);
|
||||
/** @type {kit} */
|
||||
/**
|
||||
* @var __pmGlobal__
|
||||
*/
|
||||
window.__pmGlobal__ = global;
|
||||
})(kit);
|
||||
|
||||
|
||||
@@ -28,11 +28,12 @@ __PluginManager__.registerPlugins({
|
||||
module: '/support.js',
|
||||
type: 'loader',
|
||||
},
|
||||
jQuery: {
|
||||
jquery: {
|
||||
path: __pmConfig__.assetsPath + '/jquery',
|
||||
module: '/jquery.min.js',
|
||||
type: 'loader',
|
||||
alias: '$',
|
||||
alias: ['$', 'jQuery'],
|
||||
autoRequire: true,
|
||||
},
|
||||
popper: {
|
||||
path: __pmConfig__.assetsPath + '/popper',
|
||||
@@ -132,7 +133,7 @@ __PluginManager__.registerPlugins({
|
||||
module: '/toolkit.js',
|
||||
type: 'loader',
|
||||
css: ['/toolkit.css'],
|
||||
deps: ['jQuery', 'mask'],
|
||||
deps: ['jQuery', 'mask', 'support'],
|
||||
},
|
||||
Modal: {
|
||||
path: __pmConfig__.assetsPath + '/modal',
|
||||
@@ -317,7 +318,44 @@ __PluginManager__.registerPlugins({
|
||||
alias: ['mustache.js'],
|
||||
js: '/mustache.js',
|
||||
deps: [],
|
||||
}
|
||||
},
|
||||
bxSlider: {
|
||||
path: __pmConfig__.assetsPath + '/bxSlider',
|
||||
module: '/jquery.bxslider.min.js',
|
||||
css: [
|
||||
'/jquery.bxslider.min.css',
|
||||
],
|
||||
type: 'import',
|
||||
deps: ['jQuery'],
|
||||
},
|
||||
selectric: {
|
||||
path: __pmConfig__.assetsPath + '/selectric',
|
||||
module: '/jquery.selectric.min.js',
|
||||
css: [
|
||||
'/selectric.css',
|
||||
],
|
||||
type: 'import',
|
||||
alias: ['jquerySelectric'],
|
||||
deps: ['jQuery'],
|
||||
},
|
||||
jBox: {
|
||||
path: __pmConfig__.assetsPath + '/jBox',
|
||||
module: '/jBox.min.js',
|
||||
css: [
|
||||
'/jBox.min.css',
|
||||
],
|
||||
type: 'import',
|
||||
deps: ['jQuery'],
|
||||
},
|
||||
intlTelInput: {
|
||||
path: __pmConfig__.assetsPath + '/intl-tel-input',
|
||||
module: '/js/intlTelInput.min.js',
|
||||
css: [
|
||||
'/css/intlTelInput.min.css',
|
||||
],
|
||||
type: 'import',
|
||||
alias: ['intl-tel-input'],
|
||||
},
|
||||
});
|
||||
|
||||
__pmConfig__.debug && (function(){
|
||||
|
||||
Reference in New Issue
Block a user