Skip to content

Commit bc68b3c

Browse files
author
OpenShift Bot
committed
Merge pull request #7129 from rhamilto/clipboardjs
Merged by openshift-bot
2 parents 20e8871 + 547408b commit bc68b3c

File tree

7 files changed

+34
-21
lines changed

7 files changed

+34
-21
lines changed

.jshintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"moment": false,
3131
"Messenger" : false,
3232
"URI": false,
33-
"ZeroClipboard": false,
33+
"Clipboard": false,
3434
"$": false,
3535
"_" : false,
3636
"URITemplate": false

Gruntfile.js

-7
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,6 @@ module.exports = function (grunt) {
431431
src: 'fonts/*',
432432
dest: '<%= yeoman.dist %>/styles'
433433
},
434-
{
435-
expand: true,
436-
cwd: 'bower_components/zeroclipboard/dist',
437-
src: 'ZeroClipboard.swf',
438-
dest: '<%= yeoman.dist %>/scripts'
439-
},
440-
441434
// Copy separate components
442435
{
443436
expand: true,

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ For more details on the expected scope arguments, see the source under [app/scri
127127
* toggle (attribute) - intended for Bootstrap's data-toggle=tooltip and data-toggle=popover, will automatically initialize any tooltips and popovers
128128
* alerts (element) - renders a set of alerts according to the [patternfly style](https://www.patternfly.org/widgets/#alerts)
129129
* relative-timestamp (element) - renders a relative timestamp (ex: '5 minutes ago') based on the current time, auto-updating every 30 seconds
130-
* copy-to-clipboard (element) - creates a copy to clipboard button using ZeroClipboard
130+
* copy-to-clipboard (element) - creates a copy to clipboard button using clipboard.js
131131
* back (attribute) - when the element is clicked a simulated browser back button event occurs (calls history.back)
132132
* select-on-focus (attribute) - when the element is focused, all text within it will be selected
133133
* tile-click (attribute or class) - for use with the `.tile` class, when anything on the tile is clicked, a simulated click to the `a.tile-target` link will be fired. Recommended use is by adding the `.tile-click` class to get the correct styles on hover.

app/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
<script src="bower_components/sifter/sifter.js"></script>
8181
<script src="bower_components/microplugin/src/microplugin.js"></script>
8282
<script src="bower_components/selectize/dist/js/selectize.js"></script>
83-
<script src="bower_components/zeroclipboard/dist/ZeroClipboard.js"></script>
8483
<script src="bower_components/messenger/build/js/messenger.js"></script>
8584
<script src="bower_components/messenger/build/js/messenger-theme-flat.js"></script>
8685
<script src="bower_components/kubernetes-label-selector/labelSelector.js"></script>
@@ -98,6 +97,7 @@
9897
<script src="bower_components/ace-builds/src-min-noconflict/theme-eclipse.js"></script>
9998
<script src="bower_components/angular-ui-ace/ui-ace.js"></script>
10099
<script src="bower_components/yamljs/bin/yaml.js"></script>
100+
<script src="bower_components/clipboard/dist/clipboard.js"></script>
101101
<!-- endbower -->
102102
<!-- endbuild -->
103103

app/scripts/directives/util.js

+26-7
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,33 @@ angular.module('openshiftConsole')
7878
clipboardText: "="
7979
},
8080
templateUrl: 'views/directives/_copy-to-clipboard.html',
81+
controller: function($scope) {
82+
$scope.id = _.uniqueId('clipboardJs');
83+
},
8184
link: function($scope, element) {
82-
if (ZeroClipboard.isFlashUnusable()) {
83-
$(element).hide();
84-
}
85-
else {
86-
new ZeroClipboard( $('button', element) );
87-
$("#global-zeroclipboard-html-bridge").tooltip({title: "Copy to clipboard", placement: 'bottom'});
88-
}
85+
var node = $('button', element);
86+
var clipboard = new Clipboard( node.get(0) );
87+
clipboard.on('success', function (e) {
88+
$(e.trigger)
89+
.attr('title', 'Copied!')
90+
.tooltip('fixTitle')
91+
.tooltip('show')
92+
.attr('title', 'Copy to clipboard')
93+
.tooltip('fixTitle');
94+
e.clearSelection();
95+
});
96+
clipboard.on('error', function (e) {
97+
var fallbackMsg = /Mac/i.test(navigator.userAgent) ? 'Press \u2318C to copy' : 'Press Ctrl-C to copy';
98+
$(e.trigger)
99+
.attr('title', fallbackMsg)
100+
.tooltip('fixTitle')
101+
.tooltip('show')
102+
.attr('title', 'Copy to clipboard')
103+
.tooltip('fixTitle');
104+
});
105+
element.on('$destroy', function() {
106+
clipboard.destroy();
107+
});
89108
}
90109
};
91110
})
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
<button data-clipboard-text="{{clipboardText}}" class="btn btn-default"><i class="fa fa-clipboard"/></button>
1+
<button data-clipboard-target="#{{id}}" data-toggle="tooltip" data-placement="top" title="Copy to clipboard" class="btn btn-default"><i class="fa fa-clipboard"/></button>
2+
<textarea id="{{id}}" class="sr-only">{{clipboardText}}</textarea>

bower.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"sifter": "0.3.4",
2525
"microplugin": "0.0.3",
2626
"selectize": "0.11.2",
27-
"zeroclipboard": "2.2.0",
2827
"messenger": "1.4.1",
2928
"kubernetes-label-selector": "0.0.18",
3029
"kubernetes-topology-graph": "0.0.21",
@@ -33,8 +32,9 @@
3332
"layout.attrs": "1.1.2",
3433
"bootstrap-hover-dropdown": "2.1.3",
3534
"angular-ui-ace": "0.2.3",
36-
"ace-builds": "1.2.2",
37-
"yamljs": "0.1.5"
35+
"ace-builds": "1.2.2",
36+
"yamljs": "0.1.5",
37+
"clipboard": "1.5.8"
3838
},
3939
"devDependencies": {
4040
"angular-mocks": "1.3.8",

0 commit comments

Comments
 (0)