v1.18.x
barisusakli 11 years ago
parent f8d57aae09
commit caa0c45a11

@ -4,21 +4,38 @@
define(function() {
var TopicSelect = {};
var lastSelected;
TopicSelect.init = function(onSelect) {
$('#topics-container').on('click', '.select', function() {
$('#topics-container').on('selectstart', function() {
return false;
});
$('#topics-container').on('click', '.select', function(ev) {
var select = $(this);
var isChecked = !select.hasClass('fa-square-o');
select.toggleClass('fa-check-square-o', !isChecked);
select.toggleClass('fa-square-o', isChecked);
select.parents('.category-item').toggleClass('selected', !isChecked);
if (ev.shiftKey) {
selectRange($(this).parents('.category-item').attr('data-tid'));
lastSelected = select;
return false;
}
var isSelected = select.hasClass('fa-check-square-o');
toggleSelect(select, !isSelected);
lastSelected = select;
if (typeof onSelect === 'function') {
onSelect();
}
});
};
function toggleSelect(select, isSelected) {
select.toggleClass('fa-check-square-o', isSelected);
select.toggleClass('fa-square-o', !isSelected);
select.parents('.category-item').toggleClass('selected', isSelected);
}
TopicSelect.getSelectedTids = function() {
var tids = [];
$('#topics-container .category-item.selected').each(function() {
@ -32,5 +49,35 @@ define(function() {
$('#topics-container .select').toggleClass('fa-check-square-o', false).toggleClass('fa-square-o', true);
};
function selectRange(clickedTid) {
if(!lastSelected) {
lastSelected = $('.category-item[data-tid]').first().find('.select');
}
var isClickedSelected = $('.category-item[data-tid="' + clickedTid + '"]').hasClass('selected');
var clickedIndex = getIndex(clickedTid);
var lastIndex = getIndex(lastSelected.parents('.category-item[data-tid]').attr('data-tid'));
selectIndexRange(clickedIndex, lastIndex, !isClickedSelected);
}
function selectIndexRange(start, end, isSelected) {
if (start > end) {
var tmp = start;
start = end;
end = tmp;
}
for(var i=start; i<=end; ++i) {
var topic = $('.category-item[data-tid]').eq(i);
toggleSelect(topic.find('.select'), isSelected);
}
}
function getIndex(tid) {
return $('.category-item[data-tid="' + tid + '"]').index('.category-item');
}
return TopicSelect;
});
Loading…
Cancel
Save