A Pen by Ronnie Overby on CodePen.
Created
March 5, 2015 02:56
-
-
Save ronnieoverby/889cfd2fdaa38b15ff19 to your computer and use it in GitHub Desktop.
peek @ password angular directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <p> | |
| The password input below is using the "peek-password" directive. | |
| Focusing on the input will reveal the peek icon on the right side. | |
| Hovering the mouse over the peek icon will cause the password value to be visible. | |
| Try it! | |
| </p> | |
| <form ng-app="app" class="form-horizontal"> | |
| <div class="form-group"> | |
| <label for="inputEmail3" class="col-sm-2 control-label">Email</label> | |
| <div class="col-sm-10"> | |
| <input type="email" class="form-control" id="inputEmail3" placeholder="Email"> | |
| </div> | |
| </div> | |
| <div class="form-group"> | |
| <label for="inputPassword3" class="col-sm-2 control-label">Password</label> | |
| <div class="col-sm-10"> | |
| <!-- just add the peek-password attribute to any input! --> | |
| <input type="password" class="form-control" id="inputPassword3" placeholder="Password" value="SuperSecret@1234" peek-password> | |
| </div> | |
| </div> | |
| <div class="form-group"> | |
| <div class="col-sm-offset-2 col-sm-10"> | |
| <div class="checkbox"> | |
| <label> | |
| <input type="checkbox"> Remember me | |
| </label> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="form-group"> | |
| <div class="col-sm-offset-2 col-sm-10"> | |
| <button type="submit" class="btn btn-default">Sign in</button> | |
| </div> | |
| </div> | |
| </form> | |
| <p> | |
| The directive assumes that <a href="http://getbootstrap.com/css/#forms" target="bsdocs">the bootstrap CSS for forms</a> is present. | |
| </p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angular.module('app',[]) | |
| .directive('peekPassword', function() { | |
| return { | |
| restrict:'AC', | |
| link:function(scope,el,attr) { | |
| attr.$set('type','password'); | |
| el.parent().addClass('has-feedback'); | |
| var fbSpan = angular.element('<span style="pointer-events: auto;" class="ng-hide form-control-feedback glyphicon glyphicon-eye-open"></span>'); | |
| el.after(fbSpan); | |
| el.on('focus', function() { | |
| fbSpan.removeClass('ng-hide'); | |
| }); | |
| el.on('blur', function() { | |
| fbSpan.addClass('ng-hide'); | |
| }); | |
| fbSpan.on('mouseover',function(){ | |
| attr.$set('type','text'); | |
| }); | |
| fbSpan.on('mouseleave',function(){ | |
| attr.$set('type','password'); | |
| }); | |
| } | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment