|
1 | 1 | /* |
2 | | - * Gijgo JavaScript Library v1.9.3 |
| 2 | + * Gijgo JavaScript Library v1.9.4 |
3 | 3 | * http://gijgo.com/ |
4 | 4 | * |
5 | 5 | * Copyright 2014, 2018 gijgo.com |
@@ -13078,21 +13078,35 @@ gj.dropdown.methods = { |
13078 | 13078 | }, |
13079 | 13079 |
|
13080 | 13080 | setListPosition: function (presenter, list, data) { |
13081 | | - var top, listHeight, presenterHeight, newHeight, |
13082 | | - mainElRect = presenter.getBoundingClientRect(); |
13083 | | - |
13084 | | - gj.core.setChildPosition(presenter, list); |
| 13081 | + var top, listHeight, presenterHeight, newHeight, listElRect, |
| 13082 | + mainElRect = presenter.getBoundingClientRect(), |
| 13083 | + scrollY = window.scrollY || window.pageYOffset || 0, |
| 13084 | + scrollX = window.scrollX || window.pageXOffset || 0; |
13085 | 13085 |
|
13086 | 13086 | // Reset list size |
13087 | 13087 | list.style.overflow = ''; |
13088 | 13088 | list.style.overflowX = ''; |
13089 | 13089 | list.style.height = ''; |
13090 | 13090 |
|
| 13091 | + gj.core.setChildPosition(presenter, list); |
| 13092 | + |
13091 | 13093 | listHeight = gj.core.height(list, true); |
| 13094 | + listElRect = list.getBoundingClientRect(); |
13092 | 13095 | presenterHeight = gj.core.height(presenter, true); |
13093 | | - if (!isNaN(listHeight) && data.maxHeight === 'auto' && (mainElRect.top + listHeight + presenterHeight) > window.innerHeight) { |
13094 | | - newHeight = window.innerHeight - mainElRect.top - presenterHeight - 3; |
13095 | | - } else if (!isNaN(listHeight) && !isNaN(data.maxHeight) && data.maxHeight < listHeight) { |
| 13096 | + if (data.maxHeight === 'auto') { |
| 13097 | + if (mainElRect.top < listElRect.top) { // The list is located below the main element |
| 13098 | + if (mainElRect.top + listHeight + presenterHeight > window.innerHeight) { |
| 13099 | + newHeight = window.innerHeight - mainElRect.top - presenterHeight - 3; |
| 13100 | + } |
| 13101 | + } else { // The list is located above the main element |
| 13102 | + if (mainElRect.top - listHeight - 3 > 0) { |
| 13103 | + list.style.top = Math.round(mainElRect.top + scrollY - listHeight - 3) + 'px'; |
| 13104 | + } else { |
| 13105 | + list.style.top = scrollY + 'px'; |
| 13106 | + newHeight = mainElRect.top - 3; |
| 13107 | + } |
| 13108 | + } |
| 13109 | + } else if (!isNaN(data.maxHeight) && data.maxHeight < listHeight) { |
13096 | 13110 | newHeight = data.maxHeight; |
13097 | 13111 | } |
13098 | 13112 |
|
|
0 commit comments