-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdavid.bootstrap.text.js
More file actions
118 lines (105 loc) · 3.79 KB
/
david.bootstrap.text.js
File metadata and controls
118 lines (105 loc) · 3.79 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*====================================
Text plugin will load the required file as a text file.
====================================*/
require.config({debug : true});
define(function(){
// REGEX FROM requirejs text plugin
var m_oXmlRegExp = /^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im;
var m_oBodyRegExp = /<body[^>]*>\s*([\s\S]+)\s*<\/body>/im;
var m_aLoading = [];
/**
* Gets the actual MSXML object, this function executes once and
* optimised itself based on the results. jquery may or may not be loaded
* at this point, so we will just make the assumption that it is not and
* create our own request
*/
var getXHTTPRequest = (function()
{
// Create the connector
if (window.XMLHttpRequest)
{
getXHTTPRequest = function()
{
try
{
return new XMLHttpRequest();
}
catch (ex)
{
console.error(ex);
}
};
return getXHTTPRequest;
}
else if (window.ActiveXObject)
{
// MS Browser
var laMSXML = new Array('Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.5.0',
'Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0',
'Msxml2.XMLHTTP','Microsoft.XMLHTTP');
for (var i=0, lnLength = laMSXML.length; i<lnLength; i++)
{
try
{
var loReturn = new ActiveXObject(laMSXML[i]);
if (loReturn != null)
{
getXHTTPRequest = function()
{
return new ActiveXObject(laMSXML[i]);
}
return loReturn;
}
}
catch (e)
{
// No need to log anything here as we are just figuring out the right object to use
}
}
}
// It could not be created, so we need to inform the user.
getXHTTPRequest = function()
{
console.error("Your browser doesn't seem to support XMLHttpRequests");
return null;
}
return getXHTTPRequest;
})();
return {
onLoaded : function (toModule)
{
// Do nothing here as it is handled in the completeLoad function
},
load : function (toModule)
{
var loSelf = this;
toModule.forceJS(/\.js$/.exec(toModule.getName()));
// Instead of loading through normal means, we will use an ajax request
var loRequest = getXHTTPRequest();
loRequest.open("GET", toModule.getURL(), true);
loRequest.onreadystatechange = function (toEvent)
{
// Wait for the completed resoure
if (loRequest.readyState === 4)
{
// The content has completed the load so we can clean up and notify
loSelf.completeLoad(toModule, loRequest.responseText);
}
};
loRequest.send(null);
},
completeLoad : function(toModule, tcResult)
{
tcResult = tcResult || "";
tcResult = tcResult.replace(m_oXmlRegExp, "");
var loMatches = tcResult.match(m_oBodyRegExp);
tcResult = loMatches ? loMatches[0] : tcResult;
// Create a tag for the content
var loTag = document.createElement("div");
loTag.innerHTML = tcResult;
toModule.setTag(loTag);
toModule.setDefinition(loTag);
toModule.complete();
}
};
}, true);