From 4236ae403c7ff108b84d714d5396c814c7e82311 Mon Sep 17 00:00:00 2001 From: MasaoAsano <60.percent.off@gmail.com> Date: Thu, 27 Sep 2012 03:06:38 +0900 Subject: [PATCH] fix scrollbar visibility & popup position --- jqselectable/jqselectable.js | 18 ++++++++++-------- jqselectable/jqselectable.min.js | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/jqselectable/jqselectable.js b/jqselectable/jqselectable.js index ff8d4bc..c83dc46 100644 --- a/jqselectable/jqselectable.js +++ b/jqselectable/jqselectable.js @@ -48,7 +48,7 @@ self.selected = undefined; self.selected_id = undefined; - self.has_no_maxheight = typeof document.body.style.maxHeight; + self.has_maxheight = typeof document.body.style.maxHeight; // id self.id = self.elem.id || 'jqs_' + parseInt(Math.random()*1000); @@ -138,11 +138,13 @@ scroll_top = get_scrolltop(), client_height = get_clientheight(); - if ( client_height / 2 < pos.top - scroll_top ) { - top_pos = pos.top - self.list_height + conf.top - 5; - } else { - top_pos = pos.top + $view.height() * 1.3 + conf.top; - } + // popup below if there are space below or there are no vacant above popup element + if (client_height + scroll_top - pos.top - $view.height() * 1.3 > self.list_height + || pos.top - scroll_top < self.list_height) { + top_pos = pos.top + $view.height() * 1.3 + conf.top; + } else { + top_pos = pos.top - self.list_height + conf.top - 5; + } $list.css({ top: top_pos, @@ -211,7 +213,7 @@ $elem = self.$elem; // for IE6 - if ( self.has_no_maxheight ) { + if ( ! self.has_maxheight ) { body_style = 'height: ' + height + '; overflow-y: scroll;'; // for other browsers } else { @@ -429,7 +431,7 @@ self._build(); self._eventify(); - + self.$elem.trigger('jQselectable.refresh'); }, diff --git a/jqselectable/jqselectable.min.js b/jqselectable/jqselectable.min.js index de88fd3..385948b 100644 --- a/jqselectable/jqselectable.min.js +++ b/jqselectable/jqselectable.min.js @@ -8,4 +8,4 @@ * @link https://github.com/5509/jQselectable * * 2012-04-10 00:00 - */(function(a,b,c,d){function g(a,b){var c=0,d=a.length;for(;c",'',b,"",""].join(""))},_setPosition:function(){var a=this,b=a.conf,c=a.$view,e=a.$list,f=d,g=c.offset(),j=h(),k=i();k/2":['"].join("");a+=f;a+=d.disabled?"":"";g&&/br/.test(g)&&(a+="
")});c.selected_id||(c.selected_id=b[0].value);return a},_createList:function(){var b=this,c=b.conf,e=d,f=b.id+"_mat",h="sctble_mat "+b.attr.klass,i='
',j=c.height==="auto"?"auto":c.height+"px",k=b.$elem;b.has_no_maxheight?e="height: "+j+"; overflow-y: scroll;":e="max-height: "+j+";";i=i+'
';b.has_group=k.find("optgroup").length;if(b.has_group){b.list_klass="sctble optgroup";i+=function(){var a="
",c=k.find("optgroup");g(c,function(c,d){var e=d.getElementsByTagName("option");a+="
"+d.label+"
";a=b._addItem(a,e);a+="
"});a+="
";return a}()}else{c.style==="selectable"?b.list_klass="sctble nooptgroup":b.list_klass="sBox nooptgroup";i+=function(){var a="";a=b._addItem(a,b.$option);return a}()}i+="
";return a(i).addClass(b.list_klass)},_eventify:function(){var a=this,b=a.$elem,c=a.$view,d=a.$list;c.bind("click",function(){if(a.disabled)return;b.trigger("jQselectable.click")});d.delegate("a","click",function(a){var c=this;a.preventDefault();b.trigger("jQselectable.change",{value:c.getAttribute("data-value"),anchor:c})});b.bind("jQselectable.click",function(b){a._show()});b.bind("jQselectable.change",function(b,c){a._change(c.value);a._removeSelected();a._addSelected(c.anchor);a.$view.focus()})},_show:function(){var a=this,b=a.conf,c=a.$list,e=a.$view,f=d,g=d,j=d,k=d;a._setPosition();a.state=!0;if(b.show==="slideDown"){f=h();g=i();j=e.offset();k=g/2",'',b,"",""].join(""))},_setPosition:function(){var a=this,b=a.conf,c=a.$view,e=a.$list,f=d,g=c.offset(),j=h(),k=i();(k+j-g.top-c.height()*1.3>a.list_height||g.top-j":['"].join("");a+=f;a+=d.disabled?"":"";g&&/br/.test(g)&&(a+="
")});c.selected_id||(c.selected_id=b[0].value);return a},_createList:function(){var b=this,c=b.conf,e=d,f=b.id+"_mat",h="sctble_mat "+b.attr.klass,i='
',j=c.height==="auto"?"auto":c.height+"px",k=b.$elem;!b.has_maxheight?e="height: "+j+"; overflow-y: scroll;":e="max-height: "+j+";";i=i+'
';b.has_group=k.find("optgroup").length;if(b.has_group){b.list_klass="sctble optgroup";i+=function(){var a="
",c=k.find("optgroup");g(c,function(c,d){var e=d.getElementsByTagName("option");a+="
"+d.label+"
";a=b._addItem(a,e);a+="
"});a+="
";return a}()}else{c.style==="selectable"?b.list_klass="sctble nooptgroup":b.list_klass="sBox nooptgroup";i+=function(){var a="";a=b._addItem(a,b.$option);return a}()}i+="
";return a(i).addClass(b.list_klass)},_eventify:function(){var a=this,b=a.$elem,c=a.$view,d=a.$list;c.bind("click",function(){if(a.disabled)return;b.trigger("jQselectable.click")});d.delegate("a","click",function(a){var c=this;a.preventDefault();b.trigger("jQselectable.change",{value:c.getAttribute("data-value"),anchor:c})});b.bind("jQselectable.click",function(b){a._show()});b.bind("jQselectable.change",function(b,c){a._change(c.value);a._removeSelected();a._addSelected(c.anchor);a.$view.focus()})},_show:function(){var a=this,b=a.conf,c=a.$list,e=a.$view,f=d,g=d,j=d,k=d;a._setPosition();a.state=!0;if(b.show==="slideDown"){f=h();g=i();j=e.offset();k=g/2