mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
fix
This commit is contained in:
+26
-6
@@ -147,6 +147,7 @@ kit.config = kit.config || {};
|
||||
}
|
||||
|
||||
config.loadJsAfterModule = !!config.loadJsAfterModule;
|
||||
config.isSetTimestamp = config.hasOwnProperty('isSetTimestamp')?!!config.isSetTimestamp:true;
|
||||
config.type = config.type || 'import'; //loader
|
||||
|
||||
if(typeof config.deps === 'string') {
|
||||
@@ -231,13 +232,14 @@ kit.config = kit.config || {};
|
||||
}
|
||||
|
||||
function loadScript(src, resolveCallback, rejectCallback) {
|
||||
var originSrc = src;
|
||||
src = String(src).split('?')[0];
|
||||
if(typeof resolveCallback !== 'function'){
|
||||
resolveCallback = function(){};
|
||||
}
|
||||
if(typeof rejectCallback !== 'function'){
|
||||
rejectCallback = function(res){
|
||||
console.warn(res.message);
|
||||
console.warn(res.message, originSrc);
|
||||
};
|
||||
}
|
||||
return new Promise(function(resolve, reject) {
|
||||
@@ -248,7 +250,17 @@ kit.config = kit.config || {};
|
||||
resolve();
|
||||
} else {
|
||||
var script = document.createElement('script');
|
||||
script.src = '' + src + '?__pm' + (new Date()).getTime();
|
||||
|
||||
try {
|
||||
var url = new URL(originSrc);
|
||||
if(plugin.config.isSetTimestamp){
|
||||
url.searchParams.append('__pm', (new Date()).getTime());
|
||||
}
|
||||
script.src = url.toString();
|
||||
} catch (e) {
|
||||
script.src = '' + src + '?__pm' + ((new Date()).getTime());
|
||||
}
|
||||
|
||||
script.onload = function() {resolve(script);};
|
||||
script.onerror = function() {reject(new Error(`Ошибка загрузки скрипта ${src}`));};
|
||||
document.head.append(script);
|
||||
@@ -435,10 +447,9 @@ kit.config = kit.config || {};
|
||||
if(data === undefined) {
|
||||
return;
|
||||
}
|
||||
if(this.global.hasOwnProperty(key)) {
|
||||
console.warn(`PluginManager.install(${pluginId}): key ${key} overwritten in kit (${plugin.state}).`);
|
||||
if(!this.global.hasOwnProperty(key)) {
|
||||
this.global[key] = data;
|
||||
}
|
||||
this.global[key] = data;
|
||||
if(Array.isArray(aliasList) && aliasList.length) {
|
||||
aliasList.forEach(function (alias) {
|
||||
setGlobalExtension(alias, [], data)
|
||||
@@ -452,7 +463,10 @@ kit.config = kit.config || {};
|
||||
var returnData;
|
||||
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);
|
||||
returnData = plugin.config.loader.bind(window).call(module.exports, module, module.exports, this.require.bind(this), global);
|
||||
returnData = plugin.config.loader.bind(this.global).call(this.global, module, module.exports, this.require.bind(this), this.global);
|
||||
if(returnData === undefined && module.exports){
|
||||
returnData = module.exports;
|
||||
}
|
||||
setGlobalExtension(pluginId, plugin.config.alias, returnData);
|
||||
} else if(plugin.config.type === moduleTypeList.import && typeof plugin.config.module === 'string') {
|
||||
returnData = (typeof module.exports === 'object' && module.exports.default !== undefined)?module.exports.default:module.exports;
|
||||
@@ -679,6 +693,12 @@ kit.config = kit.config || {};
|
||||
defaultPhoneMask: '+7 (999) 999-99-99',
|
||||
};
|
||||
|
||||
var script = document.currentScript;
|
||||
if(script){
|
||||
var path = script.src.split('?')[0];
|
||||
defaultConfig.assetsPath = path.split('/').slice(0, -2).join('/');
|
||||
}
|
||||
|
||||
var manager = new PluginManager(global);
|
||||
manager.register('PluginManager', {
|
||||
alias: 'pm',
|
||||
|
||||
@@ -365,6 +365,14 @@ __PluginManager__.registerPlugins({
|
||||
type: 'import',
|
||||
alias: ['intl-tel-input'],
|
||||
},
|
||||
autoComplete: {
|
||||
path: __pmConfig__.assetsPath + '/autoComplete',
|
||||
module: '/autoComplete.min.js',
|
||||
css: [
|
||||
'/css/autoComplete.css',
|
||||
],
|
||||
type: 'loader',
|
||||
},
|
||||
});
|
||||
|
||||
__pmConfig__.debug && (function(){
|
||||
|
||||
Reference in New Issue
Block a user