| 1234567891011121314151617181920212223242526272829303132333435 |
- define(['angular'], function(angular) {
- 'use strict';
- angular.module('SmartDirectives',[]).directive("focusMe", function() {
- return {
- restrict: "A",
- link: function(scope, element, attrs) {
- attrs.$observe("focusWhen", function() {
- if (attrs.focusWhen == "true") {
- element[0].focus();
- }
- });
- }
- };
- }).directive("enterAsTab",function(){
- return {
- restrict:"A",
- link:function (scope, element, attrs) {
- element.bind("keyup", function (event) {
- if(event.which === 13) {
- var focusable = document.getElementsByTagName('input');
- // Get the index of the currently focused element
- var currentIndex = Array.prototype.indexOf.call(focusable, event.target);
- // Find the next items in the list
- var nextIndex = currentIndex == focusable.length - 1 ? 0 : currentIndex + 1;
- // Focus the next element
- if(nextIndex >= 0 && nextIndex < focusable.length){
- if(focusable[nextIndex].value == 0||focusable[nextIndex].value == '')
- focusable[nextIndex].focus();
- }
- }
- });
- }
- }});
- });
|