'use strict'; /** * Password-check directive. */ app.directive('compareTo', function () { return { require: "ngModel", scope: { otherModelValue: "=compareTo" }, link: function (scope, element, attributes, ngModel) { ngModel.$validators.compareTo = function (modelValue) { return modelValue == scope.otherModelValue; }; scope.$watch("otherModelValue", function () { ngModel.$validate(); }); } }; }); app.directive('capitalize', function() { return { require: 'ngModel', link: function(scope, element, attrs, modelCtrl) { var capitalize = function(inputValue) { if (inputValue == undefined) inputValue = ''; var capitalized = inputValue.toUpperCase(); if (capitalized !== inputValue) { modelCtrl.$setViewValue(capitalized); modelCtrl.$render(); } return capitalized; } modelCtrl.$parsers.push(capitalize); capitalize(scope[attrs.ngModel]); // capitalize initial value } }; }); app.directive('disallowSpaces', function() { return { restrict: 'A', link: function($scope, $element) { $element.bind('input', function() { $(this).val($(this).val().replace(/ /g, '')); }); } }; }); app.filter('unique', function() { return function(collection, primaryKey, secondaryKey) { //optional secondary key var output = [], keys = []; angular.forEach(collection, function(item) { var key; secondaryKey === undefined ? key = item[primaryKey] : key = item[primaryKey][secondaryKey]; if(keys.indexOf(key) === -1) { keys.push(key); output.push(item); } }); return output; }; });