forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
145 lines (142 loc) · 3.87 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
'use strict';
angular.module('openshiftConsole')
// The HTML5 `autofocus` attribute does not work reliably with Angular,
// so define our own directive
.directive('takeFocus', function($timeout) {
return {
restrict: 'A',
link: function(scope, element) {
// Add a delay to allow other asynchronous components to load.
$timeout(function() {
$(element).focus();
}, 300);
}
};
})
.directive('selectOnFocus', function() {
return {
restrict: 'A',
link: function($scope, element) {
$(element).focus(function () {
$(this).select();
});
}
};
})
.directive('focusWhen', function($timeout) {
return {
restrict: 'A',
scope: {
trigger: '@focusWhen'
},
link: function(scope, element) {
scope.$watch('trigger', function(value) {
if (value) {
$timeout(function() {
$(element).focus();
});
}
});
}
};
})
.directive('tileClick', function() {
return {
restrict: 'AC',
link: function($scope, element) {
$(element).click(function (evt) {
var t = $(evt.target);
if (t && t.is('a')){
return;
}
$('a.tile-target', element).trigger("click");
});
}
};
})
.directive('clickToReveal', function() {
return {
restrict: 'A',
transclude: true,
scope: {
linkText: "@"
},
templateUrl: 'views/directives/_click-to-reveal.html',
link: function($scope, element) {
$('.reveal-contents-link', element).click(function () {
$(this).hide();
$('.reveal-contents', element).show();
});
}
};
})
.directive('copyToClipboardButton', function() {
return {
restrict: 'E',
scope: {
clipboardText: "="
},
templateUrl: 'views/directives/_copy-to-clipboard.html',
link: function($scope, element) {
if (ZeroClipboard.isFlashUnusable()) {
$(element).hide();
}
else {
new ZeroClipboard( $('button', element) );
$("#global-zeroclipboard-html-bridge").tooltip({title: "Copy to clipboard", placement: 'bottom'});
}
}
};
})
.directive('shortId', function() {
return {
restrict:'E',
scope: {
id: '@'
},
template: '<code class="short-id" title="{{id}}">{{id.substring(0, 6)}}</code>'
};
})
.directive('customIcon', function() {
return {
restrict:'E',
scope: {
resource: '=',
kind: '@',
tag: '=?'
},
controller: function($scope, $filter) {
if ($scope.tag) {
$scope.icon = $filter('imageStreamTagAnnotation')($scope.resource, "icon", $scope.tag);
} else {
$scope.icon = $filter('annotation')($scope.resource, "icon");
}
$scope.isDataIcon = $scope.icon && ($scope.icon.indexOf("data:") === 0);
if (!$scope.isDataIcon) {
// The icon class filter will at worst return the default icon for the given kind
if ($scope.tag) {
$scope.icon = $filter('imageStreamTagIconClass')($scope.resource, $scope.tag);
} else {
$scope.icon = $filter('iconClass')($scope.resource, $scope.kind);
}
}
},
templateUrl: 'views/directives/_custom-icon.html'
};
})
.directive('bottomOfWindow', function() {
return {
restrict:'A',
link: function(scope, element) {
function resized() {
var height = $(window).height() - element[0].getBoundingClientRect().top;
element.css('height', (height - 10) + "px");
}
$(window).on("resize", resized);
resized();
element.on("$destroy", function() {
$(window).off("resize", resized);
});
}
};
});