Sha256: 32196bb3434ad81b0b0e56ad3fe28d827acde736be78342dff1af79cd53dc536

Contents?: true

Size: 922 Bytes

Versions: 1

Compression:

Stored size: 922 Bytes

Contents

angular.module('EssayApp.directives').directive "uncheckable", ['$timeout', ($timeout) ->
  restrict: 'A'
  scope: true
  require: "?ngModel"
  link: (scope, element, attrs, ngModel) ->
    fn = () ->
      ngModel.$modelValue

    uncheck = (e)->
      $this = $(e.target)
      if ngModel?
        ngModel.$setViewValue(undefined)
      if $this.closest('span').hasClass('checked')
        $timeout( ->
            $this.closest('span').toggleClass('checked')
            return
          , 10)
        return false

    if attrs.ngModel? and (attrs.type is 'radio')
      scope.$watch attrs.ngModel, (v1, v2)->
        if attrs.value? && v1 is attrs.value
          element.off('click.uncheckable')
                 .on 'click.uncheckable', (e)-> uncheck(e)
        else
          element.off 'click.uncheckable'
    else
      element.off('click.uncheckable')
             .on 'click.uncheckable', (e)-> uncheck(e)

]

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_cms-0.1.5 app/assets/javascripts/app/directives/uncheckable.js.coffee