Skip to content

Commit

Permalink
fixup test by guarding element access in dollarsign.js
Browse files Browse the repository at this point in the history
  • Loading branch information
wpears committed Nov 7, 2023
1 parent d884563 commit 6e97f9b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const ready = function (callback) {
const app = {
urlValues: {},
init: function () {
// jquery promise to delay full model creation until ajax resolves
getApiValues.initialData().then((resp) => {
const [constants, expenses] = resp;
financialModel.init(constants[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@ function Query(selector) {
if (typeof selector === 'string' && selector !== '') {
this.elements = document.querySelectorAll(selector);
}

// if ( this.elements.length > 1 ) {
// return this.elements;
// } else {
// return this.elements[0];
// }
}

Query.prototype.attr = function (name, value) {
if (typeof value === 'undefined') {
return this.elements[0].getAttribute(name);
return this.elements.length ? this.elements[0].getAttribute(name) : null;
} else {
this.elements.forEach((elem) => {
elem.setAttribute(name, value);
Expand All @@ -36,13 +30,13 @@ Query.prototype.attr = function (name, value) {
};

Query.prototype.cloner = function () {
return this.elements[0].cloneNode(true);
return this.elements.length ? this.elements[0].cloneNode(true) : null;
};

Query.prototype.text = function (value) {
// getter
if (typeof value === 'undefined') {
return this.elements[0].textContent;
return this.elements.length ? this.elements[0].textContent : null;
}
//setter
else {
Expand All @@ -55,7 +49,7 @@ Query.prototype.text = function (value) {
Query.prototype.val = function (value) {
// getter
if (typeof value === 'undefined' && this.elements.length > 0) {
return this.elements[0].value;
return this.elements.length ? this.elements[0].value : null;
}
//setter
else {
Expand Down Expand Up @@ -146,19 +140,11 @@ Query.prototype.show = function (className) {
};

Query.prototype.height = function () {
if (this.elements.length > 0) {
return this.elements[0].offsetHeight;
} else {
return null;
}
return this.elements.length ? this.elements[0].offsetHeight : null;
};

Query.prototype.top = function () {
if (this.elements.length > 0) {
return this.elements[0].offsetTop;
} else {
return null;
}
return this.elements.length ? this.elements[0].offsetTop : null;
};

Query.prototype.listen = function (eventType, callback) {
Expand All @@ -168,7 +154,7 @@ Query.prototype.listen = function (eventType, callback) {
};

Query.prototype.tagName = function () {
return this.elements[0].tagName;
return this.elements.length ? this.elements[0].tagName : null;
};

Query.prototype.addClass = function (classNames) {
Expand Down

0 comments on commit 6e97f9b

Please sign in to comment.