giveFocus.js 657 B

1234567891011121314151617181920212223242526272829
  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 domEl = element[0];
  18. if (domEl.setSelectionRange) {
  19. var pos = element.val().length * 2;
  20. domEl.setSelectionRange(pos, pos);
  21. }
  22. }, 200);
  23. },true);
  24. };
  25. });
  26. });