-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jquery include seems not to be needed anywhere. The old jquery-include caused issues.
- Loading branch information
1 parent
16b8912
commit a4f06ca
Showing
2 changed files
with
62 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |