mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-01-11 17:58:41 +00:00
code fixes
This commit is contained in:
parent
e9e235e7c6
commit
ffd346417e
49
Model/Action/Dom/ChangeAttribute.js
Normal file
49
Model/Action/Dom/ChangeAttribute.js
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
import { jsOMS } from '../../../Utils/oLib.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set value of input.
|
||||||
|
*
|
||||||
|
* @param {Object} action Action data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
* @param {string} id Action element
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
export function domChangeAttribute (action, callback, id)
|
||||||
|
{
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fill = action.base === 'self'
|
||||||
|
? (action.selector === ''
|
||||||
|
? [document.getElementById(id)]
|
||||||
|
: document.getElementById(id).querySelectorAll(action.selector))
|
||||||
|
: document.querySelectorAll(action.selector);
|
||||||
|
|
||||||
|
for (const i in fill) {
|
||||||
|
/** global: HTMLElement */
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(fill, i) || !(fill[i] instanceof HTMLElement)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (action.type) {
|
||||||
|
case 'remove':
|
||||||
|
const old = fill[i].getAttribute(action.attr);
|
||||||
|
|
||||||
|
if (old.match(new RegExp('(\\s|^)' + action.value + '(\\s|$)')) !== null) {
|
||||||
|
const reg = new RegExp('(\\s|^)' + cls);
|
||||||
|
|
||||||
|
fill[i].setAttribute(action.attr, old.replace(reg, '').trim());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'add':
|
||||||
|
fill[i].setAttribute(action.attr, jsOMS.trim(fill[i].getAttribute(action.attr) + ' ' + action.value))
|
||||||
|
break;
|
||||||
|
case 'set':
|
||||||
|
fill[i].setAttribute(action.attr, action.value)
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(action.data);
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user