nodejs fixes

This commit is contained in:
j 2026-02-18 18:16:43 +01:00
commit 7ed524517d
7 changed files with 32 additions and 15 deletions

View file

@ -466,6 +466,7 @@ Ox.slice = Ox.toArray = function(collection, start, stop) {
// value. Firefox 3.6 returns an array of undefined values if a string is passed
// as value.
if (
typeof document !== 'undefined' && (
Ox.slice([0]).length == 0
|| Ox.slice('0')[0] === null
|| Ox.slice('0')[0] === void 0
@ -474,7 +475,7 @@ if (
return Ox.slice(document.getElementsByTagName('a'));
} catch (error) {}
}())
) {
)) {
// FIXME: remove toArray alias
Ox.slice = Ox.toArray = function(collection, start, stop) {
var args = stop === void 0 ? [start] : [start, stop],

View file

@ -93,13 +93,15 @@ Ox.SHORT_MONTHS = Ox.MONTHS.map(function(val) {
});
//@ Ox.PATH <s> Path of Ox.js
Ox.PATH = (function() {
// IE8 can't apply slice to NodeLists, see Ox.slice
var index, regexp = /Ox\.js(\?.+|)$/,
scripts = document.getElementsByTagName('script'), src;
for (index = scripts.length - 1; index >= 0; index--) {
src = scripts[index].src;
if (regexp.test(src)) {
return src.replace(regexp, '');
if (typeof document !== 'undefined') {
// IE8 can't apply slice to NodeLists, see Ox.slice
var index, regexp = /Ox\.js(\?.+|)$/,
scripts = document.getElementsByTagName('script'), src;
for (index = scripts.length - 1; index >= 0; index--) {
src = scripts[index].src;
if (regexp.test(src)) {
return src.replace(regexp, '');
}
}
}
// FIXME: fix path detection

View file

@ -69,7 +69,6 @@ Ox.load = function() {
callback(true);
} else {
let fn = Ox.noop
console.log("!!", modules)
if ('UI' in modules) {
fn = function(callback) {
var path = Ox.PATH + 'UI/jquery/jquery-1.7.1.min.js?' + Ox.VERSION;

View file

@ -829,6 +829,13 @@ Ox.documentReady <function> Calls a callback function once the DOM is ready
@*/
Ox.documentReady = (function() {
var callbacks = [];
if (typeof document === 'undefined') {
return function(callback) {
callback();
return true;
}
}
document.onreadystatechange = globalThis.onload = function() {
if (document.readyState == 'complete') {
callbacks.forEach(function(callback) {

View file

@ -88,6 +88,10 @@ Ox.getAsync = function(urls, get, callback) {
(function() {
if (typeof document == 'undefined') {
console.log("running in node, disable some things in Requets.js")
return
}
var cache = {},
head = document.head
|| document.getElementsByTagName('head')[0]

View file

@ -443,11 +443,13 @@ Ox.typeOf = function(value) {
// Mobile Safari returns 'DOMWindow' for null and undefined
// Firefox 30+ returns 'window' for window
if (
Ox.typeOf((function() { return arguments; }())) != 'arguments'
|| Ox.typeOf(document.getElementsByTagName('a')) != 'nodelist'
|| Ox.typeOf(null) != 'null'
|| Ox.typeOf(window) != 'global'
|| Ox.typeOf() != 'undefined'
(typeof document != 'undefined') && (
Ox.typeOf((function() { return arguments; }())) != 'arguments'
|| Ox.typeOf(document.getElementsByTagName('a')) != 'nodelist'
|| Ox.typeOf(null) != 'null'
|| Ox.typeOf(window) != 'global'
|| Ox.typeOf() != 'undefined'
)
) {
Ox.typeOf = function(value) {
var type = Object.prototype.toString.call(