choosemany.js

angular.module('homepage').
directive('choosemany', function() {
  return {
    link: choosemanyLinker,
    restrict: 'A',
    replace: false
  }

  function choosemanyLinker(scope, element, attribute) {
    var groupname = attribute.choosemany;
    var parentname = attribute.namespace && typeof attribute.namespace == 'string' && attribute.namespace.length > 0 
                      ? '.' + attribute.namespace + ' ' : '';
    var query = parentname + '[choosemany=' + groupname + ']';
    element.bind('click', function() {
      if(this.classList.contains('chosen')) {
        this.classList.remove('chosen');
      }
      else {
        this.classList.add('chosen');
      }
    })
  }
});