-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag-input.coffee
42 lines (38 loc) · 1.19 KB
/
tag-input.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
angular.module('tag-input', [])
.directive('tagInput', ['$templateCache','$parse', ($templateCache, $parse) ->
return {
restrict:'EA'
template: $templateCache.get('components/tag-input/tag-input.html')
transclude: 'element'
replace: true
priority: 10 #needed for ng-model work
scope:{}
controller: ($scope,$attrs)->
tags = $scope.tags = []
$scope.addTag = (tagText)->
$scope.$apply(->
tags.push(tagText)
serializedTags = tags.join(' ')
$parse($attrs.ngModel).assign $scope.$parent, serializedTags
)
link: (scope,element,attr,ctrl,transcludeFn)->
input_box = element.find('.input-box')
input_box.on('keypress', (event)->
if event.which == 32
scope.addTag(event.target.value)
input_box.val('')
event.preventDefault()
event.stopPropagation()
)
transcludeFn(scope.$parent,(clone,scope)->).insertAfter(element)
#transcludeFn().insertAfter(element)
}
])
.directive('itag',['$templateCache', ($templateCache) ->
return {
restrict:'EA'
template: $templateCache.get('components/tag-input/tag.html')
transclude:true
replace:true
}
])