-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFrontEndEditLightboxLoad.js
57 lines (50 loc) · 1.92 KB
/
FrontEndEditLightboxLoad.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*!
* Front-End Edit Lightbox (FEEL) for ProcessWire
* https://goo.gl/wTeQ4z
*/
var siteModules = (window.FEEL_defaults && window.FEEL_defaults.siteModules) ? window.FEEL_defaults.siteModules : '/site/modules/';
var wireModules = (window.FEEL_defaults && window.FEEL_defaults.wireModules) ? window.FEEL_defaults.wireModules : '/wire/modules/';
function FEEL_loadAssets(items) {
var item = null;
var load = true;
function FEEL_itemOnLoad() {
if(item && load && typeof item.after !== "undefined") {
// console.log('FEEL: loaded ' + item.file);
item.after();
}
if(!items.length) return;
item = items.shift();
load = typeof item.test === "undefined" || item.test();
if(load) {
FEEL_loadItem(item);
} else {
FEEL_itemOnLoad();
}
}
function FEEL_loadItem(item) {
var script = document.createElement('script');
script.onload = FEEL_itemOnLoad;
script.src = item.file;
document.body.appendChild(script);
}
FEEL_itemOnLoad();
}
// to play nice with PageFrontEdit that is also loading JqueryCore
setTimeout(function () {
FEEL_loadAssets([{
'test': function() { return (typeof jQuery === 'undefined'); },
'file': wireModules + 'Jquery/JqueryCore/JqueryCore.js',
'after': function() { jQuery.noConflict(); }
},{
'test': function() { return (typeof jQuery.magnificPopup === 'undefined'); },
'file': wireModules + 'Jquery/JqueryMagnific/JqueryMagnific.js',
'after': function() {
var asset = document.createElement('link');
asset.rel = 'stylesheet';
asset.href = wireModules + 'Jquery/JqueryMagnific/JqueryMagnific.css';
document.getElementsByTagName('head')[0].appendChild(asset);
}
},{
'file': siteModules + 'FrontEndEditLightbox/FrontEndEditLightbox.js'
}]);
}, 100);