()
| 447 | |
| 448 | // MARK: ELEMENT clsHelp |
| 449 | function enhanceElement() { |
| 450 | Element.prototype.clsOrGate = function ( test, ifTrue = 'text-success', ifFalse = 'text-danger' ) { |
| 451 | if ( test ) { |
| 452 | if ( ifTrue !== null ) { this.classList.add(ifTrue) } |
| 453 | if ( ifFalse !== null ) { this.classList.remove(ifFalse) } |
| 454 | return this |
| 455 | } |
| 456 | if ( ifFalse !== null ) { this.classList.add(ifFalse) } |
| 457 | if ( ifTrue !== null ) { this.classList.remove(ifTrue) } |
| 458 | return this |
| 459 | } |
| 460 | Element.prototype.clsOrGateArr = function ( arr, ifTrue = 'text-danger', ifFalse = 'text-success') { |
| 461 | return this.clsOrGate((Array.isArray(arr) && arr.length !== 0), ifTrue, ifFalse ) |
| 462 | } |
| 463 | |
| 464 | Element.prototype.clsHideByValue = function (value, testValue = null) { |
| 465 | return this.clsOrGate(!this.clsBoolTest(value, testValue), null, 'd-none') |
| 466 | } |
| 467 | Element.prototype.clsShowByValue = function (value, testValue = null) { |
| 468 | return this.clsOrGate(this.clsBoolTest(value, testValue), null, 'd-none') |
| 469 | } |
| 470 | Element.prototype.clsDisableByValue = function (value, testValue = null) { |
| 471 | return this.clsOrGate(!this.clsBoolTest(value, testValue), null, 'disabled') |
| 472 | } |
| 473 | Element.prototype.clsEnableByValue = function (value, testValue = null) { |
| 474 | return this.clsOrGate(this.clsBoolTest(value, testValue), null, 'disabled') |
| 475 | } |
| 476 | |
| 477 | Element.prototype.clsHide = function (test = true) { |
| 478 | return this.clsOrGate(!test, null, 'd-none') |
| 479 | } |
| 480 | Element.prototype.clsShow = function (test = true) { |
| 481 | return this.clsOrGate(test, null, 'd-none') |
| 482 | } |
| 483 | Element.prototype.clsDisable = function (test = true) { |
| 484 | return this.clsOrGate(!test, null, 'disabled') |
| 485 | } |
| 486 | Element.prototype.clsEnable = function (test = true) { |
| 487 | return this.clsOrGate(test, null, 'disabled') |
| 488 | } |
| 489 | Element.prototype.clsBoolTest = function (value, requiredValue = null ) { |
| 490 | if ( typeof value === 'undefined' || value === null || value === false || value.length === 0 || value === 0 ) { |
| 491 | return false |
| 492 | } |
| 493 | if ( Array.isArray(value) && value.filter((x) => x !== null).length === 0 ) { return true } |
| 494 | if ( requiredValue !== null ) { |
| 495 | if ( typeof value === 'string' && typeof requiredValue === 'string' && value.toLowerCase() === requiredValue.toLowerCase() ) { |
| 496 | return true |
| 497 | } else if ( typeof value === 'number' && typeof requiredValue === 'number' && value === requiredValue ) { |
| 498 | return true |
| 499 | } |
| 500 | return false |
| 501 | } |
| 502 | return true |
| 503 | } |
| 504 | |
| 505 | Element.prototype.safeAttribute = function (attrib, replacer = null) { |
| 506 | const attribValue = this.getAttribute(attrib) |
no test coverage detected