update libraries to latest
This commit is contained in:
parent
5f6984123f
commit
bec7710bdc
9 changed files with 240 additions and 105 deletions
130
js/Window/DOMLoader.XMLHttp.js
Normal file
130
js/Window/DOMLoader.XMLHttp.js
Normal file
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
|
||||
DOMLoader.XMLHttp
|
||||
--------------------------
|
||||
DOMLoader.sendRequest({
|
||||
url: "./dir/something.extension",
|
||||
data: "test!",
|
||||
onerror: function(event) {
|
||||
console.log(event);
|
||||
},
|
||||
onload: function(response) {
|
||||
console.log(response.responseText);
|
||||
},
|
||||
onprogress: function (event) {
|
||||
var percent = event.loaded / event.total * 100 >> 0;
|
||||
loader.message("loading: " + percent + "%");
|
||||
}
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
if (typeof(DOMLoader) === "undefined") var DOMLoader = {};
|
||||
|
||||
// Add XMLHttpRequest when not available
|
||||
|
||||
if (typeof (XMLHttpRequest) === "undefined") {
|
||||
var XMLHttpRequest;
|
||||
(function () { // find equivalent for IE
|
||||
var factories = [
|
||||
function () {
|
||||
return new ActiveXObject("Msxml2.XMLHTTP")
|
||||
}, function () {
|
||||
return new ActiveXObject("Msxml3.XMLHTTP")
|
||||
}, function () {
|
||||
return new ActiveXObject("Microsoft.XMLHTTP")
|
||||
}];
|
||||
for (var i = 0; i < factories.length; i++) {
|
||||
try {
|
||||
factories[i]();
|
||||
} catch (e) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
XMLHttpRequest = factories[i];
|
||||
})();
|
||||
}
|
||||
|
||||
if (typeof ((new XMLHttpRequest()).responseText) === "undefined") {
|
||||
// http://stackoverflow.com/questions/1919972/how-do-i-access-xhr-responsebody-for-binary-data-from-javascript-in-ie
|
||||
var IEBinaryToArray_ByteStr_Script =
|
||||
"<!-- IEBinaryToArray_ByteStr -->\r\n"+
|
||||
"<script type='text/vbscript'>\r\n"+
|
||||
"Function IEBinaryToArray_ByteStr(Binary)\r\n"+
|
||||
" IEBinaryToArray_ByteStr = CStr(Binary)\r\n"+
|
||||
"End Function\r\n"+
|
||||
"Function IEBinaryToArray_ByteStr_Last(Binary)\r\n"+
|
||||
" Dim lastIndex\r\n"+
|
||||
" lastIndex = LenB(Binary)\r\n"+
|
||||
" if lastIndex mod 2 Then\r\n"+
|
||||
" IEBinaryToArray_ByteStr_Last = Chr( AscB( MidB( Binary, lastIndex, 1 ) ) )\r\n"+
|
||||
" Else\r\n"+
|
||||
" IEBinaryToArray_ByteStr_Last = "+'""'+"\r\n"+
|
||||
" End If\r\n"+
|
||||
"End Function\r\n"+
|
||||
"</script>\r\n";
|
||||
|
||||
// inject VBScript
|
||||
document.write(IEBinaryToArray_ByteStr_Script);
|
||||
|
||||
DOMLoader.sendRequest = function(conf) {
|
||||
// helper to convert from responseBody to a "responseText" like thing
|
||||
function getResponseText(binary) {
|
||||
var byteMapping = {};
|
||||
for (var i = 0; i < 256; i++) {
|
||||
for (var j = 0; j < 256; j++) {
|
||||
byteMapping[String.fromCharCode(i + j * 256)] = String.fromCharCode(i) + String.fromCharCode(j);
|
||||
}
|
||||
}
|
||||
// call into VBScript utility fns
|
||||
var rawBytes = IEBinaryToArray_ByteStr(binary);
|
||||
var lastChr = IEBinaryToArray_ByteStr_Last(binary);
|
||||
return rawBytes.replace(/[\s\S]/g, function (match) {
|
||||
return byteMapping[match];
|
||||
}) + lastChr;
|
||||
};
|
||||
//
|
||||
var req = XMLHttpRequest();
|
||||
req.open("GET", conf.url, true);
|
||||
if (conf.responseType) req.responseType = conf.responseType;
|
||||
if (conf.onerror) req.onerror = conf.onerror;
|
||||
if (conf.onprogress) req.onprogress = conf.onprogress;
|
||||
req.onreadystatechange = function (event) {
|
||||
if (req.readyState === 4) {
|
||||
if (req.status === 200) {
|
||||
req.responseText = getResponseText(req.responseBody);
|
||||
} else {
|
||||
req = false;
|
||||
}
|
||||
if (conf.onload) conf.onload(req);
|
||||
}
|
||||
};
|
||||
req.setRequestHeader("Accept-Charset", "x-user-defined");
|
||||
req.send(null);
|
||||
return req;
|
||||
}
|
||||
} else {
|
||||
DOMLoader.sendRequest = function(conf) {
|
||||
var req = new XMLHttpRequest();
|
||||
req.open(conf.data ? "POST" : "GET", conf.url, true);
|
||||
if (req.overrideMimeType) req.overrideMimeType("text/plain; charset=x-user-defined");
|
||||
if (conf.data) req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
||||
if (conf.responseType) req.responseType = conf.responseType;
|
||||
if (conf.onerror) req.onerror = conf.onerror;
|
||||
if (conf.onprogress) req.onprogress = conf.onprogress;
|
||||
req.onreadystatechange = function (event) {
|
||||
if (req.readyState === 4) {
|
||||
if (req.status !== 200 && req.status != 304) {
|
||||
if (conf.onerror) conf.onerror(event, false);
|
||||
return;
|
||||
}
|
||||
if (conf.onload) {
|
||||
conf.onload(req);
|
||||
}
|
||||
}
|
||||
};
|
||||
req.send(conf.data);
|
||||
return req;
|
||||
};
|
||||
}
|
187
js/Window/DOMLoader.script.js
Normal file
187
js/Window/DOMLoader.script.js
Normal file
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
----------------------------------------------------
|
||||
DOMLoader.script.js : 0.1.2 : 2012/09/08 : http://mudcu.be
|
||||
----------------------------------------------------
|
||||
Copyright 2011-2012 Mudcube. All rights reserved.
|
||||
----------------------------------------------------
|
||||
/// No verification
|
||||
DOMLoader.script.add("../js/jszip/jszip.js");
|
||||
/// Strict loading order and verification.
|
||||
DOMLoader.script.add({
|
||||
strictOrder: true,
|
||||
srcs: [
|
||||
{
|
||||
src: "../js/jszip/jszip.js",
|
||||
verify: "JSZip",
|
||||
callback: function() {
|
||||
console.log(1)
|
||||
}
|
||||
},
|
||||
{
|
||||
src: "../inc/downloadify/js/swfobject.js",
|
||||
verify: "swfobject",
|
||||
callback: function() {
|
||||
console.log(2)
|
||||
}
|
||||
}
|
||||
],
|
||||
callback: function() {
|
||||
console.log(3)
|
||||
}
|
||||
});
|
||||
/// Just verification.
|
||||
DOMLoader.script.add({
|
||||
src: "../js/jszip/jszip.js",
|
||||
verify: "JSZip",
|
||||
callback: function() {
|
||||
console.log(1)
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
if (typeof(DOMLoader) === "undefined") var DOMLoader = {};
|
||||
|
||||
(function() { "use strict";
|
||||
|
||||
DOMLoader.script = function() {
|
||||
this.loaded = {};
|
||||
this.loading = {};
|
||||
return this;
|
||||
};
|
||||
|
||||
DOMLoader.script.prototype.add = function(config) {
|
||||
var that = this;
|
||||
if (typeof(config) === "string") {
|
||||
config = { src: config };
|
||||
}
|
||||
var srcs = config.srcs;
|
||||
if (typeof(srcs) === "undefined") {
|
||||
srcs = [{
|
||||
src: config.src,
|
||||
verify: config.verify
|
||||
}];
|
||||
}
|
||||
/// adding the elements to the head
|
||||
var doc = document.getElementsByTagName("head")[0];
|
||||
///
|
||||
var testElement = function(element, test) {
|
||||
if (that.loaded[element.src]) return;
|
||||
if (test && typeof(window[test]) === "undefined") return;
|
||||
that.loaded[element.src] = true;
|
||||
//
|
||||
if (that.loading[element.src]) that.loading[element.src]();
|
||||
delete that.loading[element.src];
|
||||
//
|
||||
if (element.callback) element.callback();
|
||||
if (typeof(getNext) !== "undefined") getNext();
|
||||
};
|
||||
///
|
||||
var batchTest = [];
|
||||
var addElement = function(element) {
|
||||
if (typeof(element) === "string") {
|
||||
element = {
|
||||
src: element,
|
||||
verify: config.verify
|
||||
};
|
||||
}
|
||||
if (/([\w\d.])$/.test(element.verify)) { // check whether its a variable reference
|
||||
element.test = element.verify;
|
||||
if (typeof(element.test) === "object") {
|
||||
for (var key in element.test) {
|
||||
batchTest.push(element.test[key]);
|
||||
}
|
||||
} else {
|
||||
batchTest.push(element.test);
|
||||
}
|
||||
}
|
||||
if (that.loaded[element.src]) return;
|
||||
var script = document.createElement("script");
|
||||
script.onreadystatechange = function() {
|
||||
if (this.readyState !== "loaded" && this.readyState !== "complete") return;
|
||||
testElement(element);
|
||||
};
|
||||
script.onload = function() {
|
||||
testElement(element);
|
||||
};
|
||||
script.onerror = function() {
|
||||
|
||||
};
|
||||
script.setAttribute("type", "text/javascript");
|
||||
script.setAttribute("src", element.src);
|
||||
doc.appendChild(script);
|
||||
that.loading[element.src] = function() {};
|
||||
};
|
||||
/// checking to see whether everything loaded properly
|
||||
var onLoad = function(element) {
|
||||
if (element) {
|
||||
testElement(element, element.test);
|
||||
} else {
|
||||
for (var n = 0; n < srcs.length; n ++) {
|
||||
testElement(srcs[n], srcs[n].test);
|
||||
}
|
||||
}
|
||||
var istrue = true;
|
||||
for (var n = 0; n < batchTest.length; n ++) {
|
||||
var test = batchTest[n];
|
||||
if (test && test.indexOf(".") !== -1) {
|
||||
test = test.split(".");
|
||||
var level0 = window[test[0]];
|
||||
if (typeof(level0) === "undefined") continue;
|
||||
if (test.length === 2) { //- this is a bit messy and could handle more cases
|
||||
if (typeof(level0[test[1]]) === "undefined") {
|
||||
istrue = false;
|
||||
}
|
||||
} else if (test.length === 3) {
|
||||
if (typeof(level0[test[1]][test[2]]) === "undefined") {
|
||||
istrue = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (typeof(window[test]) === "undefined") {
|
||||
istrue = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!config.strictOrder && istrue) { // finished loading all the requested scripts
|
||||
if (config.callback) config.callback();
|
||||
} else { // keep calling back the function
|
||||
setTimeout(function() { //- should get slower over time?
|
||||
onLoad(element);
|
||||
}, 10);
|
||||
}
|
||||
};
|
||||
/// loading methods; strict ordering or loose ordering
|
||||
if (config.strictOrder) {
|
||||
var ID = -1;
|
||||
var getNext = function() {
|
||||
ID ++;
|
||||
if (!srcs[ID]) { // all elements are loaded
|
||||
if (config.callback) config.callback();
|
||||
} else { // loading new script
|
||||
var element = srcs[ID];
|
||||
var src = element.src;
|
||||
if (that.loading[src]) { // already loading from another call (attach to event)
|
||||
that.loading[src] = function() {
|
||||
if (element.callback) element.callback();
|
||||
getNext();
|
||||
}
|
||||
} else if (!that.loaded[src]) { // create script element
|
||||
addElement(element);
|
||||
onLoad(element);
|
||||
} else { // it's already been successfully loaded
|
||||
getNext();
|
||||
}
|
||||
}
|
||||
};
|
||||
getNext();
|
||||
} else { // loose ordering
|
||||
for (var ID = 0; ID < srcs.length; ID ++) {
|
||||
addElement(srcs[ID]);
|
||||
}
|
||||
onLoad();
|
||||
}
|
||||
};
|
||||
|
||||
DOMLoader.script = (new DOMLoader.script());
|
||||
|
||||
})();
|
1756
js/Window/Event.js
Normal file
1756
js/Window/Event.js
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue