diff --git a/modules/directives/input2/input2.js b/modules/directives/input2/input2.js new file mode 100644 index 0000000..10697eb --- /dev/null +++ b/modules/directives/input2/input2.js @@ -0,0 +1,34 @@ +/* + * Defines the ui-input2 tag, attribute and class(restrict ECA). This allow an input property to be changed + */ +angular.module('ui.directives').directive('uiInput2', ['$compile', function($compile) { + return { + restrict: 'ECA', + replace: true, + template: '', + link: function(scope, iElement, iAttrs, controller) { + var clone = (function() { + var cursor = iElement; + return function(type) { + var input = angular.element(''); + angular.forEach(iAttrs.$attr, function(v,k) { + if (v != 'type') { + input.attr(v, iAttrs[k]); + } + }); + input.removeAttr('ui-input2'); + cursor.after(input); + cursor.remove(); + cursor = input; + return input; + }; + })(); + + clone('text'); + iAttrs.$observe('type', function(type) { + var input = clone(type || 'text'); + $compile(input)(scope); + }); + } + }; +}]); diff --git a/modules/directives/input2/test/input2Spec.js b/modules/directives/input2/test/input2Spec.js new file mode 100644 index 0000000..727926d --- /dev/null +++ b/modules/directives/input2/test/input2Spec.js @@ -0,0 +1,47 @@ +describe('ui-input2', function () { + var scope, $compile, elm, + inputTypes = ['text', 'number', 'checkbox', 'radio']; + + beforeEach(module('ui.directives')); + beforeEach(inject(function ($rootScope, _$compile_) { + function makeInput (type) { + return $(''); + } + + scope = $rootScope.$new(); + $compile = _$compile_; + elm = $('