forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
180 lines (176 loc) · 4.95 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
'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(IS_IOS) {
return {
restrict: 'E',
scope: {
clipboardText: "="
},
templateUrl: 'views/directives/_copy-to-clipboard.html',
controller: function($scope) {
$scope.id = _.uniqueId('clipboardJs');
},
link: function($scope, element) {
if (IS_IOS) {
$scope.hidden = true;
return;
}
var node = $('button', element);
var clipboard = new Clipboard( node.get(0) );
clipboard.on('success', function (e) {
$(e.trigger)
.attr('title', 'Copied!')
.tooltip('fixTitle')
.tooltip('show')
.attr('title', 'Copy to clipboard')
.tooltip('fixTitle');
e.clearSelection();
});
clipboard.on('error', function (e) {
var fallbackMsg = /Mac/i.test(navigator.userAgent) ? 'Press \u2318C to copy' : 'Press Ctrl-C to copy';
$(e.trigger)
.attr('title', fallbackMsg)
.tooltip('fixTitle')
.tooltip('show')
.attr('title', 'Copy to clipboard')
.tooltip('fixTitle');
});
element.on('$destroy', function() {
clipboard.destroy();
});
}
};
})
.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);
});
}
};
}).directive('onEnter', function(){
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13 && !scope.form.$invalid) {
scope.$apply(function (){
scope.$eval(attrs.onEnter);
});
event.preventDefault();
}
});
};
});