Skip to content

Commit

Permalink
Fix performance issues
Browse files Browse the repository at this point in the history
jquery include seems not to be needed anywhere. The old jquery-include caused issues.
  • Loading branch information
instantflorian committed Jan 7, 2020
1 parent 16b8912 commit a4f06ca
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 65 deletions.
2 changes: 1 addition & 1 deletion wbce/framework/class.wb.php
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ public function register_modfiles($sModfileType = "css", $sEndPosition = "fronte
if ($sModfileType == 'jquery') {
$aJqueryFiles[] = WB_URL . '/include/jquery/jquery-min.js';
$aJqueryFiles[] = WB_URL . '/include/jquery/jquery-insert.js';
$aJqueryFiles[] = WB_URL . '/include/jquery/jquery-include.js';
//$aJqueryFiles[] = WB_URL . '/include/jquery/jquery-include.js';
$aJqueryFiles[] = WB_URL . '/include/jquery/jquery-migrate-min.js';

// workout to insert ui.css and theme
Expand Down
125 changes: 61 additions & 64 deletions wbce/include/jquery/jquery-insert.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,71 @@
/* Insert Script Plugin
*
*
* Copyright (c) 2008 Kevin Martin (http://synarchydesign.com/insert)
* Licensed under the GPL license:
* http://www.gnu.org/licenses/gpl.html
/*!
* InsertLoader 1.0
*
* Copyright (c) 2016 Jonathan Nessier (https://www.neoflow.ch)
* Released under The MIT license (MIT)
*/
jQuery.insert = function(file)
{
var data = [];
var data2 = [];

if (typeof file == 'object')
{
data = file;
file = data.src !== undefined ? data.src : false;
file = file === false && data.href !== undefined ? data.href : file;
file = file === false ? file2 : false;
}

if (typeof file == 'string' && file.length)
{
var index = file.lastIndexOf('.');
var index2 = file.replace('\\', '/').lastIndexOf('/') + 1;
var ext = file.substring(index + 1, file.length);
}

switch(ext)
{
case 'js':
data2 = {
elm: 'script',
type: 'text/javascript',
src: file
};
break;

case 'css':
data2 = {
elm: 'link',
rel: 'stylesheet',
type: 'text/css',
href: file
};
break;

default:
data2 = {elm: 'link'};
break;
}
var InsertLoader = (function () {

data2.id = 'script-' + (typeof file == 'string' && file.length ?
file.substring(index2, index) : Math.round(Math.rand() * 100));
this.load = function (urls, path) {
if (!path || typeof path === 'undefined' || (typeof path === 'string' && path.length)) {
if ($.isArray(urls)) {
return loadResources(urls, path);
} else if (typeof urls === 'string') {
return loadResource(urls, path);
}
throw new Error('Multiple URLs have to be in an array or only one URL has to be a string');
}
throw new Error('Path has to be a string or empty');
};

for (var i in data)
{
data2[i] = data[i];
}
var loadResource = function (url, path) {
if (typeof url === 'string' && url.length) {

data = data2;
var tag = document.createElement(data.elm);
var extension = url.substring(url.lastIndexOf('.') + 1, url.length),
finalUrl = (path || '') + url + '?_=' + new Date().getTime(),
$head = $('head');

delete data.elm;
switch (extension) {
case 'php':
case 'js':
$head.append($('<script>', {
src: finalUrl
}));
break;
case 'css':
$head.append($('<link>', {
href: finalUrl,
rel: 'stylesheet',
type: 'test/css'
}));
break;
default:
console.warn('URL is not linking to a CSS or JS file: ' + url);
return false;
}
return true;
}
throw new Error('URL has to be a string');
};

for (i in data)
{
tag.setAttribute(i, data[i]);
}
var loadResources = function (urls, path) {
if ($.isArray(urls)) {
var result = true;
$.each(urls, function (i, url) {
if (!loadResource(url, path)) {
result = false;
}
});
return result;
}
throw new Error('Multiple URLs have to be in an array');
};

jQuery('head').append(tag);
return {
load: load
};
})();

return jQuery('#' + data.id);
$.insert = function (urls, path) {
return InsertLoader.load(urls, path);
};

0 comments on commit a4f06ca

Please sign in to comment.