Skip to content

Commit

Permalink
Fixed issue #14411: Ranking choice height is to big than needed in ca…
Browse files Browse the repository at this point in the history
…se of filter

Dev: lauch setChoiceHeight (and setListHeight) when event happen for hidden
  • Loading branch information
Shnoulle committed Jan 9, 2019
1 parent 342b4d6 commit 7677de1
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions assets/packages/questions/ranking/scripts/ranking.js
Expand Up @@ -150,12 +150,19 @@ var RankingQuestion = function (options) {
if (samechoiceheight) {
/* Do it at load */
setChoiceHeight();
/* Do it when any choice are updated by EM */
/* Do it when any choice are updated by EM (mantis #14406) */
$('#question' + questionId + ' .ls-choice').on('html:updated',function(){
$('#question' + questionId + ' .ls-choice').css("min-height","");
setChoiceHeight();
});
/* Do it on windiw resize */
/* Do it when a choice is shown/hidden by filter (mantis #14411) */
$('#question' + questionId + ' .ls-choice').on('relevance:on relevance:off', function (event, data) {
data = $.extend({style:'hidden'}, data);
if(data.style == 'hidden') {
setChoiceHeight();
}
}
/* Do it on window resize */
$(window).resize(function() {
$('#question' + questionId + ' .ls-choice').css("min-height","");
setChoiceHeight();
Expand All @@ -167,14 +174,20 @@ var RankingQuestion = function (options) {
$('#question' + questionId + ' .ls-choice').on('html:updated',function(){
setListHeight();
});
$('#question' + questionId + ' .ls-choice').on('relevance:on relevance:off', function (event, data) {
data = $.extend({style:'hidden'}, data);
if(data.style == 'hidden') {
setListHeight();
}
}
$(window).resize(function() {
setListHeight();
});
}
},
setChoiceHeight = function() {
var maxHeight = 0;
$('#question' + questionId + ' .ls-choice').each(function () {
$('#question' + questionId + ' .ls-choice').filter(":visible").each(function () {
if ($(this).actual('height') > maxHeight) {
maxHeight = $(this).actual('height');
}
Expand All @@ -183,7 +196,7 @@ var RankingQuestion = function (options) {
},
setListHeight = function() {
var totalHeight = 0;
$('#question' + questionId + ' .ls-choice').each(function () {
$('#question' + questionId + ' .ls-choice').filter(":visible").each(function () {
totalHeight = totalHeight + $(this).actual('outerHeight', {
includeMargin: true
}); /* Border not inside */
Expand All @@ -194,16 +207,20 @@ var RankingQuestion = function (options) {
triggerEmRelevanceSortable = function() {
$(".sortable-item").on('relevance:on', function (event, data) {
//~ if(event.target != this) return; // not needed now, but after maybe (2016-11-07)
//~ data = $.extend({style:'hidden'}, data);
$(event.target).closest(".ls-answers").find("option[value=" + $(event.target).data("value") + "]").prop('disabled', false);
$(event.target).removeClass("disabled");
data = $.extend({style:'hidden'}, data);
if(data.style == 'disable') { // not needed if hidden
$(event.target).closest(".ls-answers").find("option[value=" + $(event.target).data("value") + "]").prop('disabled', false);
$(event.target).removeClass("disabled");
}
});

$(".sortable-item").on('relevance:off', function (event, data) {
//~ if(event.target != this) return; // not needed now, but after maybe (2016-11-07)
//~ data = $.extend({style:'hidden'}, data);
$(event.target).closest(".ls-answers").find("option[value=" + $(event.target).data("value") + "]").prop('disabled', true);
$(event.target).addClass("disabled");
data = $.extend({style:'hidden'}, data);
if(data.style == 'disable') { // not needed if hidden
$(event.target).closest(".ls-answers").find("option[value=" + $(event.target).data("value") + "]").prop('disabled', true);
$(event.target).addClass("disabled");
}
/* reset already ranked item */
if ($(event.target).parent().hasClass("sortable-rank")) {
$(event.target).appendTo($(event.target).closest(".answers-list").find(".sortable-choice"));
Expand Down

0 comments on commit 7677de1

Please sign in to comment.