2017-12-20 05:33:33 -06:00
|
|
|
import coreModule from '../core_module';
|
2015-09-14 15:54:00 -05:00
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.directive('giveFocus', function() {
|
2015-09-14 15:54:00 -05:00
|
|
|
return function(scope, element, attrs) {
|
|
|
|
element.click(function(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
scope.$watch(
|
|
|
|
attrs.giveFocus,
|
|
|
|
function(newValue) {
|
|
|
|
if (!newValue) {
|
|
|
|
return;
|
2015-09-14 15:54:00 -05:00
|
|
|
}
|
2017-12-19 09:06:54 -06:00
|
|
|
setTimeout(function() {
|
|
|
|
element.focus();
|
2018-08-29 07:26:50 -05:00
|
|
|
const domEl = element[0];
|
2017-12-19 09:06:54 -06:00
|
|
|
if (domEl.setSelectionRange) {
|
2018-08-29 07:26:50 -05:00
|
|
|
const pos = element.val().length * 2;
|
2017-12-19 09:06:54 -06:00
|
|
|
domEl.setSelectionRange(pos, pos);
|
|
|
|
}
|
|
|
|
}, 200);
|
|
|
|
},
|
|
|
|
true
|
|
|
|
);
|
2015-09-14 15:54:00 -05:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
export default {};
|