Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

focus triger #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions dist/select-tpls.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ angular.module('oi.select')

//length less then minlength
if (String(inputValue).length < options.minlength) return;

//We don't get matches if nothing added into matches list
if (inputValue !== oldValue && (!scope.oldQuery || inputValue) && !matchesWereReset) {
listElement[0].scrollTop = 0;
Expand Down Expand Up @@ -777,10 +777,35 @@ angular.module('oi.select')

resetMatches();

element[0].addEventListener('click', click, true); //triggered before add or delete item event
// //triggered before add or delete item event
var eventTriger = '';

var focusEvent = function(e) {
eventTriger = eventTriger ? eventTriger : 'focus';
click(e);
element[0].addEventListener('click', clickEvent, true);
element[0].addEventListener('blur', blurEvent, true);
}

var clickEvent = function(e) {
eventTriger = eventTriger ? eventTriger : 'click';
click(e);
}

var blurEvent = function () {
eventTriger = ''
element[0].removeEventListener('click', clickEvent, true);
element[0].removeEventListener('blur', blurEvent, true);
}

element[0].addEventListener('focus', focusEvent, true); //triggered before add or delete item event
scope.$on('$destroy', function() {
element[0].removeEventListener('click', click, true);
element[0].removeEventListener('click', clickEvent, true);
element[0].removeEventListener('focus', focusEvent, true);
element[0].removeEventListener('blur', blurEvent, true);
});


element.on('focus', focus);
element.on('blur', blur);

Expand Down Expand Up @@ -808,7 +833,7 @@ angular.module('oi.select')
function click(event) {
//query length less then minlength
if (scope.query.length < options.minlength) return;

//option is disabled
if (oiUtils.contains(element[0], event.target, 'disabled')) return;

Expand All @@ -820,8 +845,11 @@ angular.module('oi.select')
}

if (scope.isOpen && options.closeList && (event.target.nodeName !== 'INPUT' || !scope.query.length)) { //do not reset if you are editing the query
resetMatches({query: options.editItem && !editItemIsCorrected});
scope.$evalAsync();
if (event.type == eventTriger) {
resetMatches({query: options.editItem && !editItemIsCorrected});
scope.$evalAsync();
eventTriger = '';
}
} else {
getMatches(scope.query);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/select-tpls.min.js

Large diffs are not rendered by default.

40 changes: 34 additions & 6 deletions dist/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ angular.module('oi.select')

//length less then minlength
if (String(inputValue).length < options.minlength) return;

//We don't get matches if nothing added into matches list
if (inputValue !== oldValue && (!scope.oldQuery || inputValue) && !matchesWereReset) {
listElement[0].scrollTop = 0;
Expand Down Expand Up @@ -777,10 +777,35 @@ angular.module('oi.select')

resetMatches();

element[0].addEventListener('click', click, true); //triggered before add or delete item event
// //triggered before add or delete item event
var eventTriger = '';

var focusEvent = function(e) {
eventTriger = eventTriger ? eventTriger : 'focus';
click(e);
element[0].addEventListener('click', clickEvent, true);
element[0].addEventListener('blur', blurEvent, true);
}

var clickEvent = function(e) {
eventTriger = eventTriger ? eventTriger : 'click';
click(e);
}

var blurEvent = function () {
eventTriger = ''
element[0].removeEventListener('click', clickEvent, true);
element[0].removeEventListener('blur', blurEvent, true);
}

element[0].addEventListener('focus', focusEvent, true); //triggered before add or delete item event
scope.$on('$destroy', function() {
element[0].removeEventListener('click', click, true);
element[0].removeEventListener('click', clickEvent, true);
element[0].removeEventListener('focus', focusEvent, true);
element[0].removeEventListener('blur', blurEvent, true);
});


element.on('focus', focus);
element.on('blur', blur);

Expand Down Expand Up @@ -808,7 +833,7 @@ angular.module('oi.select')
function click(event) {
//query length less then minlength
if (scope.query.length < options.minlength) return;

//option is disabled
if (oiUtils.contains(element[0], event.target, 'disabled')) return;

Expand All @@ -820,8 +845,11 @@ angular.module('oi.select')
}

if (scope.isOpen && options.closeList && (event.target.nodeName !== 'INPUT' || !scope.query.length)) { //do not reset if you are editing the query
resetMatches({query: options.editItem && !editItemIsCorrected});
scope.$evalAsync();
if (event.type == eventTriger) {
resetMatches({query: options.editItem && !editItemIsCorrected});
scope.$evalAsync();
eventTriger = '';
}
} else {
getMatches(scope.query);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/select.min.js

Large diffs are not rendered by default.

40 changes: 34 additions & 6 deletions src/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ angular.module('oi.select')

//length less then minlength
if (String(inputValue).length < options.minlength) return;

//We don't get matches if nothing added into matches list
if (inputValue !== oldValue && (!scope.oldQuery || inputValue) && !matchesWereReset) {
listElement[0].scrollTop = 0;
Expand Down Expand Up @@ -442,10 +442,35 @@ angular.module('oi.select')

resetMatches();

element[0].addEventListener('click', click, true); //triggered before add or delete item event
// //triggered before add or delete item event
var eventTriger = '';

var focusEvent = function(e) {
eventTriger = eventTriger ? eventTriger : 'focus';
click(e);
element[0].addEventListener('click', clickEvent, true);
element[0].addEventListener('blur', blurEvent, true);
}

var clickEvent = function(e) {
eventTriger = eventTriger ? eventTriger : 'click';
click(e);
}

var blurEvent = function () {
eventTriger = ''
element[0].removeEventListener('click', clickEvent, true);
element[0].removeEventListener('blur', blurEvent, true);
}

element[0].addEventListener('focus', focusEvent, true); //triggered before add or delete item event
scope.$on('$destroy', function() {
element[0].removeEventListener('click', click, true);
element[0].removeEventListener('click', clickEvent, true);
element[0].removeEventListener('focus', focusEvent, true);
element[0].removeEventListener('blur', blurEvent, true);
});


element.on('focus', focus);
element.on('blur', blur);

Expand Down Expand Up @@ -473,7 +498,7 @@ angular.module('oi.select')
function click(event) {
//query length less then minlength
if (scope.query.length < options.minlength) return;

//option is disabled
if (oiUtils.contains(element[0], event.target, 'disabled')) return;

Expand All @@ -485,8 +510,11 @@ angular.module('oi.select')
}

if (scope.isOpen && options.closeList && (event.target.nodeName !== 'INPUT' || !scope.query.length)) { //do not reset if you are editing the query
resetMatches({query: options.editItem && !editItemIsCorrected});
scope.$evalAsync();
if (event.type == eventTriger) {
resetMatches({query: options.editItem && !editItemIsCorrected});
scope.$evalAsync();
eventTriger = '';
}
} else {
getMatches(scope.query);
}
Expand Down