403Webshell
Server IP : 157.230.181.24  /  Your IP : 216.73.217.11
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux conductive 6.8.0-117-generic #117-Ubuntu SMP PREEMPT_DYNAMIC Tue May 5 19:26:24 UTC 2026 x86_64
User :  ( 1000)
PHP Version : 8.3.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/vhosts/conductive-digital/resources/assets/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/vhosts/conductive-digital/resources/assets/js/utility.js
/**
 * @module Utility
 * @description Utility functions for doing arbitrary things
 * @author Shelton Clinard | Untold Digital | untold-digital.com
 */
const U = {

	/**
	 * Toggles a class on an element
	 * @param el {Element}
	 * @param className {string}
	 */
	toggleClass(el, className) {
		if (el != null) {
			el.classList.contains(className) ?
				el.classList.remove(className) :
				el.classList.add(className);
		}
	},

	/**
	 * Loop through an array and execute a callback on each item in the array.
	 * @param array
	 * @param callback
	 * @param scope
	 * @example U.forEach(document.querySelectorAll('li'), _foo)
	 */
	forEachElement(array, callback, scope) {
		if (array !== undefined && array.length) {
			for (var i = 0; i < array.length; i++) {
				callback.call(scope, i, array[i]); // passes back stuff we need
			}
		} else {
			console.info('No array found to loop through');
		}
	},

	/**
	 * Check if an element has a child with a specific name or class
	 * @param element {Element}
	 * @param query {String}
	 * @returns {boolean}
	 */
	hasChild(element, query) {
		let child = element.querySelector(query);

		return child !== null
	},

	/**
	 * check if an element exists, and if it does execute a callback
	 * @param element
	 * @param callback
	 * @param scope
	 */
	ifExists(element, callback, scope) {
		if (element != null) {
			callback.call(scope);
		}
	},

	/**
	 * check if element is a valid node
	 * @param element
	 * @param callback
	 * @param scope
	 * @returns {*|boolean}
	 */
	isValidElement(element, callback, scope) {
		if (element !== null && element !== undefined) {
			callback.call(scope);
		}
	},

	setClassOnMany(array, cssClass = 'is-active') {
		this.forEachElement(array, (i) => {
			array[i].classList.add(cssClass);
		});
	},

	removeClassOnMany(array, cssClass = 'is-active') {
		this.forEachElement(array, (i) => {
			array[i].classList.remove(cssClass);
		});
	},

	setClassOnOne(array, index, cssClass = 'is-active') {
		this.forEachElement(array, (i) => {
			array[i].classList.remove(cssClass);

			if (i === index) {
				array[i].classList.add(cssClass);
			}
		});
	},

	getOffsetTop(elem) {
		var offsetTop = 0;
		do {
			if (!isNaN(elem.offsetTop)) {
				offsetTop += elem.offsetTop;
			}
		} while (elem = elem.offsetParent);
		return offsetTop;
	},

	/**
	 * Calculate the height of an item WITH it's margin included
	 * @param element
	 * @returns {number}
	 */
	heightWithMargin(element) {
		var style  = element.currentStyle || window.getComputedStyle(element),
		    height = element.offsetHeight, // or use style.width
		    margin = parseFloat(style.marginTop) + parseFloat(style.marginBottom);

		return height + margin;
	},

	/**
	 * Check the screen size, based on the Bootsrap 4 breakpoints.
	 * @returns {boolean}
	 */
	isLgDown() {
		return screen.width < 1200;
	},

	isMdDown() {
		return screen.width < 992;
	},

	isSmDown() {
		return screen.width < 768;
	},

	isXsDown() {
		return screen.width < 576;
	}
};

module.exports = U;

Youez - 2016 - github.com/yon3zu
LinuXploit