Логика подсвечивания картинок для каждой отдельной папки

parent 42189fcf
......@@ -2,7 +2,10 @@ $(document).ready(function(){
var
$foldersContentWrap = $('.b-preview'),
colorsActive = $foldersContentWrap.data('colors');
colorsActive = $foldersContentWrap.data('colors'),
freeNumbers = [1,2,3,4,5],
currentNumToSelect = {},
hasSelectedFoto = {};
function RenderFilesList(folderName, data)
{
......@@ -21,6 +24,8 @@ $(document).ready(function(){
);
$foldersContentWrap.append(templateFolderContent({folder: folderName, files: data}));
currentNumToSelect[folderName] = 1;
hasSelectedFoto[folderName] = false; // Выбрали одну картинку (есть подсвеченное фото)
}
// Клик на папку для загрузки фотографий:
......@@ -66,39 +71,49 @@ $(document).ready(function(){
});
var
currentNumToSelect = 1,
freeNumbers = [1,2,3,4,5],
hasSelectedFoto = false; // Выбрали одну картинку (есть подсвеченное фото)
// Клик на фото:
$foldersContentWrap.on('click', '.b-foto_inner', function(){
var
$this = $(this),
num;
num,
$currentFolderWrap = $this.parents('.b-folder-content'),
folderName = $currentFolderWrap.data('folder');
console.log('AAA folderName ', folderName);
/*
freeNumbers.some(function(el) {
currentNumToSelect = el;
return ($('.b-foto_inner[data-num="' + el + '"]', $currentFolderWrap).length == 0);
});
*/
console.log('AAA currentNumToSelect ', currentNumToSelect);
if (!$this.hasClass('selected')) {
if (!$this.hasClass('selected'))
{
// Клик по фото без рамки
if (hasSelectedFoto) {
if (!hasSelectedFoto[folderName]) {
// выбор первого фото для пары:
console.log('AAA 1-е фото в пару');
num = currentNumToSelect[folderName];
hasSelectedFoto[folderName] = true;
} else {
// выбор второго фото для пары (пара сформирована):
console.log('AAA 2-е фото в пару');
num = currentNumToSelect;
num = currentNumToSelect[folderName];
$this.addClass('paired');
$('.b-foto_inner[data-num="' + num + '"]').addClass('paired');
$('.b-foto_inner[data-num="' + num + '"]', $currentFolderWrap).addClass('paired');
freeNumbers.some(function(el) {
currentNumToSelect = el;
return ($('.b-foto_inner[data-num="' + el + '"]').length == 0);
currentNumToSelect[folderName] = el;
return ($('.b-foto_inner[data-num="' + el + '"]', $currentFolderWrap).length == 0);
});
hasSelectedFoto = false;
} else {
// выбор первого фото для пары:
console.log('AAA 1-е фото в пару');
num = currentNumToSelect;
hasSelectedFoto = true;
hasSelectedFoto[folderName] = false;
}
......@@ -107,48 +122,16 @@ $(document).ready(function(){
$this.css('border-color', colorsActive[num]);
$this.addClass('selected');
} else {
}
else
{
// Клик по фото с рамкой
console.log('AAA убираем пару');
var
pairedNum = $this.attr('data-num'),
$pairedFotos = $('.b-foto_inner[data-num="' + pairedNum + '"]');
/*
$('.b-foto_number', $this).text('');
$this.attr('data-num', '');
$this.css('border-color', '#8D9094');
$this.removeClass('selected');
if (hasSelectedFoto) {
// убираем фото без пары:
console.log('AAA убираем 1-е фото из пары');
if (pairedNum == currentNumToSelect) {
console.log('AAA фото без пары');
freeNumbers.some(function(el) {
currentNumToSelect = el;
return ($('.b-foto_inner[data-num="' + el + '"]').length == 0);
});
hasSelectedFoto = false;
} else {
console.log('AAA фото из пары, но имеется подсвеченное другое');
}
} else {
// Убираем фото из пары:
console.log('AAA убираем 2-е фото из пары');
hasSelectedFoto = true;
currentNumToSelect = pairedNum;
$('.b-foto_inner[data-num="' + pairedNum + '"]').removeClass('paired');
$this.removeClass('paired');
}
*/
console.log('AAA убираем пару');
hasSelectedFoto = false;
$pairedFotos = $('.b-foto_inner[data-num="' + pairedNum + '"]', $currentFolderWrap),
isFromPair = $this.hasClass('paired');
$('.b-foto_number', $pairedFotos).text('');
$pairedFotos.attr('data-num', '')
......@@ -156,11 +139,16 @@ $(document).ready(function(){
.removeClass('selected')
.css('border-color', '#8D9094');
freeNumbers.some(function(el) {
currentNumToSelect = el;
return ($('.b-foto_inner[data-num="' + el + '"]').length == 0);
});
// Клик по фото из пары при выделеной одной фото из другой пары:
if (!hasSelectedFoto[folderName] || !isFromPair) {
hasSelectedFoto[folderName] = false;
freeNumbers.some(function(el) {
currentNumToSelect[folderName] = el;
return ($('.b-foto_inner[data-num="' + el + '"]', $currentFolderWrap).length == 0);
});
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment