-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfila_content_replace_script.js
More file actions
91 lines (88 loc) · 3.26 KB
/
fila_content_replace_script.js
File metadata and controls
91 lines (88 loc) · 3.26 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var swastik;
var filesExecuted = false;
var CONTENTREPLACE = CONTENTREPLACE || (function() {
var _args = {}; // private
return {
init: function(Args) {
_args = Args;
// some other initialising
},
executeAjaxCall: function() {
jQuery(document).ready(function() {
var allContentLoaded = false;
jQuery(_args[1]).empty();
jQuery(_args[1]).addClass('CORScontentIsLoading');
jQuery(_args[1]).append('<div class="CORScontentLoaderDiv">Loading Your Content Please wait...</div>');
function Exception(type, message) {
this.message = message;
this.name = type;
}
jQuery.ajax({
url: _args[0],
type: "GET",
dataType: "html",
success: function(data) {
data = data.replace(/\n/g, "");
jQueryobj = jQuery(data);
var scriptsArray = [];
var stylesArray = [];
jQueryobj.each(function(key, item) {
if (item.nodeName === 'BASE') {
jQuery('head').append(item);
// Appending the base tag on head tag
}
if (item.nodeName === 'SCRIPT') {
scriptsArray.push(item);
//Collecting all the script tags
}
if (item.nodeName === 'STYLE') {
jQuery('head').append(item);
//Appending all the styles tag
}
});
jQueryobj.each(function(key, item) {
if (item.className === 'mainContentRegion') {
jQuery(_args[1]).append(item);
//Appending the HTML
}
});
//First of adding Drupal.settings to an array
scriptsArray.forEach(function(d, i) {
if (d.getAttribute('src') === null) {
jQuery('body').append(d);
if (d.innerHTML.indexOf('Drupal.settings') > -1) {
var drupalSettingsJSON = d.innerHTML.substring(d.innerHTML.indexOf('jQuery.extend(Drupal.settings,'), d.innerHTML.indexOf('//--><!]]>'));
swastik = drupalSettingsJSON;
}
}
});
//After that adding all scripts other than custom.js and contentreplace.js
var url = jQuery('base').attr('href');
function getScripts(i) {
if (scriptsArray[i] !== undefined) {
//Only getting local scripts
if (scriptsArray[i].getAttribute('src') !== null && scriptsArray[i].getAttribute('src').indexOf('http://') === -1) {
var req_arr = url + scriptsArray[i].getAttribute('src');
jQuery.getScript(req_arr, function() {
getScripts(i + 1);
});
} else {
getScripts(i + 1);
}
}
else{
if(jQuery(_args[1]).hasClass('CORScontentIsLoading')){
eval(Drupal.attachBehaviors(document, Drupal.settings));
}
}
}
getScripts(0);
},
error: function(xhr, status) {
console.log("Sorry, there was a problem! Status " + status);
}
});
});
}
};
}());