Sha256: 2543fc6cc38fbc7fccb733b31072db77f72bb7d058e9cf7d7b10f0949b876b15

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

angular.module('EssayApp.directives').directive 'ngShowpassword', ['$timeout', '$compile', ($timeout, $compile) ->
  restrict: 'A'
  scope: true
  require: 'ngModel'
  link: (scope, element, attrs, ngModel) ->
    scope.TOGGLER_HTML = '<span class="show_button" ng-click="showPasswordToggle()"></span>'
    scope.ENABLER_HTML = '<input type="text"/>'

    scope.is_shown = false

    fn = ->
      element?.attr('class')

    scope.$watch fn, (val)->
      scope.enabler?.attr('class', val)

    scope.showPasswordToggle = ->
      scope.is_shown = !scope.is_shown
      if scope.is_shown
        element.hide()
        scope.enabler.val(element.val())
        scope.enabler.attr('class', element.attr('class'))
        scope.enabler.show().trigger('focusout')
        scope.toggler.attr('class', 'show_button show')
        scope.enabler[0].focus()
      else
        scope.enabler.hide()
        element.val(scope.enabler.val())
        ngModel.$setViewValue(scope.enabler.val())
        element.show().trigger('focusout')
        scope.toggler.attr('class', 'show_button hide')
        element[0].focus()
      return

    $timeout (->
      scope.toggler = $compile(scope.TOGGLER_HTML)(scope)
      _enabler = $compile(scope.ENABLER_HTML)(scope)
      scope.enabler = $compile(_enabler)(scope).hide()

      element.after(scope.toggler)
             .after(scope.enabler)
             .data('tailElements', scope.enabler)

      scope.enabler.on 'focusout', ->
        element.val(scope.enabler.val())
        ngModel.$setViewValue(scope.enabler.val())
        element.trigger('focusout')

      return
    ), 0, false

]

Version data entries

1 entries across 1 versions & 1 rubygems

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