giveFocus.js 571 B

1234567891011121314151617181920212223242526
  1. define([
  2. 'angular'
  3. ],
  4. function (angular) {
  5. 'use strict';
  6. angular.module('grafana.directives').directive('giveFocus', function() {
  7. return function(scope, element, attrs) {
  8. element.click(function(e) {
  9. e.stopPropagation();
  10. });
  11. scope.$watch(attrs.giveFocus,function (newValue) {
  12. if (!newValue) {
  13. return;
  14. }
  15. setTimeout(function() {
  16. element.focus();
  17. var pos = element.val().length * 2;
  18. element[0].setSelectionRange(pos, pos);
  19. }, 200);
  20. },true);
  21. };
  22. });
  23. });