From 2ea64a658becab3faecdce1550e76be19265510b Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 27 Nov 2012 21:32:53 +0000 Subject: [PATCH] Better handling of different hights & open up vs down --- phpgwapi/js/jquery/chosen/chosen.jquery.js | 36 +++++++++++++++++++--- phpgwapi/js/jsapi/egw_utils.js | 6 ++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/phpgwapi/js/jquery/chosen/chosen.jquery.js b/phpgwapi/js/jquery/chosen/chosen.jquery.js index bd5939b71d..f5ff671460 100644 --- a/phpgwapi/js/jquery/chosen/chosen.jquery.js +++ b/phpgwapi/js/jquery/chosen/chosen.jquery.js @@ -373,17 +373,21 @@ Copyright (c) 2011 by Harvest this.search_results.css('max-height', 'none'); var windowHeight = $(window).height() + $('html').scrollTop(), - dropdownHeight = this.dropdown.height(), - dropdownTop = Math.ceil(this.dropdown.offset().top), + dropdownHeight = egw.getHiddenDimensions ? egw.getHiddenDimensions(this.dropdown,true)['h'] : this.dropdown.height(), + dropdownTop = egw.getHiddenDimensions ? egw.getHiddenDimensions(this.dropdown,true)['top'] : Math.ceil(this.dropdown.offset().top), totalHeight = dropdownHeight + dropdownTop; if (totalHeight > windowHeight) { var difference = totalHeight - windowHeight, - height = dropdownHeight - difference; + height = dropdownHeight - difference - this.search_container.height(); +console.log("windowHeight:" + windowHeight + " Total height: " + totalHeight + ' height: ' + height, this.container); if (height > 100) { this.search_results.css('max-height', height); } else { + var to_top = egw.getHiddenDimensions ? egw.getHiddenDimensions(this.container,true)['top'] : this.container.offset().top; + var to_bottom = windowHeight - to_top; +console.log("Distance to top: %d Distance to bottom %d", to_top, to_bottom, this.container.offset()); this.dropdown.addClass('chzn-above'); this.search_results.css('max-height', this.search_results.data('initialMaxHeight')); } @@ -631,7 +635,31 @@ Copyright (c) 2011 by Harvest "top": dd_top + "px", "left": 0 }); - + // Check to see if there's enough space below + // Thanks, corryworrell https://github.com/harvesthq/chosen/issues/155 + this.search_results.css('max-height', 'none'); + this.dropdown.removeClass('chzn-above'); + + var windowHeight = $(window).height() + $('html').scrollTop(), + dropdownHeight = this.dropdown.height(), + dropdownTop = Math.ceil(this.dropdown.offset().top), + totalHeight = dropdownHeight + dropdownTop; + + if (totalHeight > windowHeight) { + var difference = totalHeight - windowHeight, + height = dropdownHeight - difference - (this.is_multiple ? 0: this.search_container.height()); + + if (height > 100) { + if(!this.is_multiple) height -= this.search_container.height(); + height = Math.min(parseInt(this.search_results.data('initialMaxHeight')), height); + } else { + this.dropdown.addClass('chzn-above'); + height = Math.min(parseInt(this.search_results.data('initialMaxHeight')), this.container.offset().top+this.search_container.height()); + } + this.search_results.css('max-height', height); + } else { + this.search_results.css('max-height', this.search_results.data('initialMaxHeight')); + } this.results_showing = true; this.search_field.focus(); this.search_field.val(this.search_field.val()); diff --git a/phpgwapi/js/jsapi/egw_utils.js b/phpgwapi/js/jsapi/egw_utils.js index 41b9b9a481..a5943dda1f 100644 --- a/phpgwapi/js/jsapi/egw_utils.js +++ b/phpgwapi/js/jsapi/egw_utils.js @@ -221,7 +221,7 @@ egw.extend('utils', egw.MODULE_GLOBAL, function() { getHiddenDimensions: function(element, boolOuter) { var $item = $j(element); var props = { position: "absolute", visibility: "hidden", display: "block" }; - var dim = { "w":0, "h":0 }; + var dim = { "w":0, "h":0 , "left":0, "top":0}; var $hiddenParents = $item.parents().andSelf().not(":visible"); var oldProps = []; @@ -229,13 +229,15 @@ egw.extend('utils', egw.MODULE_GLOBAL, function() { var old = {}; for ( var name in props ) { old[ name ] = this.style[ name ]; - this.style[ name ] = props[ name ]; } + $j(this).show(); oldProps.push(old); }); dim.w = (boolOuter === true) ? $item.outerWidth() : $item.width(); dim.h = (boolOuter === true) ? $item.outerHeight() : $item.height(); + dim.top = $item.offset().top; + dim.left = $item.offset().left; $hiddenParents.each(function(i) { var old = oldProps[i];