summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/directives/prevent-double-click/prevent-double-click.ts
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-ui/src/app/directives/prevent-double-click/prevent-double-click.ts')
-rw-r--r--catalog-ui/src/app/directives/prevent-double-click/prevent-double-click.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/catalog-ui/src/app/directives/prevent-double-click/prevent-double-click.ts b/catalog-ui/src/app/directives/prevent-double-click/prevent-double-click.ts
new file mode 100644
index 0000000000..fff25c4d9c
--- /dev/null
+++ b/catalog-ui/src/app/directives/prevent-double-click/prevent-double-click.ts
@@ -0,0 +1,41 @@
+/**
+ * Created by ob0695 on 5/15/2018.
+ */
+'use strict';
+
+export class PreventDoubleClickDirective implements ng.IDirective {
+
+ constructor(private $timeout:ng.ITimeoutService) {
+ }
+
+ restrict:'A';
+
+ link = (scope, elem) => {
+
+ let delay = 600;
+ let disabled = false;
+
+ scope.onClick = (evt) => {
+ if (disabled) {
+ evt.preventDefault();
+ evt.stopImmediatePropagation();
+ } else {
+ disabled = true;
+ this.$timeout(function () {
+ disabled = false;
+ }, delay, false);
+ }
+ }
+
+ scope.$on('$destroy', function () {
+ elem.off('click', scope.onClick);
+ });
+ elem.on('click', scope.onClick);
+ };
+
+ public static factory = ($timeout:ng.ITimeoutService) => {
+ return new PreventDoubleClickDirective($timeout);
+ }
+}
+
+PreventDoubleClickDirective.factory.$inject = ['$timeout']; \ No newline at end of file