sogo/UI/WebServerResources/js/Common/sgFocus.directive.js
Francis Lachapelle 1dc5f0d412 (js) New file structure for Angular modules
JavaScript files are now merged by the 'js' Grunt task.
2015-06-12 12:01:21 -04:00

31 lines
704 B
JavaScript

/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
(function() {
'use strict';
/**
* sgFocusOn - A directive that sets the focus on its element when the specified string is broadcasted
* @memberof SOGo.Common
* @see {@link SOGo.Common.sgFocus}
* @ngInject
* @example:
<input type="text"
sg-focus-on="username" />
*/
function sgFocusOn() {
return function(scope, elem, attr) {
scope.$on('sgFocusOn', function(e, name) {
if (name === attr.sgFocusOn) {
elem[0].focus();
elem[0].select();
}
});
};
}
angular
.module('SOGo.Common')
.directive('sgFocusOn', sgFocusOn);
})();