pull out some common functions. wrap coffee compiled stuff in a function call. escape string for regexp.

fix-space-nbsp
Dmitri Akatov 11 years ago
parent 07bc5cbd4a
commit 330417ed10

@ -25,7 +25,6 @@ module.exports = (grunt) ->
gruntfile:
files: src: ['Gruntfile.coffee']
coffee: src:
options: bare: true
files:
'<%= meta.target %>radians.js': [
'<%= meta.src %>**/*.coffee'

@ -1,3 +1,11 @@
# 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 /<img[^>]*>/g, ''
angular.module('radians.contenteditable', [])
.directive('contenteditable', ->
require: 'ngModel',
@ -22,11 +30,12 @@ angular.module('radians.contenteditable', [])
null
)
.filter('typeaheadHighlight', ->
# don't highlight anything!
(matchItem, query) -> matchItem
)
.filter('ignoreImgFilter', ->
noImg = (s) -> s.replace(/<img[^>]*>/, '')
# when matching query against the items, ignore all img tags
(items, query) ->
item for item in items \
when noImg(item).match(new RegExp(noImg(query), 'gi'))
when noImg(item).match(new RegExp(escapeRegexp(noImg(query)), 'gi'))
)