Local variables are one of the things CoffeeScript doesn't compile to modern JavaScript automatically: it uses `var` instead of `const` or `let`. Besides, using `$this = $(this)` is usually done to reference the current object in another function where the current object is a different one. Here we were using it with no clear purpose.
26 lines
673 B
CoffeeScript
26 lines
673 B
CoffeeScript
"use strict"
|
|
|
|
App.Managers =
|
|
|
|
generatePassword: ->
|
|
possible_chars = "aAbcdeEfghiJkmnpqrstuUvwxyz23456789"
|
|
|
|
chars = Array.apply(null, length: 12).map ->
|
|
i = Math.floor(Math.random() * possible_chars.length)
|
|
possible_chars.charAt(i)
|
|
|
|
chars.join("")
|
|
|
|
togglePassword: (type) ->
|
|
$("#user_password").prop "type", type
|
|
|
|
initialize: ->
|
|
$(".generate-random-value").on "click", ->
|
|
$("#user_password").val(App.Managers.generatePassword())
|
|
|
|
$(".show-password").on "click", ->
|
|
if $("#user_password").is("input[type='password']")
|
|
App.Managers.togglePassword("text")
|
|
else
|
|
App.Managers.togglePassword("password")
|