From ada7e2de99de2b87f5a1ca3ba7f1896c8a664d21 Mon Sep 17 00:00:00 2001 From: mattkae Date: Wed, 22 Jun 2022 21:04:35 -0400 Subject: Remove leftover files --- mini-jquery.js~ | 122 -------------------------------------------------------- 1 file changed, 122 deletions(-) delete mode 100644 mini-jquery.js~ (limited to 'mini-jquery.js~') diff --git a/mini-jquery.js~ b/mini-jquery.js~ deleted file mode 100644 index 1e674b3..0000000 --- a/mini-jquery.js~ +++ /dev/null @@ -1,122 +0,0 @@ -// -// mini-jquery.js -// -// Matthew Kosarek -// -// 2021-08-08 -// -// JQuery is huge and I use the smallest portion of it. -// This is my attempt to make a JQuery lookalike that does -// enough for me, but doesn't bloat things. -// - -function MiniJQueryObject(arg) { - this.elementList = []; - if (typeof arg === 'string') { - arg = arg.trim(); - - if (arg[0] === '<' && arg[arg.length - 1] === '>') { - // Trying to create an html element - arg = arg.substring(1, arg.length - 1); - var element = document.createElement(arg); - this.elementList.push(element); - } else { - // Trying to query an html element - - switch (arg[0]) { - case '#': { - arg = arg.substring(1); - var idElement = document.getElementById(arg); - if (idElement) { - this.elementList.push(idElement); - } - break; - } - case '.': { - arg = arg.substring(1); - this.fromHTMLCollection(document.getElementsByClassName(arg)); - break; - } - default: { - this.fromHTMLCollection(document.getElementsByTagName(arg)); - break; - } - } - } - } else if (arg instanceof HTMLElement) { - this.elementList.push(arg); - } else { - console.error('Unknown object: ', arg); - } -} - -MiniJQueryObject.prototype.fromHTMLCollection = function(collection) { - for (var i = 0; i < collection.length; i++) { - this.elementList.push(collection.item(i)); - } -}; - -MiniJQueryObject.prototype.append = function(otherMinJqueryObject) { - this.elementList.forEach(function(element) { - otherMinJqueryObject.elementList.forEach(function(otherElement) { - element.appendChild(otherElement); - }); - }); -}; - -MiniJQueryObject.prototype.appendTo = function(otherMinJqueryObject) { - otherMinJqueryObject.append(this); - return this; -}; - -MiniJQueryObject.prototype.empty = function() { - this.elementList.forEach(function(element) { - element.innerHTML = ''; - }); - return this; -}; - -MiniJQueryObject.prototype._set = function(field, value) { - this.elementList.forEach(function(element) { - element[field] = value; - }); - return this; -}; - -MiniJQueryObject.prototype.type = function(type) { - return this._set('type', type); -}; - -MiniJQueryObject.prototype.val = function(val) { - return this._set('value', val); -}; - -MiniJQueryObject.prototype.disabled = function(val) { - return this._set('disabled', val ? 'true' : undefined); -}; - -MiniJQueryObject.prototype.on = function(event, callback) { - this.elementList.forEach(function(element) { - element.addEventListener(event, callback); - }); - return this; -}; - -MiniJQueryObject.prototype.addClass = function(className) { - this.elementList.forEach(function(element) { - element.classList.add(className); - }); - return this; -}; - -MiniJQueryObject.prototype.removeClass = function(className) { - this.elementList.forEach(function(element) { - element.classList.remove(className); - }); - return this; -}; - -var $ = function(arg) { - return new MiniJQueryObject(arg); -}; -window.$ = $; -- cgit v1.2.1