diff options
author | brantje <brantje@gmail.com> | 2016-10-16 18:52:52 +0300 |
---|---|---|
committer | brantje <brantje@gmail.com> | 2016-10-16 19:08:59 +0300 |
commit | 1a4c1346cccc2b5930834fe87d9d434af8f408b0 (patch) | |
tree | 37a0bb4a28ca99fadde9bf04537dc3b3c2b94132 /js/app/directives | |
parent | 94d4f309487e066c55ed154dfe894303520cae80 (diff) |
Better searchbox behaviour.
Add a clear icon.
Diffstat (limited to 'js/app/directives')
-rw-r--r-- | js/app/directives/clearbutton2.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/js/app/directives/clearbutton2.js b/js/app/directives/clearbutton2.js new file mode 100644 index 00000000..17c97d6a --- /dev/null +++ b/js/app/directives/clearbutton2.js @@ -0,0 +1,37 @@ +(function () { + 'use strict'; + /** + * @ngdoc directive + * @name passmanApp.directive:clearBtn + * @description + * # clearBtn + */ + angular.module('passmanApp') + .directive('clearBtn', ['$parse', function ($parse) { + return { + link: function (scope, elm, attr) { + elm.wrap("<div style='position: relative'></div>"); + var btn = '<span id=' + Math.round(Math.random() * 1000000000) + ' class="searchclear ng-hide fa fa-times-circle-o"></span>'; + var angularBtn = angular.element(btn); + elm.after(angularBtn); + //clear the input + angularBtn.on("click", function () { + elm.val('').trigger("change"); + $parse(attr.ngModel).assign(scope, ''); + scope.$apply(); + }); + + // show clear btn on focus + elm.bind('focus keyup change paste propertychange', function () { + if (elm.val() && elm.val().length > 0) { + angularBtn.removeClass("ng-hide"); + } else { + angularBtn.addClass("ng-hide"); + } + }); + } + }; + }]); +}()); + + |