generated from tripleten-com/se_project_aroundtheus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8230a9
commit ba3d8e8
Showing
6 changed files
with
209 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
export default class Card { | ||
constructor({ name, link }, cardSelector) { | ||
this._name = name; | ||
this._link = link; | ||
this._cardSelector = cardSelector; | ||
} | ||
|
||
_setEventListeners() { | ||
this._cardElement | ||
.querySelector(".card__like-button") | ||
.addEventListener("click", () => { | ||
this._handleLikeIcon(); | ||
}); | ||
|
||
this._cardElement | ||
.querySelector(".card__delete-button") | ||
.addEventListener("click", () => { | ||
this._handleDeleteCard; | ||
}); | ||
} | ||
|
||
_handleDeleteCard() { | ||
this._cardElement.remove(); | ||
this._cardElement = null; | ||
} | ||
|
||
_handleLikeIcon() { | ||
this._cardElement | ||
.querySelector(".card__like-button") | ||
.classList.toggle("card__like-button_active"); | ||
} | ||
|
||
getView() { | ||
this._cardElement = document | ||
.querySelector(this._cardSelector) | ||
.content.querySelector(".card") | ||
.cloneNode(true); | ||
|
||
//get card | ||
//set listeners | ||
this._setEventListeners(); | ||
//return card | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
export default class FormValidator { | ||
constructor(config, formElement) { | ||
this._inputSelector = config.inputSelector; | ||
this._submitButtonSelector = config.submitButtonSelector; | ||
this._inactiveButtonClass = config.inactiveButtonClass; | ||
this._inputErrorClass = config.inputErrorClass; | ||
this._errorClass = config.errorClass; | ||
|
||
this._formElement = formElement; | ||
} | ||
|
||
_showInputError(inputEl) { | ||
const errorMessageEl = this._formElement.querySelector( | ||
"#" + inputEl.id + "-error" | ||
); | ||
inputEl.classList.add(this._inputErrorClass); | ||
errorMessageEl.textContent = inputEl.validationMessage; | ||
errorMessageEl.classList.add(this._errorClass); | ||
} | ||
|
||
_hideInputError(inputEl) { | ||
const errorMessageEl = this._formElement.querySelector( | ||
"#" + inputEl.id + "-error" | ||
); | ||
inputEl.classList.remove(this._inputErrorClass); | ||
errorMessageEl.textContent = ""; | ||
errorMessageEl.classList.remove(this._errorClass); | ||
} | ||
|
||
_checkInputValidity(inputElement) { | ||
if (!inputElement.validity.valid) { | ||
this._showInputError(inputElement); | ||
} else { | ||
this._hideInputError(inputElement); | ||
} | ||
} | ||
|
||
_toggleButtonState(inputEls, submitButton) { | ||
let foundInvalid = false; | ||
|
||
inputEls.forEach((inputEl) => { | ||
if (!inputEl.validity.valid) { | ||
foundInvalid = true; | ||
} | ||
}); | ||
|
||
if (foundInvalid) { | ||
submitButton.classList.add(this._inactiveButtonClass); | ||
submitButton.disabled = true; | ||
} else { | ||
submitButton.classList.remove(this._inactiveButtonClass); | ||
submitButton.disabled = false; | ||
} | ||
} | ||
|
||
_setEventListeners() { | ||
const inputEls = this._formElement.querySelectorAll(this._inputSelector); | ||
const submitButton = this._formElement.querySelector( | ||
this._submitButtonSelector | ||
); | ||
this._toggleButtonState(inputEls, submitButton); | ||
inputEls.forEach((inputEl) => { | ||
inputEl.addEventListener("input", (e) => { | ||
this._checkInputValidity(inputEl); | ||
this._toggleButtonState(inputEls, submitButton); | ||
}); | ||
}); | ||
} | ||
|
||
enableValidation() { | ||
this._formElement.addEventListener("submit", (evt) => { | ||
evt.preventDefault(); | ||
}); | ||
|
||
this._setEventListeners(); | ||
} | ||
} | ||
|
||
const formValidationconfig = { | ||
inputSelector: ".modal__input", | ||
submitButtonSelector: ".modal__button", | ||
inactiveButtonClass: "modal__button_disabled", | ||
inputErrorClass: "modal__input_type_error", | ||
errorClass: "modal__error_visible", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters