diff --git a/lib/angular-contenteditable.js b/lib/angular-contenteditable.js index f6899eb..f79c352 100644 --- a/lib/angular-contenteditable.js +++ b/lib/angular-contenteditable.js @@ -1,14 +1,4 @@ (function() { - var escapeRegexp, noImg; - - escapeRegexp = function(str) { - return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); - }; - - noImg = function(str) { - return str.replace(/]*>/g, ''); - }; - angular.module('contenteditable', []).directive('contenteditable', function() { return { require: 'ngModel', @@ -41,22 +31,6 @@ }; } }; - }).filter('typeaheadHighlight', function() { - return function(matchItem, query) { - return matchItem; - }; - }).filter('ignoreImg', function() { - return function(items, query) { - var item, _i, _len, _results; - _results = []; - for (_i = 0, _len = items.length; _i < _len; _i++) { - item = items[_i]; - if (noImg(item).match(new RegExp(escapeRegexp(noImg(query)), 'gi'))) { - _results.push(item); - } - } - return _results; - }; }); }).call(this); diff --git a/src/contenteditable.coffee b/src/contenteditable.coffee index 84e79b0..6cf67c5 100644 --- a/src/contenteditable.coffee +++ b/src/contenteditable.coffee @@ -1,11 +1,3 @@ -# utility functions to escape a query -# @param str the string to escape -escapeRegexp = (str) -> str.replace /([.?*+^$[\]\\(){}|-])/g, "\\$1" - -# removes all img tags -# @param str a string possibly containing img tags -noImg = (str) -> str.replace /]*>/g, '' - angular.module('contenteditable', []) .directive('contenteditable', -> require: 'ngModel', @@ -34,13 +26,3 @@ angular.module('contenteditable', []) sel.removeAllRanges() sel.addRange(range) ) -.filter('typeaheadHighlight', -> - # don't highlight anything! - (matchItem, query) -> matchItem -) -.filter('ignoreImg', -> - # when matching query against the items, ignore all img tags - (items, query) -> - item for item in items \ - when noImg(item).match(new RegExp(escapeRegexp(noImg(query)), 'gi')) -) diff --git a/test/fixtures/typeahead1.html b/test/fixtures/typeahead1.html index 718854a..04e08e6 100644 --- a/test/fixtures/typeahead1.html +++ b/test/fixtures/typeahead1.html @@ -1,5 +1,5 @@ - + @@ -9,19 +9,18 @@ -
+
Model: {{selected| json}}
-
diff --git a/test/fixtures/typeahead2.html b/test/fixtures/typeahead2.html index cdff979..1e729f3 100644 --- a/test/fixtures/typeahead2.html +++ b/test/fixtures/typeahead2.html @@ -1,5 +1,5 @@ - + @@ -9,8 +9,8 @@ +.filter('ignoreImg', function(){ + var escapeRegexp = function(str) { + return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1") + } + var noImg = function (str) { + return str.replace(/]*>/g, '') + } + return function(items, query) { + var ret = [] + items.forEach(function(item){ + if (noImg(item).match(new RegExp(escapeRegexp(noImg(query)), 'gi'))) + ret.push(item) + }) + return ret + } +}) +// override typeahead's Highlight filter - don't highlight anything +.filter('typeaheadHighlight', function() { + return function(matchItem, query){return matchItem} +}) + -
+
Model: {{ selected | json }}
diff --git a/test/fixtures/typeahead3.html b/test/fixtures/typeahead3.html index a73a0c3..2c4e3bf 100644 --- a/test/fixtures/typeahead3.html +++ b/test/fixtures/typeahead3.html @@ -1,5 +1,5 @@ - + @@ -9,8 +9,8 @@ -
+
Model: {{ selected | json }}