(function () { 'use strict'; angular.module('song-overdubbers', ['artist-popover']) .directive('songOverdubbers', function () { return { transclude: true, restrict: 'E', template: '
\ {{firstMsg}}', link: function(scope, element, attr) { var max = attr.max; scope.width=attr.width || '21px'; scope.height=attr.height || '21px'; scope.firstMsg= attr.type == 'contest' ? 'Be the first to join this contest!' : 'Be the first to overdub this song'; var toWatch = attr.type == 'contest' ? 'song.participants' : 'song.overdubbers'; scope.$watch(toWatch, function (o) { if (o) { if (o.length < max) { scope.showMore=false; scope.song.shownOverdubbers=o; scope.showOverdubbers=true; } if (o.length == max) { scope.song.shownOverdubbers = o.slice(0, max); scope.showOverdubbers=true; } if (o.length > max) { scope.allOverdubbers = o; scope.song.shownOverdubbers = o.slice(0, max-1); scope.xtra = scope.allOverdubbers.length - scope.song.shownOverdubbers.length + '+'; scope.showMore = true; scope.showOverdubbers=true; } if (o.length==0) { scope.showOverdubbers=false; } } }) } } }) }());