Action box update with change from keyInObject to objectKeyExists
All checks were successful
JavaScriptUtilsVitest / ci-tests (push) Successful in 18s

This commit is contained in:
2025-05-09 15:19:51 +09:00
parent 0968085084
commit 082cb761c0
2 changed files with 39 additions and 9 deletions

View File

@@ -5,7 +5,7 @@ Creator: Clemens Schwaighofer
*/ */
export { ActionBox }; export { ActionBox };
import { keyInObject, getObjectCount } from './JavaScriptHelpers.mjs'; import { objectKeyExists, getObjectCount } from './JavaScriptHelpers.mjs';
import { exists } from './DomHelpers.mjs'; import { exists } from './DomHelpers.mjs';
import { setCenter, getWindowSize } from './ResizingAndMove.mjs'; import { setCenter, getWindowSize } from './ResizingAndMove.mjs';
@@ -155,7 +155,7 @@ class ActionBox {
} }
// adjust zIndex so its above all other and set action box zindex +1 // adjust zIndex so its above all other and set action box zindex +1
$('#overlayBox').show(); $('#overlayBox').show();
if (!keyInObject(target_id, this.zIndex.boxes)) { if (!objectKeyExists(this.zIndex.boxes, target_id)) {
this.zIndex.boxes[target_id] = this.zIndex.max; this.zIndex.boxes[target_id] = this.zIndex.max;
// increase by ten // increase by ten
this.zIndex.max += 10; this.zIndex.max += 10;
@@ -197,7 +197,7 @@ class ActionBox {
} }
// clear storage object // clear storage object
if ( if (
keyInObject(target_id, this.action_box_storage) && clean === true objectKeyExists(this.action_box_storage, target_id) && clean === true
) { ) {
this.action_box_storage[target_id] = {}; this.action_box_storage[target_id] = {};
} }
@@ -249,18 +249,18 @@ class ActionBox {
settings = {}, settings = {},
show_close = true show_close = true
) { ) {
if (!keyInObject(target_id, this.action_box_storage)) { if (!objectKeyExists(this.action_box_storage, target_id)) {
this.action_box_storage[target_id] = {}; this.action_box_storage[target_id] = {};
} }
// settings can have the following // settings can have the following
// : header_css:[] // : header_css:[]
// : action_box_css:[] // : action_box_css:[]
let header_css = []; let header_css = [];
if (keyInObject('header_css', settings)) { if (objectKeyExists(settings, 'header_css')) {
header_css = settings.header_css; header_css = settings.header_css;
} }
let action_box_css = []; let action_box_css = [];
if (keyInObject('action_box_css', settings)) { if (objectKeyExists(settings, 'action_box_css')) {
action_box_css = settings.action_box_css; action_box_css = settings.action_box_css;
} }
let elements = []; let elements = [];
@@ -288,7 +288,7 @@ class ActionBox {
// if we have header content, add that here // if we have header content, add that here
if (getObjectCount(headers) > 0) { if (getObjectCount(headers) > 0) {
// if the element has an entry called "raw_string" then this does not need to be converted // if the element has an entry called "raw_string" then this does not need to be converted
if (keyInObject('raw_string', headers)) { if (objectKeyExists(headers, 'raw_string')) {
elements.push(headers.raw_string); elements.push(headers.raw_string);
} else { } else {
elements.push(this.hec.phfo(headers)); elements.push(this.hec.phfo(headers));
@@ -297,7 +297,7 @@ class ActionBox {
// main content part (this should NOT be empty), if empty, add empty _content block // main content part (this should NOT be empty), if empty, add empty _content block
if (getObjectCount(contents) > 0) { if (getObjectCount(contents) > 0) {
// if the element has an entry called "raw_string" then this does not need to be converted // if the element has an entry called "raw_string" then this does not need to be converted
if (keyInObject('raw_string', contents)) { if (objectKeyExists(contents, 'raw_string')) {
elements.push(contents.raw_string); elements.push(contents.raw_string);
} else { } else {
elements.push(this.hec.phfo(contents)); elements.push(this.hec.phfo(contents));

View File

@@ -5,7 +5,8 @@ Creator: Clemens Schwaighofer
*/ */
export { export {
errorCatch, isFunction, executeFunctionByName, errorCatch, isFunction,
executeFunctionByName, runFunction, runFunctionArgsArray,
isObject, getObjectCount, isObject, getObjectCount,
keyInObject, objectKeyExists, keyInObject, objectKeyExists,
getKeyByValue, valueInObject, objectValueExists, getKeyByValue, valueInObject, objectValueExists,
@@ -77,6 +78,35 @@ function executeFunctionByName(functionName, context /*, args */)
return context[func].apply(context, args); return context[func].apply(context, args);
} }
/**
* call a function by string
* call runFunctionArgArray
* @param {string} name Function name to call
* @param {Array} arguments all next function arguments are passed on as argument to the function
* @returns void
*/
function runFunction(name)
{
var args = Array.prototype.slice.call(arguments, 1);
runFunctionArgsArray(name, args);
}
/**
* call a function with a string, argumens as array
* @param {string} name Function name to call
* @param {array} args function arguments as arry
* @returns void
*/
function runFunctionArgsArray(name, args)
{
var fn = window[name];
if(typeof fn !== 'function') {
return;
}
fn.apply(window, args);
}
/** /**
* checks if a variable is an object * checks if a variable is an object
* @param {any} val possible object * @param {any} val possible object