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

@ -1,8 +1,10 @@
{ {
"name": "@0x2620/oxjs", "name": "@0x2620/oxjs",
"version": "1.0.0", "version": "1.0.0",
"module": "min/Ox.esm.js", "main": "min/Ox/Ox.js",
"module": "min/Ox/Ox.js",
"browser": "min/Ox.js", "browser": "min/Ox.js",
"type": "module",
"devDependencies": { "devDependencies": {
"@rollup/plugin-node-resolve": "^16.0.3", "@rollup/plugin-node-resolve": "^16.0.3",
"@rollup/plugin-terser": "^0.4.4", "@rollup/plugin-terser": "^0.4.4",

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

View file

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

View file

@ -69,7 +69,6 @@ Ox.load = function() {
callback(true); callback(true);
} else { } else {
let fn = Ox.noop let fn = Ox.noop
console.log("!!", modules)
if ('UI' in modules) { if ('UI' in modules) {
fn = function(callback) { fn = function(callback) {
var path = Ox.PATH + 'UI/jquery/jquery-1.7.1.min.js?' + Ox.VERSION; 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() { Ox.documentReady = (function() {
var callbacks = []; var callbacks = [];
if (typeof document === 'undefined') {
return function(callback) {
callback();
return true;
}
}
document.onreadystatechange = globalThis.onload = function() { document.onreadystatechange = globalThis.onload = function() {
if (document.readyState == 'complete') { if (document.readyState == 'complete') {
callbacks.forEach(function(callback) { callbacks.forEach(function(callback) {

View file

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

View file

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