Skip to content

Commit

Permalink
рабочая версия, до устранения дребезга
Browse files Browse the repository at this point in the history
  • Loading branch information
Наташа committed Jul 5, 2018
1 parent 6f43ede commit f5f402c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 41 deletions.
2 changes: 1 addition & 1 deletion js/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

window.error = {
show: showError,
message: setMessage
setMessage: setMessage
};

})();
84 changes: 44 additions & 40 deletions js/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,7 @@
picturesSection.appendChild(fragment);
};

// получаем данные с сервера
var onSuccess = function (data) {
picturesData = data;
// при получении добавляю id в массив для открытия большого фото
for (var i = 0; i < picturesData.length; i++) {
picturesData[i].id = i;
}
appendPictures(picturesData);
filtersBox.classList.remove(INACTIVE_CLASS);
};

var onError = function (message) {
window.error.message(message);
window.error.show();
};

window.backend.download(onSuccess, onError);

// --- Сортировки картинок
// --- Сортировки картинок

var ACTIVE_CLASS = 'img-filters__button--active';
var INACTIVE_CLASS = 'img-filters--inactive';
Expand All @@ -143,27 +125,49 @@


filterBtns.forEach(function (btn) {
btn.addEventListener('click', function (evt) {
var photos = picturesData.slice(0);
var currentBtn = evt.target;
var currentFilter = currentBtn.id;

if (!currentBtn.classList.contains(ACTIVE_CLASS)) {
photos = filterMethods[currentFilter](photos);

filterActiveBtn.classList.remove(ACTIVE_CLASS);
currentBtn.classList.add(ACTIVE_CLASS);
filterActiveBtn = currentBtn;

// Зачистка предыдущих фото:
var photosListItemElement = picturesSection.querySelectorAll('.picture__link');
photosListItemElement.forEach(function (item) {
item.parentNode.removeChild(item);
});

appendPictures(photos);
}
});
btn.addEventListener('click', switchFilter);
});

var clearPictures = function () {
var photosList = picturesSection.querySelectorAll('.picture__link');
photosList.forEach(function (item) {
item.parentNode.removeChild(item);
});
};

var switchFilter = function (evt) {
var photos = picturesData.slice(0);
var currentBtn = evt.target;
var currentFilter = currentBtn.id;

if (!currentBtn.classList.contains(ACTIVE_CLASS)) {
photos = filterMethods[currentFilter](photos);

filterActiveBtn.classList.remove(ACTIVE_CLASS);
currentBtn.classList.add(ACTIVE_CLASS);
filterActiveBtn = currentBtn;

clearPictures();
appendPictures(photos);
}
};

// получаем данные с сервера
var onSuccess = function (data) {
picturesData = data;
// при получении добавляю id в массив для открытия большого фото
for (var i = 0; i < picturesData.length; i++) {
picturesData[i].id = i;
}
appendPictures(picturesData);
filtersBox.classList.remove(INACTIVE_CLASS);
};

var onError = function (message) {
window.error.setMessage(message);
window.error.show();
};

window.backend.download(onSuccess, onError);

})();

0 comments on commit f5f402c

Please sign in to comment.