diff options
Diffstat (limited to 'js/vendor/angular-ui/modules/filters')
9 files changed, 338 insertions, 0 deletions
diff --git a/js/vendor/angular-ui/modules/filters/format/format.js b/js/vendor/angular-ui/modules/filters/format/format.js new file mode 100644 index 000000000..cedd3fb84 --- /dev/null +++ b/js/vendor/angular-ui/modules/filters/format/format.js @@ -0,0 +1,34 @@ + +/** + * A replacement utility for internationalization very similar to sprintf. + * + * @param replace {mixed} The tokens to replace depends on type + * string: all instances of $0 will be replaced + * array: each instance of $0, $1, $2 etc. will be placed with each array item in corresponding order + * object: all attributes will be iterated through, with :key being replaced with its corresponding value + * @return string + * + * @example: 'Hello :name, how are you :day'.format({ name:'John', day:'Today' }) + * @example: 'Records $0 to $1 out of $2 total'.format(['10', '20', '3000']) + * @example: '$0 agrees to all mentions $0 makes in the event that $0 hits a tree while $0 is driving drunk'.format('Bob') + */ +angular.module('ui.filters').filter('format', function(){ + return function(value, replace) { + if (!value) { + return value; + } + var target = value.toString(), token; + if (replace === undefined) { + return target; + } + if (!angular.isArray(replace) && !angular.isObject(replace)) { + return target.split('$0').join(replace); + } + token = angular.isArray(replace) && '$' || ':'; + + angular.forEach(replace, function(value, key){ + target = target.split(token+key).join(value); + }); + return target; + }; +}); diff --git a/js/vendor/angular-ui/modules/filters/format/test/formatSpec.js b/js/vendor/angular-ui/modules/filters/format/test/formatSpec.js new file mode 100644 index 000000000..5d83fdb63 --- /dev/null +++ b/js/vendor/angular-ui/modules/filters/format/test/formatSpec.js @@ -0,0 +1,21 @@ +describe('format', function() { + var formatFilter; + + beforeEach(module('ui.filters')); + beforeEach(inject(function($filter) { + formatFilter = $filter('format'); + })); + + it('should replace all instances of $0 if string token is passed', function() { + expect(formatFilter('First $0, then $0, finally $0', 'bob')).toEqual('First bob, then bob, finally bob'); + }); + it('should replace all instances of $n based on order of token array', function() { + expect(formatFilter('First is $0, then $1, finally $2', ['bob','frank','dianne'])).toEqual('First is bob, then frank, finally dianne'); + }); + it('should replace all instances :tokens based on keys of token object', function() { + expect(formatFilter('First is :first, next is :second, finally there is :third', {first:'bob',second:'frank',third:'dianne'})).toEqual('First is bob, next is frank, finally there is dianne'); + }); + it('should do nothing if tokens are undefined', function() { + expect(formatFilter('Hello There')).toEqual('Hello There'); + }); +});
\ No newline at end of file diff --git a/js/vendor/angular-ui/modules/filters/highlight/highlight.js b/js/vendor/angular-ui/modules/filters/highlight/highlight.js new file mode 100644 index 000000000..1d1cf6e48 --- /dev/null +++ b/js/vendor/angular-ui/modules/filters/highlight/highlight.js @@ -0,0 +1,21 @@ +/** + * Wraps the + * @param text {string} haystack to search through + * @param search {string} needle to search for + * @param [caseSensitive] {boolean} optional boolean to use case-sensitive searching + */ +angular.module('ui.filters').filter('highlight', function () { + return function (text, search, caseSensitive) { + if (search || angular.isNumber(search)) { + text = text.toString(); + search = search.toString(); + if (caseSensitive) { + return text.split(search).join('<span class="ui-match">' + search + '</span>'); + } else { + return text.replace(new RegExp(search, 'gi'), '<span class="ui-match">$&</span>'); + } + } else { + return text; + } + }; +}); diff --git a/js/vendor/angular-ui/modules/filters/highlight/highlight.less b/js/vendor/angular-ui/modules/filters/highlight/highlight.less new file mode 100644 index 000000000..a5839712c --- /dev/null +++ b/js/vendor/angular-ui/modules/filters/highlight/highlight.less @@ -0,0 +1,5 @@ + +/* highlight */ +.ui-match { + background: yellow; +} diff --git a/js/vendor/angular-ui/modules/filters/highlight/test/highlightSpec.js b/js/vendor/angular-ui/modules/filters/highlight/test/highlightSpec.js new file mode 100644 index 000000000..aae3ee0bb --- /dev/null +++ b/js/vendor/angular-ui/modules/filters/highlight/test/highlightSpec.js @@ -0,0 +1,48 @@ +describe('highlight', function () {
+ var highlightFilter, testPhrase = 'Prefix Highlight Suffix';
+
+ beforeEach(module('ui.filters'));
+ beforeEach(inject(function ($filter) {
+ highlightFilter = $filter('highlight');
+ }));
+ describe('case insensitive', function () {
+ it('should highlight a matching phrase', function () {
+ expect(highlightFilter(testPhrase, 'highlight')).toEqual('Prefix <span class="ui-match">Highlight</span> Suffix');
+ });
+ it('should highlight nothing if no match found', function () {
+ expect(highlightFilter(testPhrase, 'no match')).toEqual(testPhrase);
+ });
+ it('should highlight nothing for the undefined filter', function () {
+ expect(highlightFilter(testPhrase, undefined)).toEqual(testPhrase);
+ });
+ it('should work correctly for number filters', function () {
+ expect(highlightFilter('3210123', 0)).toEqual('321<span class="ui-match">0</span>123');
+ });
+ it('should work correctly for number text', function () {
+ expect(highlightFilter(3210123, '0')).toEqual('321<span class="ui-match">0</span>123');
+ });
+ });
+ describe('case sensitive', function () {
+ it('should highlight a matching phrase', function () {
+ expect(highlightFilter(testPhrase, 'Highlight', true)).toEqual('Prefix <span class="ui-match">Highlight</span> Suffix');
+ });
+ it('should highlight nothing if no match found', function () {
+ expect(highlightFilter(testPhrase, 'no match', true)).toEqual(testPhrase);
+ });
+ it('should highlight nothing for the undefined filter', function () {
+ expect(highlightFilter(testPhrase, undefined, true)).toEqual(testPhrase);
+ });
+ it('should work correctly for number filters', function () {
+ expect(highlightFilter('3210123', 0, true)).toEqual('321<span class="ui-match">0</span>123');
+ });
+ it('should work correctly for number text', function () {
+ expect(highlightFilter(3210123, '0', true)).toEqual('321<span class="ui-match">0</span>123');
+ });
+ it('should not highlight a phrase with different letter-casing', function () {
+ expect(highlightFilter(testPhrase, 'highlight', true)).toEqual(testPhrase);
+ });
+ });
+ it('should highlight nothing if empty filter string passed - issue #114', function () {
+ expect(highlightFilter(testPhrase, '')).toEqual(testPhrase);
+ });
+});
\ No newline at end of file diff --git a/js/vendor/angular-ui/modules/filters/inflector/inflector.js b/js/vendor/angular-ui/modules/filters/inflector/inflector.js new file mode 100644 index 000000000..4ab74093a --- /dev/null +++ b/js/vendor/angular-ui/modules/filters/inflector/inflector.js @@ -0,0 +1,44 @@ +/** + * Converts variable-esque naming conventions to something presentational, capitalized words separated by space. + * @param {String} value The value to be parsed and prettified. + * @param {String} [inflector] The inflector to use. Default: humanize. + * @return {String} + * @example {{ 'Here Is my_phoneNumber' | inflector:'humanize' }} => Here Is My Phone Number + * {{ 'Here Is my_phoneNumber' | inflector:'underscore' }} => here_is_my_phone_number + * {{ 'Here Is my_phoneNumber' | inflector:'variable' }} => hereIsMyPhoneNumber + */ +angular.module('ui.filters').filter('inflector', function () { + function ucwords(text) { + return text.replace(/^([a-z])|\s+([a-z])/g, function ($1) { + return $1.toUpperCase(); + }); + } + + function breakup(text, separator) { + return text.replace(/[A-Z]/g, function (match) { + return separator + match; + }); + } + + var inflectors = { + humanize: function (value) { + return ucwords(breakup(value, ' ').split('_').join(' ')); + }, + underscore: function (value) { + return value.substr(0, 1).toLowerCase() + breakup(value.substr(1), '_').toLowerCase().split(' ').join('_'); + }, + variable: function (value) { + value = value.substr(0, 1).toLowerCase() + ucwords(value.split('_').join(' ')).substr(1).split(' ').join(''); + return value; + } + }; + + return function (text, inflector, separator) { + if (inflector !== false && angular.isString(text)) { + inflector = inflector || 'humanize'; + return inflectors[inflector](text); + } else { + return text; + } + }; +}); diff --git a/js/vendor/angular-ui/modules/filters/inflector/test/inflectorSpec.js b/js/vendor/angular-ui/modules/filters/inflector/test/inflectorSpec.js new file mode 100644 index 000000000..1dcb236c6 --- /dev/null +++ b/js/vendor/angular-ui/modules/filters/inflector/test/inflectorSpec.js @@ -0,0 +1,39 @@ +describe('inflector', function () { + var inflectorFilter, testPhrase = 'here isMy_phone_number'; + + beforeEach(module('ui.filters')); + beforeEach(inject(function ($filter) { + inflectorFilter = $filter('inflector'); + })); + + describe('default', function () { + it('should default to humanize', function () { + expect(inflectorFilter(testPhrase)).toEqual('Here Is My Phone Number'); + }); + it('should fail gracefully for invalid input', function () { + expect(inflectorFilter(undefined)).toBeUndefined(); + }); + it('should do nothing for empty input', function () { + expect(inflectorFilter('')).toEqual(''); + }); + }); + + describe('humanize', function () { + it('should uppercase first letter and separate words with a space', function () { + expect(inflectorFilter(testPhrase, 'humanize')).toEqual('Here Is My Phone Number'); + }); + }); + describe('underscore', function () { + it('should lowercase everything and separate words with an underscore', function () { + expect(inflectorFilter(testPhrase, 'underscore')).toEqual('here_is_my_phone_number'); + }); + }); + describe('variable', function () { + it('should remove all separators and camelHump the phrase', function () { + expect(inflectorFilter(testPhrase, 'variable')).toEqual('hereIsMyPhoneNumber'); + }); + it('should do nothing if already formatted properly', function () { + expect(inflectorFilter("hereIsMyPhoneNumber", 'variable')).toEqual('hereIsMyPhoneNumber'); + }); + }); +});
\ No newline at end of file diff --git a/js/vendor/angular-ui/modules/filters/unique/test/uniqueSpec.js b/js/vendor/angular-ui/modules/filters/unique/test/uniqueSpec.js new file mode 100644 index 000000000..ae1251f4b --- /dev/null +++ b/js/vendor/angular-ui/modules/filters/unique/test/uniqueSpec.js @@ -0,0 +1,81 @@ +describe('unique', function () {
+ var uniqueFilter;
+
+ beforeEach(module('ui.filters'));
+ beforeEach(inject(function ($filter) {
+ uniqueFilter = $filter('unique');
+ }));
+
+ it('should return unique entries based on object equality', function () {
+ var arrayToFilter = [
+ {key: 'value'},
+ {key: 'value2'},
+ {key: 'value'}
+ ];
+ expect(uniqueFilter(arrayToFilter)).toEqual([
+ {key: 'value'},
+ {key: 'value2'}
+ ]);
+ });
+
+ it('should return unique entries based on object equality for complex objects', function () {
+ var arrayToFilter = [
+ {key: 'value', other: 'other1'},
+ {key: 'value2', other: 'other2'},
+ {other: 'other1', key: 'value'}
+ ];
+ expect(uniqueFilter(arrayToFilter)).toEqual([
+ {key: 'value', other: 'other1'},
+ {key: 'value2', other: 'other2'}
+ ]);
+ });
+
+ it('should return unique entries based on the key provided', function () {
+ var arrayToFilter = [
+ {key: 'value'},
+ {key: 'value2'},
+ {key: 'value'}
+ ];
+ expect(uniqueFilter(arrayToFilter, 'key')).toEqual([
+ {key: 'value'},
+ {key: 'value2'}
+ ]);
+ });
+
+ it('should return unique entries based on the key provided for complex objects', function () {
+ var arrayToFilter = [
+ {key: 'value', other: 'other1'},
+ {key: 'value2', other: 'other2'},
+ {key: 'value', other: 'other3'}
+ ];
+ expect(uniqueFilter(arrayToFilter, 'key')).toEqual([
+ { key: 'value', other: 'other1' },
+ { key: 'value2', other: 'other2' }
+ ]);
+ });
+
+ it('should return unique primitives in arrays', function () {
+ expect(uniqueFilter([1, 2, 1, 3])).toEqual([1, 2, 3]);
+ });
+
+ it('should work correctly for arrays of mixed elements and object equality', function () {
+ expect(uniqueFilter([1, {key: 'value'}, 1, {key: 'value'}, 2, "string", 3])).toEqual([1, {key: 'value'}, 2, "string", 3]);
+ });
+
+ it('should work correctly for arrays of mixed elements and a key specified', function () {
+ expect(uniqueFilter([1, {key: 'value'}, 1, {key: 'value'}, 2, "string", 3], 'key')).toEqual([1, {key: 'value'}, 2, "string", 3]);
+ });
+
+ it('should return unmodified object if not array', function () {
+ expect(uniqueFilter('string', 'someKey')).toEqual('string');
+ });
+
+ it('should return unmodified array if provided key === false', function () {
+ var arrayToFilter = [
+ {key: 'value1'},
+ {key: 'value2'}
+ ];
+ expect(uniqueFilter(arrayToFilter, false)).toEqual(arrayToFilter);
+ });
+
+});
\ No newline at end of file diff --git a/js/vendor/angular-ui/modules/filters/unique/unique.js b/js/vendor/angular-ui/modules/filters/unique/unique.js new file mode 100644 index 000000000..382712297 --- /dev/null +++ b/js/vendor/angular-ui/modules/filters/unique/unique.js @@ -0,0 +1,45 @@ +/** + * Filters out all duplicate items from an array by checking the specified key + * @param [key] {string} the name of the attribute of each object to compare for uniqueness + if the key is empty, the entire object will be compared + if the key === false then no filtering will be performed + * @return {array} + */ +angular.module('ui.filters').filter('unique', function () { + + return function (items, filterOn) { + + if (filterOn === false) { + return items; + } + + if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) { + var hashCheck = {}, newItems = []; + + var extractValueToCompare = function (item) { + if (angular.isObject(item) && angular.isString(filterOn)) { + return item[filterOn]; + } else { + return item; + } + }; + + angular.forEach(items, function (item) { + var valueToCheck, isDuplicate = false; + + for (var i = 0; i < newItems.length; i++) { + if (angular.equals(extractValueToCompare(newItems[i]), extractValueToCompare(item))) { + isDuplicate = true; + break; + } + } + if (!isDuplicate) { + newItems.push(item); + } + + }); + items = newItems; + } + return items; + }; +}); |