-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
2 changed files
with
86 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,68 @@ | ||
import { | ||
render, | ||
RenderPosition | ||
} from './render.js'; | ||
import TripInfoView from './view/create-trip.js'; | ||
import FiltersView from './view/create-filter.js'; | ||
import PointsPresenter from './presenter/board-presenter.js'; | ||
|
||
const tripMainContainer = document.querySelector('.trip-main'); | ||
const tripEventsContainer = document.querySelector('.trip-events'); | ||
const filtersContainer = tripMainContainer.querySelector('.trip-controls__filters'); | ||
|
||
import PointsModel from './model/event-points-model.js'; | ||
import OffersModel from './model/offers-model.js'; | ||
import DestinationsModel from './model/destinations-model.js'; | ||
|
||
const pointsModel = new PointsModel(); | ||
const offersModel = new OffersModel(); | ||
const destinationsModel = new DestinationsModel(); | ||
|
||
const pointsPresenter = new PointsPresenter({ | ||
tripEventsContainer, | ||
pointsModel, | ||
offersModel, | ||
destinationsModel | ||
}); | ||
|
||
render(new TripInfoView(), tripMainContainer, RenderPosition.AFTERBEGIN); | ||
render(new FiltersView(), filtersContainer); | ||
|
||
pointsPresenter.init(); | ||
import {createElement} from '../render.js'; | ||
import './abstract-view.css'; | ||
|
||
/** @const {string} Класс, реализующий эффект "покачивания головой" */ | ||
const SHAKE_CLASS_NAME = 'shake'; | ||
|
||
/** @const {number} Время анимации в миллисекундах */ | ||
const SHAKE_ANIMATION_TIMEOUT = 600; | ||
|
||
/** | ||
* Абстрактный класс представления | ||
*/ | ||
export default class AbstractView { | ||
/** @type {HTMLElement|null} Элемент представления */ | ||
#element = null; | ||
|
||
/** @type {Object} Объект с колбэками. Может использоваться для хранения обработчиков событий */ | ||
_callback = {}; | ||
|
||
constructor() { | ||
if (new.target === AbstractView) { | ||
throw new Error('Can\'t instantiate AbstractView, only concrete one.'); | ||
} | ||
} | ||
|
||
/** | ||
* Геттер для получения элемента | ||
* @returns {HTMLElement} Элемент представления | ||
*/ | ||
get element() { | ||
if (!this.#element) { | ||
this.#element = createElement(this.template); | ||
} | ||
|
||
return this.#element; | ||
} | ||
|
||
/** | ||
* Геттер для получения разметки элемента | ||
* @abstract | ||
* @returns {string} Разметка элемента в виде строки | ||
*/ | ||
get template() { | ||
throw new Error('Abstract method not implemented: get template'); | ||
} | ||
|
||
/** Метод для удаления элемента */ | ||
removeElement() { | ||
this.#element = null; | ||
} | ||
|
||
/** | ||
* Метод, реализующий эффект "покачивания головой" | ||
* @param {shakeCallback} [callback] Функция, которая будет вызвана после завершения анимации | ||
*/ | ||
shake(callback) { | ||
this.element.classList.add(SHAKE_CLASS_NAME); | ||
setTimeout(() => { | ||
this.element.classList.remove(SHAKE_CLASS_NAME); | ||
callback?.(); | ||
}, SHAKE_ANIMATION_TIMEOUT); | ||
} | ||
} | ||
|
||
/** | ||
* Функция, которая будет вызвана методом shake после завершения анимации | ||
* @callback shakeCallback | ||
*/ |
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 |
---|---|---|
@@ -1,28 +1,31 @@ | ||
import { | ||
render, | ||
RenderPosition | ||
} from './render.js'; | ||
import TripInfoView from './view/create-trip.js'; | ||
import FiltersView from './view/create-filter.js'; | ||
import PointsPresenter from './presenter/board-presenter.js'; | ||
|
||
const tripMainContainer = document.querySelector('.trip-main'); | ||
const tripEventsContainer = document.querySelector('.trip-events'); | ||
const filtersContainer = tripMainContainer.querySelector('.trip-controls__filters'); | ||
|
||
import PointsModel from './model/event-points-model.js'; | ||
import OffersModel from './model/offers-model.js'; | ||
import DestinationsModel from './model/destinations-model.js'; | ||
import PointsPresenter from './presenter/points-presenter.js'; | ||
import FiltersPresenter from './presenter/filters-presenter.js'; | ||
import TripInfoPresenter from './presenter/trip-presenter.js'; | ||
import MockService from './service/mock-service.js'; | ||
|
||
const mockService = new MockService(); | ||
const pointsModel = new PointsModel(mockService); | ||
const offersModel = new OffersModel(mockService); | ||
const destinationsModel = new DestinationsModel(mockService); | ||
|
||
const pointsContainer = document.querySelector('.trip-events'); | ||
const pointsModel = new PointsModel(); | ||
const offersModel = new OffersModel(); | ||
const destinationsModel = new DestinationsModel(); | ||
|
||
const pointsPresenter = new PointsPresenter({ | ||
pointsContainer, | ||
tripEventsContainer, | ||
pointsModel, | ||
offersModel, | ||
destinationsModel | ||
}); | ||
|
||
const filtersPresenter = new FiltersPresenter({pointsModel}); | ||
const tripInfoPresenter = new TripInfoPresenter(); | ||
render(new TripInfoView(), tripMainContainer, RenderPosition.AFTERBEGIN); | ||
render(new FiltersView(), filtersContainer); | ||
|
||
pointsPresenter.init(); | ||
filtersPresenter.init(); | ||
tripInfoPresenter.init(); |