Skip to content

Commit b105b9d

Browse files
committed
Add forceRenderAbove option
This options overrides the isInViewport detection and force the above class.
1 parent 1d93433 commit b105b9d

File tree

8 files changed

+55
-15
lines changed

8 files changed

+55
-15
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ $('select').selectric({
248248
*/
249249
allowWrap: true,
250250

251+
/*
252+
* Type: Boolean
253+
* Description: By default the options box gets opened above if it's outside the window.
254+
* In case this auto detection doesn't work as expected (e.g. in transform/relative scopes)
255+
* you may force opening above.
256+
*/
257+
forceRenderAbove: false,
258+
251259
/*
252260
* Type: Object
253261
* Description: Customize select "multiple" behavior

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jquery-selectric",
33
"description": "Fast, simple and light jQuery plugin to customize HTML selects",
4-
"version": "1.11.1",
4+
"version": "1.12.0",
55
"keywords": [
66
"select",
77
"selectbox",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "selectric",
3-
"version": "1.11.1",
3+
"version": "1.12.0",
44
"main": "public/jquery.selectric.js",
55
"title": "jQuery Selectric",
66
"author": {

public/demo.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,22 @@ <h3>Custom markup for items box</h3>
269269
</div>
270270
</div>
271271

272+
<div class="demo">
273+
<h3>Force render above</h3>
274+
275+
<div class="view">
276+
<select id="forceRenderAbove">
277+
<option value="lorem">lorem</option>
278+
<option value="ipsum">ipsum</option>
279+
<option value="dolor">dolor</option>
280+
</select>
281+
</div>
282+
283+
<div class="code">
284+
<pre><code class="language-javascript">$('select').selectric({ forceRenderAbove: true });</code></pre>
285+
</div>
286+
</div>
287+
272288
<div class="demo-spacer"></div>
273289
</div>
274290

public/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ <h2>Options</h2>
335335
*/
336336
allowWrap: true,
337337

338+
/*
339+
* Type: Boolean
340+
* Description: By default the options box gets opened above if it's outside the window.
341+
* In case this auto detection doesn't work as expected (e.g. in transform/relative scopes)
342+
* you may force opening above.
343+
*/
344+
forceRenderAbove: false,
345+
338346
/*
339347
* Type: Object
340348
* Description: Customize select "multiple" behavior

public/lib/demo.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@
160160

161161
$('#basic').selectric();
162162

163+
$('#forceRenderAbove').selectric({ forceRenderAbove: true });
164+
163165
/*------------------------------------*/
164166

165167
// Cache the target element

selectric.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "selectric",
3-
"version": "1.11.1",
3+
"version": "1.12.0",
44
"title": "jQuery Selectric",
55
"author": {
66
"name": "Leonardo Santos",

src/jquery.selectric.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -753,21 +753,26 @@
753753
/** Detect if the options box is inside the window */
754754
isInViewport: function() {
755755
var _this = this;
756-
var scrollTop = $win.scrollTop();
757-
var winHeight = $win.height();
758-
var uiPosX = _this.elements.outerWrapper.offset().top;
759-
var uiHeight = _this.elements.outerWrapper.outerHeight();
760756

761-
var fitsDown = (uiPosX + uiHeight + _this.itemsHeight) <= (scrollTop + winHeight);
762-
var fitsAbove = (uiPosX - _this.itemsHeight) > scrollTop;
757+
if (_this.options.forceRenderAbove === true) {
758+
_this.elements.outerWrapper.addClass(_this.classes.above);
759+
} else {
760+
var scrollTop = $win.scrollTop();
761+
var winHeight = $win.height();
762+
var uiPosX = _this.elements.outerWrapper.offset().top;
763+
var uiHeight = _this.elements.outerWrapper.outerHeight();
764+
765+
var fitsDown = (uiPosX + uiHeight + _this.itemsHeight) <= (scrollTop + winHeight);
766+
var fitsAbove = (uiPosX - _this.itemsHeight) > scrollTop;
763767

764-
// If it does not fit below, only render it
765-
// above it fit's there.
766-
// It's acceptable that the user needs to
767-
// scroll the viewport to see the cut off UI
768-
var renderAbove = !fitsDown && fitsAbove;
768+
// If it does not fit below, only render it
769+
// above it fit's there.
770+
// It's acceptable that the user needs to
771+
// scroll the viewport to see the cut off UI
772+
var renderAbove = !fitsDown && fitsAbove;
769773

770-
_this.elements.outerWrapper.toggleClass(_this.classes.above, renderAbove);
774+
_this.elements.outerWrapper.toggleClass(_this.classes.above, renderAbove);
775+
}
771776
},
772777

773778
/**
@@ -1058,6 +1063,7 @@
10581063
preventWindowScroll : true,
10591064
inheritOriginalWidth : false,
10601065
allowWrap : true,
1066+
forceRenderAbove : false,
10611067
stopPropagation : true,
10621068
optionsItemBuilder : '{text}', // function(itemData, element, index)
10631069
labelBuilder : '{text}', // function(currItem)

0 commit comments

Comments
 (0)