assets/javascripts/semantic_ui/definitions/modules/dropdown.js in less-rails-semantic_ui-2.2.10.0 vs assets/javascripts/semantic_ui/definitions/modules/dropdown.js in less-rails-semantic_ui-2.2.11.0
- old
+ new
@@ -675,11 +675,13 @@
: module.get.query(),
afterFiltered = function() {
if(module.is.multiple()) {
module.filterActive();
}
- module.select.firstUnfiltered();
+ if(query || (!query && module.get.activeItem().length == 0)) {
+ module.select.firstUnfiltered();
+ }
if( module.has.allResultsFiltered() ) {
if( settings.onNoResults.call(element, searchTerm) ) {
if(settings.allowAdditions) {
if(settings.hideAdditions) {
module.verbose('User addition with no menu, setting empty style');
@@ -1466,11 +1468,10 @@
event.preventDefault();
}
// down arrow (open menu)
if(pressedKey == keys.downArrow && !module.is.visible()) {
module.verbose('Down key pressed, showing dropdown');
- module.select.firstUnfiltered();
module.show();
event.preventDefault();
}
}
}
@@ -2365,25 +2366,35 @@
}
}
},
direction: function($menu) {
if(settings.direction == 'auto') {
- if(module.is.onScreen($menu)) {
+ // reset position
+ module.remove.upward();
+
+ if(module.can.openDownward($menu)) {
module.remove.upward($menu);
}
else {
module.set.upward($menu);
}
+ if(!module.is.leftward($menu) && !module.can.openRightward($menu)) {
+ module.set.leftward($menu);
+ }
}
else if(settings.direction == 'upward') {
module.set.upward($menu);
}
},
- upward: function($menu) {
- var $element = $menu || $module;
+ upward: function($currentMenu) {
+ var $element = $currentMenu || $module;
$element.addClass(className.upward);
},
+ leftward: function($currentMenu) {
+ var $element = $currentMenu || $menu;
+ $element.addClass(className.leftward);
+ },
value: function(value, text, $selected) {
var
escapedValue = module.escape.value(value),
hasInput = ($input.length > 0),
isAddition = !module.has.value(value),
@@ -2727,14 +2738,18 @@
$module.removeClass(className.loading);
},
initialLoad: function() {
initialLoad = false;
},
- upward: function($menu) {
- var $element = $menu || $module;
+ upward: function($currentMenu) {
+ var $element = $currentMenu || $module;
$element.removeClass(className.upward);
},
+ leftward: function($currentMenu) {
+ var $element = $currentMenu || $menu;
+ $element.removeClass(className.leftward);
+ },
visible: function() {
$module.removeClass(className.visible);
},
activeItem: function() {
$item.removeClass(className.active);
@@ -3035,10 +3050,14 @@
return ($subMenu)
? $subMenu.transition && $subMenu.transition('is animating')
: $menu.transition && $menu.transition('is animating')
;
},
+ leftward: function($subMenu) {
+ var $selectedMenu = $subMenu || $menu;
+ return $selectedMenu.hasClass(className.leftward);
+ },
disabled: function() {
return $module.hasClass(className.disabled);
},
focused: function() {
return (document.activeElement === $module[0]);
@@ -3053,50 +3072,10 @@
return !module.is.visible($subMenu);
},
initialLoad: function() {
return initialLoad;
},
- onScreen: function($subMenu) {
- var
- $currentMenu = $subMenu || $menu,
- canOpenDownward = true,
- onScreen = {},
- calculations
- ;
- $currentMenu.addClass(className.loading);
- calculations = {
- context: {
- scrollTop : $context.scrollTop(),
- height : $context.outerHeight()
- },
- menu : {
- offset: $currentMenu.offset(),
- height: $currentMenu.outerHeight()
- }
- };
- if(module.is.verticallyScrollableContext()) {
- calculations.menu.offset.top += calculations.context.scrollTop;
- }
- onScreen = {
- above : (calculations.context.scrollTop) <= calculations.menu.offset.top - calculations.menu.height,
- below : (calculations.context.scrollTop + calculations.context.height) >= calculations.menu.offset.top + calculations.menu.height
- };
- if(onScreen.below) {
- module.verbose('Dropdown can fit in context downward', onScreen);
- canOpenDownward = true;
- }
- else if(!onScreen.below && !onScreen.above) {
- module.verbose('Dropdown cannot fit in either direction, favoring downward', onScreen);
- canOpenDownward = true;
- }
- else {
- module.verbose('Dropdown cannot fit below, opening upward', onScreen);
- canOpenDownward = false;
- }
- $currentMenu.removeClass(className.loading);
- return canOpenDownward;
- },
inObject: function(needle, object) {
var
found = false
;
$.each(object, function(index, property) {
@@ -3155,10 +3134,18 @@
overflowY = ($context.get(0) !== window)
? $context.css('overflow-y')
: false
;
return (overflowY == 'auto' || overflowY == 'scroll');
+ },
+ horizontallyScrollableContext: function() {
+ var
+ overflowX = ($context.get(0) !== window)
+ ? $context.css('overflow-X')
+ : false
+ ;
+ return (overflowX == 'auto' || overflowX == 'scroll');
}
},
can: {
activate: function($item) {
@@ -3171,10 +3158,83 @@
if(module.has.maxSelections() && $item.hasClass(className.active)) {
return true;
}
return false;
},
+ openDownward: function($subMenu) {
+ var
+ $currentMenu = $subMenu || $menu,
+ canOpenDownward = true,
+ onScreen = {},
+ calculations
+ ;
+ $currentMenu
+ .addClass(className.loading)
+ ;
+ calculations = {
+ context: {
+ scrollTop : $context.scrollTop(),
+ height : $context.outerHeight()
+ },
+ menu : {
+ offset: $currentMenu.offset(),
+ height: $currentMenu.outerHeight()
+ }
+ };
+ if(module.is.verticallyScrollableContext()) {
+ calculations.menu.offset.top += calculations.context.scrollTop;
+ }
+ onScreen = {
+ above : (calculations.context.scrollTop) <= calculations.menu.offset.top - calculations.menu.height,
+ below : (calculations.context.scrollTop + calculations.context.height) >= calculations.menu.offset.top + calculations.menu.height
+ };
+ if(onScreen.below) {
+ module.verbose('Dropdown can fit in context downward', onScreen);
+ canOpenDownward = true;
+ }
+ else if(!onScreen.below && !onScreen.above) {
+ module.verbose('Dropdown cannot fit in either direction, favoring downward', onScreen);
+ canOpenDownward = true;
+ }
+ else {
+ module.verbose('Dropdown cannot fit below, opening upward', onScreen);
+ canOpenDownward = false;
+ }
+ $currentMenu.removeClass(className.loading);
+ return canOpenDownward;
+ },
+ openRightward: function($subMenu) {
+ var
+ $currentMenu = $subMenu || $menu,
+ canOpenRightward = true,
+ isOffscreenRight = false,
+ calculations
+ ;
+ $currentMenu
+ .addClass(className.loading)
+ ;
+ calculations = {
+ context: {
+ scrollLeft : $context.scrollLeft(),
+ width : $context.outerWidth()
+ },
+ menu: {
+ offset : $currentMenu.offset(),
+ width : $currentMenu.outerWidth()
+ }
+ };
+ if(module.is.horizontallyScrollableContext()) {
+ calculations.menu.offset.left += calculations.context.scrollLeft;
+ }
+ isOffscreenRight = (calculations.menu.offset.left + calculations.menu.width >= calculations.context.scrollLeft + calculations.context.width);
+ if(isOffscreenRight) {
+ module.verbose('Dropdown cannot fit in context rightward', isOffscreenRight);
+ canOpenRightward = false;
+ }
+ $currentMenu.removeClass(className.loading);
+ return canOpenRightward;
+ },
click: function() {
return (hasTouch || settings.on == 'click');
},
extendSelect: function() {
return settings.allowAdditions || settings.apiSettings;
@@ -3272,13 +3332,10 @@
debug : settings.debug,
verbose : settings.verbose,
queue : true,
onStart : start,
onComplete : function() {
- if(settings.direction == 'auto') {
- module.remove.upward($subMenu);
- }
callback.call(element);
}
})
;
}
@@ -3704,9 +3761,10 @@
sizer : 'sizer',
search : 'search',
selected : 'selected',
selection : 'selection',
upward : 'upward',
+ leftward : 'left',
visible : 'visible'
}
};