2021-11-09 01:37:16 -06:00
|
|
|
import coreModule from './core_module';
|
2015-09-14 15:54:00 -05:00
|
|
|
|
2018-09-04 10:02:32 -05:00
|
|
|
coreModule.directive('giveFocus', () => {
|
2019-04-28 02:58:12 -05:00
|
|
|
return (scope: any, element: any, attrs: any) => {
|
|
|
|
element.click((e: any) => {
|
2015-09-14 15:54:00 -05:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
scope.$watch(
|
|
|
|
attrs.giveFocus,
|
2019-04-28 02:58:12 -05:00
|
|
|
(newValue: any) => {
|
2017-12-19 09:06:54 -06:00
|
|
|
if (!newValue) {
|
|
|
|
return;
|
2015-09-14 15:54:00 -05:00
|
|
|
}
|
2018-09-04 10:02:32 -05:00
|
|
|
setTimeout(() => {
|
2017-12-19 09:06:54 -06:00
|
|
|
element.focus();
|
2019-03-12 09:27:02 -05:00
|
|
|
const domEl: any = 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 {};
|