diff --git a/src/common.js b/src/common.js index ba7023424..cc564ab3f 100644 --- a/src/common.js +++ b/src/common.js @@ -107,6 +107,7 @@ var uis = angular.module('ui.select', []) return latestId++; }, appendToBody: false, + preventPageScroll: true, spinnerEnabled: false, spinnerClass: 'glyphicon-refresh ui-select-spin', backspaceReset: true diff --git a/src/uiSelectChoicesDirective.js b/src/uiSelectChoicesDirective.js index 911e83132..982e3a6f0 100644 --- a/src/uiSelectChoicesDirective.js +++ b/src/uiSelectChoicesDirective.js @@ -52,7 +52,20 @@ uis.directive('uiSelectChoices', clickTarget.attr('ng-click', '$select.select(' + parserResult.itemName + ',$select.skipFocusser,$event)'); return function link(scope, element, attrs, $select) { + + if ($select.preventPageScroll) {// Prevent the whole page for scrolling when the choices ul reaches it's scroll limits. + element.on('mousewheel', function(event) { + var heightDif = this.offsetHeight - this.clientHeight, + maxScrollTop = this.scrollHeight - this.offsetHeight + heightDif; + if ((this.scrollTop === maxScrollTop && event.deltaY > 0) || + (this.scrollTop === 0 && event.deltaY < 0)) { + event.preventDefault(); + } + }); + } + + $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult $select.disableChoiceExpression = attrs.uiDisableChoice; diff --git a/src/uiSelectController.js b/src/uiSelectController.js index e304279d4..53506bd1b 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -56,6 +56,8 @@ uis.controller('uiSelectCtrl', } })(); + ctrl.preventPageScroll = undefined; //Initialized inside uiSelect directive link function + ctrl.searchInput = $element.querySelectorAll('input.ui-select-search'); if (ctrl.searchInput.length !== 1) { throw uiSelectMinErr('searchInput', "Expected 1 input.ui-select-search but got '{0}'.", ctrl.searchInput.length); diff --git a/src/uiSelectDirective.js b/src/uiSelectDirective.js index 285cfb4ac..a59cf7f8d 100644 --- a/src/uiSelectDirective.js +++ b/src/uiSelectDirective.js @@ -52,6 +52,14 @@ uis.directive('uiSelect', } }(); + $select.preventPageScroll = function() { + if (angular.isDefined(attrs.preventPageScroll)) { + return $parse(attrs.preventPageScroll)(); + } else { + return uiSelectConfig.preventPageScroll; + } + }(); + scope.$watch('skipFocusser', function() { var skipFocusser = scope.$eval(attrs.skipFocusser); $select.skipFocusser = skipFocusser !== undefined ? skipFocusser : uiSelectConfig.skipFocusser;