summaryrefslogtreecommitdiffstats
path: root/js/vendor/angular-ui/modules/filters/highlight
diff options
context:
space:
mode:
Diffstat (limited to 'js/vendor/angular-ui/modules/filters/highlight')
-rw-r--r--js/vendor/angular-ui/modules/filters/highlight/highlight.js21
-rw-r--r--js/vendor/angular-ui/modules/filters/highlight/highlight.less5
-rw-r--r--js/vendor/angular-ui/modules/filters/highlight/test/highlightSpec.js48
3 files changed, 74 insertions, 0 deletions
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