mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-06 15:04:58 +00:00
Update webloader.js
This commit is contained in:
parent
469c1d41aa
commit
1b91503d7e
182
webloader.js
182
webloader.js
|
@ -1,86 +1,82 @@
|
|||
/*
|
||||
* webloader.js
|
||||
*/
|
||||
|
||||
var FILE = require('lib/file');
|
||||
|
||||
// https://stackoverflow.com/questions/597268/element-prototype-in-ie7
|
||||
if (!window.Element) {
|
||||
Element = function() {};
|
||||
|
||||
var __createElement = document.createElement;
|
||||
document.createElement = function(tagName) {
|
||||
var element = __createElement(tagName);
|
||||
for (var key in Element.prototype) {
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
for (var key in Element.prototype)
|
||||
element[key] = Element.prototype[key];
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
var __getElementById = document.getElementById;
|
||||
document.getElementById = function(id) {
|
||||
var element = __getElementById(id);
|
||||
for (var key in Element.prototype) {
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
for (var key in Element.prototype)
|
||||
element[key] = Element.prototype[key];
|
||||
}
|
||||
return element;
|
||||
}
|
||||
}
|
||||
|
||||
// https://gist.github.com/jonathantneal/3748027
|
||||
if (!window.addEventListener) {
|
||||
(function(WindowPrototype, DocumentPrototype, ElementPrototype, registry) {
|
||||
DocumentPrototype.head = (function() {
|
||||
return DocumentPrototype.getElementsByTagName("head")[0];
|
||||
})();
|
||||
(function(WindowPrototype, DocumentPrototype, ElementPrototype, registry) {
|
||||
DocumentPrototype.head = (function() {
|
||||
return DocumentPrototype.getElementsByTagName("head")[0];
|
||||
})();
|
||||
|
||||
var addEventListener = function(type, listener) {
|
||||
var target = this;
|
||||
var inject = function(obj, registry) {
|
||||
obj.addEventListener = function(type, listener) {
|
||||
var target = this;
|
||||
|
||||
registry.unshift([target, type, listener, function(event) {
|
||||
event.currentTarget = target;
|
||||
event.preventDefault = function() {
|
||||
event.returnValue = false
|
||||
};
|
||||
event.stopPropagation = function() {
|
||||
event.cancelBubble = true
|
||||
};
|
||||
event.target = event.srcElement || target;
|
||||
registry.unshift([target, type, listener, function(event) {
|
||||
event.currentTarget = target;
|
||||
event.preventDefault = function() {
|
||||
event.returnValue = false
|
||||
};
|
||||
event.stopPropagation = function() {
|
||||
event.cancelBubble = true
|
||||
};
|
||||
event.target = event.srcElement || target;
|
||||
|
||||
listener.call(target, event);
|
||||
}]);
|
||||
listener.call(target, event);
|
||||
}]);
|
||||
|
||||
this.attachEvent("on" + type, registry[0][3]);
|
||||
};
|
||||
WindowPrototype.addEventListener = addEventListener;
|
||||
DocumentPrototype.addEventListener = addEventListener;
|
||||
ElementPrototype.ElementPrototype = addEventListener;
|
||||
this.attachEvent("on" + type, registry[0][3]);
|
||||
};
|
||||
|
||||
var removeEventListener = function(type, listener) {
|
||||
for (var index = 0, register; register = registry[index]; ++index) {
|
||||
if (register[0] == this && register[1] == type && register[2] == listener) {
|
||||
return this.detachEvent("on" + type, registry.splice(index, 1)[0][3]);
|
||||
obj.removeEventListener = function(type, listener) {
|
||||
for (var index = 0, register; register = registry[index]; ++index) {
|
||||
if (register[0] == this && register[1] == type && register[2] == listener) {
|
||||
return this.detachEvent("on" + type, registry.splice(index, 1)[0][3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
WindowPrototype.removeEventListener = removeEventListener;
|
||||
DocumentPrototype.removeEventListener = removeEventListener;
|
||||
ElementPrototype.removeEventListener = removeEventListener;
|
||||
};
|
||||
|
||||
var dispatchEvent = function(eventObject) {
|
||||
return this.fireEvent("on" + eventObject.type, eventObject);
|
||||
obj.dispatchEvent = function(eventObject) {
|
||||
return this.fireEvent("on" + eventObject.type, eventObject);
|
||||
};
|
||||
};
|
||||
WindowPrototype.dispatchEvent = dispatchEvent;
|
||||
DocumentPrototype.dispatchEvent = dispatchEvent;
|
||||
ElementPrototype.dispatchEvent = dispatchEvent;
|
||||
|
||||
inject(WindowPrototype, registry);
|
||||
inject(DocumentPrototype, registry);
|
||||
inject(ElementPrototype, registry);
|
||||
})(window, document, Element.prototype, []);
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/10964966/detect-ie-version-prior-to-v9-in-javascript
|
||||
// https://stackoverflow.com/a/18249612
|
||||
var IEVersion = (function() {
|
||||
var undef,
|
||||
v = 3,
|
||||
var undef,
|
||||
v = 3,
|
||||
div = document.createElement('div'),
|
||||
all = div.getElementsByTagName('i');
|
||||
|
||||
|
@ -94,85 +90,75 @@ var IEVersion = (function() {
|
|||
|
||||
return {
|
||||
setWindowDraggable: function() {
|
||||
// https://stackoverflow.com/questions/21493777/how-to-make-a-tab-to-move-the-window-of-an-hta-application-in-vbscript
|
||||
// https://stackoverflow.com/a/21497175
|
||||
var grip = document.getElementById('app'),
|
||||
oX, oY,
|
||||
mouseDown = function (e) {
|
||||
mouseDown = function(e) {
|
||||
if (e.offsetY + e.offsetX < 0) return;
|
||||
oX = e.screenX;
|
||||
oY = e.screenY;
|
||||
window.addEventListener('mousemove', mouseMove);
|
||||
window.addEventListener('mouseup', mouseUp);
|
||||
},
|
||||
mouseMove = function (e) {
|
||||
mouseMove = function(e) {
|
||||
window.moveTo(screenX + e.screenX - oX, screenY + e.screenY - oY);
|
||||
oX = e.screenX;
|
||||
oY = e.screenY;
|
||||
},
|
||||
gripMouseMove = function (e) {
|
||||
gripMouseMove = function(e) {
|
||||
this.style.cursor = (e.offsetY + e.offsetX > -1) ? 'move' : 'default';
|
||||
},
|
||||
mouseUp = function (e) {
|
||||
mouseUp = function(e) {
|
||||
window.removeEventListener('mousemove', mouseMove);
|
||||
window.removeEventListener('mouseup', mouseUp);
|
||||
};
|
||||
|
||||
grip.addEventListener('mousedown', mouseDown);
|
||||
grip.addEventListener('mousemove', gripMouseMove);
|
||||
},
|
||||
getIEVersion: function() {
|
||||
return IEVersion;
|
||||
},
|
||||
addScript: function(url, callback, test) {
|
||||
var _callback = function(el) {
|
||||
setTimeout(function() {
|
||||
var result = test(el);
|
||||
if(typeof(result) !== "undefined") {
|
||||
callback(el);
|
||||
} else {
|
||||
_callback(el);
|
||||
}
|
||||
}, 50);
|
||||
};
|
||||
addScript: function(url, callback, test, ttl) {
|
||||
var _callback = function(el, ttl) {
|
||||
setTimeout(function() {
|
||||
var result = test(el);
|
||||
if (typeof(result) !== "undefined") {
|
||||
callback(el);
|
||||
} else {
|
||||
if (ttl > 0) {
|
||||
_callback(el, ttl - 50);
|
||||
} else {
|
||||
console.log("failed load " + url);
|
||||
}
|
||||
}
|
||||
}, 50);
|
||||
};
|
||||
|
||||
var el = document.createElement("script");
|
||||
var el = document.createElement("script");
|
||||
el.src = url;
|
||||
el.type = "text/javascript";
|
||||
el.charset = "utf-8";
|
||||
document.head.appendChild(el);
|
||||
|
||||
if(typeof(test) === "function") {
|
||||
_callback();
|
||||
} else if(typeof(callback) === "function") {
|
||||
if (typeof(test) === "function") {
|
||||
// Time-To-Live: default value is 30 seconds
|
||||
ttl = (typeof(ttl) == "number" ? ttl : 30000);
|
||||
_callback(el, ttl);
|
||||
} else if (typeof(callback) === "function") {
|
||||
el.onload = callback(el);
|
||||
}
|
||||
|
||||
return el;
|
||||
},
|
||||
addStylesheet: function(url, callback, test) {
|
||||
var _callback = function(el) {
|
||||
setTimeout(function() {
|
||||
var result = test(el);
|
||||
if(typeof(result) !== "undefined") {
|
||||
callback(el);
|
||||
} else {
|
||||
_callback(el);
|
||||
}
|
||||
}, 50);
|
||||
};
|
||||
|
||||
addStylesheet: function(url, callback) {
|
||||
var el = document.createElement("link");
|
||||
el.href = url;
|
||||
el.rel = "stylesheet";
|
||||
el.type = "text/css";
|
||||
document.head.appendChild(el);
|
||||
|
||||
if(typeof(test) === "function") {
|
||||
_callback();
|
||||
} else if(typeof(callback) === "function") {
|
||||
if (typeof(callback) === "function") {
|
||||
el.onload = callback(el);
|
||||
}
|
||||
|
||||
return el;
|
||||
},
|
||||
main: function() {
|
||||
|
@ -189,29 +175,29 @@ return {
|
|||
this.addScript("app/assets/js/json3.min.js");
|
||||
this.addScript("app/assets/js/es6-shim.min.js");
|
||||
this.addScript("app/assets/js/es6-sham.min.js");
|
||||
if(this.getIEVersion() < 9) {
|
||||
if (this.getIEVersion() < 9) {
|
||||
this.addScript("app/assets/js/html5shiv-printshiv.min.js");
|
||||
this.addScript("app/assets/js/jquery-1.11.3.min.js");
|
||||
} else {
|
||||
this.addScript("app/assets/js/jquery-3.5.1.min.js", function(el) {
|
||||
jQuery.support.cors = true;
|
||||
jQuery.support.cors = true;
|
||||
}, function(el) {
|
||||
return window.jQuery;
|
||||
});
|
||||
return window.jQuery;
|
||||
});
|
||||
}
|
||||
if(this.getIEVersion() < 10) {
|
||||
if (this.getIEVersion() < 10) {
|
||||
this.addScript("app/assets/js/jquery.html5-placeholder-shim.js");
|
||||
}
|
||||
this.addScript("app/assets/js/jquery.form.min.js");
|
||||
this.addScript("app/assets/js/jquery.toast.min.js", function(el) {
|
||||
if(messages.length > 0) {
|
||||
for(var i in messages) {
|
||||
console.log(messages[i]);
|
||||
}
|
||||
}
|
||||
}, function(el) {
|
||||
return window.jQuery.toast;
|
||||
});
|
||||
if (messages.length > 0) {
|
||||
for (var i in messages) {
|
||||
console.log(messages[i]);
|
||||
}
|
||||
}
|
||||
}, function(el) {
|
||||
return window.jQuery.toast;
|
||||
});
|
||||
this.addScript("app/assets/js/index.js");
|
||||
|
||||
// set window draggable
|
||||
|
|
Loading…
Reference in New Issue
Block a user