Skip to content

Commit

Permalink
Bump up to 1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
indrimuska committed Oct 11, 2017
1 parent ddd8880 commit 7d5ebe9
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-selector",
"version": "1.5.0",
"version": "1.6.0",
"authors": [
"Indri Muska <[email protected]>"
],
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-selector.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! angular-selector - v1.5.0 - https://github.com/indrimuska/angular-selector - (c) 2015 Indri Muska - MIT */
/*! angular-selector - v1.6.0 - https://github.com/indrimuska/angular-selector - (c) 2015 Indri Muska - MIT */
@-webkit-keyframes selector-rotate { 0% { -webkit-transform: rotateZ(-359deg); } 100% { -webkit-transform: rotateZ(0deg); } }
@-moz-keyframes selector-rotate { 0% { -moz-transform: rotateZ(-359deg); } 100% { -moz-transform: rotateZ(0deg); } }
@-o-keyframes selector-rotate { 0% { -o-transform: rotateZ(-359deg); } 100% { -o-transform: rotateZ(0deg); } }
Expand Down
59 changes: 39 additions & 20 deletions dist/angular-selector.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! angular-selector - v1.5.0 - https://github.com/indrimuska/angular-selector - (c) 2015 Indri Muska - MIT */
/*! angular-selector - v1.6.0 - https://github.com/indrimuska/angular-selector - (c) 2015 Indri Muska - MIT */
(function (angular) {

// Key codes
Expand Down Expand Up @@ -81,6 +81,7 @@
remoteParam: 'q',
remoteValidationParam: 'value',
removeButton: true,
showCreateOption: false,
viewItemTemplate: 'selector/item-default.html',
dropdownItemTemplate: 'selector/item-default.html',
dropdownCreateTemplate: 'selector/item-create.html',
Expand Down Expand Up @@ -189,13 +190,13 @@
if (!angular.isDefined(scope.remoteValidation))
scope.remoteValidation = false;
if (scope.remote)
$timeout(function () {
scope.$evalAsync(function () {
$q.when(!scope.hasValue() || !scope.remoteValidation
? angular.noop
: scope.fetchValidation(scope.value)
).then(function () {
scope.$watch('search', function () {
$timeout(scope.fetch);
scope.$evalAsync(scope.fetch);
});
});
});
Expand Down Expand Up @@ -276,7 +277,7 @@
if (scope.multiple && (scope.selectedValues || []).length >= scope.limit) return;
scope.isOpen = true;
scope.dropdownPosition();
$timeout(scope.scrollToHighlighted);
scope.$evalAsync(scope.scrollToHighlighted);
};
scope.close = function () {
scope.isOpen = false;
Expand All @@ -292,28 +293,30 @@
scope.scrollToHighlighted();
};
scope.highlight = function (index) {
if (attrs.create && scope.search && index == -1)
scope.highlighted = -1;
else
if (scope.filteredOptions.length)
scope.highlighted = (scope.filteredOptions.length + index) % scope.filteredOptions.length;
var length = scope.filteredOptions.length;
if (length) scope.highlighted = (length + index) % length;
if (scope.showCreateOption) {
if (index == -1 || index == length) scope.highlighted = -1;
if (index == -2) scope.highlighted = length - 1;
}
};
scope.scrollToHighlighted = function () {
var dd = dropdown[0],
option = dd.querySelectorAll('li.selector-option')[scope.highlighted],
index = scope.highlighted + (scope.showCreateOption ? 1 : 0),
option = dd.querySelectorAll('li.selector-option')[index],
styles = getStyles(option),
marginTop = parseFloat(styles.marginTop || 0),
marginBottom = parseFloat(styles.marginBottom || 0);

if (!scope.filteredOptions.length) return;

if (option.offsetTop + option.offsetHeight + marginBottom > dd.scrollTop + dd.offsetHeight)
$timeout(function () {
scope.$evalAsync(function () {
dd.scrollTop = option.offsetTop + option.offsetHeight + marginBottom - dd.offsetHeight;
});

if (option.offsetTop - marginTop < dd.scrollTop)
$timeout(function () {
scope.$evalAsync(function () {
dd.scrollTop = option.offsetTop - marginTop;
});
};
Expand Down Expand Up @@ -358,8 +361,8 @@
scope.keydown = function (e) {
switch (e.keyCode) {
case KEYS.up:
if (!scope.isOpen) break;
scope.decrementHighlighted();
if (!scope.isOpen) scope.open();
else scope.decrementHighlighted();
e.preventDefault();
break;
case KEYS.down:
Expand Down Expand Up @@ -387,7 +390,7 @@
scope.unset();
scope.open();
if (scope.softDelete && !scope.disableSearch)
$timeout(function () {
scope.$evalAsync(function () {
scope.search = search;
});
e.preventDefault();
Expand Down Expand Up @@ -434,6 +437,14 @@
var index = scope.filteredOptions.indexOf(scope.selectedValues[0]);
if (index >= 0) scope.highlight(index);
}
// show create item option
if (scope.create) {
scope.showCreateOption = scope.create && scope.search && scope.filteredOptions.filter(function (option) {
return scope.getObjValue(option, scope.labelAttr).toLowerCase() == scope.search.toLowerCase();

}).length == 0;
if (scope.showCreateOption && scope.filteredOptions.length == 0 && scope.highlighted != -1) scope.highlighted = -1;
}
};

// Input width utilities
Expand All @@ -457,7 +468,7 @@
scope.resetInput = function () {
input.val('');
scope.setInputWidth();
$timeout(function () { scope.search = ''; });
scope.$evalAsync(function () { scope.search = ''; });
};

scope.$watch('[search, options, value]', function () {
Expand Down Expand Up @@ -512,15 +523,16 @@
}, true);

// DOM event listeners
angular.element(element[0].querySelector('.selector-input'))
.on('click', function () {
input[0].focus();
});
input = angular.element(element[0].querySelector('.selector-input input'))
.on('focus', function () {
$timeout(function () {
scope.$apply(scope.open);
});
})
.on('blur', function () {
scope.$apply(scope.close);
})
.on('keydown', function (e) {
scope.$apply(function () {
scope.keydown(e);
Expand All @@ -536,6 +548,13 @@
angular.element($window)
.on('resize', function () {
scope.dropdownPosition();
})
.on('click', function (e) {
if (angular.equals(element, e.target)) return;
if (scope.isOpen) {
scope.$evalAsync(scope.close);
e.preventDefault();
}
});

// Update select controller
Expand Down Expand Up @@ -598,7 +617,7 @@
'</div>' +
'</label>' +
'<ul class="selector-dropdown" ng-show="filteredOptions.length > 0 || (create && search)">' +
'<li class="selector-option create" ng-class="{active: highlighted == -1}" ng-if="create && search" ' +
'<li class="selector-option create" ng-class="{active: highlighted == -1}" ng-if="showCreateOption" ' +
'ng-include="dropdownCreateTemplate" ng-mouseover="highlight(-1)" ng-click="createOption(search)"></li>' +
'<li ng-repeat-start="(index, option) in filteredOptions track by index" class="selector-optgroup" ' +
'ng-include="dropdownGroupTemplate" ng-show="groupAttr && ' +
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-selector.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7d5ebe9

Please sign in to comment.